Skip to content

Commit 38ce455

Browse files
saphidclaude
andcommitted
fix(server): record the interrupted turn's event under its own root node
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 570fc06 commit 38ce455

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,15 @@ function makeLocalCommandHarness(input: {
367367
// A steering restart superseded this attempt but could not stop its provider turn.
368368
const interruptedAttemptId = RunAttemptId.make("attempt-native-account-command-interrupted");
369369
const interruptedProviderTurnId = ProviderTurnId.make("provider-turn-native-account-command");
370+
const interruptedRootNodeId = NodeId.make("root-native-account-command-interrupted");
370371
const addInterruptedProviderTurn = () => {
371372
projection = {
372373
...projection,
373374
attempts: [
374375
{
375376
...projection.attempts[0]!,
376377
id: interruptedAttemptId,
378+
rootNodeId: interruptedRootNodeId,
377379
reason: "initial",
378380
status: "superseded",
379381
startedAt: now,
@@ -389,7 +391,7 @@ function makeLocalCommandHarness(input: {
389391
{
390392
id: interruptedProviderTurnId,
391393
providerThreadId,
392-
nodeId: rootNodeId,
394+
nodeId: interruptedRootNodeId,
393395
runAttemptId: interruptedAttemptId,
394396
nativeTurnRef: null,
395397
ordinal: 1,
@@ -596,6 +598,7 @@ function makeLocalCommandHarness(input: {
596598
dropAttempts,
597599
addInterruptedProviderTurn,
598600
interruptedProviderTurnId,
601+
interruptedRootNodeId,
599602
failStartingRun: (failedRunId: RunId = runId) =>
600603
Effect.gen(function* () {
601604
yield* (yield* ProviderTurnStart.ProviderTurnStartServiceV2).failStartingRun({
@@ -862,6 +865,9 @@ effectIt.effect("stops the provider turn a failed restart could not interrupt",
862865
{ id: harness.interruptedProviderTurnId, status: "interrupted" },
863866
]);
864867
expect(projection.providerTurns[0]?.completedAt).not.toBeNull();
868+
expect(harness.events.find((event) => event.type === "provider-turn.updated")?.nodeId).toBe(
869+
harness.interruptedRootNodeId,
870+
);
865871
}),
866872
);
867873

‎apps/server/src/orchestration-v2/ProviderTurnStartService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,17 +378,19 @@ export const layer: Layer.Layer<
378378
]),
379379
...(input.interruptedProviderTurns ?? []).map((providerTurn) => ({
380380
type: "provider-turn.updated" as const,
381+
// A restarted run's earlier turn belongs to the root it replaced.
382+
nodeId: providerTurn.nodeId,
381383
payload: { ...providerTurn, status: "interrupted" as const, completedAt: now },
382384
})),
383385
] as const;
384386
const events = yield* Effect.forEach(eventPayloads, (event) =>
385387
Effect.gen(function* () {
386388
return {
389+
nodeId: rootNode.id,
387390
...event,
388391
id: yield* idAllocator.allocate.event({ threadId: projection.thread.id }),
389392
threadId: projection.thread.id,
390393
runId,
391-
nodeId: rootNode.id,
392394
providerInstanceId: input.providerInstanceId,
393395
occurredAt: now,
394396
} satisfies OrchestrationV2DomainEvent;

0 commit comments

Comments
 (0)