summaryrefslogtreecommitdiffhomepage
path: root/packages/session-orchestrator/src
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-22 02:53:20 +0900
committerAdam Malczewski <[email protected]>2026-06-22 02:53:20 +0900
commit20db60b0705ab65b6ade67ff614d347e13dc9803 (patch)
tree02361b6b94d6a397355b42e7208b1c3ba39fb692 /packages/session-orchestrator/src
parentd233842752d32659bba6f0e47b536e50d03145aa (diff)
downloaddispatch-20db60b0705ab65b6ade67ff614d347e13dc9803.tar.gz
dispatch-20db60b0705ab65b6ade67ff614d347e13dc9803.zip
feat: stop generation mid-turn (POST /conversations/:id/stop)
Add stopTurn to the orchestrator: aborts the in-flight turn's AbortController without changing conversation status. The turn seals normally (finishReason: 'aborted'), partial messages are persisted, and the conversation transitions active → idle via the normal settle path. Distinct from closeConversation which marks the conversation closed. - POST /conversations/:id/stop endpoint - dispatch stop <id> CLI command - FE handoff: frontend-stop-generation-handoff.md
Diffstat (limited to 'packages/session-orchestrator/src')
-rw-r--r--packages/session-orchestrator/src/orchestrator.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/session-orchestrator/src/orchestrator.ts b/packages/session-orchestrator/src/orchestrator.ts
index b46ecc1..bc9e78b 100644
--- a/packages/session-orchestrator/src/orchestrator.ts
+++ b/packages/session-orchestrator/src/orchestrator.ts
@@ -218,6 +218,14 @@ export interface SessionOrchestrator {
* Idempotent — closing an idle/unknown conversation just emits the hook.
*/
closeConversation(conversationId: string): { readonly abortedTurn: boolean };
+ /**
+ * Stop an in-flight generation WITHOUT closing the conversation. Aborts
+ * the turn's AbortController — the kernel finishes with
+ * `finishReason: "aborted"`, partial messages are persisted, and the turn
+ * seals normally (status transitions active → idle via the normal settle
+ * path). Idempotent — stopping an idle/unknown conversation is a no-op.
+ */
+ stopTurn(conversationId: string): { readonly abortedTurn: boolean };
handleMessage(input: {
conversationId: string;
text: string;
@@ -567,6 +575,15 @@ export function createSessionOrchestrator(
return { abortedTurn };
},
+ stopTurn(conversationId) {
+ const turn = activeTurns.get(conversationId);
+ const abortedTurn = turn !== undefined;
+ if (turn !== undefined) {
+ turn.controller.abort();
+ }
+ return { abortedTurn };
+ },
+
async handleMessage({ conversationId, text, onEvent, modelName, cwd, reasoningEffort }) {
const turnInput: StartTurnInput = {
conversationId,