Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(grok): close background commands from KillTask results #22515

ClosedSouthCarpet(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/22515/headopened View on GitHub

Problem

A Grok background command can stay running after a completed kill call when no separate task-completion notification arrives. The fallback misses the KillTask result type and request variant. The command can then hold the turn open after the reply ends.

Change

Recognize rawOutput.type: "KillTask" and rawInput.variant: "KillTask" while keeping legacy recognition. For the new shapes, reject only an explicit failed outcome and leave the command unchanged. The legacy title and kill variant keep base behavior for every outcome, including when KillTask fields are present.

Retain the terminal result in the existing background-command completion state. This stops a stored BackgroundTaskStarted acknowledgement from restoring running when any background completion result has no output. Preserve any earlier terminal status and output.

Add parser and ACP adapter regression tests for the reported shapes, a failed outcome, legacy outcome compatibility, native-child parser compatibility, and preservation of a known failed result. The ACP peer sends each kill shape without a task-completion notification and leaves its prompt RPC open. The adapter tests check command termination, one completed turn, and the visible kill tool.

Scope and approval

This is a focused fix for triaged issue #15888. Thanks to @filipproch, @al0x99, @paralyses2193, @wookiist and @EgerDev for the reports, and to @3xcalibur-tech for the live checks.

A live run on a build at d36b7da, reported in #15888 by @3xcalibur-tech, closed both killed and already_exited scenarios because Grok also sent task_completed. This change provides the fallback when that notification is missing; the ACP peer tests prove that case, and the live Grok run did not test it.

The change keeps early task_completed handling, native subagent lifecycle policy, MultiResult parsing, and the call-id TaskOutput parser in #22329 unchanged. The subagent work in #17779 and #21094 remains separate. Only Grok currently supplies the background-completion hook used by the shared adapter change.

Verification

To reproduce the baseline with the new tests, start from a clean working tree containing this change. Write the two production modules from base commit d36b7da, run the KillTask tests, then restore the files from HEAD:

git show d36b7da:packages/provider-grok/src/server/xaiAcpExtension.ts > packages/provider-grok/src/server/xaiAcpExtension.ts
git show d36b7da:packages/provider-acp/src/server/adapter.ts > packages/provider-acp/src/server/adapter.ts
vp test run packages/provider-grok/src/server/xaiAcpExtension.test.ts apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts -t KillTask --maxWorkers 1
git show HEAD:packages/provider-grok/src/server/xaiAcpExtension.ts > packages/provider-grok/src/server/xaiAcpExtension.ts
git show HEAD:packages/provider-acp/src/server/adapter.ts > packages/provider-acp/src/server/adapter.ts

The same baseline was checked in a separate worktree at d36b7da, with only the new test files and ACP mock agent copied in. Results:

AssertionError: expected [] to deeply equal [ { taskId: 'call-bg-1', …(2) } ]
TimeoutError: Operation timed out after '15s'
Tests  8 failed | 7 passed | 187 skipped (202)

Both legacy-title tests use variant: "Kill" and outcome: "failed", once without and once with rawOutput.type: "KillTask". Both pass on base and on this change. A separate base run selects them alone: 2 passed, 65 skipped.

On this change:

vp test run packages/provider-grok/src/server/xaiAcpExtension.test.ts apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts -t KillTask --maxWorkers 1
vp test run packages/provider-grok/src/server apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts --maxWorkers 1

The KillTask run passes all 15 selected tests. The wider run passes 284 tests, with 8 skipped.

All three scoped typechecks exit 0:

node node_modules/tsc-rs/bin/tsc-rs --noEmit --project packages/provider-grok/tsconfig.json
node node_modules/tsc-rs/bin/tsc-rs --noEmit --project packages/provider-acp/tsconfig.json
node node_modules/tsc-rs/bin/tsc-rs --noEmit --project apps/server/tsconfig.json

Changed-file lint exits 0 with four warnings on unchanged lines. Strict production complexity lint reports the same 21 existing violations as the base, with none in the changed functions. Changed-file formatting and git diff --check pass. The #22329 patch passes git apply --check.

These checks use the real Grok adapter with an ACP protocol peer. Live Grok inference and desktop/mobile builds were not checked. No CI run was triggered.

Created with GPT-6.1 Sol in Codex. Verified with Claude Sonnet 5.5 and Claude Opus 5.5 in T3 Code.

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

    2. Approvability

      Verdict: Approved at ab243f1

      Macroscope's review found this PR approvable — This is a narrowly scoped Grok compatibility fix that recognizes structured KillTask results and prevents completed background commands from being reopened as running. It includes focused parser and end-to-end regression coverage, with no product-default, deployment, schema, or static-analysis changes.

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

      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: 21269176-90d3-41ca-ad6a-6625f60a95b6
      📥 Commits

      Reviewing files that changed from the base of the PR and between ca140c435f38612656dd655fc42e2f78efbfb4c9 and ab243f18d01b58ce9a3b6513b8c5b9177188ea21.

      📒 Files selected for processing: 5
      • apps/server/scripts/acp-mock-agent.ts
      • apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
      • packages/provider-acp/src/server/adapter.ts
      • packages/provider-grok/src/server/xaiAcpExtension.test.ts
      • packages/provider-grok/src/server/xaiAcpExtension.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 Grok ACP extension now recognizes structured KillTask calls and uses successful outcomes to mark targeted background tasks complete. The ACP adapter preserves terminal command status and output during task hydration. Mock scenarios and regression tests cover completion shapes and failure cases.

      Changes: Grok KillTask completion

      Layer / File(s)Summary
      Recognize KillTask completion
      packages/provider-grok/src/server/xaiAcpExtension.ts, packages/provider-grok/src/server/xaiAcpExtension.test.ts
      The extension recognizes structured KillTask outputs and variants. It ignores explicit failed outcomes, while legacy kill calls retain their existing behavior. Tests cover background tasks and native child targets.
      Retain terminal command results
      packages/provider-acp/src/server/adapter.ts
      The adapter retains terminal command status and output for registered background tasks during hydration, preventing a later running update from reopening a completed command.
      Exercise completion scenarios
      apps/server/scripts/acp-mock-agent.ts, apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
      The mock agent emits background-task and KillTask notifications for configured shapes. A live parameterized test checks terminal events, command results, and KillTask frame retention.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge, stienswout

      Merge Risk: ⚪ Minimal · up to ab243

      The reported mixed-shape behavior preserves the tested legacy contract. No actionable merge-blocking risk remains after normal checks.

      Architecture risk: 🟡 Medium · up to ab243

      The change affects 3 systems.

      Changed systems: apps/server, packages/provider-acp, packages/provider-grok

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — apps/server (service) was modified; 2 changed files map to changed impact.
      • observed — packages/provider-acp (library) was modified; 1 changed file maps to changed impact.
      • observed — packages/provider-grok (library) was modified; 2 changed files map to changed impact.

      Before / after behavior

      • observed — Modified behavior in apps/server/scripts/acp-mock-agent.ts: Added the grokKillTaskShape environment-variable configuration used to select the Grok kill-task mock scenario.
      • observed — Modified behavior in apps/server/scripts/acp-mock-agent.ts: Added emitGrokKillTaskScenario, which emits background-task start, optional known-failure completion, kill-task completion, and _x.ai/session/prompt_complete notifications. The outcome is already_exited for already_exited or known_failure; otherwise it is killed, with shape-specific omission of the kill variant or raw output.
      • observed — Modified behavior in apps/server/scripts/acp-mock-agent.ts: When grokKillTaskShape is set during prompt handling, invokes the kill-task scenario with the request session and prompt ID, then leaves the prompt and peer alive indefinitely.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts: Added a parameterized live Grok KillTask test covering output-only, variant-only, killed, already-exited, and known-failure results. It configures the mock runtime per shape, waits up to 15 seconds for terminal events, requires one completed turn, checks no subagent projection, and validates command status/output plus retention of the KillTask frame.

      Reliability and maintainability

      • inferred — Risk-relevant change factors for apps/server: blast_radius_1; direct_dependents_1
      • inferred — Risk-relevant change factors for packages/provider-acp: blast_radius_1; direct_dependents_1
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the primary change: closing Grok background commands from KillTask results.
      Description checkPassedThe description includes all required sections. It explains the problem, change, scope and approval, verification results, limitations, and agent attribution.
      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.
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • 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.
    4. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Your commits from this PR are in #22709, with your authorship kept, together with the other half of the Grok fix and the delegate-finalize fix for #17512. The only changes on top: the test files are rebased onto the pruned versions on main, the KillTask retain helper is inlined, 3 unit tests that already pass on main are dropped, and the Effect.timeout calls are removed (the project timeout is the limit). Thanks for tracking these down.

    5. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Closing as merged through #22709 (163bdeaa11), which includes your commits with your authorship. Thanks @SouthCarpet.

Sign in to join this conversation.