Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Dispatch schedule runs through the session and turn HTTP APIs. (#517)

Heer Ambavi4ced8efbdd77
diff --git a/.changeset/schedule-session-turn.md b/.changeset/schedule-session-turn.md
new file mode 100644
index 000000000..81f6ad57c
--- /dev/null
+++ b/.changeset/schedule-session-turn.md
@@ -0,0 +1,5 @@
+---
+"@truefoundry/trueforge": patch
+---
+
+Dispatch schedule runs through the session/turn API: get-or-create a session keyed by run id, then create a turn only when that session has none.
diff --git a/packages/trueforge/package.json b/packages/trueforge/package.json
index 78f0635b7..e6db4ebd2 100644
--- a/packages/trueforge/package.json
+++ b/packages/trueforge/package.json
@@ -42,8 +42,11 @@
"migrate": "NODE_OPTIONS='--conditions=trueforge-dev' STANDALONE=false tsx --env-file=.env src/db/postgres/migrate-cli.ts",
"openapi:write": "pnpm run build:gen && NODE_OPTIONS='--conditions=trueforge-dev' tsx --env-file=.env.test scripts/write-openapi.ts",
"pack:dry": "pnpm pack --dry-run",
- "predev:no-watch": "pnpm --filter @truefoundry/trueforge-core build:gen && pnpm run build:gen",
- "predev": "pnpm --filter @truefoundry/trueforge-core build:gen && pnpm run build:gen",
+ "predev:no-watch": "pnpm run sdk:build && pnpm --filter @truefoundry/trueforge-core build:gen && pnpm run build:gen",
+ "predev": "pnpm run sdk:build && pnpm --filter @truefoundry/trueforge-core build:gen && pnpm run build:gen",
+ "pretest": "pnpm run sdk:build",
+ "pretypecheck": "pnpm run sdk:build",
+ "sdk:build": "pnpm --filter @truefoundry/trueforge-sdk build",
"test:eventsub": "jest --config jest.eventsub.config.cjs",
"test:store:postgres": "jest --config jest.store.postgres.config.cjs",
"test:store:sqlite": "jest --config jest.store.sqlite.config.cjs",
@@ -62,6 +65,7 @@
"@hono/zod-openapi": "^1.6.1",
"@modelcontextprotocol/sdk": "^1.30.0",
"@truefoundry/trueforge-core": "workspace:*",
+ "@truefoundry/trueforge-sdk": "workspace:*",
"better-sqlite3": "^13.0.3",
"cron-parser": "^5.4.0",
"env-paths": "^4.0.0",
diff --git a/packages/trueforge/src/controller.ts b/packages/trueforge/src/controller.ts
index 443a4f2d7..159e7bc66 100644
--- a/packages/trueforge/src/controller.ts
+++ b/packages/trueforge/src/controller.ts
@@ -1,70 +1,47 @@
-/**
- * Controller entry point — the control loops as their own process.
- *
- * Distributed mode only. Server replicas run no loops, so this deployment is the sole
- * controller for the database. Loops assume no peer runs alongside them,
- * so it MUST have exactly one replica.
- *
- * In standalone mode the controller runs inside the server instead — one process owns
- * everything, and this entry point refuses to start.
- */
-import { extractErrorLogFields } from '@truefoundry/trueforge-core/core';
-
-let configuration: typeof import('./config').default;
-
-try {
- ({ default: configuration } = await import('./config'));
-} catch (error) {
- console.error(
- 'Failed to start controller: Failed to load configuration:',
- error instanceof Error ? error.message : error,
- );
- process.exit(1);
-}
-
+import { TrueForge } from '@truefoundry/trueforge-sdk';
+import type { Logger } from 'winston';
import { Controller } from './controller/Controller';
-import { createScheduleDispatchLoop, logTriggeredRun } from './controller/scheduleDispatch';
-import { createDb } from './db/postgres/client';
-import { PostgresScheduleStore } from './db/postgres/schedule-store/PostgresScheduleStore';
-import { createServerLogger } from './logger';
-import { PACKAGE_VERSION } from './packageVersion';
-
-try {
- const logger = createServerLogger({
- level: configuration.LOG_LEVEL,
- standalone: configuration.STANDALONE,
- version: PACKAGE_VERSION,
- });
+import { scheduleDispatchLoop } from './controller/scheduleDispatch';
+import type { IScheduleStore } from './db/scheduleStore';
+import type { WithTransaction } from './db/transaction';
- // Narrow through a const: the config union is keyed on STANDALONE, and only the
- // distributed variant carries the Postgres connection settings.
- const config = configuration;
- if (config.STANDALONE) {
- throw new Error(
- 'The controller process is for distributed mode only. ' +
- 'In standalone mode the server runs the control loops in-process.',
- );
- }
-
- const db = createDb({
- connectionString: config.DATABASE_URL,
- poolMax: config.DATABASE_POOL_MAX,
- statementTimeoutMs: config.POSTGRES_STATEMENT_TIMEOUT_MS,
- idleInTransactionSessionTimeoutMs: config.POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT_MS,
- });
- const controller = new Controller({
+/**
+ * The loops the controller runs.
+ */
+export function createController<TTransaction>(params: {
+ scheduleStore: IScheduleStore<TTransaction>;
+ withTransaction: WithTransaction<TTransaction>;
+ logger: Logger;
+ baseUrl: string;
+}): Controller {
+ const { scheduleStore, withTransaction, logger, baseUrl } = params;
+ return new Controller({
loops: [
- createScheduleDispatchLoop({
- scheduleStore: new PostgresScheduleStore(db),
- withTransaction: callback => db.transaction().execute(callback),
- onTriggered: logTriggeredRun(logger),
+ scheduleDispatchLoop({
+ scheduleStore,
+ client: new TrueForge({ baseUrl, auth: false }),
+ withTransaction,
logger,
}),
],
logger,
});
+}
- logger.info('TrueForge controller starting', { mode: 'distributed' });
+/**
+ * Runs the controller: starts the loops and drains them on SIGTERM/SIGINT.
+ */
+export function runController<TTransaction>(params: {
+ scheduleStore: IScheduleStore<TTransaction>;
+ withTransaction: WithTransaction<TTransaction>;
+ logger: Logger;
+ baseUrl: string;
+ gracefulTimeoutSeconds: number;
+ /** Releases what the caller opened for the loops, e.g. its database pool. */
+ onStopped?: () => Promise<void>;
+}): Controller {
+ const { logger, gracefulTimeoutSeconds, onStopped } = params;
+ const controller = createController(params);
controller.start();
let shuttingDown = false;
@@ -75,17 +52,14 @@ try {
shuttingDown = true;
logger.info(`Received ${signal}, stopping control loops`);
- // Start the deadline at the top of shutdown; unref so this timer alone cannot keep the process
- // alive. Passes only hold short transactions, so this should never elapse.
+ // Passes only hold short transactions, so the deadline should never elapse.
setTimeout(() => {
- logger.warn(`Controller drain timed out after ${String(configuration.GRACEFUL_TIMEOUT_SECONDS)}s, exiting`);
+ logger.warn(`Controller drain timed out after ${String(gracefulTimeoutSeconds)}s, exiting`);
process.exit(1);
- }, configuration.GRACEFUL_TIMEOUT_SECONDS * 1000).unref();
+ }, gracefulTimeoutSeconds * 1000).unref();
await controller.stop();
- await db.destroy().catch((error: unknown) => {
- logger.warn('Error closing the database pool during shutdown', extractErrorLogFields(error));
- });
+ await onStopped?.();
process.exit(0);
};
process.on('SIGTERM', signal => {
@@ -94,7 +68,6 @@ try {
process.on('SIGINT', signal => {
void shutdown(signal);
});
-} catch (error) {
- console.error('Failed to start controller:', error instanceof Error ? error.message : error);
- process.exit(1);
+
+ return controller;
}
diff --git a/packages/trueforge/src/controller/Controller.ts b/packages/trueforge/src/controller/Controller.ts
index ec89c7cc8..04b5de6bc 100644
--- a/packages/trueforge/src/controller/Controller.ts
+++ b/packages/trueforge/src/controller/Controller.ts
@@ -6,7 +6,7 @@
*
* The controller runs in exactly ONE process per database. In standalone mode that is
* the server itself; when `STANDALONE=false` it is the dedicated single-replica
- * process in `src/controller.ts`. Loops are written assuming this.
+ * process. Loops are written assuming this.
*/
import type { Logger } from 'winston';
diff --git a/packages/trueforge/src/controller/scheduleDispatch.ts b/packages/trueforge/src/controller/scheduleDispatch.ts
index 8b80daf9a..6b1160b62 100644
--- a/packages/trueforge/src/controller/scheduleDispatch.ts
+++ b/packages/trueforge/src/controller/scheduleDispatch.ts
@@ -1,3 +1,4 @@
+import type { TrueForge } from '@truefoundry/trueforge-sdk';
import type { Logger } from 'winston';
import {
cronRunName,
@@ -31,6 +32,34 @@ const SCHEDULE_DISPATCH_INTERVAL_MS = 60_000;
/** The loop's name. */
const SCHEDULE_DISPATCH_LOOP_NAME = 'schedule-dispatch';
+type ScheduleRunApiClient = Pick<TrueForge, 'sessions' | 'internal'>;
+
+/**
+ * Hands a due schedule run to the API:
+ * 1. Get or create a session keyed by `run.id`.
+ * 2. Create a non-streaming turn only when that session has no turns.
+ *
+ * This call is hence idempotent.
+ */
+function executeScheduledRun(client: ScheduleRunApiClient): (item: ScheduleDispatchItem) => Promise<void> {
+ return async ({ run, schedule }) => {
+ const { data: session } = await client.internal.sessions.getOrCreateByExternalId({
+ externalId: run.id,
+ agent: { name: schedule.agent_name },
+ });
+
+ const turns = await client.sessions.listTurns(session.id, { limit: 1 });
+ if (turns.data.length > 0) {
+ return;
+ }
+
+ await client.sessions.createTurn(session.id, {
+ input: [{ type: 'user.message', content: schedule.manifest.task }],
+ previousTurnId: 'none',
+ });
+ };
+}
+
/**
* Mark the current run with `status`, then add the schedule's next scheduled run
* if the schedule is still active and its cron still has a later trigger time.
@@ -113,7 +142,7 @@ async function finishScheduledRun<TTransaction>(params: {
*
* - **pause**: drops the pending run in its own transaction, and stops the advance.
* It never cancels a row that still exists: whatever pause did not delete is
- * executed (or recorded `missed`) so history has no unexplained gap.
+ * executed (and recorded `triggered` or `failed`) so history has no unexplained gap.
* If pause commits first, the row is gone and there is nothing to run.
* If dispatch commits first, the run triggers and pause deletes the pending row
* dispatch just added, so triggering stops from the next tick — at most one extra run.
@@ -202,41 +231,20 @@ export async function dispatchScheduledRuns<TTransaction>(params: {
return { dispatched, failed };
}
-/**
- * Stand-in until the run executor lands: records the hand-off and drops it.
- *
- * Called before the row is marked `triggered`; if nothing commits afterward the
- * same scheduled row will be offered again on the next pass.
- *
- * TODO(executor): replace with the real executor. Note it runs in the controller's
- * process, so the dedicated deployment will need everything a turn needs — model
- * provider credentials, MCP egress, sandbox access — not just database reach.
- */
-export function logTriggeredRun(logger: Logger): (item: ScheduleDispatchItem) => void | Promise<void> {
- return item => {
- logger.warn('Schedule run triggered but no executor is configured; run will not execute', {
- schedule_id: item.schedule.id,
- run_id: item.run.id,
- agent_name: item.schedule.agent_name,
- scheduled_for: item.run.scheduled_for,
- });
- };
-}
-
-export function createScheduleDispatchLoop<TTransaction>(params: {
+export function scheduleDispatchLoop<TTransaction>(params: {
scheduleStore: IScheduleStore<TTransaction>;
- onTriggered: (item: ScheduleDispatchItem) => void | Promise<void>;
+ client: ScheduleRunApiClient;
logger: Logger;
withTransaction: WithTransaction<TTransaction>;
}): ControlLoop {
- const { scheduleStore, withTransaction, onTriggered, logger } = params;
+ const { scheduleStore, client, withTransaction, logger } = params;
return {
name: SCHEDULE_DISPATCH_LOOP_NAME,
intervalMs: SCHEDULE_DISPATCH_INTERVAL_MS,
async tick(signal: AbortSignal): Promise<void> {
const result = await dispatchScheduledRuns({
store: scheduleStore,
- onTriggered,
+ onTriggered: executeScheduledRun(client),
logger,
withTransaction,
signal,
diff --git a/packages/trueforge/src/db/indexes.ts b/packages/trueforge/src/db/indexes.ts
new file mode 100644
index 000000000..1d546d39f
--- /dev/null
+++ b/packages/trueforge/src/db/indexes.ts
@@ -0,0 +1,2 @@
+/** Partial unique index on `session (tenant_id, external_id) WHERE external_id IS NOT NULL`. */
+export const SESSION_EXTERNAL_ID_UQ = 'session_external_id_uq';
diff --git a/packages/trueforge/src/db/postgres/migrations/20260831_000001_session_external_id.ts b/packages/trueforge/src/db/postgres/migrations/20260831_000001_session_external_id.ts
index 2ea3cbf57..9fccca8fa 100644
--- a/packages/trueforge/src/db/postgres/migrations/20260831_000001_session_external_id.ts
+++ b/packages/trueforge/src/db/postgres/migrations/20260831_000001_session_external_id.ts
@@ -1,4 +1,5 @@
import { sql, type Kysely } from 'kysely';
+import { SESSION_EXTERNAL_ID_UQ } from '../../indexes';
/**
* Optional session `external_id`, unique within a tenant when set.
@@ -8,7 +9,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
await db.schema.alterTable('session').addColumn('external_id', 'text').execute();
await sql`
- CREATE UNIQUE INDEX ${sql.raw('session_external_id_uq')}
+ CREATE UNIQUE INDEX ${sql.raw(SESSION_EXTERNAL_ID_UQ)}
ON session (tenant_id, external_id)
WHERE external_id IS NOT NULL
`.execute(db);
@@ -16,6 +17,6 @@ export async function up(db: Kysely<unknown>): Promise<void> {
export async function down(db: Kysely<unknown>): Promise<void> {
await sql`SET LOCAL lock_timeout = '5s'`.execute(db);
- await sql`DROP INDEX IF EXISTS ${sql.raw('session_external_id_uq')}`.execute(db);
+ await sql`DROP INDEX IF EXISTS ${sql.raw(SESSION_EXTERNAL_ID_UQ)}`.execute(db);
await db.schema.alterTable('session').dropColumn('external_id').execute();
}
diff --git a/packages/trueforge/src/db/postgres/session-store/queries/sessions.ts b/packages/trueforge/src/db/postgres/session-store/queries/sessions.ts
index 876e0d219..6daba7963 100644
--- a/packages/trueforge/src/db/postgres/session-store/queries/sessions.ts
+++ b/packages/trueforge/src/db/postgres/session-store/queries/sessions.ts
@@ -19,6 +19,7 @@ import {
SessionStoreInvariantError,
} from '@truefoundry/trueforge-core/agent-session/store/SessionStoreErrors';
import { sql, type Kysely } from 'kysely';
+import { SESSION_EXTERNAL_ID_UQ } from '../../../indexes';
import { sessionAgentFromColumns, sessionAgentToColumns } from '../../../sessionAgentColumns';
import { isPgConstraint, isUniqueViolation } from '../../client';
import { json } from '../../sqlExpressions';
@@ -107,7 +108,7 @@ export async function createSession(db: Kysely<Database>, input: CreateSessionIn
.execute();
} catch (error) {
if (isUniqueViolation(error)) {
- if (isPgConstraint(error, 'session_external_id_uq') && input.external_id) {
+ if (isPgConstraint(error, SESSION_EXTERNAL_ID_UQ) && input.external_id) {
throw new SessionExternalIdConflictError(input.external_id, { cause: error });
}
throw new SessionAlreadyExistsError(input.session_id, { cause: error });
diff --git a/packages/trueforge/src/db/sqlite/migrations/20260831_000001_session_external_id.ts b/packages/trueforge/src/db/sqlite/migrations/20260831_000001_session_external_id.ts
index 9eb5bed47..3ca8b59a9 100644
--- a/packages/trueforge/src/db/sqlite/migrations/20260831_000001_session_external_id.ts
+++ b/packages/trueforge/src/db/sqlite/migrations/20260831_000001_session_external_id.ts
@@ -1,4 +1,5 @@
import { type Kysely, sql } from 'kysely';
+import { SESSION_EXTERNAL_ID_UQ } from '../../indexes';
/**
* Optional session `external_id`, unique within a tenant when set.
@@ -8,7 +9,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
await db.transaction().execute(async trx => {
await sql`ALTER TABLE session ADD COLUMN external_id TEXT`.execute(trx);
await sql`
- CREATE UNIQUE INDEX ${sql.raw('session_external_id_uq')}
+ CREATE UNIQUE INDEX ${sql.raw(SESSION_EXTERNAL_ID_UQ)}
ON session (tenant_id, external_id)
WHERE external_id IS NOT NULL
`.execute(trx);
@@ -17,7 +18,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
export async function down(db: Kysely<unknown>): Promise<void> {
await db.transaction().execute(async trx => {
- await sql`DROP INDEX IF EXISTS ${sql.raw('session_external_id_uq')}`.execute(trx);
+ await sql`DROP INDEX IF EXISTS ${sql.raw(SESSION_EXTERNAL_ID_UQ)}`.execute(trx);
await sql`ALTER TABLE session DROP COLUMN external_id`.execute(trx);
});
}
diff --git a/packages/trueforge/src/main.ts b/packages/trueforge/src/main.ts
index 047d0f7a1..5acd9f54a 100644
--- a/packages/trueforge/src/main.ts
+++ b/packages/trueforge/src/main.ts
@@ -51,8 +51,7 @@ import { ModelCatalog } from './catalog/ModelCatalog';
import { SandboxCatalog } from './catalog/SandboxCatalog';
import { SkillCatalog } from './catalog/SkillCatalog';
import { type DistributedServerConfiguration } from './config';
-import { Controller } from './controller/Controller';
-import { createScheduleDispatchLoop, logTriggeredRun } from './controller/scheduleDispatch';
+import { createController } from './controller';
import type { IAgentStore } from './db/agentStore';
import type { IMcpServerStore } from './db/mcpServerStore';
import type { IModelProviderStore } from './db/modelProviderStore';
@@ -233,16 +232,11 @@ async function createServerRuntime<TTransaction>(persistence: ServerPersistence<
// Standalone is one process, so it owns the control loops too.
const controller = configuration.STANDALONE
- ? new Controller({
- loops: [
- createScheduleDispatchLoop({
- scheduleStore,
- withTransaction,
- onTriggered: logTriggeredRun(logger),
- logger,
- }),
- ],
+ ? createController({
+ scheduleStore,
+ withTransaction,
logger,
+ baseUrl: `http://localhost:${String(configuration.PORT)}`,
})
: undefined;
@@ -269,8 +263,6 @@ async function createServerRuntime<TTransaction>(persistence: ServerPersistence<
oidcClient,
});
- controller?.start();
-
return { activeTurns, app, controller, destroyDb, redis, requestReplyRouter };
}
@@ -353,6 +345,8 @@ try {
const server = serve({ fetch: app.fetch, port: configuration.PORT, hostname: configuration.HOST }, info => {
logger.info(`Agent server listening on http://${configuration.HOST}:${String(info.port)} (docs at /api/v1/docs)`);
+ // The controller calls this server over HTTP.
+ controller?.start();
});
server.on('error', (error: unknown) => {
diff --git a/packages/trueforge/tests/unit/controller/scheduleDispatch.test.ts b/packages/trueforge/tests/unit/controller/scheduleDispatch.test.ts
new file mode 100644
index 000000000..be9ccd5c2
--- /dev/null
+++ b/packages/trueforge/tests/unit/controller/scheduleDispatch.test.ts
@@ -0,0 +1,122 @@
+import { scheduleDispatchLoop } from '../../../src/controller/scheduleDispatch';
+import type { ScheduleDispatchItem, ScheduleRunRecord } from '../../../src/db/scheduleStore';
+import { ScheduleManifestSchema } from '../../../src/schemas/schedule';
+
+function item(): ScheduleDispatchItem {
+ return {
+ run: {
+ id: 'run-1',
+ tenant_id: 'default',
+ schedule_id: 'sched-1',
+ name: 'sched-1',
+ scheduled_for: '2026-08-31T00:00:00.000Z',
+ status: 'scheduled',
+ triggered_by: 'tester',
+ triggered_at: null,
+ created_at: '2026-08-31T00:00:00.000Z',
+ updated_at: '2026-08-31T00:00:00.000Z',
+ },
+ schedule: {
+ id: 'sched-1',
+ tenant_id: 'default',
+ agent_name: 'reporter',
+ name: 'daily',
+ manifest: ScheduleManifestSchema.parse({
+ task: 'Write the report',
+ cron: '0 * * * *',
+ timezone: 'UTC',
+ status: 'active',
+ }),
+ status: 'active',
+ created_by: 'tester',
+ created_at: '2026-08-31T00:00:00.000Z',
+ updated_at: '2026-08-31T00:00:00.000Z',
+ },
+ };
+}
+
+function fakeLogger() {
+ return { error: jest.fn(), debug: jest.fn(), info: jest.fn(), warn: jest.fn() };
+}
+
+function fakeStore(dispatchItem: ScheduleDispatchItem) {
+ return {
+ listScheduledRuns: jest.fn().mockResolvedValue([dispatchItem.run]),
+ getSchedule: jest.fn().mockResolvedValue(dispatchItem.schedule),
+ getScheduleForUpdate: jest.fn().mockResolvedValue(dispatchItem.schedule),
+ updateRunStatus: jest.fn().mockResolvedValue(dispatchItem.run satisfies ScheduleRunRecord),
+ createRun: jest.fn().mockResolvedValue(undefined),
+ };
+}
+
+/**
+ * Mirrors how the SDK splits these calls: get-or-create is only on `internal.sessions`,
+ * turns only on the public `sessions`. Giving each client just its own methods means a call
+ * routed to the wrong one throws instead of silently resolving.
+ */
+async function tickDispatch(mocks: {
+ getOrCreateByExternalId: jest.Mock;
+ listTurns: jest.Mock;
+ createTurn: jest.Mock;
+}) {
+ const dispatchItem = item();
+ const store = fakeStore(dispatchItem);
+ const logger = fakeLogger();
+ const loop = scheduleDispatchLoop({
+ scheduleStore: store as never,
+ client: {
+ sessions: { listTurns: mocks.listTurns, createTurn: mocks.createTurn },
+ internal: { sessions: { getOrCreateByExternalId: mocks.getOrCreateByExternalId } },
+ } as never,
+ logger: logger as never,
+ withTransaction: async callback => callback({} as never),
+ });
+ await loop.tick(new AbortController().signal);
+ return { store, logger };
+}
+
+describe('scheduleDispatchLoop', () => {
+ it('creates a session and turn through the API client', async () => {
+ const getOrCreateByExternalId = jest.fn().mockResolvedValue({ data: { id: 'sess-1' } });
+ const listTurns = jest.fn().mockResolvedValue({ data: [] });
+ const createTurn = jest.fn().mockResolvedValue({ data: { id: 'turn-1' } });
+
+ await tickDispatch({ getOrCreateByExternalId, listTurns, createTurn });
+
+ expect(getOrCreateByExternalId).toHaveBeenCalledWith({
+ externalId: 'run-1',
+ agent: { name: 'reporter' },
+ });
+ expect(listTurns).toHaveBeenCalledWith('sess-1', { limit: 1 });
+ expect(createTurn).toHaveBeenCalledWith('sess-1', {
+ input: [{ type: 'user.message', content: 'Write the report' }],
+ previousTurnId: 'none',
+ });
+ });
+
+ it('does not call create-turn when the session already has a turn', async () => {
+ const getOrCreateByExternalId = jest.fn().mockResolvedValue({ data: { id: 'sess-1' } });
+ const listTurns = jest.fn().mockResolvedValue({ data: [{ id: 'turn-1' }] });
+ const createTurn = jest.fn();
+
+ await tickDispatch({ getOrCreateByExternalId, listTurns, createTurn });
+
+ expect(createTurn).not.toHaveBeenCalled();
+ });
+
+ it('propagates API failures without attempting a turn', async () => {
+ const getOrCreateByExternalId = jest.fn().mockRejectedValue(new Error('Agent not found: reporter'));
+ const createTurn = jest.fn();
+ const { logger } = await tickDispatch({
+ getOrCreateByExternalId,
+ listTurns: jest.fn(),
+ createTurn,
+ });
+
+ expect(createTurn).not.toHaveBeenCalled();
+ expect(logger.error).toHaveBeenCalledWith(
+ 'Failed to hand off triggered run',
+ expect.objectContaining({ run_id: 'run-1' }),
+ );
+ });
+});
diff --git a/packages/trueforge/tsup.config.ts b/packages/trueforge/tsup.config.ts
index 49c0fe815..6156c2f75 100644
--- a/packages/trueforge/tsup.config.ts
+++ b/packages/trueforge/tsup.config.ts
@@ -36,7 +36,6 @@ export default defineConfig([
...shared,
entry: {
main: 'src/main.ts',
- controller: 'src/controller.ts',
// Emit both engines under dist/{postgres,sqlite}/migrations/.
// Runtime selects migrations via STANDALONE (false → postgres, true → sqlite).
...migrationEntries('postgres'),
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 00ad637fe..9ce441bf3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -138,6 +138,9 @@ importers:
'@truefoundry/trueforge-core':
specifier: workspace:*
version: link:../trueforge-core
+ '@truefoundry/trueforge-sdk':
+ specifier: workspace:*
+ version: link:../trueforge-sdk
better-sqlite3:
specifier: ^13.0.3
version: 13.0.3