perf(server): OpenCode 2 stops writing unchanged session status updates #16775
main fromrefs/pull/16775/head·merged by juliusmarminge View on GitHubProblem#
OpenCode 2 shares one server session across every thread on an instance, and ProviderSessionManager persists each provider_session.updated once per attached thread. setSessionStatus emitted on every turn start, finish and request change, even when the status didn't change. With ~80 threads attached, one running to running call wrote ~80 events that differed only in updatedAt.
On one machine running OpenCode 2 all day, 348k of that day's 384k session events (91%) were repeats like this, about 0.9 GB of payload before indexes.
Change#
setSessionStatus now returns early when status and lastError haven't changed. Those are the only fields it sets besides updatedAt, so every distinct state still gets written, including error changes and a return to an earlier status. updatedAt now only moves on a real change. Nothing treats it as a heartbeat: ProviderSwitchService uses it to pick the newest session, and the OpenCode 2 session id is stable per instance, so that pick doesn't change. Idle tracking reads raw adapter events, not this timestamp.
This PR also used to cache the last node per block in the adapter. #19429 now skips unchanged node.updated writes in ProviderEventIngestor for every adapter, so I removed that part and its test.
Scope and approval#
Theo asked for this shape in this comment: keep the session change, drop the node cache, rebase. Related to #16428, which is the same kind of growth from the ACP adapter.
Verification#
- New test in
OpenCode2AdapterV2.test.tsruns turns on two sessions on the same instance, so the second turn starts and the first one ends while the shared session stays running. It asserts the session reportsrunningandreadyonce each. On main it gets four updates instead of two and fails. - All 100 tests in that file pass. Typecheck in
packages/provider-opencode,vp fmt --checkandvp linton the touched dirs are clean. - The 91% figure comes from comparing each session event in that day's event log to the previous one on the same stream, ignoring
updatedAt. I didn't re-measure a live instance after the rebase.
Built with Claude Opus 5.5 in T3 Code (OpenCode harness). Reviewed with GPT-6 Astra.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
6dd71aaMacroscope's review found this PR approvable — The adapter now skips redundant session-status persistence while retaining every meaningful status or error transition. The focused regression test covers concurrent threads sharing one OpenCode session, and no schema, default, security, or static-analysis changes are involved.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4f497974-8f7d-4357-ad18-92423b0a865c
📥 Commits
-
Reviewing files that changed from the base of the PR and between 5a4155a760b988d0403c86863ad32e051607a031 and 6dd71aaa38ec0eb1f04add42c782fb1155df625b.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
ef6ec335-35c1-42a3-b8cf-b40e588eec41
📥 Commits
-
Reviewing files that changed from the base of the PR and between b5288bad19a790aa8f5c24df19312386663f4317 and 5a4155a760b988d0403c86863ad32e051607a031.
📒 Files selected for processing (2)
-
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.tspackages/provider-opencode/src/server/v2/adapter.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
The OpenCode adapter now skips node updates when the serialized node state is unchanged. Tests cover reasoning text and status updates, plus shared-session status updates across overlapping turns.
Changes: Adapter update deduplication
Layer / File(s) Summary Node update deduplication
packages/provider-opencode/src/server/v2/adapter.ts,apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.tsActive turns cache emitted node state. The adapter skips unchanged node updates and clears the cached state for subagent nodes before subsequent updates. A replay test checks reasoning statuses and text deltas. Session status deduplication
packages/provider-opencode/src/server/v2/adapter.ts,apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.tsA comment describes the existing unchanged-status guard. A test checks that two threads sharing a session emit runningand thenready, without a duplicate update.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
5a415-
No merge-blocking issue was identified with the OpenCode update deduplication change.
Security Architecture Review
-
Security architecture risk: 🔵 Low · up to
5a415The change is narrowly scoped and preserves normal lifecycle transitions and streaming content. No new privilege or access boundary was identified. Interrupted delivery and retry behavior remain insufficiently established to classify the change as minimal risk.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The changed persistence behavior is bounded to an OpenCode runtime and its attached threads, including their execution-node histories. The full diff does not introduce a new external caller, credential authority, network endpoint or deployment configuration.
Trust Boundaries and Controls
- observed — Provider-originated node events continue through existing run/child-thread ownership routing. Shared-session persistence verifies the current runtime identity before writing to attached threads. Deduplication changes event frequency without changing these identity checks or granting tool authority.
Resilience and Maintainability Implications
- inferred — Interrupted publication remains a proof gap, not an established vulnerability: the cache is mutated before queue acceptance, and reconciliation can be interrupted and retried on a surviving turn. Counterevidence is the unbounded queue, serialized event processing, and queue closure only after terminal failure handling; interruption semantics were not available to resolve the gap.
- observed — Known idle-release controls use busy-turn membership, runtime identity, activity generations and pending-background-work checks rather than provider-session updatedAt. Streaming item events still provide activity signals. This is counterevidence to timestamp suppression weakening session-release controls, but does not establish every timestamp consumer's semantics.
-
Pre-merge checks:
4-
Passed checks: 4 passed-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly identifies the main change: preventing unchanged OpenCode 2 session status updates. It uses a concise conventional-commit format. Description check The description covers the problem, implementation, scope and approval, verification results, limitations, and agent attribution. It explains the affected behavior and includes focused test details.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
The node half of this PR is now on
main. #19429 skips anynode.updatedthat matches the stored node. The check is inProviderEventIngestor, so it covers every adapter, including theemitTextandemitToolrepeats here.The session-status half is still needed, because #19429 does not touch
provider_session.updated. Please remove the node cache from the OpenCode 2 adapter, keep the session change, and rebase.Abdullah1738(GitHub profile, opens in a new tab) changed the title
Done. Dropped the node cache and its test, kept the session status guard, rebased on main. Updated the title and description to match.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this73e5d5b
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed