Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): unblock OpenCode approvals and stop #9653

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/9653/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

OpenCode could show an Approval badge with no controls, appear stuck on TodoWrite, and keep showing a running turn after Stop.

This fixes the approval and turn lifecycle across the server, web, desktop, and mobile:

  • Show every permission, including old saved requests. Keep failed replies retryable and close completed requests even when reply events are lost.
  • Keep OpenCode output pipes drained and automatic replies out of the event loop. Handle disconnects, reconnects, and confirmed stops without stale requests or running states.
  • Show native task progress and command results. Do not treat TodoWrite or approval history as file edits or executed commands.
  • Label OpenCode's shared permission scope as Allow for workspace.

Verified with 576 focused tests, scoped typechecks and lint, and the real OpenCode 1.18.23 CLI using an isolated local test model. The client pass covered approvals, denial, questions, Stop, and follow-up prompts. Stop cleared the running state and closed the model connection in 343 ms in this test.

BeforeAfter
Approval badge without controlsActionable OpenCode approval

Stop recording

Created with GPT-6 Astra (preview) in Codex.

Fixes #4795 Fixes #7113 Fixes #5760


Note

Medium Risk Touches approval projection, OpenCode session/event-pump lifecycle, and permission policy; behavior is heavily tested but errors could affect badges, stop, or what runs without a prompt.

Overview Fixes broken OpenCode Approval UX (badge with no controls), stuck turns after Stop, and misleading progress when TodoWrite or approval events were treated like real tool work.

Clients (derivePendingApprovals on web, mobile, and related tests) now surface legacy OpenCode requests even when the kind is unknown (default command), while excluding tool_user_input and auth_tokens_refresh from the approval queue.

Projections re-open pending approvals when a user’s reply was optimistically cleared but the provider reports a non-stale provider.approval.respond.failed, unless another client already resolved the request.

Runtime ingestion treats turn.aborted like other terminal turn events: interrupted session state, stricter guards so late aborts cannot stomp a newer turn, and assistant text finalized on abort.

OpenCode adapter is the bulk of the change: every permission maps to an actionable approval (with Allow once / Allow for workspace / Deny); full-access auto-replies run off the event pump with timeout and fallback to the dialog; reconnect closes missing pending requests and warns on SSE loss; Stop clears open permissions/questions; HTTP replies are idempotent with locally emitted terminal events; todo.updated drives turn.plan.updated only for the active turn; tool lifecycle payloads include command/output details.

Permission rules in supervised modes auto-allow workspace reads, search, skills, and todowrite, while keeping .env* asks; acceptAlways maps to OpenCode always.

OpenCode server startup keeps draining stdout/stderr so buffers cannot block requests. Work log presentation stops counting approval activities as executed tools. User docs describe approvals, progress, stop cleanup, and reconnect.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a9b37fc0a41e370ed3434927a158382a30d8cc0a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Fix OpenCode approval lifecycle, stop cleanup, and turn.aborted ingestion

  • Reworks OpenCodeAdapter.ts so pending permissions and questions are closed or recovered when a turn completes, errors, or is aborted; adds a bounded, cancellable pending-request recovery loop and openPermissionRequest dialog helper with allow-once, workspace-allow, and deny decisions
  • Adds 10-second timeouts and abort-signal propagation to session lookups, permission/question replies, auto-replies, and inventory loads throughout the adapter and opencodeRuntime.ts
  • Defaults unrecognized or absent OpenCode request kinds to command approvals in session-logic.ts and threadActivity.ts, and excludes tool_user_input and auth_tokens_refresh from pending approvals
  • Restores a resolved approval row to pending after a non-terminal provider.approval.respond.failed in ProjectionPipeline.ts
  • Settles accepted turn.aborted events as interrupted in ProviderRuntimeIngestion.ts, clearing the active turn, error, and finalizing assistant text; ignores late or untargeted aborts
  • Allows workspace reads, searches, LSP, skill use, and todowrite without approval in non-full-access modes, while keeping environment-file reads, commands, network, and external-directory access as ask operations
  • Maps acceptAlways decisions to OpenCode's always reply and caps server startup output at 64 KiB per stream
  • Risk: mapPermissionToRequestType no longer returns unknown; all unrecognized permissions now map to command-execution approval. toToolLifecycleItemType now classifies todowrite/todoread as dynamic tool calls instead of file-change. Reconnect and abort paths emit synthetic terminal events for pending requests, which out-of-tree consumers reading raw provider events may not expect.
Macroscope summarized a9b37fc.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.6 KiB13.5 KiB−52 B (−0.4%)15.1 KiB✅
      CodexThread snapshot wire7.0 KiB7.0 KiB−3 B (−0.0%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.5 KiB−49 B (−0.7%)7.8 KiB✅
      CodexLive turn WebSocket decoded57.1 KiB57.0 KiB−88 B (−0.2%)66.4 KiB✅
      CodexLive turn messages108−2 (−20.0%)21✅
      ClaudeTotal thread wire13.6 KiB13.6 KiB−21 B (−0.2%)15.1 KiB✅
      ClaudeThread snapshot wire7.0 KiB7.0 KiB−6 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB−15 B (−0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.9 KiB57.9 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages10100 (0.0%)21✅

      Baseline: d5b9410 · PR result: a9b37fc · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 113.8 KiB
      • Claude decoded thread snapshot: 114.5 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/3c1884eeada718689944248489a10db6389d7a0a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts#L1643

      A late turn.aborted for an older turn overwrites a ready session with interrupted when activeTurnId is already null. The shared terminal fallback accepts any non-null turnId; restrict that fallback to turn.completed so aborts without an active turn are rejected.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts around line 1643:
      
      A late `turn.aborted` for an older turn overwrites a `ready` session with `interrupted` when `activeTurnId` is already `null`. The shared terminal fallback accepts any non-null `turnId`; restrict that fallback to `turn.completed` so aborts without an active turn are rejected.
    4. Note

      🤖 GPT-6 Astra (preview) responding on behalf of Theo

      Fixed in e8675f12a5. Aborts now require a matching active turn. The test covers a late abort after a newer turn completes and while another turn is starting. All 55 ingestion tests and the server typecheck pass.

    5. Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e8675f12a568b6f49977da7460ad47b730135529. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR makes broad production changes to OpenCode approvals, permission defaults, reconnect/stop lifecycle, turn state, and progress handling across the server and clients. The changed default permission behavior and cross-layer asynchronous runtime logic warrant human review despite the extensive test coverage.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).

Sign in to join this conversation.