Repository navigation
fix(server): an accepted Stop no longer ends the run as completed #41685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1992831
f1b808f
6003208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import * as CheckpointService from "./CheckpointService.ts"; | |
| import * as EventSink from "./EventSink.ts"; | ||
| import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; | ||
| import * as ProjectionStore from "./ProjectionStore.ts"; | ||
| import { makeInterruptResultTurnItem } from "./runInterruptResult.ts"; | ||
| import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts"; | ||
|
|
||
| // Git processes are already capped server-wide; this keeps one thread from taking every slot. | ||
|
|
@@ -259,6 +260,19 @@ export const layer: Layer.Layer< | |
| if (currentRun.status !== "waiting" && !stoppedNow) { | ||
| return; | ||
| } | ||
| // A Stop accepted once the provider's turn had ended stored only its request: the | ||
| // terminal already wrote `waiting`. That Stop still wins, and gets its result here. | ||
| const stopSignals = stoppedNow | ||
| ? [] | ||
| : (yield* projections.getThreadRecords(input.threadId, ["turnItems"], { | ||
| turnItemTypes: ["run_interrupt_request", "run_interrupt_result"], | ||
| turnItemRunIds: [run.id], | ||
| })).turnItems; | ||
| const stopRequest = stopSignals.some((item) => item.type === "run_interrupt_result") | ||
| ? undefined | ||
| : stopSignals.find((item) => item.type === "run_interrupt_request"); | ||
| const settledStatus = | ||
| stopRequest === undefined ? ("completed" as const) : ("interrupted" as const); | ||
| // Omit delegatedCompletion to preserve cohort writes made after capture loaded the run. | ||
| const { delegatedCompletion: _delegatedCompletion, ...runWithoutDelegatedCompletion } = | ||
| currentRun; | ||
|
|
@@ -328,6 +342,27 @@ export const layer: Layer.Layer< | |
| completedAt: capturedAt, | ||
| }), | ||
| }, | ||
| ...(stopRequest?.type !== "run_interrupt_request" | ||
| ? [] | ||
| : [ | ||
| { | ||
| id: yield* ids.allocate.event({ threadId: input.threadId, commandId }), | ||
| type: "turn-item.updated" as const, | ||
| threadId: input.threadId, | ||
| runId: run.id, | ||
| nodeId: rootNode.id, | ||
| providerInstanceId: run.providerInstanceId, | ||
| occurredAt: capturedAt, | ||
| payload: makeInterruptResultTurnItem({ | ||
| idAllocator: ids, | ||
| run, | ||
| rootNode, | ||
| providerThread, | ||
| reason: stopRequest.message, | ||
| completedAt: capturedAt, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Timestamp the Stop result at finalization.
Read a separate result timestamp under the finalization lock. Use it for the result item and result event. Keep the existing capture and provider-duration timestamps unchanged.
|
||
| }), | ||
| }, | ||
| ]), | ||
| { | ||
| id: yield* ids.allocate.event({ threadId: input.threadId, commandId }), | ||
| type: "run.updated", | ||
|
|
@@ -340,7 +375,7 @@ export const layer: Layer.Layer< | |
| ? { ...runWithoutDelegatedCompletion, checkpointId: checkpoint.id } | ||
| : { | ||
| ...runWithoutDelegatedCompletion, | ||
| status: "completed", | ||
| status: settledStatus, | ||
| completedAt: capturedAt, | ||
| checkpointId: checkpoint.id, | ||
| }, | ||
|
|
@@ -358,7 +393,7 @@ export const layer: Layer.Layer< | |
| occurredAt: capturedAt, | ||
| payload: { | ||
| ...rootNode, | ||
| status: "completed" as const, | ||
| status: settledStatus, | ||
| completedAt: capturedAt, | ||
| checkpointScopeId: scope.id, | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the
checkpointcase expectation at line 654. The new capture rule settles that run asinterrupted.When Stop lands during checkpoint capture, the provider turn has already ended and the run is
waiting. The request has no paired result, soCheckpointCaptureServicenow settles the run and root node asinterrupted. The assertion still requirescompletedfor everycancelBackgroundOnlyTaskcase, so thecheckpointvariant fails. Make the expected status depend on that case, and add a check that the pairedrun_interrupt_resultis present.Suggested fix