gstack icon indicating copy to clipboard operation
gstack copied to clipboard

autoplan: publication hook denies every native reviewer dispatch on Claude Code 2.1.29x (Agent schema strips `run_in_background` under the fork-subagent gate)

Open yolo-jared opened this issue 1 month ago • 3 comments

Summary

On Claude Code 2.1.292 with default settings, /autoplan cannot enter any review phase. Every native reviewer Agent dispatch is denied with a "retry" message, and retrying never helps. The cause is in autoplan/bin/phase-publication-hook.ts, at the identity check that compares the journal against the hook payload:

// gstack 1.91.32, phase-publication-hook.ts:428
!isDeepStrictEqual(nativeToolInput(current[0]!.input, input.cwd), nativeToolInput(input.tool_input, input.cwd))
// nativeToolInput (lines 38-39) only normalises file_path

Claude Code journals the model's raw tool input but gives PreToolUse the schema-parsed input. Since the fork-subagent gate (CLAUDE_CODE_FORK_SUBAGENT, default ON in 2.1.29x) removes run_in_background from the Agent schema, any dispatch that carries the key, including the one the phase sections ask for, has it in the journal and not in the payload. The deep-equal can never pass. (Claude Code side filed as: anthropics/claude-code#100117.)

Symptoms (11 journaled denials across 2 sessionKind: "bg" sessions, all explained)

Agent input Denial Count
run_in_background sent (journaled as string "false") Current native phase-entry identity is unavailable. Retry this phase-entry tool after the journal is available. 7/7
key omitted, sessionKind: "bg" session Native parent evidence has not reached the journal yet. Retry... (2 s poll; Claude Code doesn't flush the tool_use until the hook returns) 4/4

Both messages say "retry", but neither failure is transient.

Workaround (verified)

Set CLAUDE_CODE_FORK_SUBAGENT=false (for example in the env block of ~/.claude/settings.json) and restart Claude Code. The Agent schema then exposes run_in_background, run_in_background: false runs in the foreground, and the journal records a real boolean, so the journal and the payload match. Verified with a probe dispatch on 2.1.292. Not yet verified through a full /autoplan run.

Suggested fix

  1. In nativeToolInput, for tool === 'Agent', drop run_in_background from both sides before the deep-equal. It only selects foreground or background; it can't change the phase or the prompt, and the prompt stays bound by consumption(). A diff is attached below and was tested offline against the real journals: the 6 RED cases go GREEN, while a changed prompt, a changed description and an added model all stay denied.
  2. When the current tool is Agent and the payload lacks a key the journal has, deny with a specific cause instead of "retry": name the fork-subagent gate and the CLAUDE_CODE_FORK_SUBAGENT=false workaround, and add a docs/troubleshooting.md anchor.
  3. Optional: put a one-line preflight in the phase sections. If the Agent schema doesn't expose run_in_background and the session is bg, warn before init that dispatch will hang on the journal poll.
-const nativeToolInput = (input: unknown, cwd: string): unknown =>
-  object(input) && typeof input.file_path === 'string' ? { ...input, file_path: requestedPath(cwd, input.file_path) } : input;
+const nativeToolInput = (input: unknown, cwd: string, tool?: string): unknown => {
+  if (!object(input)) return input;
+  let out: Record<string, any> = input;
+  if (typeof out.file_path === 'string') out = { ...out, file_path: requestedPath(cwd, out.file_path) };
+  // Claude journals raw Agent input but PreToolUse gets the schema-parsed input; when the Agent schema omits
+  // run_in_background (fork-subagent gate, bg sessions) the parse strips it. It selects fg/bg only; compare the rest exactly.
+  if (tool === 'Agent' && 'run_in_background' in out) { const { run_in_background: _ignored, ...rest } = out; out = rest; }
+  return out;
+};
@@
-        !isDeepStrictEqual(nativeToolInput(current[0]!.input, input.cwd), nativeToolInput(input.tool_input, input.cwd))) fail(...)
+        !isDeepStrictEqual(nativeToolInput(current[0]!.input, input.cwd, input.tool_name), nativeToolInput(input.tool_input, input.cwd, input.tool_name))) fail(...)

Related

  • #2977 (closed): mentions the journal-flush half as harness-side
  • #2440 (closed): run_in_background guidance since v2.1.198
  • #3050 (closed): the fallback wording (/plan-ceo-review, /plan-devex-review, /plan-eng-review) is what users need here as well
  • anthropics/claude-code#91225: the fork gate overriding foreground

Environment

gstack 1.91.32.0 (also 1.91.25.0), Claude Code 2.1.292, macOS.

yolo-jared avatar Oct 07 '26 03:10 yolo-jared

Follow-up after the CLAUDE_CODE_FORK_SUBAGENT=false workaround: Cause A (the Agent key strip) is fixed, but in a sessionKind: "bg" session the journal-flush half also denies hook-guarded native Reads, not only Agent dispatch. That blocks /autoplan before the CEO methodology finishes loading.

Setup: gstack 1.91.32.0, Claude Code 2.1.292 (macOS), fork gate off. A haiku probe with run_in_background: false passed: it ran in the foreground and the journal recorded boolean false. init returned reused: true. Then I Read methodology.md in its 5 readRanges.

Timeline from the session journal (tool_use timestamp → tool_result timestamp):

tool_use written result Read offset outcome
03:37:00.754 03:37:02.856 1 denied
03:37:01.670 03:37:03.777 601 denied
03:37:02.669 03:37:04.773 1201 denied
03:37:03.620 03:37:05.310 1801 OK
03:37:04.608 03:37:05.023 2401 OK
03:37:10.239 03:37:12.299 1 (solo retry) denied
03:38:14.239 … 03:38:17.089 +2.06 s each 1, 601, 1201, 1 denied
03:38:18.040 / 18.931 19.667 / 19.614 601 / 1201 OK

Denial text, every time:

[autoplan] Native parent evidence has not reached the journal yet. Retry this phase-entry tool; no missing-publication conclusion has been made.

What it shows:

  • In a bg session, Claude Code writes each tool_use to the journal about 0.95 s after the previous one in the same message.
  • Every denial takes about 2.06 s, which is the hook's journal poll.
  • So the first ~3 guarded calls of any message are always denied. Only calls late in a batch pass.
  • A solo retry is always first in its message, so retrying never helps. The "retry" wording is misleading here too.
  • The native Agent dispatch has to be the only call in its message, so in a bg session it will hit the same wall.

Suggestions on top of the original issue:

  1. Make the poll window configurable, or longer for sessionKind: "bg". Waiting about 1 s per position in the message would cover this.
  2. Better still, deny up front: when sessionKind is bg, say "relaunch in a foreground session" instead of "retry".
  3. Add a foreground check to the autoplan preflight before init.

Workaround: relaunch as a plain foreground claude from a terminal (no --bg, no --fork-session, not from the agents view), with CLAUDE_CODE_FORK_SUBAGENT=false still set.

yolo-jared avatar Oct 07 '26 03:10 yolo-jared

More data on the journal-flush half, from a foreground session. In it, a parallel tool call's write lets the guarded Agent dispatch through.

Setup: gstack 1.91.19.0, Claude Code 2.1.292, Linux. entrypoint: "cli", no sessionKind: "bg" in the journal. None of these dispatches sent run_in_background, so Cause A does not apply.

Native reviewer Agent dispatches in one /autoplan run (journal tool_use timestamp → tool_result timestamp):

tool_use written result Same message also had Outcome
09:04:22.343 09:04:24.459 (+2.12 s) nothing denied, "Native parent evidence has not reached the journal yet"
09:04:29.536 09:04:31.675 (+2.14 s) text block only denied
09:04:39.243 09:04:41.322 (+2.08 s) nothing denied
09:05:07.014 09:05:09.149 (+2.14 s) text + thinking denied
09:05:33.649 09:05:34.875 (+1.23 s) a Bash tool_use (its result was written at 09:05:34.604) allowed (hook_success)
09:09:13.035 09:09:13.843 (+0.81 s) a Bash tool_use (its result was written at 09:09:13.537) allowed

I replayed the journal truncated right after each Agent tool_use line through readOwnedClaudePublicTranscript. All 6 come back status: "ready" with the tool_use_id present, including the 4 denied ones. So the guard logic is correct. The record simply isn't on disk while a lone call's PreToolUse hook is running.

What this adds:

  • It isn't limited to bg sessions. A plain foreground CLI session deadlocks in the same way whenever the guarded call is the only tool call still pending.
  • In both allowed cases, the sibling tool's result arrived inside the 2 s poll, and the journal write it caused also put the pending Agent record on disk.
  • So "retry" can never succeed for a lone dispatch. That's the same conclusion as the comment above, now confirmed outside bg.

Workaround (2/2 in this session): issue the native Agent dispatch in the same message as a cheap Bash call.

Possible fix on the guard side: when the poll times out and the journal is otherwise ready, with every earlier record consistent, treat the missing current tool_use as "not yet flushed". Then either allow with the existing unverifiedEntry advisory, or check the payload's tool_input against the phase evidence already in the journal, instead of denying with "retry".

crblabs avatar Oct 07 '26 09:10 crblabs

Fixed in v1.91.34.0 (#3069). Both causes are handled. (1) The hook now ignores only run_in_background, which the fork-subagent schema drops from the payload. (2) When the current call isn't journaled yet, the hook checks the payload Claude Code handed it against the journaled records instead of waiting for a record that arrives with the tool result. A phase report counts once a later record follows it, so each phase publishes its report in its own message (true autoplan-published <phase>). When Claude Code leaves a call impossible to check, /autoplan now continues with a visible warning; integrity failures are still refused. Verified live on 2.1.292 in the foreground and through claude --bg + claude attach. CI now pins 2.1.292, and a daily canary checks the newest release. Upgrade with /gstack-upgrade (or cd ~/.claude/skills/gstack && git pull && ./setup). No restart needed, and CLAUDE_CODE_FORK_SUBAGENT=false is no longer required. Thanks @yolo-jared and @crblabs for the timelines and diagnosis.

capy-ai[bot] avatar Oct 07 '26 23:10 capy-ai[bot]