Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): delegates finish when their leftover work settles, and Grok commands stop holding runs open #22709

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

Problem

Delegates could stay "running" in the parent forever, and the parent agent was never woken with their result.

  • #17512, #19612: a child's run ended while it still had background commands or its own subagents running. The parent's task waits for that work, which is correct. But the task was only re-checked when a child run ended. When the leftover work settled later, nothing checked it again until a server restart. #19612 is the same thing one level deeper: an interrupted child whose own delegated tasks settled after its run.
  • #15888: Grok children could hold their run open forever when Grok never sent task_completed for a background command. This happened when a TaskOutput poll returned a call-<uuid>-<n> task id, or when the command ended through KillTask.

Fix

  • Server: a new listener re-checks a delegated child when its leftover work settles. That means a subagent.updated that is no longer active, or a provider thread whose background roster empties after it was seen non-empty. The re-check is the same finalizeAppOwnedSubagent that runs at run end, under the parent's lock. It writes the result and wakes the parent once.
  • Grok: @SouthCarpet's #22329 and #22515, cherry-picked with authorship kept:
    • TaskOutput results with call- task ids close the command.
    • A command result in a mixed-id poll no longer completes an unrelated subagent.
    • KillTask results close the command, and the adapter keeps that completion so BackgroundTaskStarted cannot reopen it.
    • One extra commit inlines the retain helper, drops 3 tests that already pass on main, and drops 2 test timeouts.

#19938 fixed the Grok path people hit most (task_completed arriving before the prompt settles). These are the fallbacks for when Grok never sends task_completed.

Not in this PR: the missing Grok result text (#22341), MultiResult polls for commands, and the running-subagent hold (#17779).

Proof

Each new test fails on main. The two DelegatedCompletionDelivery cases (background command, nested subagent) stay stuck until timeout on main and pass with the fix. The KillTask adapter cases hang without the adapter change. The call-id cases time out or return nothing on main. 190 delegation tests and 120 Grok/ACP tests pass. Typecheck is clean in server, provider-acp and provider-grok.

Fixes #17512. Fixes #19612. Fixes #15888. Supersedes #22329 and #22515 (thanks @SouthCarpet).

Reviewed with sol-loop: 2 rounds with GPT-6.1-Sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code, running in T3 Code. Grok commits by @SouthCarpet.

🤖 Generated with Claude Code

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

      Approvability

      Verdict: Approved at 77ddef9

      Macroscope's review found this PR approvable — This is a targeted bug fix that releases delegated runs when previously missed background or nested work settles and improves Grok command completion parsing. Production behavior changes are confined to existing orchestration/provider lifecycle paths and are covered by focused unit and live integration tests.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    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 wire5.0 KiB4.9 KiB−23 B (−0.5%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB−23 B (−1.9%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.8 KiB−41 B (−0.2%)29.3 KiB✅
      CodexLive turn messages21−1 (−50.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: a93b03c · PR result: 77ddef9 · 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: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

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

    3. Review in Change Stack →
      ✨ Finishing Touches: 💡 1
      🛠️ Fix failing CI checks: 💡
      • Commit to this branch
      • Create a new PR
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.