Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(grok): surface plan mode approval in proposed plan cards #5409

Closedahmed-besic(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/5409/headopened View on GitHub

What Changed

When Grok Build enters plan mode, it writes plan.md and then calls exit_plan_mode. That tool is intercepted and reverse-RPCs the client over ACP as _x.ai/exit_plan_mode / x.ai/exit_plan_mode with planContent, expecting the TUI plan approval window (approve / request changes / abandon).

T3 never handled that extension method, so the turn stalled with no UI, and the plan content never showed up as a proposed plan. Users had to open the same session in the Grok terminal and approve there to continue.

This:

  • Registers handlers for x.ai/exit_plan_mode and _x.ai/exit_plan_mode
  • Emits turn.proposed.completed with the plan markdown so the existing proposed-plan card appears
  • Responds with outcome: "abandoned" plus a client-capture message so the native gate unblocks without auto-implementing (same idea as Claude's ExitPlanMode capture)
  • Also promotes mid-plan plan.md writes (tool_call / tool_call_update targeting …/plan.md) into the same proposed-plan path so the card updates while plan mode is still active

Why

Grok threads that entered plan mode looked dead: no output, no approval UI, and no way to continue without leaving T3. Claude already maps ExitPlanMode into proposed plans; Cursor maps cursor/create_plan. Grok needed the same product path for its xAI extension method.

Live probe against grok agent stdio 0.2.118 confirmed the wire shape: { sessionId, toolCallId, planContent } and a successful unblock with { outcome: "abandoned", feedback }.

UI Changes

Uses the existing proposed plan card — no new UI components.

  • Before: Grok plan mode hangs after writing the plan; no plan card; conversation cannot continue without approving in the Grok TUI.
  • After: As plan.md is written, the plan card appears and updates. On exit_plan_mode, the turn finishes and the card stays actionable (implement / follow-up) like Claude/Cursor plans.

Validation

  • vp test run src/provider/acp/XAiAcpExtension.test.ts src/provider/Layers/GrokAdapter.test.ts — 35 passed
  • Live ACP probe: _x.ai/exit_plan_mode payload + abandoned response unblocks the prompt
  • Manual T3 web UI (AeroSpace / grok-4.5): plan mode write surfaces the plan card; exit no longer stalls the thread

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (happy to add after a UI smoke against a Grok plan-mode thread)
  • A video is not applicable (no animation/timing change)

Made by Grok Build via the Grok Build harness while working on T3 Code.


Note

Medium Risk Touches Grok ACP session/turn lifecycle and a new reverse-RPC handler that auto-abandons Grok’s plan gate. Incorrect handling could stall turns or emit the wrong plan markdown.

Overview Grok plan mode no longer stalls waiting on the native TUI approval window. The adapter now captures the plan into the existing proposed-plan card (same product path as Claude ExitPlanMode).

Handlers for x.ai/exit_plan_mode / _x.ai/exit_plan_mode emit turn.proposed.completed and reply with outcome: "abandoned" so the prompt unblocks without auto-implementing. While enter_plan_mode is active, writes to Grok’s session …/.grok/sessions/…/plan.md also update that card; workspace plan.md files are ignored.

Plan markdown is deduped per turn and cleared when a turn ends or a new one starts, so a later empty exit_plan_mode cannot resurrect the previous plan. Mock ACP coverage plus unit tests cover both the exit RPC and mid-plan writes.

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

Note

Surface Grok plan mode approval as proposed plan cards in GrokAdapter

  • Adds plan-mode tracking to GrokSessionContext (fields lastKnownProposedPlanMarkdown, lastKnownProposedPlanTurnId, planModeActive) so the adapter can detect and dedupe proposed-plan emissions per turn
  • Intercepts _x.ai/exit_plan_mode ext requests in GrokAdapter.ts, extracts plan markdown via XAiAcpExtension.ts, emits a turn.proposed.completed event, and responds with an abandoned outcome so the turn does not hang
  • While plan mode is active, promotes writes to ~/.grok/sessions/.../plan.md (detected by isGrokPlanMarkdownPath) into turn.proposed.completed events with per-turn dedupe
  • Adds mock-agent feature flags T3_ACP_EMIT_XAI_EXIT_PLAN_MODE and T3_ACP_EMIT_XAI_PLAN_MD_WRITE in acp-mock-agent.ts for testing both flows
  • Behavioral Change: clearProposedPlanFallback resets plan state at turn boundaries and on turn completion; plan.md writes outside ~/.grok/sessions/ paths are intentionally excluded by isGrokPlanMarkdownPath
Macroscope summarized d6e12ef.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 029eba3c-21c1-4c3e-a3af-1f8edd192f5c

      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

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

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

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/a5b1757d30f1ab9dbe12d38ab78f50f751ccf499/apps/server/src/provider/Layers/GrokAdapter.ts#L105

      lastKnownProposedPlanMarkdown is never reset between turns or plan-mode attempts, so a later exit_plan_mode with absent/blank planContent falls back to the stale value from a previous turn and emits the old plan as the current proposal. This can present and implement stale instructions from an earlier turn. Consider clearing lastKnownProposedPlanMarkdown when a turn ends or when a new plan-mode cycle begins.

      No longer relevant as of 511e92bbd3dcbbc7b09f7fd2eee3320b61030384

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

      Approvability

      Verdict: Skipped

      Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically.

    5. I know you have disabled plan mode, and its fine, i dont use it either, the issue is sometimes grok will enter plan mode by itself and the thread will die. This fixes it

    6. I just ran into this issue. I didn't use /plan, I simply told it "let's plan this".

      Is something wrong with Plan mode? I personally really like it when I want the agent to think without making changes and get my agreement before going forward.

    7. I use plan mode all the time. Sometimes Grok also enters plan mode on its own, and that currently makes the thread broken in T3 Code: the plan stays empty / never appears, and I have to leave T3 and resume/approve in the Grok CLI to continue.

      Please merge this — it is a real daily-driver issue, not an edge case.

    8. Merged current main. Plan-mode tests and server typecheck are passing.

    9. Cursor Bugbot has reviewed your changes using high 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 d6e12ef185a704e42d6d117fc6a0f4393327e70f. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -198,0 +296,21 @@
      296+ (typeof rawInput.file_path === "string" ? rawInput.file_path : undefined) ??
      297+ (typeof rawInput.path === "string" ? rawInput.path : undefined);
      298+ const content = typeof rawInput.content === "string" ? rawInput.content : undefined;
      299+ if (isGrokPlanMarkdownPath(filePath) && content && content.trim().length > 0) {
      300+ return content.trim();
      301+ }
      302+ }
      303+
      304+ const content = data.content;
      305+ if (Array.isArray(content)) {
      306+ for (const block of content) {
      307+ if (!isRecord(block) || block.type !== "diff") {
      308+ continue;
      309+ }
      310+ const path = typeof block.path === "string" ? block.path : undefined;
      311+ const newText = typeof block.newText === "string" ? block.newText : undefined;
      312+ if (isGrokPlanMarkdownPath(path) && newText && newText.trim().length > 0) {
      313+ return newText.trim();
      314+ }
      315+ }
      316+ }

      Stale plan from rawInput preference

      Medium Severity

      extractGrokPlanMarkdownFromToolCallData returns rawInput.content before checking diff newText. Merged ToolCallUpdated state keeps earlier rawInput when a later update only refreshes content, so mid-plan promotion can keep emitting the first draft. Turn-scoped dedupe then blocks the real plan, and an exit_plan_mode with empty planContent can fall back to that stale markdown.

      Additional Locations (1)
      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d6e12ef185a704e42d6d117fc6a0f4393327e70f. Configure [here](https://www.cursor.com/dashboard/bugbot).
    10. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      I am closing this because #8358 has landed in main and covers the same Grok proposed-plan capture. The stale-plan concern found during review is separate from this implementation and should be tracked independently.

      Thank you for putting this together. The closure is only because the work is now covered elsewhere, not because there was a problem with your contribution.

Sign in to join this conversation.