Skip to content

Add TrueFoundryAgentStore for agents - #560

Merged
bhaveshpatel640 merged 15 commits into
mainfrom
AGE-2064
Sep 3, 2026
Merged

Add TrueFoundryAgentStore for agents#560
bhaveshpatel640 merged 15 commits into
mainfrom
AGE-2064

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Wire agent create/update/delete to ServiceFoundry in TrueFoundry mode via TrueFoundryAgentStore (SF-first, remote id in external_id). Standalone stays DB-only.

Linear: AGE-2064

Changes

  • TrueFoundryAgentStore + putRemoteAgent / deleteRemoteAgent / toPutRemoteAgentPayload
  • Shared SF client; resolveAgentStore (same pattern as models/MCP)
  • Unit tests; patch changeset; map* / to* convention in src/truefoundry/AGENTS.md

How was this tested?

  • Unit: tests/unit/truefoundry/TrueFoundryAgentStore.test.ts (create/update/delete + failure paths)
  • Related router/deps tests updated for resolveAgentStore
  • tsc --noEmit for @truefoundry/trueforge

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 (N/A — no new env; AGENTS.md mapper convention only)

Note

Medium Risk
Agent CRUD now coordinates local Postgres with ServiceFoundry; partial failures rely on cleanup/restore logic, though standalone mode is unchanged.

Overview
In TrueFoundry mode, agent create/update/delete now goes through TrueFoundryAgentStore, which keeps the local DB as source of truth but mirrors changes to ServiceFoundry (PUT/DELETE on /internal/tfg/agents) and persists the returned agentId in external_id. Create/update use transactional advisory locks and rollback paths when remote or local writes fail.

Wiring matches models/MCP: a shared TrueFoundryServiceFoundryServerClient (with separate 10s default vs 3s agent CRUD timeouts) and per-request resolveAgentStore so HTTP handlers use the token-bound decorator while the scheduler stays on DB-only persistence.

listAgents now accepts an optional external_ids filter (store contract + Postgres/SQLite). Agent create rejects reserved names tfg and trueforge, and AgentExternalIdConflictError maps to 409 alongside name conflicts.

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

@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8060262

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 marked this pull request as draft September 2, 2026 19:22
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 2, 2026 19:52
@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 2, 2026 19:52
Base automatically changed from AGE-2083 to main September 3, 2026 05:50
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 3, 2026 06:06
@bhaveshpatel640
bhaveshpatel640 marked this pull request as draft September 3, 2026 06:06
@bhaveshpatel640 bhaveshpatel640 changed the title Add TrueFoundryAgentStore for SF remote agent sync Add TrueFoundryAgentStore for agents Sep 3, 2026
@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review September 3, 2026 08:33
Comment thread packages/trueforge/src/apis/agents.ts
Comment thread docs/openapi.json Outdated
cursor[bot]

This comment was marked as outdated.

Comment thread packages/trueforge/src/truefoundry/toPutRemoteAgentPayload.ts Outdated
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts Outdated
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts Outdated
Comment thread packages/trueforge/src/db/postgres/agent-store/PostgresAgentStore.ts Outdated
Comment thread packages/trueforge/src/truefoundry/TrueFoundryServiceFoundryServerClient.ts Outdated
Comment thread packages/trueforge/src/truefoundry/TrueFoundryServiceFoundryServerClient.ts Outdated
Comment thread packages/trueforge/src/app.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
@bhaveshpatel640
bhaveshpatel640 force-pushed the AGE-2064 branch 2 times, most recently from f85a757 to ac37e94 Compare September 3, 2026 17:09
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts

@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 1 potential issue.

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 8060262. Configure here.

Comment thread packages/trueforge/src/truefoundry/TrueFoundryAgentStore.ts
@bhaveshpatel640
bhaveshpatel640 merged commit 38abb11 into main Sep 3, 2026
9 checks passed
@bhaveshpatel640
bhaveshpatel640 deleted the AGE-2064 branch September 3, 2026 18:00
return row === undefined ? undefined : toRecord(row);
}

withTransaction<T>(fn: (transaction: Transaction<Database>) => Promise<T>): Promise<T> {

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.

Why do we need this? Why can't we take db as an argument in the TrueFoundryAgentStore Constructor?


async createAgent(input: CreateAgentInput, transaction?: TTransaction): Promise<AgentRecord> {
// Lets the DB unique constraint pick one winner for this tenant ID and name.
// Prevents concurrent requests from both creating the same remote agent.

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.

This is only true if transaction is present. I do not see any code validating that. The type allows undefined.

return this.#inner.updateAgent(input, transaction);
}

return this.#withUpdateLock(input, transaction, async txn => {

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.

Please ensure we validate that the transaction is actually present here and is not undefined or absent.

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