Skip to content

fix(session): cancel stalled streams and preserve partial findings - #1527

Merged
anandgupta42 merged 2 commits into
feat/analyst-harness-dab-2026-10from
fix/stalled-stream-budget
Oct 16, 2026
Merged

anandgupta42 merged 2 commits into
feat/analyst-harness-dab-2026-10from
fix/stalled-stream-budget

Conversation

@anandgupta42

@anandgupta42 anandgupta42 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #1484

Stacked on feat/analyst-harness-dab-2026-10 (#1441).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Why: a provider stream that stops delivering events (and ignores cancellation) kept a run hung past its time budget, and partial findings from interrupted work were lost.

Root cause: LLM.stream() and the provider iterator were awaited directly, so abort was only observed after another event; hard abort published idle before partial output was committed; task discarded child findings when the child prompt rejected/returned empty; failure notes replaced earlier unfinished text.

Before -> after:

  • Stalled provider setup/read: hung indefinitely -> abort/deadline ends the wait (module-scope abortable-stream.ts, listeners removed, iterator cleanup requested without awaiting a stuck return()).
  • Hard abort: idle published first -> partial text/reasoning and task results committed, then idle.
  • Interrupted task: "Tool execution aborted" -> committed child findings returned, labelled incomplete (task-output.ts); metadata publishes child session and prompt message IDs before dispatch.
  • Budget finalization failure: note only -> note plus Partial assistant response (not finalized).

Deferred: no new post-tool timeout (no evidence of the historical transport cause); soft-interrupt polling unchanged. Review follow-ups (P2, not fixed): recovery after compaction/continuation turns only sees the original prompt lineage; batched tasks publish metadata on the outer batch part so recovery does not apply to them; a finalization stall before the first step leaves unfinished text without the warning note.

How did you verify your code works?

  • New regressions: stalled setup/post-tool reads under soft/hard cancel (0/4 before, 4/4 after), abort-time commit ordering, parent abort preserving child findings, task recovery cases, output-collector fallback.
  • Independent Codex review: no P0/P1; three P2s listed above.
  • bun run typecheck in packages/opencode: pass. git diff --check: clean.
  • Marker audit against the v1.17.9 baseline: processor.ts, task.ts, run.ts exist upstream; all altimate edits are inside balanced, non-nested altimate_change markers (one nested pair in processor.ts fixed).
  • Tests touching the changed modules (session, tool, cli, upstream, release-validation, etc.): the full combined run showed timeout failures under concurrent machine load (28); every failing file passes when re-run alone (prompt 52, registry 14, project-scan 86, db 1, processor-effect 59, abortable-stream 4, task 13, run-output 10, budget-finalization+time-budget+compaction 95, 0 fail).

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code


Note

Medium Risk
Touches core session streaming, abort lifecycle, and task delegation—behavior changes on cancel and time-budget exits, though covered by new tests and scoped upstream_fix markers.

Overview
Fixes runs that could hang past time budgets when a provider stream stalled, and stops losing partial work on cancellation.

Provider cancellation: LLM.stream() consumption now goes through abortableStream, so abort/deadline wins races on stream open, pending next(), and triggers iterator cleanup without waiting on a stuck return().

Abort commit ordering: On hard abort, partial text/reasoning and in-flight tools are finalized first (including task tools that recover child session text via interruptedTaskOutput / messageID in metadata); SessionStatus idle is deferred until after those commits. Soft generation interrupt still closes open parts without clearing finish when only the request was aborted.

Task tool & adapters: Cancelled tasks return labelled partial child findings instead of a bare abort error; metadata is published (with child messageID) before the child prompt runs, with throwIfAborted after async metadata. Legacy/batch tool bridges now await async metadata() instead of fire-and-forget.

CLI --output: When bounded finalization cannot produce an answer, the harness note can append Partial assistant response (not finalized) from the last non-final step text (OutputCollector.preserveLastText).

Reviewed by Cursor Bugbot for commit be50cc0. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes runs hung past their time budget when provider streams stall or ignore cancellation, and preserves partial findings from interrupted work instead of discarding them.

  • Wraps LLM.stream() in abortableStream so provider setup, reads, and iterator cleanup race the abort signal and cannot hang the session.
  • Hard aborts now commit partial text, tool results, and child task findings before publishing idle status; interrupted task outputs are labelled incomplete and recover committed child findings.
  • Budget-finalization failures now append the last unfinished assistant text under Partial assistant response (not finalized) instead of emitting a note alone.
  • Cancellation during task metadata publication aborts before starting child work; batched tools now await asynchronous metadata publication.

No migration steps. Deferred: recovery after compaction only sees the original prompt lineage, batched tasks still publish metadata on the outer batch part, and a finalization stall before the first step leaves unfinished text without a warning note.

Written for commit be50cc0. Summary will update on new commits.

View guided diff Turn on auto-fix

- add `abortableStream` so provider setup and each read race the abort signal, independent of provider cooperation
- hard abort now commits partial text and task results before publishing idle
- `task` tool recovers committed child findings (labelled incomplete) after cancellation
- budget-finalization fallback notes keep the last unfinished assistant text

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 16a9c1c6-4910-4bab-af98-2ecf652b78ff

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor

cursor Bot commented Oct 15, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: dfbd88f0-7f2e-48ef-bbb1-940ca53d1753)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-16T03:52:07.997150Z be50cc0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd4b8eb720

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/cli/cmd/run-output.ts
Comment thread packages/opencode/src/session/abortable-stream.ts
Comment thread packages/opencode/src/tool/task.ts
Comment thread packages/opencode/src/tool/task.ts
Comment thread packages/opencode/src/tool/batch.ts
Comment thread packages/opencode/src/cli/cmd/run.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 13 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread packages/opencode/src/session/task-output.ts
Comment thread packages/opencode/src/session/abortable-stream.ts
Comment thread packages/opencode/src/cli/cmd/run-output.ts
Comment thread packages/opencode/src/session/processor.ts
Comment thread packages/opencode/src/session/task-output.ts
@kilo-code-bot

kilo-code-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 5
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/opencode/src/session/abortable-stream.ts 8 Unhandled promise rejection when pending (iterator.next()) rejects after losing Promise.race to signal abort
packages/opencode/src/tool/task.ts 249 Aborted task with no child output resolves SessionPrompt.prompt with empty parts and returns a completed empty <task_result> instead of aborting
packages/opencode/src/tool/task.ts 25 Nested altimate_change markers inside the outer 18–40 block
packages/opencode/src/tool/batch.ts 31 Nested altimate_change markers inside toEffectContext (17–40)
packages/opencode/src/cli/cmd/run.ts 1988 Nested altimate_change markers inside the outer 1915–1997 block
Files Reviewed (13 files)
  • packages/opencode/src/altimate/tool-zod-compat.ts - 0 issues
  • packages/opencode/src/cli/cmd/run-output.ts - 0 issues
  • packages/opencode/src/cli/cmd/run.ts - 1 issue
  • packages/opencode/src/session/abortable-stream.ts - 1 issue
  • packages/opencode/src/session/processor.ts - 0 issues
  • packages/opencode/src/session/task-output.ts - 0 issues
  • packages/opencode/src/tool/batch.ts - 1 issue
  • packages/opencode/src/tool/task.ts - 2 issues
  • packages/opencode/test/cli/cmd/run-output.test.ts - 0 issues
  • packages/opencode/test/cli/run/budget-finalization.test.ts - 0 issues
  • packages/opencode/test/session/abortable-stream.test.ts - 0 issues
  • packages/opencode/test/session/processor-effect.test.ts - 0 issues
  • packages/opencode/test/tool/task.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by gemini-4-argon · Input: 140K · Output: 6.1K · Cached: 1.1M

Review guidance: REVIEW.md from base branch feat/analyst-harness-dab-2026-10

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cursor

cursor Bot commented Oct 16, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: ecf9fe27-0c7b-44c4-90ef-ee596d20e3ef)

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@anandgupta42
anandgupta42 merged commit 5891314 into feat/analyst-harness-dab-2026-10 Oct 16, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant