Skip to content

perf(server): OpenCode 2 stops writing unchanged session status updates - #16775

Open
Abdullah1738 wants to merge 1 commit into
pingdotgg:mainfrom
Abdullah1738:perf/opencode2-skip-unchanged-updates
Open

Abdullah1738 wants to merge 1 commit into
pingdotgg:mainfrom
Abdullah1738:perf/opencode2-skip-unchanged-updates

Conversation

@Abdullah1738

@Abdullah1738 Abdullah1738 commented Oct 7, 2026 •

Copy link
Copy Markdown

Problem

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.ts runs 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 reports running and ready once 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 --check and vp lint on 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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Oct 7, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 7, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 6dd71aa

Macroscope'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.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 5a4155a and 6dd71aa.

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

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 b5288ba and 5a4155a.

📒 Files selected for processing (2)
  • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
  • packages/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.ts
Active 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.ts
A comment describes the existing unchanged-status guard. A test checks that two threads sharing a session emit running and then ready, 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 5a415

The 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: Passed 4
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly identifies the main change: preventing unchanged OpenCode 2 session status updates. It uses a concise conventional-commit format.
Description check Passed 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

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

@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 11, 2026 — with ChatGPT Codex Connector
@macroscopeapp
macroscopeapp Bot dismissed their stale review October 11, 2026 06:14

Dismissing prior approval to re-evaluate b5288ba

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Oct 11, 2026
@t3dotgg

t3dotgg commented Oct 14, 2026

Copy link
Copy Markdown
Member

Note

🤖 Claude Opus 5.5 responding on behalf of Theo

The node half of this PR is now on main. #19429 skips any node.updated that matches the stored node. The check is in ProviderEventIngestor, so it covers every adapter, including the emitText and emitTool repeats 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
Abdullah1738 force-pushed the perf/opencode2-skip-unchanged-updates branch from 5a4155a to 6dd71aa Compare October 14, 2026 14:30
@Abdullah1738 Abdullah1738 changed the title perf(server): OpenCode 2 stops writing unchanged session and node updates perf(server): OpenCode 2 stops writing unchanged session status updates Oct 14, 2026
@Abdullah1738

Copy link
Copy Markdown
Author

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 github-actions Bot added size:XS 0-9 changed lines (additions + deletions). and removed size:S 10-29 changed lines (additions + deletions). labels Oct 14, 2026
@macroscopeapp
macroscopeapp Bot dismissed their stale review October 14, 2026 14:31

Dismissing prior approval to re-evaluate 6dd71aa

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants