fix(server): prevent premature OpenCode turn completion - #10805
fix(server): prevent premature OpenCode turn completion#10805NaveDanan wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a narrowly scoped OpenCode server bug fix that prevents recovered turns from being marked complete before delegated work finishes. The production change is confined to existing admission/reconciliation logic and is covered by focused regression tests, with no schema, deployment, security, billing, default, or static-analysis configuration impact. You can add or adjust custom eligibility rules. Learn more. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2841bac938
ℹ️ 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".
| context.promptAdmission = undefined; | ||
| context.awaitingBusyAfterInterruption = false; | ||
| return; |
There was a problem hiding this comment.
Preserve completion recovery after clearing admission
When server.connected arrives while prompt submission is still settling, the reconnect handler sees promptAdmission and therefore does not start idle reconciliation. If recovery later finds the persisted user message after OpenCode completed during the outage, this branch clears the admission and returns without polling or scheduling reconciliation; because the idle event was missed and is not replayed, activeTurnId and the session remain running indefinitely. Keep a completion-recovery path armed after clearing this state, particularly for reconnect-before-acceptance flows.
AGENTS.md reference: AGENTS.md:L19-L21
Useful? React with 👍 / 👎.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe OpenCode adapter changes prompt admission recovery to use idle reconciliation and message-history validation. Tests cover reconnect recovery, delegated child activity, compaction, pending status requests, lookup failures, and cancellation races. ChangesOpenCode turn recovery
Priority: ⬇️ Low Estimated code review effort: 4 (Complex) | ~45 minutes Merge Risk: ⚪ Minimal · up to The change keeps recovered OpenCode turns active until valid idle reconciliation and adds broad race coverage. No actionable merge-blocking risk is currently established. Sequence Diagram(s)sequenceDiagram
participant OpenCodeAdapter
participant OpenCodeSession
participant RuntimeState
OpenCodeAdapter->>OpenCodeSession: recover prompt admission
OpenCodeAdapter->>OpenCodeSession: poll recent messages
OpenCodeSession-->>OpenCodeAdapter: latest assistant reply with parentID
OpenCodeAdapter->>RuntimeState: schedule idle reconciliation
RuntimeState-->>OpenCodeAdapter: complete the matching turn
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Bugbot is paused — on-demand spend limit reachedBugbot uses usage-based billing for this team and has hit its on-demand spend limit. A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue. |
|
Note 🤖 GPT-6 Astra responding on behalf of NaveDanan Codex review caught a real reconnect regression in this PR. While testing it, I also found a related bug that was already there before this PR. Both could leave a finished thread showing as running. Both are now fixed, with regression tests added. All 267 tests and the targeted checks pass. |
Persisted OpenCode prompts could be marked complete while their session loop had not started or delegated work was still running. Keep recovered prompts active until an idle event confirms completion.
When reconnect happens before prompt acceptance, retain completion recovery after admission clears. A reply tied to the current prompt establishes that processing started before checking idle status. Retry unavailable message history with capped backoff, and reject stale responses after steering, interruption, or a new turn.
Validation: 267 tests passed across nine OpenCode and related provider test files, including delayed work, reconnect ordering, lookup failures, steering, interruption, shutdown, and replacement turns. Targeted lint, formatting, and server typecheck passed. Independent standards and behavior reviews found no remaining actionable findings.
Model: GPT-6. Harness: Codex.
Summary by CodeRabbit