Skip to content

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

feat: Generate and persist active_executor_id (#799)

Srajan Asthanafad55d81ab5d
diff --git a/.changeset/turn-active-executor-id.md b/.changeset/turn-active-executor-id.md
new file mode 100644
index 000000000..d2d370313
--- /dev/null
+++ b/.changeset/turn-active-executor-id.md
@@ -0,0 +1,6 @@
+---
+"@truefoundry/trueforge": patch
+"@truefoundry/trueforge-core": patch
+---
+
+Persist turn ownership as `active_executor_id` on the turn row, mint plain ULID turn ids, and peer cancel via the DB owner instead of embedding the executor in the turn id.
diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json
index 214ea2acb..7a06b406e 100644
--- a/.github/fern/openapi/openapi.json
+++ b/.github/fern/openapi/openapi.json
@@ -5816,7 +5816,7 @@
"info": {
"description": "HTTP API for the TrueForge agent server (`/api/v1`). Interactive docs are served at `/api/v1/docs` (OpenAPI JSON at `/api/v1/openapi.json`).\n\n**Authentication:** Standalone auth accepts requests without credentials — middleware stamps a local default user. When OIDC or TrueFoundry auth is configured, protected routes require a valid cookie or `Authorization: Bearer` token. There is no built-in API-key scheme; pass custom headers only if your reverse proxy or IdP layer requires them.\n\nCovers DB-backed sessions, the agent registry, settings catalogs, and model/MCP/skill/sandbox providers.",
"title": "TrueForge API",
- "version": "0.2.0-rc.13"
+ "version": "0.2.0-rc.14"
},
"openapi": "3.1.0",
"paths": {
diff --git a/docs/openapi.json b/docs/openapi.json
index 214ea2acb..7a06b406e 100644
--- a/docs/openapi.json
+++ b/docs/openapi.json
@@ -5816,7 +5816,7 @@
"info": {
"description": "HTTP API for the TrueForge agent server (`/api/v1`). Interactive docs are served at `/api/v1/docs` (OpenAPI JSON at `/api/v1/openapi.json`).\n\n**Authentication:** Standalone auth accepts requests without credentials — middleware stamps a local default user. When OIDC or TrueFoundry auth is configured, protected routes require a valid cookie or `Authorization: Bearer` token. There is no built-in API-key scheme; pass custom headers only if your reverse proxy or IdP layer requires them.\n\nCovers DB-backed sessions, the agent registry, settings catalogs, and model/MCP/skill/sandbox providers.",
"title": "TrueForge API",
- "version": "0.2.0-rc.13"
+ "version": "0.2.0-rc.14"
},
"openapi": "3.1.0",
"paths": {
diff --git a/packages/trueforge-core/src/agent-session/SessionHandle.ts b/packages/trueforge-core/src/agent-session/SessionHandle.ts
index 825a8f042..ecaa2aeaa 100644
--- a/packages/trueforge-core/src/agent-session/SessionHandle.ts
+++ b/packages/trueforge-core/src/agent-session/SessionHandle.ts
@@ -174,6 +174,7 @@ export class SessionHandle<
*/
async createTurn(input: {
turn_id: string;
+ active_executor_id: string;
input?: TurnInputItem[] | undefined;
/** 'auto'/omitted → session.last_turn_id; 'none' → new root; id → fork from that turn. */
previous_turn_id?: string | undefined;
@@ -284,6 +285,7 @@ export class SessionHandle<
first_turn_id: previous?.first_turn_id ?? turnId,
ancestor_ids: previous ? [...previous.ancestor_ids, previous.turn_id].slice(-MAX_TURN_ANCESTORS) : [],
previous_turn_id: previousTurnId,
+ active_executor_id: input.active_executor_id,
state: { status: 'running' },
input: input.input ?? [],
created_at: now,
diff --git a/packages/trueforge-core/src/agent-session/models/TurnRecord.ts b/packages/trueforge-core/src/agent-session/models/TurnRecord.ts
index 5c9502e7b..99fb9669c 100644
--- a/packages/trueforge-core/src/agent-session/models/TurnRecord.ts
+++ b/packages/trueforge-core/src/agent-session/models/TurnRecord.ts
@@ -28,6 +28,7 @@ export interface TurnRecord<TCustom extends object = Record<string, never>> {
*/
ancestor_ids: string[];
previous_turn_id: string | null;
+ active_executor_id: string;
state: TurnState;
input: TurnInputItem[];
snapshot: TurnSnapshot;
diff --git a/packages/trueforge-core/tests/agent-session/capabilityState.test.ts b/packages/trueforge-core/tests/agent-session/capabilityState.test.ts
index f9bc70f63..f6866bf0d 100644
--- a/packages/trueforge-core/tests/agent-session/capabilityState.test.ts
+++ b/packages/trueforge-core/tests/agent-session/capabilityState.test.ts
@@ -19,6 +19,7 @@ import {
makeSilentLogger,
makeTestResolver,
mintTestTurnId,
+ TEST_ACTIVE_EXECUTOR_ID,
} from './testHelpers';
function makePlanShapedCapability(options: {
@@ -74,6 +75,7 @@ describe('capability_state (tfy.plan fixture)', () => {
const turn1 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'start' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -102,6 +104,7 @@ describe('capability_state (tfy.plan fixture)', () => {
loads = [];
const turn2 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'continue' }],
previous_turn_id: 'auto',
signal: new AbortController().signal,
@@ -145,6 +148,7 @@ describe('capability_state (tfy.plan fixture)', () => {
const turn1 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'start' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -178,6 +182,7 @@ describe('capability_state (tfy.plan fixture)', () => {
const turn3 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'no plan' }],
previous_turn_id: 'auto',
signal: new AbortController().signal,
@@ -235,6 +240,7 @@ describe('capability_state (tfy.plan fixture)', () => {
});
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'x' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
diff --git a/packages/trueforge-core/tests/agent-session/resolveAgentSpec.test.ts b/packages/trueforge-core/tests/agent-session/resolveAgentSpec.test.ts
index 4747b679e..7be5397c7 100644
--- a/packages/trueforge-core/tests/agent-session/resolveAgentSpec.test.ts
+++ b/packages/trueforge-core/tests/agent-session/resolveAgentSpec.test.ts
@@ -3,7 +3,14 @@ import { EventType } from '../../src/agent-session/schemas/events';
import { Sessions } from '../../src/agent-session/Sessions';
import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
import { TurnResourceResolver } from '../../src/agent-session/TurnResourceResolver';
-import { makeAgentSpec, makeMockILLM, makeSilentLogger, makeTestResolver, mintTestTurnId } from './testHelpers';
+import {
+ makeAgentSpec,
+ makeMockILLM,
+ makeSilentLogger,
+ makeTestResolver,
+ mintTestTurnId,
+ TEST_ACTIVE_EXECUTOR_ID,
+} from './testHelpers';
describe('TurnResourceResolver.resolveAgentSpec', () => {
it('fails closed when deps.agent is not wired for a named lookup', async () => {
@@ -98,6 +105,7 @@ describe('SessionHandle.createTurn named resolve', () => {
const agent = jest.fn().mockResolvedValue(live);
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hi' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
diff --git a/packages/trueforge-core/tests/agent-session/sessions.test.ts b/packages/trueforge-core/tests/agent-session/sessions.test.ts
index 39e7861be..34a060cf3 100644
--- a/packages/trueforge-core/tests/agent-session/sessions.test.ts
+++ b/packages/trueforge-core/tests/agent-session/sessions.test.ts
@@ -4,7 +4,7 @@ import { Sessions } from '../../src/agent-session/Sessions';
import { InMemorySessionStore } from '../../src/agent-session/store/InMemorySessionStore';
import { TurnNotFoundError } from '../../src/agent-session/store/SessionStoreErrors';
import { TurnHandle } from '../../src/agent-session/TurnHandle';
-import { makeAgentSpec, makeTestResolver, mintTestTurnId } from './testHelpers';
+import { makeAgentSpec, makeTestResolver, mintTestTurnId, TEST_ACTIVE_EXECUTOR_ID } from './testHelpers';
describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
const tenant = 'tenant-1';
@@ -137,6 +137,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
});
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -168,6 +169,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
});
const created = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
previous_turn_id: 'none',
signal: new AbortController().signal,
resolver: makeTestResolver(),
@@ -206,6 +208,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
});
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
previous_turn_id: 'none',
signal: new AbortController().signal,
resolver: makeTestResolver(),
@@ -235,6 +238,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
});
const t1 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'one' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -245,6 +249,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
const t2 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'two' }],
previous_turn_id: 'auto',
signal: new AbortController().signal,
@@ -266,6 +271,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
});
const first = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'one' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -277,6 +283,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
}
const root2 = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'fresh root' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -300,6 +307,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
await expect(
session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
// Mixed batch — rejected by SessionHandle.toSendBatch / orchestrator validation path.
input: [
{ type: EventType.USER_MESSAGE, content: 'hi' },
@@ -341,6 +349,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
await expect(
session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
// Mixed batch — rejected after sandbox/thread resolution.
input: [
{ type: EventType.USER_MESSAGE, content: 'hi' },
@@ -362,6 +371,7 @@ describe('Sessions / SessionHandle / TurnHandle (storage + createTurn)', () => {
const closeOnSuccess = jest.fn().mockResolvedValue(undefined);
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
diff --git a/packages/trueforge-core/tests/agent-session/store/storeContractSuite.ts b/packages/trueforge-core/tests/agent-session/store/storeContractSuite.ts
index 6c3cd36ac..28a85e43f 100644
--- a/packages/trueforge-core/tests/agent-session/store/storeContractSuite.ts
+++ b/packages/trueforge-core/tests/agent-session/store/storeContractSuite.ts
@@ -28,6 +28,7 @@ import {
makeModelMessageEvent,
makeTurnCreatedEvent,
makeTurnDoneEvent,
+ TEST_ACTIVE_EXECUTOR_ID,
} from '../testHelpers';
const ContractPassthroughEventSchema = z.object({
@@ -616,6 +617,7 @@ export function runStoreContractSuite(createStore: () => ISessionStore) {
await seedSession(store);
await store.createTurn(makeCreateTurnInput({ sessionId, turnId: 'turn-1' }));
const recreated = mustGet(await store.getTurn({ session_id: sessionId, turn_id: 'turn-1' }));
+ expect(recreated.active_executor_id).toBe(TEST_ACTIVE_EXECUTOR_ID);
expect(recreated.snapshot.threads[MAIN_THREAD_ID]?.context).toEqual([]);
expect(recreated.snapshot.threads[MAIN_THREAD_ID]?.capability_state).toBeNull();
expect(recreated.snapshot.mcp_servers).toBeNull();
diff --git a/packages/trueforge-core/tests/agent-session/testHelpers.ts b/packages/trueforge-core/tests/agent-session/testHelpers.ts
index ab81ef32f..fd1ddc88a 100644
--- a/packages/trueforge-core/tests/agent-session/testHelpers.ts
+++ b/packages/trueforge-core/tests/agent-session/testHelpers.ts
@@ -25,6 +25,8 @@ export function mintTestTurnId(): string {
return ulid().toLowerCase();
}
+export const TEST_ACTIVE_EXECUTOR_ID = 'test-executor';
+
/** Minimal AgentSpec for session/turn tests — interactive builtins off; FQN model required. */
export function makeAgentSpec(
overrides: {
@@ -162,6 +164,7 @@ const defaultRootThread: NewThreadInit = {
export function makeCreateTurnInput(input: {
sessionId: string;
turnId: string;
+ activeExecutorId?: string;
previousTurnId?: string | null;
firstTurnId?: string;
new_threads?: NewThreadInit[];
@@ -172,6 +175,7 @@ export function makeCreateTurnInput(input: {
const turn = makeRunningTurnRecord({
sessionId: input.sessionId,
turnId: input.turnId,
+ ...(input.activeExecutorId !== undefined ? { activeExecutorId: input.activeExecutorId } : {}),
...(input.previousTurnId !== undefined ? { previousTurnId: input.previousTurnId } : {}),
...(input.firstTurnId !== undefined ? { firstTurnId: input.firstTurnId } : {}),
});
@@ -209,6 +213,7 @@ export function makeCancelledTurnState(
export function makeRunningTurnRecord(input: {
sessionId: string;
turnId: string;
+ activeExecutorId?: string;
previousTurnId?: string | null;
firstTurnId?: string;
}): TurnRecord {
@@ -219,6 +224,7 @@ export function makeRunningTurnRecord(input: {
first_turn_id: input.firstTurnId ?? input.turnId,
ancestor_ids: input.previousTurnId ? [input.previousTurnId] : [],
previous_turn_id: input.previousTurnId ?? null,
+ active_executor_id: input.activeExecutorId ?? TEST_ACTIVE_EXECUTOR_ID,
state: { status: 'running' },
input: [],
custom: null,
diff --git a/packages/trueforge-core/tests/agent-session/turnStream.test.ts b/packages/trueforge-core/tests/agent-session/turnStream.test.ts
index f5a103a67..15b857110 100644
--- a/packages/trueforge-core/tests/agent-session/turnStream.test.ts
+++ b/packages/trueforge-core/tests/agent-session/turnStream.test.ts
@@ -12,6 +12,7 @@ import {
makeSilentLogger,
makeTestResolver,
mintTestTurnId,
+ TEST_ACTIVE_EXECUTOR_ID,
} from './testHelpers';
describe('TurnHandle.stream()', () => {
@@ -41,6 +42,7 @@ describe('TurnHandle.stream()', () => {
const { store, session } = await createSession();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -83,6 +85,7 @@ describe('TurnHandle.stream()', () => {
const { session } = await createSession();
const turn = await session.createTurn({
turn_id: 'turn-usage',
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -118,6 +121,7 @@ describe('TurnHandle.stream()', () => {
const turn1 = await session.createTurn({
turn_id: 'turn-isolation-1',
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'turn one' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -145,6 +149,7 @@ describe('TurnHandle.stream()', () => {
const turn2 = await session.createTurn({
turn_id: 'turn-isolation-2',
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'turn two' }],
previous_turn_id: 'auto',
signal: new AbortController().signal,
@@ -183,6 +188,7 @@ describe('TurnHandle.stream()', () => {
const { session } = await createSession();
const turn = await session.createTurn({
turn_id: 'turn-cache-read',
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -209,6 +215,7 @@ describe('TurnHandle.stream()', () => {
const { session } = await createSession();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -227,6 +234,7 @@ describe('TurnHandle.stream()', () => {
const { session } = await createSession();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -251,6 +259,7 @@ describe('TurnHandle.stream()', () => {
let closeCalls = 0;
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -282,6 +291,7 @@ describe('TurnHandle.stream()', () => {
const controller = new AbortController();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: controller.signal,
@@ -308,6 +318,7 @@ describe('TurnHandle.stream()', () => {
const controller = new AbortController();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: controller.signal,
@@ -336,6 +347,7 @@ describe('TurnHandle.stream()', () => {
const controller = new AbortController();
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: controller.signal,
@@ -364,6 +376,7 @@ describe('TurnHandle.stream()', () => {
let closeCalls = 0;
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -407,6 +420,7 @@ describe('TurnHandle.stream()', () => {
// Spec already has sandbox.enabled from createSession helper.
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hello' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
@@ -522,6 +536,7 @@ describe('TurnResourceResolver caches', () => {
});
const turn = await session.createTurn({
turn_id: mintTestTurnId(),
+ active_executor_id: TEST_ACTIVE_EXECUTOR_ID,
input: [{ type: EventType.USER_MESSAGE, content: 'hi' }],
previous_turn_id: 'none',
signal: new AbortController().signal,
diff --git a/packages/trueforge/src/apis/sessions.ts b/packages/trueforge/src/apis/sessions.ts
index 8d4e680aa..37083e58b 100644
--- a/packages/trueforge/src/apis/sessions.ts
+++ b/packages/trueforge/src/apis/sessions.ts
@@ -39,7 +39,6 @@ import {
updateSessionRoute,
} from '../routes/sessionRoutes';
import type { ActiveTurnRegistry } from '../runtime/activeTurns';
-import { executorFromTurnId } from '../runtime/peeringIds';
import { validateAgentSpec } from '../runtime/sessionResources';
import { honoQueriesToRecord } from '../schemas/deepObjectQuery';
import { isSessionAgentNameRef, parseListSessionsQuery, type Session } from '../schemas/session';
@@ -159,9 +158,9 @@ export async function cancelSessionTurn(
return;
}
- const owner = executorFromTurnId(turnId);
- // Without a Redis client there is no peer to ask, so an id naming another
- // replica falls through to the local lookup and freezes if the run is gone.
+ const owner = turn.active_executor_id;
+ // Without a Redis client there is no peer to ask, so a different owner falls
+ // through to the local lookup and freezes if the run is gone.
if (owner !== configuration.EXECUTOR_ID && deps.redis) {
try {
const reply = await redisRequest<CancelPeerBody>({
diff --git a/packages/trueforge/src/apis/turns.ts b/packages/trueforge/src/apis/turns.ts
index 99f9456ee..5d933410f 100644
--- a/packages/trueforge/src/apis/turns.ts
+++ b/packages/trueforge/src/apis/turns.ts
@@ -49,7 +49,6 @@ import {
} from '../routes/turnRoutes';
import type { ActiveTurnRegistry } from '../runtime/activeTurns';
import { StreamGoneError, type EventSubscription, type EventSubscriptionRegistry } from '../runtime/event-subscription';
-import { mintPeeredTurnId } from '../runtime/peeringIds';
import { validateSandboxFilePath } from '../runtime/sandboxFilePath';
import {
buildTurnSandbox,
@@ -64,6 +63,7 @@ import {
} from '../runtime/sessionResources';
import { checkSnapshotStatus } from '../sandbox/providerUtils';
import { MAX_SESSION_TITLE_LENGTH } from '../schemas/session';
+import { newId } from '../utils/id';
import { resolveWebSearchProvider } from '../websearch/providers';
import { canReadAgentBoundResource } from './agentAccess';
@@ -401,7 +401,7 @@ export async function beginTurnExecution(params: {
}): Promise<{ turn: TurnHandle; drainInput: TurnEventDrainInput }> {
const { session, input, previous_turn_id: previousTurnId, userRef, tfyMetadata, deps } = params;
const sessionId = session.session_id;
- const turnId = mintPeeredTurnId(configuration.EXECUTOR_ID);
+ const turnId = newId();
const abortController = new AbortController();
const tenant_id = session.tenant_id;
@@ -426,6 +426,7 @@ export async function beginTurnExecution(params: {
const turn = await session.createTurn({
turn_id: turnId,
+ active_executor_id: configuration.EXECUTOR_ID,
input,
previous_turn_id: previousTurnId,
signal: abortController.signal,
diff --git a/packages/trueforge/src/db/postgres/migrations/20260918_000001_turn_active_executor_id.ts b/packages/trueforge/src/db/postgres/migrations/20260918_000001_turn_active_executor_id.ts
new file mode 100644
index 000000000..73a534014
--- /dev/null
+++ b/packages/trueforge/src/db/postgres/migrations/20260918_000001_turn_active_executor_id.ts
@@ -0,0 +1,34 @@
+import { sql, type Kysely } from 'kysely';
+
+/**
+ * Persist turn ownership on the turn row. Backfills from the legacy peered
+ * turn_id grammar `{ulid}.{executorId}`; non-peered ids (e.g. import migration)
+ * get sentinel `default` — those source executors are gone.
+ * Runs inside the Migrator's transaction — do not nest `db.transaction()`.
+ */
+export async function up(db: Kysely<unknown>): Promise<void> {
+ await sql`
+ SET LOCAL lock_timeout = '5s';
+
+ ALTER TABLE turn
+ ADD COLUMN active_executor_id text;
+
+ UPDATE turn
+ SET active_executor_id = split_part(turn_id, '.', 2)
+ WHERE turn_id ~ '^[^.]+[.][^.]+$';
+
+ UPDATE turn
+ SET active_executor_id = 'default'
+ WHERE active_executor_id IS NULL;
+
+ ALTER TABLE turn
+ ALTER COLUMN active_executor_id SET NOT NULL;
+ `.execute(db);
+}
+
+export async function down(db: Kysely<unknown>): Promise<void> {
+ await sql`
+ SET LOCAL lock_timeout = '5s';
+ ALTER TABLE turn DROP COLUMN IF EXISTS active_executor_id;
+ `.execute(db);
+}
diff --git a/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts b/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts
index a44502cc7..76b6ce66b 100644
--- a/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts
+++ b/packages/trueforge/src/db/postgres/session-store/PostgresSessionStore.ts
@@ -162,6 +162,7 @@ export class PostgresSessionStore implements ISessionStore<SessionCustom, TurnCu
first_turn_id: input.turn.first_turn_id,
previous_turn_id: input.turn.previous_turn_id,
ancestor_ids: input.turn.ancestor_ids,
+ active_executor_id: input.turn.active_executor_id,
input: input.turn.input,
state: input.turn.state,
custom: input.turn.custom,
@@ -355,6 +356,8 @@ export class PostgresSessionStore implements ISessionStore<SessionCustom, TurnCu
for (const turn of turns) {
const turnId = turn.turn_id;
const updatedAt = new Date(turn.updated_at);
+ // import: source_turn_ids can be in a different format. source executors are gone; do not parse turn_id.
+ const activeExecutorId = 'default';
await trx
.insertInto('turn')
.values({
@@ -363,6 +366,7 @@ export class PostgresSessionStore implements ISessionStore<SessionCustom, TurnCu
first_turn_id: turn.first_turn_id,
previous_turn_id: turn.previous_turn_id,
ancestor_ids: turn.ancestor_ids,
+ active_executor_id: activeExecutorId,
input: jsonUnknown<TurnInputItem[]>(turn.input),
state: jsonUnknown<TurnState>(turn.state),
checkpoint: jsonUnknown<TurnCheckpoint>(turn.checkpoint ?? { mcp_servers: null, sandbox_info: null }),
diff --git a/packages/trueforge/src/db/postgres/session-store/queries/turns.ts b/packages/trueforge/src/db/postgres/session-store/queries/turns.ts
index 0739e3508..06bcda570 100644
--- a/packages/trueforge/src/db/postgres/session-store/queries/turns.ts
+++ b/packages/trueforge/src/db/postgres/session-store/queries/turns.ts
@@ -72,6 +72,7 @@ export interface CreateTurnTurnFields {
first_turn_id: string;
previous_turn_id: string | null;
ancestor_ids: string[];
+ active_executor_id: string;
input: TurnInputItem[];
state: TurnState;
custom: Record<string, unknown> | null;
@@ -344,6 +345,7 @@ async function assembleTurnRecord(
first_turn_id: turn.first_turn_id,
ancestor_ids: turn.ancestor_ids,
previous_turn_id: turn.previous_turn_id,
+ active_executor_id: turn.active_executor_id,
state: turn.state,
input: turn.input,
snapshot,
@@ -359,6 +361,7 @@ interface TurnInsertValues {
first_turn_id: string;
previous_turn_id: string | null;
ancestor_ids: string[];
+ active_executor_id: string;
input: RawBuilder<CreateTurnInput['turn']['input']>;
state: CreateTurnInput['turn']['state'];
checkpoint: TurnCheckpoint;
@@ -515,6 +518,7 @@ export async function createTurn(db: Kysely<Database>, input: CreateTurnInput):
first_turn_id: input.turn.first_turn_id,
previous_turn_id: input.turn.previous_turn_id ?? null,
ancestor_ids: input.turn.ancestor_ids,
+ active_executor_id: input.turn.active_executor_id,
input: json(input.turn.input),
state: input.turn.state,
checkpoint,
@@ -726,6 +730,7 @@ export async function listTurns(db: Kysely<Database>, input: ListTurnsInput): Pr
first_turn_id: row.first_turn_id,
ancestor_ids: row.ancestor_ids,
previous_turn_id: row.previous_turn_id,
+ active_executor_id: row.active_executor_id,
state: row.state,
input: row.input,
created_at: row.created_at,
diff --git a/packages/trueforge/src/db/postgres/types.ts b/packages/trueforge/src/db/postgres/types.ts
index cdc6bcd64..41d78f462 100644
--- a/packages/trueforge/src/db/postgres/types.ts
+++ b/packages/trueforge/src/db/postgres/types.ts
@@ -128,6 +128,8 @@ export interface TurnTable {
* (spill through older turns); typed array
*/
ancestor_ids: string[];
+ /** top: replica currently owning the in-memory ActiveTurn */
+ active_executor_id: string;
/** top: big + written once at create; TOAST pointer stable after */
// Insert arrays/objects via json() helper (bare JS arrays become PG arrays via node-pg).
input: JSONColumnType<TurnInputItem[], TurnInputItem[] | string, TurnInputItem[] | string>;
diff --git a/packages/trueforge/src/db/sqlite/migrations/20260918_000001_turn_active_executor_id.ts b/packages/trueforge/src/db/sqlite/migrations/20260918_000001_turn_active_executor_id.ts
new file mode 100644
index 000000000..88e0d2cb5
--- /dev/null
+++ b/packages/trueforge/src/db/sqlite/migrations/20260918_000001_turn_active_executor_id.ts
@@ -0,0 +1,38 @@
+import { sql, type Kysely } from 'kysely';
+
+/**
+ * Persist turn ownership on the turn row. Backfills from the legacy peered
+ * turn_id grammar `{ulid}.{executorId}`; non-peered ids (e.g.import migration)
+ * get sentinel `default` — those source executors are gone.
+ * Mirrors db/postgres/migrations/20260918_000001_turn_active_executor_id.ts.
+ * Kysely does not wrap SQLite migrations — keep schema + backfill atomic.
+ */
+export async function up(db: Kysely<unknown>): Promise<void> {
+ await db.transaction().execute(async trx => {
+ await sql`
+ ALTER TABLE turn
+ ADD COLUMN active_executor_id TEXT NOT NULL DEFAULT ''
+ `.execute(trx);
+
+ await sql`
+ UPDATE turn
+ SET active_executor_id = substr(turn_id, instr(turn_id, '.') + 1)
+ WHERE turn_id GLOB '*.*'
+ AND turn_id NOT GLOB '*.*.*'
+ AND turn_id NOT GLOB '.*'
+ AND turn_id NOT GLOB '*.'
+ `.execute(trx);
+
+ await sql`
+ UPDATE turn
+ SET active_executor_id = 'default'
+ WHERE active_executor_id = ''
+ `.execute(trx);
+ });
+}
+
+export async function down(db: Kysely<unknown>): Promise<void> {
+ await db.transaction().execute(async trx => {
+ await sql`ALTER TABLE turn DROP COLUMN active_executor_id`.execute(trx);
+ });
+}
diff --git a/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts b/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts
index 61425e954..f0c597a68 100644
--- a/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts
+++ b/packages/trueforge/src/db/sqlite/session-store/SqliteSessionStore.ts
@@ -137,6 +137,7 @@ export class SqliteSessionStore implements ISessionStore<SessionCustom, TurnCust
first_turn_id: input.turn.first_turn_id,
previous_turn_id: input.turn.previous_turn_id,
ancestor_ids: input.turn.ancestor_ids,
+ active_executor_id: input.turn.active_executor_id,
input: input.turn.input,
state: input.turn.state,
custom: input.turn.custom,
diff --git a/packages/trueforge/src/db/sqlite/session-store/queries/turns.ts b/packages/trueforge/src/db/sqlite/session-store/queries/turns.ts
index 75038bb4f..db230fd20 100644
--- a/packages/trueforge/src/db/sqlite/session-store/queries/turns.ts
+++ b/packages/trueforge/src/db/sqlite/session-store/queries/turns.ts
@@ -72,6 +72,7 @@ export interface CreateTurnTurnFields {
first_turn_id: string;
previous_turn_id: string | null;
ancestor_ids: string[];
+ active_executor_id: string;
input: TurnInputItem[];
state: TurnState;
custom: Record<string, unknown> | null;
@@ -209,6 +210,7 @@ async function assembleTurnRecord(
'turn_id',
'first_turn_id',
'previous_turn_id',
+ 'active_executor_id',
jsonText<string[]>(sql.ref('ancestor_ids')).as('ancestor_ids'),
jsonText<TurnInputItem[]>(sql.ref('input')).as('input'),
jsonText<TurnState>(sql.ref('state')).as('state'),
@@ -330,6 +332,7 @@ async function assembleTurnRecord(
first_turn_id: turn.first_turn_id,
ancestor_ids: turn.ancestor_ids,
previous_turn_id: turn.previous_turn_id,
+ active_executor_id: turn.active_executor_id,
state: turn.state,
input: turn.input,
snapshot,
@@ -469,6 +472,7 @@ export async function createTurn(db: Kysely<Database>, input: CreateTurnInput):
first_turn_id: input.turn.first_turn_id,
previous_turn_id: input.turn.previous_turn_id ?? null,
ancestor_ids: jsonbBind(input.turn.ancestor_ids),
+ active_executor_id: input.turn.active_executor_id,
input: jsonbBind(input.turn.input),
state: jsonbBind(input.turn.state),
checkpoint: jsonbBind(checkpoint),
@@ -754,6 +758,7 @@ export async function listTurns(db: Kysely<Database>, input: ListTurnsInput): Pr
'turn_id',
'first_turn_id',
'previous_turn_id',
+ 'active_executor_id',
jsonText<string[]>(sql.ref('ancestor_ids')).as('ancestor_ids'),
jsonText<TurnInputItem[]>(sql.ref('input')).as('input'),
jsonText<TurnState>(sql.ref('state')).as('state'),
@@ -777,6 +782,7 @@ export async function listTurns(db: Kysely<Database>, input: ListTurnsInput): Pr
first_turn_id: row.first_turn_id,
ancestor_ids: row.ancestor_ids,
previous_turn_id: row.previous_turn_id,
+ active_executor_id: row.active_executor_id,
state: row.state,
input: row.input,
created_at: new Date(row.created_at),
diff --git a/packages/trueforge/src/db/sqlite/types.ts b/packages/trueforge/src/db/sqlite/types.ts
index c4340877b..9c2b62303 100644
--- a/packages/trueforge/src/db/sqlite/types.ts
+++ b/packages/trueforge/src/db/sqlite/types.ts
@@ -98,6 +98,8 @@ export interface TurnTable {
previous_turn_id: string | null;
/** JSONB array of turn ids — topology only; not a SQL join key. */
ancestor_ids: JsonbColumn<string[]>;
+ /** Replica currently owning the in-memory ActiveTurn. */
+ active_executor_id: string;
input: JsonbColumn<TurnInputItem[]>;
state: JsonbColumn<TurnState>;
checkpoint: JsonbColumn<TurnCheckpoint>;
diff --git a/packages/trueforge/src/runtime/peeringIds.ts b/packages/trueforge/src/runtime/peeringIds.ts
deleted file mode 100644
index b32b24850..000000000
--- a/packages/trueforge/src/runtime/peeringIds.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import { HTTPException } from 'hono/http-exception';
-import { newId } from '../utils/id';
-
-/**
- * Mints a turn id owned by `executorId`. The server calls this at turn
- * creation (the id is opaque to the session library); `executorFromTurnId`
- * is the matching decoder on the routing path.
- */
-export function mintPeeredTurnId(executorId: string): string {
- return `${newId()}.${executorId}`;
-}
-
-/** Decodes the owning executor; throws 400 for an id outside the grammar. */
-export function executorFromTurnId(turnId: string): string {
- const parts = turnId.split('.');
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
- throw new HTTPException(400, { message: `ID ${turnId} is not a valid turn id` });
- }
- return parts[1];
-}
diff --git a/packages/trueforge/tests/unit/apis/sessions.test.ts b/packages/trueforge/tests/unit/apis/sessions.test.ts
index 7af166b49..ddc8ef3db 100644
--- a/packages/trueforge/tests/unit/apis/sessions.test.ts
+++ b/packages/trueforge/tests/unit/apis/sessions.test.ts
@@ -5,7 +5,6 @@ import type { RedisClientType } from 'redis';
import { cancelSessionTurn } from '../../../src/apis/sessions';
import configuration from '../../../src/config';
import { ActiveTurnRegistry } from '../../../src/runtime/activeTurns';
-import { mintPeeredTurnId } from '../../../src/runtime/peeringIds';
jest.mock('@truefoundry/trueforge-core/request-reply', () => {
const actual = jest.requireActual<typeof import('@truefoundry/trueforge-core/request-reply')>(
@@ -21,19 +20,21 @@ const redisRequestMock = jest.mocked(redisRequest);
const SESSION_ID = 's1';
const REDIS = {} as RedisClientType;
+const REMOTE_EXECUTOR = 'other1';
function silentLogger(): { warn: jest.Mock } {
return { warn: jest.fn() };
}
-function turnRecord(turnId: string, state: TurnState): TurnRecord {
+function turnRecord(input: { turnId: string; state: TurnState; activeExecutorId?: string }): TurnRecord {
return {
- turn_id: turnId,
+ turn_id: input.turnId,
session_id: SESSION_ID,
- first_turn_id: turnId,
+ first_turn_id: input.turnId,
ancestor_ids: [],
previous_turn_id: null,
- state,
+ active_executor_id: input.activeExecutorId ?? configuration.EXECUTOR_ID,
+ state: input.state,
input: [],
snapshot: { threads: {}, mcp_servers: null, sandbox_info: null },
created_at: new Date('2026-07-31T00:00:00.000Z'),
@@ -97,27 +98,33 @@ describe('cancelSessionTurn', () => {
it('aborts a turn running in this process without freezing', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId(configuration.EXECUTOR_ID);
+ const turnId = 'turn-local-running';
const abortController = trackRun(activeTurns, turnId);
const session = sessionHandle();
- await cancelSessionTurn(cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session }), {
- turnId,
- });
+ await cancelSessionTurn(
+ cancelDeps({ activeTurns, turn: turnRecord({ turnId: turnId, state: { status: 'running' } }), session }),
+ {
+ turnId,
+ },
+ );
expect(abortController.signal.aborted).toBe(true);
expect(abortController.signal.reason).toBe(CancellationReason.ClientCancelled);
expect(session.freezeTurn).not.toHaveBeenCalled();
});
- it('freezes when this executor owns the turn id but the run is gone', async () => {
+ it('freezes when this executor owns the turn but the run is gone', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId(configuration.EXECUTOR_ID);
+ const turnId = 'turn-local-gone';
const session = sessionHandle();
- await cancelSessionTurn(cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session }), {
- turnId,
- });
+ await cancelSessionTurn(
+ cancelDeps({ activeTurns, turn: turnRecord({ turnId: turnId, state: { status: 'running' } }), session }),
+ {
+ turnId,
+ },
+ );
expect(session.freezeTurn).toHaveBeenCalledWith({
turn_id: turnId,
@@ -127,12 +134,17 @@ describe('cancelSessionTurn', () => {
it('freezes when the run is not in this process and there is no Redis client', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-no-redis';
const session = sessionHandle();
- await cancelSessionTurn(cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session }), {
- turnId,
- });
+ await cancelSessionTurn(
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ }),
+ { turnId },
+ );
expect(session.freezeTurn).toHaveBeenCalledWith({
turn_id: turnId,
@@ -142,27 +154,41 @@ describe('cancelSessionTurn', () => {
it('does not freeze when the owning peer aborts', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-ok';
const session = sessionHandle();
redisRequestMock.mockResolvedValue({ status: 200, body: {} });
await cancelSessionTurn(
- cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session, redis: REDIS }),
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ redis: REDIS,
+ }),
{ turnId },
);
- expect(redisRequestMock).toHaveBeenCalled();
+ expect(redisRequestMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ executorId: REMOTE_EXECUTOR,
+ }),
+ );
expect(session.freezeTurn).not.toHaveBeenCalled();
});
it('freezes when the owning peer is alive but the turn is not running there', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-412';
const session = sessionHandle();
redisRequestMock.mockResolvedValue({ status: 412, body: { message: 'Turn is not running on this executor' } });
await cancelSessionTurn(
- cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session, redis: REDIS }),
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ redis: REDIS,
+ }),
{ turnId },
);
@@ -171,74 +197,100 @@ describe('cancelSessionTurn', () => {
it('freezes when the owning executor is unreachable', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-no-responder';
const session = sessionHandle();
const logger = silentLogger();
- redisRequestMock.mockRejectedValue(new NoResponderError('other1'));
+ redisRequestMock.mockRejectedValue(new NoResponderError(REMOTE_EXECUTOR));
await expect(
cancelSessionTurn(
- cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session, redis: REDIS, logger }),
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ redis: REDIS,
+ logger,
+ }),
{ turnId },
),
).resolves.toBeUndefined();
expect(session.freezeTurn).toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalledWith(
'Failed to reach owning executor over Redis; freezing the running turn',
- expect.objectContaining({ sessionId: SESSION_ID, turnId, owner: 'other1' }),
+ expect.objectContaining({ sessionId: SESSION_ID, turnId, owner: REMOTE_EXECUTOR }),
);
});
it('freezes when waiting for the owning executor times out', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-timeout';
const session = sessionHandle();
const logger = silentLogger();
redisRequestMock.mockRejectedValue(new RequestTimeoutError(60_000));
await expect(
cancelSessionTurn(
- cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session, redis: REDIS, logger }),
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ redis: REDIS,
+ logger,
+ }),
{ turnId },
),
).resolves.toBeUndefined();
expect(session.freezeTurn).toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalledWith(
'Timed out waiting for owning executor to cancel; freezing the running turn',
- expect.objectContaining({ sessionId: SESSION_ID, turnId, owner: 'other1' }),
+ expect.objectContaining({ sessionId: SESSION_ID, turnId, owner: REMOTE_EXECUTOR }),
);
});
it('freezes when Redis itself cannot be reached', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId('other1');
+ const turnId = 'turn-remote-redis-down';
const session = sessionHandle();
const logger = silentLogger();
redisRequestMock.mockRejectedValue(new Error('Redis connection closed'));
await expect(
cancelSessionTurn(
- cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session, redis: REDIS, logger }),
+ cancelDeps({
+ activeTurns,
+ turn: turnRecord({ turnId: turnId, state: { status: 'running' }, activeExecutorId: REMOTE_EXECUTOR }),
+ session,
+ redis: REDIS,
+ logger,
+ }),
{ turnId },
),
).resolves.toBeUndefined();
expect(session.freezeTurn).toHaveBeenCalled();
expect(logger.warn).toHaveBeenCalledWith(
'Failed to reach owning executor over Redis; freezing the running turn',
- expect.objectContaining({ sessionId: SESSION_ID, turnId, owner: 'other1', error: 'Redis connection closed' }),
+ expect.objectContaining({
+ sessionId: SESSION_ID,
+ turnId,
+ owner: REMOTE_EXECUTOR,
+ error: 'Redis connection closed',
+ }),
);
});
it('treats a missing turn as a successful cancel', async () => {
const activeTurns = new ActiveTurnRegistry();
- const turnId = mintPeeredTurnId(configuration.EXECUTOR_ID);
+ const turnId = 'turn-missing';
const session = sessionHandle();
session.freezeTurn = jest.fn().mockRejectedValue(new TurnNotFoundError(turnId));
await expect(
- cancelSessionTurn(cancelDeps({ activeTurns, turn: turnRecord(turnId, { status: 'running' }), session }), {
- turnId,
- }),
+ cancelSessionTurn(
+ cancelDeps({ activeTurns, turn: turnRecord({ turnId: turnId, state: { status: 'running' } }), session }),
+ {
+ turnId,
+ },
+ ),
).resolves.toBeUndefined();
});
});
diff --git a/packages/trueforge/tests/unit/runtime/peeringIds.test.ts b/packages/trueforge/tests/unit/runtime/peeringIds.test.ts
deleted file mode 100644
index 051bd8ec6..000000000
--- a/packages/trueforge/tests/unit/runtime/peeringIds.test.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { HTTPException } from 'hono/http-exception';
-import { executorFromTurnId, mintPeeredTurnId } from '../../../src/runtime/peeringIds';
-
-describe('turn ids', () => {
- it('decodes back to the owning executor', () => {
- expect(executorFromTurnId(mintPeeredTurnId('abc123'))).toBe('abc123');
- });
-
- it('rejects ids outside the grammar', () => {
- for (const invalid of ['', '.', 'a.', '.b', 'a.b.c', 'noseparator']) {
- let thrown: unknown;
- try {
- executorFromTurnId(invalid);
- } catch (error) {
- thrown = error;
- }
- expect(thrown).toBeInstanceOf(HTTPException);
- if (!(thrown instanceof HTTPException)) {
- throw new Error(`expected ${JSON.stringify(invalid)} to be rejected`);
- }
- expect(thrown.status).toBe(400);
- }
- });
-});