Skip to content

fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads - #3352

Closed
nightskytech wants to merge 1 commit into
kunchenguid:mainfrom
nightskytech:fix/pi-code-stop-autoarm-standdown
Closed

nightskytech wants to merge 1 commit into
kunchenguid:mainfrom
nightskytech:fix/pi-code-stop-autoarm-standdown

Conversation

@nightskytech

Copy link
Copy Markdown

Fixes #3343.

What

bin/fm-claude-stop-autoarm.sh now stands down when its Stop payload was delivered by pi-code, exactly as it already does for Cursor. The stand-down is scoped to this one hook; every other Claude-shaped hook pi-code delivers keeps running.

Why

pi-code loads the tracked .claude/settings.json but has no asyncRewake support: it awaits every Stop hook (await Promise.all(...), verified through pi-code 1.0.14, reported upstream as ilovepixelart/pi-code#123). The auto-arm's foreground monitoring therefore runs synchronously inside Pi's turn end and holds the turn open for the declared 28,800s timeout. Observed live 2026-08-30: pi blocked on the hook process tree, all typed input queued; killing the hook released the session immediately. Triage on the issue classed this restore and asked for exactly this scoped payload guard.

How

Per the payload-not-environment principle in bin/fm-hook-host-lib.sh: pi-code stamps every hook payload's transcript_path with Pi's own session file, which always contains a .pi/ path component (~/.pi/agent/sessions/...); a Claude transcript path never does. The guard exits 0 when transcript_path contains /.pi/. Fail direction is unchanged: missing payload, missing jq, or missing transcript_path means the hook runs, because a skipped run under a genuine Claude primary is the worse failure.

Tests

Two regressions added to tests/fm-claude-stop-autoarm.test.sh:

  • test_stands_down_on_pi_code_delivered_payload — a pi-stamped payload exits 0 silently with no arm, no epoch write.
  • test_claude_transcript_path_still_arms — a payload carrying a genuine Claude transcript_path still arms and rewakes (exit 2), so the discriminator can only fail toward running.

Verification

  • bash tests/fm-claude-stop-autoarm.test.sh: 41 ok, 0 failures (39 pre-existing + 2 new), macOS arm64.
  • bin/fm-lint.sh with pinned ShellCheck 0.11.0 and actionlint 1.7.12: clean.
  • Live: the same guard has been running as a hotfix on the reporting installation since 2026-08-30; the Pi primary completes turns and accepts input immediately, and a synthetic pi-shaped payload exits the hook instantly while a Claude-shaped payload follows the normal path.

🤖 Generated with Claude Code

…yloads

pi-code loads the tracked Claude settings but has no asyncRewake support: it
awaits every Stop hook, so the auto-arm's foreground monitoring holds Pi's
turn open for the declared multi-hour timeout (observed live 2026-08-30).
Stand down when the payload's transcript_path carries a .pi/ component, the
stamp pi-code puts on every payload and a Claude transcript never has.
Fail direction is unchanged: missing payload, jq, or transcript_path runs.

Fixes #3343.
@greptile-apps

greptile-apps Bot commented Aug 30, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge with no concrete changed-code defect identified.

The guard is narrowly scoped to Pi-shaped transcript paths, fails toward retaining existing behavior when payload data or jq is unavailable, and includes regression coverage for both sides of the discriminator.

Reviews (1): Last reviewed commit: "fix(bin): stand down the Claude Stop aut..." | Re-trigger Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: first look of #3352 vs main d71f4b9cf1e6a8c647867d9a92c67ab0a6bb460f. Diff reviewed; this is the covering PR for #3343. Waiting on the author.

HEAD: 5b935073d49c7e969d3a50638cf56a262e9b7f76
Attestation: MISSING — PR body has no <!-- no-mistakes-pipeline-attestation:v1 {\"head_sha\":... bind. NM run 33328529982 failed: "This PR was not raised through no-mistakes."
Contract-class: restore — inspected bin/fm-claude-stop-autoarm.sh (main + this HEAD) and bin/fm-hook-host-lib.sh on main. The existing specified stand-down is Cursor via fm_hook_payload_is_foreign_host (cursor_version string). This PR only adds a scoped payload check on this one hook: transcript_path contains /.pi/, then exit 0. Fail-open is unchanged (missing payload, jq, or transcript_path still runs). No new unconfigured always-on path; other Claude-shaped hooks pi-code delivers are untouched.

VISION (per major section; files: VISION.md @ main d71f4b9, bin/fm-claude-stop-autoarm.sh main+PR, bin/fm-hook-host-lib.sh main, tests/fm-claude-stop-autoarm.test.sh PR, issue #3343):

  • One captain, one interface: aligns — a frozen Pi primary is the opposite of peace of mind.
  • Authority is explicit: aligns — stand-down only; no new autonomy.
  • Scripts vs agents: aligns — payload predicate is exact script work.
  • Restart is a non-event: aligns — the turn must settle without a multi-hour sync hold.
  • Delegation with a spine: cannot tell — not about task contracts; N/A to the core claim.
  • Fleet outlives any vendor: aligns — defend against pi-code compatibility hazards; Pi native extensions own Pi supervision.
  • Scope: aligns — command-layer hook guard, scoped to this Stop arm.

Security (fail-closed): workflow-zero (only bin/fm-claude-stop-autoarm.sh +17 and tests/fm-claude-stop-autoarm.test.sh +42). Discriminator is the PAYLOAD, not the environment, matching fm-hook-host-lib.sh. contains(\"/.pi/\") does not match a genuine Claude transcript under ~/.claude/projects/ (project paths there are dash-encoded, so even a project living under .pi would not produce /.pi/). A too-broad stand-down would disable this safety hook on real Claude; this one is not that. Fail-open toward running is the documented worse-failure direction. Fork PR: not a security risk after that review.

CI/NM this HEAD:

  • First-time fork workflows approved this pass: CI 33328529961, Require no-mistakes 33328529982.
  • NM 33328529982 FAILURE (missing attestation).
  • CI 33328529961 in_progress after approval (coverage guard SUCCESS, repo invariants SUCCESS; behavior/lint jobs still running). Greptile 5/5.

Overlap: none that needs a hold. This is the covering PR for #3343. Older auto-arm PRs (#3163, #2584, #2149) do not implement the pi-code stand-down. Will honestly close #3343 once it lands.

Waiting on author: rebind this HEAD through git push no-mistakes so the body attests 5b935073d49c7e969d3a50638cf56a262e9b7f76. Cannot merge while attestation is MISSING / NM is red. Not waiting on the captain.

@nightskytech

Copy link
Copy Markdown
Author

Withdrawing this PR: the scoped Stop-hook fix grew into predicate, session-start-ownership, and documentation work that belongs with the project rather than an outside reporter. All investigation evidence is in #3343 and the review findings above; the freeze itself is reproducible, and the narrow guard in this PR's original commit (5b93507) works and is running as a local hotfix on the reporting installation. Yours to finish in whatever shape fits the vision.

@nightskytech
nightskytech deleted the fix/pi-code-stop-autoarm-standdown branch August 31, 2026 02:48
kunchenguid pushed a commit that referenced this pull request Sep 25, 2026
…yloads (#5657)

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads

pi-code loads the tracked Claude settings but has no asyncRewake, so it
awaits every Stop hook; without a stand-down the auto-arm runs
synchronously inside Pi's turn end and holds it open for the declared
multi-hour timeout. Stand down when the payload's transcript_path
contains a /.pi/ path component, the same discriminator the closed-but-
unmerged fix in #3352 used, with an explicit string-type check on the
jq filter.

Fixes #3343

* no-mistakes(document): document pi-code stand-down in harness integrations reference
mituso89 pushed a commit to mituso89/firstmate that referenced this pull request Sep 26, 2026
…yloads (kunchenguid#5657)

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads

pi-code loads the tracked Claude settings but has no asyncRewake, so it
awaits every Stop hook; without a stand-down the auto-arm runs
synchronously inside Pi's turn end and holds it open for the declared
multi-hour timeout. Stand down when the payload's transcript_path
contains a /.pi/ path component, the same discriminator the closed-but-
unmerged fix in kunchenguid#3352 used, with an explicit string-type check on the
jq filter.

Fixes kunchenguid#3343

* no-mistakes(document): document pi-code stand-down in harness integrations reference
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…yloads (kunchenguid#5657)

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads

pi-code loads the tracked Claude settings but has no asyncRewake, so it
awaits every Stop hook; without a stand-down the auto-arm runs
synchronously inside Pi's turn end and holds it open for the declared
multi-hour timeout. Stand down when the payload's transcript_path
contains a /.pi/ path component, the same discriminator the closed-but-
unmerged fix in kunchenguid#3352 used, with an explicit string-type check on the
jq filter.

Fixes kunchenguid#3343

* no-mistakes(document): document pi-code stand-down in harness integrations reference
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…yloads (kunchenguid#5657)

* fix(bin): stand down the Claude Stop auto-arm on pi-code-delivered payloads

pi-code loads the tracked Claude settings but has no asyncRewake, so it
awaits every Stop hook; without a stand-down the auto-arm runs
synchronously inside Pi's turn end and holds it open for the declared
multi-hour timeout. Stand down when the payload's transcript_path
contains a /.pi/ path component, the same discriminator the closed-but-
unmerged fix in kunchenguid#3352 used, with an explicit string-type check on the
jq filter.

Fixes kunchenguid#3343

* no-mistakes(document): document pi-code stand-down in harness integrations reference
ashkonmousavi added a commit to ashkonmousavi/firstmate that referenced this pull request Sep 26, 2026