Skip to content

Tighten NameSchema to hyphen-only 2–64 and migrate legacy ./_ names - #536

Open
bhaveshpatel640 wants to merge 3 commits into
mainfrom
AGE-2065
Open

Tighten NameSchema to hyphen-only 2–64 and migrate legacy ./_ names#536
bhaveshpatel640 wants to merge 3 commits into
mainfrom
AGE-2065

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Align TrueForge shared NameSchema (ResourceName) with ServiceFoundry agent-identity / RemoteAgentV2: hyphen-only, 2–64 (^[a-z][a-z0-9-]{0,62}[a-z0-9]$).

One schema for local resource names (agents, skills, MCP servers, models, schedules). Postgres + SQLite migration rewrites legacy local names that used . / _.

Closes AGE-2065

Why

  • TF agent names must match SVC PUT /internal/tfg/agents / agent-identity (source=trueforge).
  • Older TF ResourceName allowed . / _; that breaks SVC sync and diverges from RemoteAgentV2.
  • Prefer one shared NameSchema over a separate AgentNameSchema so standalone create/list/update stay consistent after migrate.

Changes

Schema

  • Tighten NameSchema in packages/trueforge/src/schemas/common.ts to hyphen-only 2–64.
  • OpenAPI name remains ResourceName (CI regenerates OpenAPI + SDK; no hand-edits).
  • Document TFY vs standalone vs migration behavior on NameSchema.

API / validation impact

  • Create/update APIs that use NameSchema reject names with . or _ (e.g. my.agent, my_agent).
  • Reserved agent names (tfg, trueforge) unchanged.
  • AgentSpec refs (model / skills / MCP) stay plain strings — FQNs and long SVC names still allowed in manifests.

TrueFoundry mode

  • Agents: created/synced under NameSchema (must satisfy SVC identity).
  • Skills / MCP / models: fetched from SVC; not NameSchema-checked on those paths (FQNs / longer SVC MCP names OK).
  • Schedules: still local; use NameSchema.

Standalone mode

  • Agents, skills, MCP, models, schedules are created locally under the same NameSchema.

Migration (20260911_000001_name_hyphen_only)

  • Shared planner: planHyphenOnlyRenames.ts
  • Shared apply: applyNameHyphenOnlyMigration.ts
  • Wired for Postgres and SQLite
  • Rewrites only strings matching legacy NameSchema that fail the new rule (contain . / _)
  • Replace . / _-, always append -<4 hex>; truncate to ≤ 64
  • Leaves alone: already hyphen-only names, FQNs, other non-matching strings
  • Updates:
    • agent.name + denorm session.agent_name / schedule.agent_name
    • skill.name
    • mcp_server.name (+ manifest.name)
    • model_provider.name (+ nested models[].name, custom manifest.name)
    • schedule.name
    • AgentSpec refs on agent/session manifests
  • Irreversible (down throws); originals not retained; no occupancy / collision check on suffix

Tests

  • nameSchema.test.ts — accept/reject matrix
  • planHyphenOnlyRenames.test.ts — rename + FQN skip + AgentSpec rewrite maps
  • agents.test.ts — API rejects my.agent / my_agent
  • trueFoundryNaming.test.ts — TFY runtime: agent name still NameSchema; skill FQN / long MCP / model FQN work on create/update, stores, mappers; OpenAPI MCP schemas may still be stricter than runtime (documented)

Release

  • Patch changeset for @truefoundry/trueforge
  • OpenAPI / @truefoundry/trueforge-sdk regenerate in CI after merge (do not hand-edit)

Out of scope / known skew

  • SVC TrueFoundryAgentManifest (3–32, no --) is not the TF ensure path; TF aligns to agent-identity (2–64).
  • TFY MCP list/get can return names longer than 64 / outside NameSchema; some OpenAPI MCP types still declare ResourceName — runtime path does not re-parse those schemas today.
  • Clients hardcoding old . / _ local names must switch to post-migration names.

How was this tested?

  • Unit: nameSchema, planHyphenOnlyRenames, trueFoundryNaming, agents API reject cases
  • Full package / root pnpm test (as needed before merge)
  • pnpm smoke / migrate against a DB that still has legacy . / _ names (recommended)
  • Manual: create agent with hyphen name; reject dotted name; TFY agent with skill FQN + model FQN in manifest

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

High Risk
Irreversible multi-table data migration renames user resources and embedded references; API validation breaks clients still using ./_ local names.

Overview
ResourceName / NameSchema now allows only lowercase letters, digits, and hyphens (2–64 chars), aligned with ServiceFoundry agent identity. Dotted and underscored local names are rejected on create/update; OpenAPI ResourceName pattern matches.

A one-time, irreversible Postgres/SQLite migration renames existing local rows whose names still used . or _: providers (including nested model names), skills, MCP servers, schedules, and agents, then fixes session / schedule agent_name and model / MCP / skill refs inside agent and session JSON. Renames hyphenate, append a short random suffix, and skip FQNs and names already compliant.

Tests cover schema rules, rename planning, SQLite migration integrity, agent API rejection, and TrueFoundry mode where agent names stay strict while manifest refs can remain FQNs or long SVC names.

Reviewed by Cursor Bugbot for commit 2d7604c. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ab5cf4c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@truefoundry/trueforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 2 times, most recently from a62baaa to 8b89256 Compare September 1, 2026 12:09
Comment thread packages/trueforge/src/db/planAgentNameHyphenRenames.ts Outdated
Comment thread packages/trueforge/src/db/planAgentNameHyphenRenames.ts Outdated
@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 1, 2026 13:07
@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 2 times, most recently from b442af5 to 1081bee Compare September 3, 2026 12:25
@bhaveshpatel640 bhaveshpatel640 changed the title Align TrueForge agent names to hyphen-only 2–64 char and migration to enforce hyphen-only naming convention Constrain agent names to hyphen-only 2–64 and migrate existing names with ./_ Sep 3, 2026
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 3, 2026 12:26
@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 3, 2026 12:27
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 3, 2026 13:45
@bhaveshpatel640 bhaveshpatel640 changed the title Constrain agent names to hyphen-only 2–64 and migrate existing names with ./_ Constrain agent names to hyphen-only 2–64 and migrate ./_ names Sep 3, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 2 times, most recently from b9f437a to 561a438 Compare September 10, 2026 10:35
cursor[bot]

This comment was marked as outdated.

@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 11, 2026 08:19
@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 2 times, most recently from 6f9428d to a964381 Compare September 11, 2026 09:03
@bhaveshpatel640 bhaveshpatel640 changed the title Constrain agent names to hyphen-only 2–64 and migrate ./_ names Tighten NameSchema to hyphen-only 2–64 and migrate legacy ./_ names Sep 11, 2026
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 11, 2026 09:03
cursor[bot]

This comment was marked as outdated.

@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 3 times, most recently from 8cd8b58 to ab9ec81 Compare September 11, 2026 09:21

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 83940f2. Configure here.

Comment thread .github/fern/openapi/openapi.json
Comment thread packages/trueforge/src/db/planHyphenOnlyRenames.ts
@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2065 branch 2 times, most recently from 5e580ff to 975885d Compare September 11, 2026 10:00
for (const row of providerRows.rows) {
const providerTo = planHyphenOnlyName(row.name) ?? row.name;
if (providerTo !== row.name) {
providerRenames.push({ tenant_id: row.tenant_id, from: row.name, to: providerTo });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this after 286 check.

@cursor

cursor Bot commented Sep 11, 2026

Copy link
Copy Markdown

Current version of PR was reviewed by /review-bugbot with additional instructions on Sep 11, 16:31 GMT+5:30. It flagged 1 finding.

Show 1 finding

1. Provider rename map without row update

packages/trueforge/src/db/applyNameHyphenOnlyMigration.ts:280 · Medium Severity

In the model-provider loop, a provider rename is appended to providerRenames before the manifest is parsed, but an unparseable manifest triggers continue and skips the UPDATE. Step 5 then rewrites agent and session specs to the planned new provider name while the model_provider row still holds the legacy name.

Bugbot on commit ab5cf4c is skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants