Skip to content

fix(session): settle busy status after stream close#14

Merged
CreatorGhost merged 1 commit into
devfrom
session-settle-status
Jul 12, 2026
Merged

fix(session): settle busy status after stream close#14
CreatorGhost merged 1 commit into
devfrom
session-settle-status

Conversation

@CreatorGhost

@CreatorGhost CreatorGhost commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Port of upstream anomalyco/opencode#36002.

Adds a settle() transition to SessionRunState and calls it when the prompt SSE stream closes, so sessions no longer report busy forever when a stream terminates without a final status event.

Verified: bun test test/server/httpapi-sdk.test.ts (19 pass), bun test test/session/prompt.test.ts (55 pass; the 1 failure — 'failed subtask preserves metadata on error tool state' — is pre-existing on dev, confirmed by running the same test without this change), bun typecheck clean. Applied cleanly.

Summary by CodeRabbit

  • Bug Fixes

    • Session status now settles correctly after a prompt response finishes streaming.
    • Sessions no longer remain incorrectly marked as active or busy after completion.
    • Status checks now reflect the finalized session state immediately after prompting.
  • Tests

    • Added coverage to verify prompt completion and session status finalization.
    • Updated session lifecycle tests to validate proper state transitions.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1f7735b4-755c-4ffe-96c0-7f8eee1be2f0

📥 Commits

Reviewing files that changed from the base of the PR and between f862420 and f9a203d.

📒 Files selected for processing (4)
  • packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts
  • packages/opencode/src/session/run-state.ts
  • packages/opencode/test/server/httpapi-sdk.test.ts
  • packages/opencode/test/session/prompt.test.ts

📝 Walkthrough

Walkthrough

Prompt response streams now settle session run state after completion unless noReply is enabled. The run-state service exposes settlement logic, and HTTP and session prompt tests verify the resulting status behavior.

Changes

Session settlement

Layer / File(s) Summary
Run-state settlement operation
packages/opencode/src/session/run-state.ts, packages/opencode/test/session/prompt.test.ts
Adds SessionRunState.settle, wires it into the service, and updates prompt status testing to invoke the settlement transition.
Prompt stream settlement integration
packages/opencode/src/server/routes/instance/httpapi/handlers/session.ts, packages/opencode/test/server/httpapi-sdk.test.ts
Wraps completed prompt streams with conditional settlement and verifies that the session status entry is cleared after streaming.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SessionHttpApi.prompt
  participant ResponseStream
  participant SessionRunState
  participant SessionStatus
  Client->>SessionHttpApi.prompt: Submit prompt
  SessionHttpApi.prompt->>ResponseStream: Stream generated message
  ResponseStream-->>SessionHttpApi.prompt: Complete stream
  SessionHttpApi.prompt->>SessionRunState: settle(sessionID)
  SessionRunState->>SessionStatus: Set status to idle or remove runner state
  SessionHttpApi.prompt-->>Client: Return HTTP response
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main fix and verification, but it omits required template sections like issue link, change type, screenshots, and checklist. Add the missing template sections: issue reference, type of change, detailed fix explanation, verification steps, screenshots if needed, and checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the core change: settling session busy state when the prompt stream closes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch session-settle-status

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@CreatorGhost CreatorGhost force-pushed the session-settle-status branch from a0b24bc to f9a203d Compare July 12, 2026 06:56
@CreatorGhost

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CreatorGhost

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@CreatorGhost CreatorGhost merged commit 9f48b36 into dev Jul 12, 2026
5 of 7 checks passed
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