Skip to content

feat(agents): plan mode runtime + escalating retry + auto-continue [Phase 3.C]#67538

Closed
100yenadmin wants to merge 20 commits into
openclaw:mainfrom
electricsheephq:phase3/plan-mode
Closed

feat(agents): plan mode runtime + escalating retry + auto-continue [Phase 3.C]#67538
100yenadmin wants to merge 20 commits into
openclaw:mainfrom
electricsheephq:phase3/plan-mode

Conversation

@100yenadmin

@100yenadmin 100yenadmin commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Three complementary features to fix GPT-5.4's planning-only behavior: (1) opt-in plan mode that gates mutating tools until user approval, (2) escalating retry instructions with 3 urgency levels, and (3) opt-in auto-continue that keeps the agent working without human intervention. Together these close the gap between GPT-5.4's cautious defaults and agentic execution.

Tracking

What this PR does

Plan mode runtime (opt-in)

Two-phase execution: plan (mutation gate ON, read-only tools allowed) → execute (full tool access after approval).

  • Mutation gate: blocks 11 tools (write, edit, exec, apply_patch, message, subagents, etc.), allows read/search/plan
  • Exec whitelist: read-only commands (ls, cat, grep, git log, git diff) pass through even during planning
  • Approval state machine: none → pending → approved | edited | rejected | timed_out
  • Rejection UX: captures feedback text + increments cycle counter for plan revision

Escalating retry (automatic, GPT-5 only)

When planning-only turn detected (text with zero tool calls), up to 3 retries with escalating urgency:

Retry Instruction
1 "Act now: take the first concrete tool action"
2 "CRITICAL: You MUST call a tool in this turn"
3 "FINAL WARNING: Call a tool NOW or this task will be cancelled"

Retry limit raised from 2 → 3 for strict-agentic contract.

Auto-continue (opt-in config)

After retries exhausted, instead of blocking for user input, injects ACK fast-path automatically:

{
  "agents": {
    "defaults": {
      "embeddedPi": {
        "autoContinue": {
          "enabled": true,     // default: false
          "maxCycles": 3,      // each cycle ≈ 4 API calls
          "stopOnMutation": true
        }
      }
    }
  }
}

Flow diagrams

Escalating retry + auto-continue

Model responds (text only, 0 tool calls)
    │
    ├── retry 1: "Act now"
    ├── retry 2: "CRITICAL"
    ├── retry 3: "FINAL WARNING"
    │
    └── retries exhausted
         │
    ┌────┴──────────────┐
    ▼                   ▼
auto-continue       block for user
enabled?             (default)
    │
    ▼
inject ACK, reset retries, cycle++
    │
    ├── cycle < maxCycles → retry again
    └── cycle = maxCycles → block for user

Plan mode

User message → Plan phase (read-only tools) → Plan produced
    → Approval gate (pending) → User approves/rejects
    → approved: Execute phase (full tools)
    → rejected: Feedback + retry plan phase

API call math

Config Formula Worst case
Default (no auto-continue) 1 + 3 retries 4 calls
Auto-continue, maxCycles=3 1 + 3 × (3 retries + 1 ACK) 13 calls
Auto-continue, maxCycles=5 1 + 5 × (3 retries + 1 ACK) 21 calls

Files changed

File Change
src/agents/plan-mode/*.ts (6 files) New — mutation gate, approval state machine, types
qa/scenarios/gpt54-*.md (5 files) New — QA parity scenarios
src/agents/pi-embedded-runner/run.ts Auto-continue wiring, ACK injection, plan event emission
src/agents/pi-embedded-runner/run/incomplete-turn.ts Escalating retry, limit 2→3
src/agents/pi-embedded-runner/run.incomplete-turn.test.ts Updated + new tests
src/agents/agent-scope.ts resolveAgentAutoContinue() config resolver
src/config/types.agent-defaults.ts autoContinue type
src/config/zod-schema.agent-defaults.ts autoContinue Zod schema

Tests

  • 30 mutation gate tests (tool blocking, exec whitelist, word-boundary matching)
  • 7 approval state machine tests (all transitions, feedback, cycle counting)
  • Escalating retry tests (correct instruction per index, boundary conditions)
  • Auto-continue integration test (maxCycles budget, ACK injection)
  • Total: 50 tests in this PR's test files

Rollback

Feature Disable Effect
Plan mode Don't activate PlanMode runtime Mutation gate never instantiated
Escalating retry Revert incomplete-turn.ts limit 3→2 Single-message retry
Auto-continue autoContinue.enabled: false (default) Blocks for user input

All features are additive. No existing behavior changes unless opted in.

Dependencies

What follows

  • Dashboard Continue button
  • Channel-native approval buttons (Slack/Discord)
  • /plan slash command

…ne, types

Phase 3.C of the GPT 5.4 parity sprint. Implements plan mode as an
opt-in feature where mutation tools are blocked during Phase A (plan)
until the user approves the plan, then Phase B (execute) runs normally
with full tool access.

## Plan mode mutation gate (mutation-gate.ts)
- Blocks 11 mutation tools by exact name: apply_patch, edit, exec,
  gateway, message, nodes, process, sessions_send, sessions_spawn,
  subagents, write
- Blocks suffix patterns: *.write, *.edit, *.delete
- Allows: read, web_search, web_fetch, memory_search, memory_get,
  update_plan, exit_plan_mode, session_status
- Special exec whitelist: read-only commands (ls, cat, git status,
  grep, find, etc.) are allowed; mutating commands are blocked
- 30 unit tests covering all paths

## Approval state machine (approval.ts)
- States: none → pending → approved | edited | rejected | timed_out
- approve: transitions to normal mode, records confirmedAt
- edit: re-enters plan mode with edited plan
- reject/timeout: transitions to normal mode, aborts turn
- buildApprovedPlanInjection(): generates system message for Phase B
- 7 unit tests

## Types (types.ts)
- PlanMode, PlanApprovalState, PlanModeSessionState
- DEFAULT_PLAN_MODE_STATE

Built independently of PR #61845. Plan mode is NEVER auto-enabled —
it requires explicit user opt-in via config, slash command, or UI
toggle (entry points follow in a separate commit).

Tracking: #66345, #67520.
@greptile-apps

greptile-apps Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR implements three complementary features for GPT-5.4 agentic parity: escalating retry instructions (3 urgency levels), opt-in auto-continue cycling (ACK injection after retry exhaustion), and plan-mode primitives (mutation gate, approval state machine, crypto-secure approval IDs). Previous critical findings from earlier review rounds—shell compound-operator bypass in the exec whitelist and stale approvalId accepted when current state had no token—were resolved.

Two P2 gaps remain:

  • stopOnMutation is non-functional: autoContinueAccumulatedMutation can never be set because resolvePlanningOnlyRetryInstruction returns null (blocking entry into the auto-continue block) whenever hadPotentialSideEffects is true. The default stopOnMutation: true provides no runtime guard.
  • planModeActive not forwarded: incomplete-turn.ts added a planModeActive parameter to suppress retry pressure during plan mode, but none of the four call sites in run.ts pass it. Plan mode itself is not yet connected to the execution pipeline (no PlanModeSessionState tracking, no checkMutationGate calls in run.ts), so this is a latent integration hazard for the follow-up wiring PR.

Confidence Score: 4/5

Safe to merge with awareness of two P2 gaps in stopOnMutation correctness and plan-mode integration readiness.

Both prior P1 issues (exec whitelist shell bypass, stale approvalId fail-open) are resolved. The stopOnMutation option is documented as a safety valve but has no runtime effect due to mutual exclusion with planning-only detection. The planModeActive forwarding gap is a latent integration concern for the next plan-mode wiring PR rather than a current defect.

src/agents/pi-embedded-runner/run.ts — autoContinueAccumulatedMutation mutation tracking block and planModeActive call sites for the four retry resolvers.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 1816-1831

Comment:
**`stopOnMutation` is effectively a no-op**

`autoContinueAccumulatedMutation` can never be set to `true` in the current implementation because the conditions for entering this block are mutually exclusive with having produced side effects.

The outer guard requires `nextPlanningOnlyRetryInstruction` to be non-null, but `resolvePlanningOnlyRetryInstruction` returns `null` whenever `attempt.replayMetadata.hadPotentialSideEffects` is `true` (see `incomplete-turn.ts` line 594). So by the time execution reaches line 1820, `hadPotentialSideEffects` is always `false` for the current attempt, and the flag is never flipped.

For mutations from earlier loop iterations: a previous attempt with mutations would have had `nextPlanningOnlyRetryInstruction == null`, so it bypassed this block entirely and `autoContinueAccumulatedMutation` was never updated.

The result is that `stopOnMutation: true` (the default) provides no actual guard. The config option is accepted and stored but has no runtime effect.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 1708-1730

Comment:
**`planModeActive` flag not forwarded to retry resolvers**

`incomplete-turn.ts` added a `planModeActive?: boolean` parameter to `resolvePlanningOnlyRetryInstruction`, `resolveReasoningOnlyRetryInstruction`, `resolveEmptyResponseRetryInstruction`, and `resolveAckExecutionFastPathInstruction`. The parameter comment explicitly states that when plan mode is active, planning-only IS the desired state and retry pressure should be suppressed.

None of the four call sites here pass `planModeActive`. When plan mode is eventually wired into `run.ts` (the gate, state machine, and session tracking from `src/agents/plan-mode/` are not connected yet), forgetting to update these calls means the escalating retry instructions will fire against the agent even during plan phases where it's supposed to produce a plan and call `exit_plan_mode`. The missing link is easy to overlook in a follow-up PR.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "fix(agents): #67538 — per-field merge fo..." | Re-trigger Greptile

Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread src/agents/plan-mode/approval.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f123cdd10

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a standalone plan-mode runtime module under src/agents/plan-mode/ to support a two-phase workflow (planning vs execution) by (a) gating mutation-capable tools during planning and (b) tracking user approval outcomes.

Changes:

  • Introduces plan-mode session/approval types and defaults.
  • Adds a mutation-gate helper that blocks selected tools (with an exec read-only prefix whitelist) while in plan mode.
  • Adds an approval state transition helper plus approved-plan system-message injection, with Vitest coverage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/agents/plan-mode/types.ts New plan-mode state/approval type definitions and defaults
src/agents/plan-mode/mutation-gate.ts Mutation-gating logic for plan mode (blocklist, suffix patterns, exec whitelist)
src/agents/plan-mode/mutation-gate.test.ts Unit tests for mutation gate behavior
src/agents/plan-mode/approval.ts Approval state machine transitions + approved-plan injection builder
src/agents/plan-mode/approval.test.ts Unit tests for approval transitions and injection formatting
src/agents/plan-mode/index.ts Public exports for plan-mode module

Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/approval.ts
Comment thread src/agents/plan-mode/approval.ts Outdated
Comment thread src/agents/plan-mode/mutation-gate.test.ts
Comment thread src/agents/plan-mode/mutation-gate.test.ts
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Eva added 2 commits April 16, 2026 13:39
…efault deny, confirmedAt

- Block shell compound operators (&&, ||, |, ;, >, >>, backticks, $())
  in exec/bash commands to prevent chaining past the prefix allowlist
- Add "bash" to the mutation tool blocklist (alias for exec)
- Default to blocked for unknown tools (fail-closed, not fail-open)
- Clear confirmedAt on "edit" transition to prevent stale approval leaking
- Remove unused PlanApprovalState import

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a44b85cda

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
…itelist

Two Codex P1 issues at 95%+ confidence:

1. Newlines as shell separators: "ls\nrm -rf tmp" bypassed the
   compound operator check because \n wasn't in the regex.
   Added \n and \r to the operator detection pattern.

2. Dangerous flags on allowed prefixes: "find . -delete" passed
   because "find" is whitelisted. Added a dangerous-flag check
   for -delete, -exec, -execdir, --delete, -rf, -i that runs
   after the operator check but before the prefix allowlist.

Added 4 new test cases covering both vectors + bash alias.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d9ee0671b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread src/agents/plan-mode/approval.ts
Eva added 3 commits April 16, 2026 14:13
`env` as a prefix allows arbitrary command execution (e.g.
`env npm install`). Remove it — users who need environment
variables can use `printenv` which is already allowlisted.
- Convert args from mappings to arrays
- Replace sendAgentMessage with state.addInboundMessage
- Replace waitForToolCall with waitForOutboundMessage + lambda predicates
- Replace assertions: blocks with assert: actions
- Add waitForGatewayHealthy + waitForQaChannelReady setup
- Use ref: state / ref: env for runtime objects
- Fix gpt54-plan-mode-default-off scenario ID to match filename
- Simplify injection-scan to baseline check (scanner unit-tested in #67512)
- Add explicit tests for bash tool blocked in plan mode, shell compound
  operators (redirect, pipe, semicolon), newlines in commands, and
  dangerous flags (find -delete, find -exec)
- Add early-return guard in resolvePlanApproval for stale timeouts that
  fire after the user has already acted on the approval
- Add test verifying stale timeout is ignored after approval is resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8e5c22981b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/plan-mode/mutation-gate.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.

Comment thread qa/scenarios/gpt54-cancelled-status.md
Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread qa/scenarios/gpt54-plan-mode-default-off.md
Comment thread qa/scenarios/gpt54-cancelled-status.md
Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/approval.ts
Comment thread qa/scenarios/gpt54-mandatory-tool-use.md
Comment thread qa/scenarios/gpt54-mandatory-tool-use.md Outdated
Comment thread qa/scenarios/gpt54-plan-mode-default-off.md
…ear confirmedAt

Three fixes at 95%+ confidence from Copilot review:

1. Remove -i from DANGEROUS_FLAGS — blocks grep -i (case-insensitive
   search), the most common grep usage in plan mode. The remaining
   flags (-delete, -exec, -execdir, --delete, -rf) are genuinely
   dangerous.

2. Add read-only suffix patterns (.read, .search, .list, .get, .view)
   so MCP read tools like custom_mcp.read pass the fail-closed default.
   Mutation suffixes (.write, .edit, .delete) are still blocked.

3. Clear confirmedAt on reject and timeout transitions in the approval
   state machine. Previously only edit cleared it; reject/timeout
   spread current which could leak a stale confirmedAt.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 285dc1e9a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/agents/plan-mode/mutation-gate.ts Outdated
Comment thread qa/scenarios/gpt54-mandatory-tool-use.md

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Comment thread src/agents/plan-mode/mutation-gate.ts
Comment thread src/agents/plan-mode/types.ts
Comment thread src/agents/pi-embedded-runner/run/incomplete-turn.ts
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Plan-mode rollout series — status update

This PR is part of a 10-PR plan-mode rollout. The cumulative state ships locally as OpenClaw 2026.4.15 (3a6ec73) from branch feat/plan-channel-parity (= PR #68441 head).

Series overview + landing order: see #68441 (latest comment).

This PR's role in the series: see the original PR description above.

Live test status: covered by the cumulative install — all behaviors from this PR are verified in production-like usage on Telegram + webchat. No regressions detected since the live install (2026-04-18).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread src/agents/plan-mode/index.ts
Comment thread src/config/zod-schema.agent-defaults.ts
Comment thread src/agents/pi-embedded-runner/run/incomplete-turn.ts
Comment thread src/agents/plan-mode/approval.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread src/agents/pi-embedded-runner/run.ts
Comment thread src/agents/agent-scope.test.ts
Comment thread qa/scenarios/gpt54-plan-mode-default-off.md
Comment thread src/agents/plan-mode/index.ts
@100yenadmin

Copy link
Copy Markdown
Contributor Author

📋 Architecture & Status — single source of truth (commit 39e63febad)

The plan-mode rollout now has a durable architecture document at docs/plans/PLAN-MODE-ARCHITECTURE.md that survives session compactions and tracks the full series.

Quick reference:

  • This is one of 10 open PRs in the cumulative plan-mode rollout (PR-A through PR-11 internal sprint numbering).
  • Recommended landing order: 5 waves (see ARCHITECTURE.md "Recommended landing waves").
  • The cumulative branch feat/plan-channel-parity is the LIVE install (OpenClaw 2026.4.15 (39e63fe)).
  • All 10 PRs target upstream main; each carries forward the cumulative diff which inflates the file count beyond Greptile's 100-file review cap.

Resolution path for the file-count inflation: land PRs in dependency order so the cumulative diff naturally shrinks as upstream main absorbs them. No PR closure/reopen needed — that would lose review history without solving the structural cumulative-rollout pattern.

Hardening status (review pass 1):

Newly-resolved escalation (commit 39e63febad): the previously-deferred #3104743333 (Codex P2 — update_plan merge-mode sidebar refresh) is now fixed via option C (re-emit merged steps via existing agent_plan_event channel). New AgentPlanEventData.mergedSteps field carries the full structured plan; UI subscribes via new maybeForwardMergedPlanEvent handler.

Current status of THIS PR specifically: see the existing comments + bot reviews above. Triage + reply pass coming in the next sprint.

cc @copilot @greptile-apps @chatgpt-codex-connector

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create an environment for this repo.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/agents/pi-embedded-runner/run/incomplete-turn.ts:360

  • shouldApplyPlanningOnlyRetryGuard() is now used to gate reasoning-only and empty-response retries, and it returns false when planModeActive is true. That would disable recovery for reasoning-only/empty-response failures during plan mode (even though those failure modes aren’t “planning-only” and still need remediation to produce a visible plan). Suggest splitting this into (a) a provider/model guard for retry features and (b) a separate “suppress act-now pressure in plan mode” check that applies only to the planning-only retry + ACK fast-path logic.
  if (
    !shouldApplyPlanningOnlyRetryGuard({
      provider: params.provider,
      modelId: params.modelId,
      planModeActive: params.planModeActive,
    })
  ) {
    return null;
  }

  const assistant = params.attempt.currentAttemptAssistant ?? params.attempt.lastAssistant;
  if (params.attempt.assistantTexts.join("\n\n").trim().length > 0) {
    return null;
  }
  if (assistant?.stopReason === "error") {
    return null;
  }
  if (!isReasoningOnlyAssistantTurn(assistant)) {
    return null;
  }

  return REASONING_ONLY_RETRY_INSTRUCTION;
}

export function resolveEmptyResponseRetryInstruction(params: {
  provider?: string;
  modelId?: string;
  payloadCount: number;
  aborted: boolean;
  timedOut: boolean;
  attempt: IncompleteTurnAttempt;
  /** When true, planning-only is the desired state — skip retry pressure. */
  planModeActive?: boolean;
}): string | null {
  if (
    params.aborted ||
    params.timedOut ||
    params.attempt.clientToolCall ||
    params.attempt.yieldDetected ||
    params.attempt.didSendDeterministicApprovalPrompt ||
    params.attempt.lastToolError ||
    params.attempt.replayMetadata.hadPotentialSideEffects
  ) {
    return null;
  }

  if (
    !shouldApplyPlanningOnlyRetryGuard({
      provider: params.provider,
      modelId: params.modelId,
      planModeActive: params.planModeActive,
    })
  ) {
    return null;
  }

Comment thread src/agents/agent-scope.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment on lines +272 to +287
/**
* Auto-continuation for planning-only turns. When enabled, the runner
* automatically injects an ACK fast-path instruction instead of surfacing
* the plan to the user, up to `maxCycles` consecutive auto-continue cycles.
* Each cycle = 1 ACK injection + up to 3 planning retries = ~4 API calls.
*/
autoContinue?: {
/** Enable auto-continuation. Default: false. */
enabled?: boolean;
/**
* Max auto-continue cycles before pausing for user review. Default: 3.
* Total worst-case API calls = 1 + (maxCycles x 4). Default 3 = ~13 calls max.
*/
maxCycles?: number;
/** Pause when any attempt in the run produces mutating tool calls. Default: true. */
stopOnMutation?: boolean;

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment’s worst-case call formula (1 + (maxCycles x 4)) is inconsistent with the runner’s behavior: strict-agentic can already do the initial attempt + 3 retries before any auto-continue cycles, and each cycle can add 1 auto-continue attempt + up to 3 retries. Update the formula (and/or the meaning of maxCycles) to match the real budgeting so operators don’t underestimate API usage.

Copilot uses AI. Check for mistakes.
export const PLANNING_ONLY_RETRY_INSTRUCTION_FIRM =
"CRITICAL: You have described the plan multiple times without acting. You MUST call a tool in this turn. No more planning or narration. If a real blocker prevents action, state the exact blocker in one sentence. Otherwise, call the first tool NOW.";
export const PLANNING_ONLY_RETRY_INSTRUCTION_FINAL =
"Final reminder: this is the third planning-only turn. Please call a tool now to make progress. If a real blocker prevents action, state the exact blocker in one sentence so the user can unblock you.";

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLANNING_ONLY_RETRY_INSTRUCTION_FINAL says “this is the third planning-only turn”, but it’s selected on the 3rd retry (attemptIndex >= 2), which typically means the model is about to produce a 4th planning-only turn including the original. Consider adjusting the wording to match what’s actually happening (e.g. “third retry” / “final retry”) so the instruction is accurate.

Suggested change
"Final reminder: this is the third planning-only turn. Please call a tool now to make progress. If a real blocker prevents action, state the exact blocker in one sentence so the user can unblock you.";
"Final reminder: this is the final planning-only retry. Please call a tool now to make progress. If a real blocker prevents action, state the exact blocker in one sentence so the user can unblock you.";

Copilot uses AI. Check for mistakes.
@100yenadmin

Copy link
Copy Markdown
Contributor Author

Closing in favor of consolidated PR #68939.

Rationale: this branch was 734 commits behind upstream/main and the
PR's review feedback was firing against a stale base. Rebased the
full 135-commit feature work onto upstream/main @ v2026.4.19-beta.2
(only 5 conflicts to resolve) and consolidated the 10-PR series into
a single umbrella PR for cleaner bot review + faster maintainer
context-loading.

The full iteration history + decision log lives in
docs/plans/PLAN-MODE-ARCHITECTURE.md on the new branch. All
reviewed-and-resolved threads from this PR are honored — see the
architecture doc for what landed where.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants