Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

MergedAbdullah1738(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/16775/headmerged by juliusmarminge View on GitHub

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.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      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](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 5a4155a760b988d0403c86863ad32e051607a031 and 6dd71aaa38ec0eb1f04add42c782fb1155df625b.

      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 b5288bad19a790aa8f5c24df19312386663f4317 and 5a4155a760b988d0403c86863ad32e051607a031.

      📒 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 nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly identifies the main change: preventing unchanged OpenCode 2 session status updates. It uses a concise conventional-commit format.
      Description checkPassedThe 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.
    4. juliusmarminge added labelsmacroscope-review

    5. 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.

    6. Done. Dropped the node cache and its test, kept the session status guard, rebased on main. Updated the title and description to match.

    7. juliusmarminge merged this73e5d5b

    8. juliusmarminge closed this

Sign in to join this conversation.