Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): Grok's reply to a finished background command opens its own run #14488

Mergedjuliusmarmingemerged 3 commits intot3code/codex-turn-mapping fromrefs/pull/14488/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

When Grok ran a background command, its later reply to the finished command ("the command printed BG_DONE") streamed into the original run, and no continuation run opened. Claude and Codex show that reply as its own continuation run, and so did Grok's own fixture.

Grok 1.0.41 and 1.0.44 send the same notifications for this: task_backgrounded, then task_completed, then a reply turn whose frames carry a task-completed-* prompt id. Only the timing differs. 1.0.41 waited about a minute after task_completed before replying. By then T3's 3s finish debounce had already settled the root run, so the reply took the wake path. 1.0.44 replies about 2s after task_completed, inside that debounce, while the root run is still held open for the command, so those frames went into the held run.

Now, when a root turn is being held for background work, frames with a Grok task-completed-* prompt id first settle the held root turn (or wait in the wake buffer if work is still pending). They then take the post-settle wake path, which opens the continuation run. Detection is a new optional flavor hook, isProviderWakeNotification, and only the Grok adapter sets it. It depends on the prompt id, not on timing, so both the slow and the fast case take the same path.

Tests

  • grok_background_bash (Grok 1.0.41, slow reply) is unchanged and still passes.
  • New grok_background_bash_fast_wake: the same prompt recorded from Grok 1.0.44, replayed without the wake gate so the reply lands inside the debounce as it does live. It reuses grok_background_bash's assertions; only the command description Grok picked differs. Without the fix, run 2 never opens and the test times out; with it, the test passes.
  • All replay fixtures and the ACP/Grok/xAI unit tests pass, and the server typecheck is clean.

Also carries a follow-up to #14487 (merged before this review landed): the xAI prompt failure no longer puts Grok's raw agentResult into AcpRequestError.errorMessage. That message is now fixed text, Grok's text rides only on the cause (XAiPromptError), and the Grok adapter reads it from there so makeProviderFailure redacts and bounds it. Users still see the same message.

Done by Claude Opus 5.5 in Claude Code (via T3 Code).

🤖 Generated with Claude Code

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

      Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.

    2. juliusmarminge added labelsmacroscope-review

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

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

      Approvability

      Verdict: Approved at ce1d8fa

      Macroscope's review found this PR approvable — This is a targeted Grok orchestration bug fix that routes background-task completion replies into continuation runs without changing other providers. It includes a focused replay regression fixture and no product-default, schema, deployment, security, or static-analysis changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—4.9 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.7 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—20.4 KiB—29.3 KiB✅
      CodexLive turn messages—2—8✅
      ClaudeTotal thread wire—4.9 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.7 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—20.8 KiB—29.3 KiB✅
      ClaudeLive turn messages—2—8✅

      Baseline: unavailable · PR result: ce1d8fa · 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: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

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

    6. juliusmarminge closed this

    7. juliusmarminge reopened this

    8. juliusmarminge merged this9449473

    9. juliusmarminge closed this

Sign in to join this conversation.