Skip to content

fix(session): finalize interrupted assistant messages - #27254

Merged
rekram1-node merged 3 commits into
devfrom
fix-loop-bug
May 14, 2026
Merged

fix(session): finalize interrupted assistant messages#27254
rekram1-node merged 3 commits into
devfrom
fix-loop-bug

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Summary

  • Finalize persisted assistant messages as aborted if prompt execution is interrupted before processor cleanup can complete them.
  • Add a deterministic regression test for cancellation during processor creation.

Testing

  • bun test test/session/prompt.test.ts -t 'finalizes assistant when cancelled before processor creation completes'
  • bun test test/session/prompt.test.ts -t 'cancel records MessageAbortedError on interrupted process'
  • bun test test/session/prompt.test.ts -t 'loop calls LLM and returns assistant message'

@rekram1-node

Copy link
Copy Markdown
Collaborator Author

/review

@github-actions

Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node
rekram1-node merged commit e76cf96 into dev May 14, 2026
10 checks passed
@rekram1-node
rekram1-node deleted the fix-loop-bug branch May 14, 2026 06:19
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
Astro-Han added a commit to Astro-Han/pawwork that referenced this pull request Jun 10, 2026
Root cause / goal:
SessionPrompt persists an assistant scaffold before processor handling fully owns the turn. Cancellation in that early window could leave an empty unfinished assistant message with no abort error or completion timestamp, poisoning later session history. This ports the focused upstream anomalyco/opencode#27254 behavior only.

Change boundary:
- Finalize the current unfinished assistant scaffold from the shared prompt-loop interrupt cleanup path when cancellation happens before processor cleanup owns the assistant.
- Preserve existing cancel semantics and diagnostics, and avoid importing #1252 tool-drain behavior, #30804 filtering, provider/MCP/UI/package changes, or adjacent refactors.
- Add regression coverage for cancellation after assistant scaffold persistence and after processor handle creation but before process starts.

Verification:
- RED proof: new regression first failed because the canceled scaffold had no MessageAbortedError.
- Focused regression: bun test --timeout 30000 ./test/session/prompt-effect.test.ts -t "cancel after assistant scaffold save finalizes before processor handle|cancel after processor handle creation finalizes before process starts" -> 2 passed.
- Prompt interruption suite: bun test --timeout 30000 ./test/session/prompt-effect.test.ts -> 65 passed.
- Processor abort slice: bun test --timeout 30000 ./test/session/processor-effect.test.ts -t "abort|interrupt" -> 6 passed.
- Typecheck: bun run typecheck in packages/opencode -> passed.
- Whitespace: git diff --check origin/dev...HEAD -> passed.
- PR CI: required checks green; full current check set including windows-advisory green.

Reviews:
- Terminal Claude review: PASS after final diff.
- Independent terminal Occam fresh-eye review: PASS, no P0/P1/P2 after addressing the post-handle/pre-process cancellation window.
- GitHub review threads: none unresolved.

Residual risk:
Canceled assistants still follow existing semantics and do not set finish; this PR only ensures aborted scaffolds carry MessageAbortedError and time.completed.
isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant