Skip to content

fix: wake pi crewmates after each turn - #12

Merged
kunchenguid merged 2 commits into
mainfrom
fix/pi-turn-end
Jun 13, 2026
Merged

kunchenguid merged 2 commits into
mainfrom
fix/pi-turn-end

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix firstmate's pi crewmate turn-end hook. fm-spawn's generated pi extension listened on pi's 'agent_end' event, which (per pi 0.79.1 type docs) fires only once when the whole agent run exits - so the turn-end backstop never fired at per-turn boundaries for pi crewmates, leaving firstmate reliant on crewmate status appends alone and blind to an idle crewmate that stopped without writing status. Change the hook to 'turn_end', which fires after each turn the agent finishes, matching how the claude/codex/opencode adapters behave. One-line change to the pi-ext template in bin/fm-spawn.sh plus an explanatory comment; no other behavior change.

What Changed

  • Updated the pi harness extension generated by bin/fm-spawn.sh to listen for turn_end instead of agent_end, so firstmate receives a turn-ended signal after each completed pi turn rather than only when the whole agent run exits.
  • Added an inline comment explaining why the pi hook must use turn_end for per-turn idle detection.
  • Documented the pi adapter requirement in AGENTS.md so future harness changes preserve the same watcher behavior.

Risk Assessment

✅ Low: The branch is a narrow one-line event-name correction plus explanatory generated-code comments, with no broader control-flow or API surface changes.

Testing

Baseline bootstrap could not run due missing local firstmate config state, but the focused end-to-end spawn path was exercised: fm-spawn.sh generated and launched a pi extension using turn_end; live pi execution stopped at the trust prompt, which I did not accept because it would change user-level trust outside the worktree boundary, so I supplemented it with a mocked extension event simulation proving the generated hook would touch the turn-ended sentinel. All focused checks passed and temporary worktree test scaffolding was removed.

Evidence: Generated pi extension evidence

The emitted extension registers pi.on("turn_end", ...) and touches state/pi-hook-e2e.turn-ended; it contains no pi.on("agent_end", ...) registration.

// Firstmate turn-end signal; written by fm-spawn.
// Use "turn_end" (fires after each turn the agent finishes), not "agent_end"
// (fires once, only when the whole run exits): the watcher needs a signal at
// every turn boundary so an idle crewmate is surfaced, not just at shutdown.
import { execFile } from "node:child_process";
export default function (pi: any) {
  pi.on("turn_end", () => execFile("touch", ["/Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/state/pi-hook-e2e.turn-ended"]));
}
Evidence: Pi spawn pane transcript

Shows the real spawn command launching pi -e /Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/state/pi-hook-e2e.pi-ext.ts ... before pi displayed its project trust prompt.

treehouse get
01KV18PMDX505TN87957JNNXTT HEAD
❯ treehouse get
🌳 Setting up worktree...
🌳 Entered worktree at ~/.treehouse/01KV18PMDX505TN87957JNNXTT-b8697d/1/01KV18PMDX505TN87957JNNXTT. Type 'exit' to return.
01KV18PMDX505TN87957JNNXTT HEAD
❯ pi -e /Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/state/pi-hook-e2e.pi-ext.ts "$(cat /Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/data/pi-hook-e2e/brief.md)"
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

 Trust project folder?
 /Users/kunchen/.treehouse/01KV18PMDX505TN87957JNNXTT-b8697d/1/01KV18PMDX505TN87957JNNXTT

 This allows pi to load .pi settings and resources, install missing project packages, and execute project extensions.

 → Trust
   Trust parent folder (/Users/kunchen/.treehouse/01KV18PMDX505TN87957JNNXTT-b8697d/1)
   Trust (this session only)
   Do not trust
   Do not trust (this session only)

 ↑↓ navigate  enter select  escape/ctrl+c cancel

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Evidence: Generated extension event simulation

registered_event=turn_end execFile_command=touch execFile_arg=/Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/state/pi-hook-e2e.turn-ended

registered_event=turn_end
execFile_command=touch
execFile_arg=/Users/kunchen/.no-mistakes/worktrees/016d88035d58/01KV18PMDX505TN87957JNNXTT/state/pi-hook-e2e.turn-ended

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bin/fm-bootstrap.sh - attempted baseline bootstrap; it failed because this isolated worktree lacks config/crew-harness parent state, so validation continued without creating persistent config.
  • Created temporary data/pi-hook-e2e/brief.md and state/, then ran bin/fm-spawn.sh pi-hook-e2e . pi --scout to exercise the real pi spawn path.
  • Captured state/pi-hook-e2e.pi-ext.ts and the tmux pane transcript into /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KV18PMDX505TN87957JNNXTT.
  • node -e '...' asserted the generated pi extension contains pi.on("turn_end"...) and does not register pi.on("agent_end"...).
  • node -e '...' asserted the captured spawn transcript launched pi -e .../state/pi-hook-e2e.pi-ext.ts.
  • node <<'NODE' ... NODE loaded the generated extension text with a mocked pi event emitter and verified triggering the registered callback calls touch on state/pi-hook-e2e.turn-ended.
  • bin/fm-teardown.sh pi-hook-e2e tore down the spawned scout task; git status --short confirmed no temporary worktree scaffolding remained.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid
kunchenguid merged commit d9ec890 into main Jun 13, 2026
3 checks passed
@kunchenguid
kunchenguid deleted the fix/pi-turn-end branch June 13, 2026 20:12
vipentti pushed a commit to vipentti/firstmate that referenced this pull request Aug 5, 2026
* fix(spawn): fire pi turn-end on turn_end, not agent_end

* no-mistakes(document): Document pi turn-end event
@jazz127

jazz127 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Superseded by https://github.com/jazz127/relationship-intelligence/pull/16, which carries the same work merged with dev and has landed.

@azwrth13

azwrth13 commented Oct 9, 2026

Copy link
Copy Markdown

Live validation after the rebase onto main

Head tested: 8825fd9, after the CI-monitor rebase onto 57cb57d and the review and test fix rounds.

The pipeline's sandbox has no Windows interop, so I ran the Studio fixtures from my own session. I followed the shared-slot rule: took the preview_sync lock, synced this exact tree, stopped my own playtest, re-synced main, then released the lock.

Studio fixture Result
tests/studio-boss.luau PASS: Dust Call telegraph 1.49s, stagger cancels the attack, defeat pays $150 plus a Rare box, Junk Toss hits the wall then the Core, Static Zap jams a turret
tests/studio-boss-night.luau PASS: Boss Night starts; Inspect shows a NIGHT phase with the Dust King present (220 HP)
tests/studio-core.luau PASS: Sock Brutes spawn, Core 150 → 142
tests/studio-walls.luau PASS: the wall collides and takes damage, and both the player shot and the turret fire through it
tests/studio-combat.luau PASS: Pistol, Spray, Launcher, Melee

The console showed no errors in either session.

Local checks on the same tree:

  • These pass with the pinned Rokit tools: stylua --check, selene (0 errors), lune tests/logic.luau (including the Explosive blast and Restock rules), lune tests/feedback_policy.luau, strict luau-lsp and rojo build.
  • scripts/asset_catalog.py and the Python unittests fail exactly as they do on main 57cb57d (party_capsule trim vs rarityColors). That is pre-existing; the fix is in https://github.com/azwrth13/blind-box-survival/pull/14, and this PR will rebase onto it once it lands.

Not covered by any fixture:

  • Client-side early clearing of telegraph rings on stagger, pop or night end. This is cosmetic only.
  • The Explosive telegraph being skipped over a broken wall. Only the logic tests cover this.

fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…rotation (kunchenguid#12)

* feat(primary): add optional quota-aware orchestrator handoff

Automate primary rotation when provider quota crosses a threshold, with an
atomic session-lock transfer that never allows two live holders, and keep
the feature inert unless config/primary-handoff is enabled.

Co-authored-by: Cursor <cursoragent@cursor.com>

* no-mistakes(review): fix float threshold, release-stale race, docs, cleanup helper

* no-mistakes(test): fix jq-1.6 cmux liveness probe and test fixtures

* docs: list primary-handoff state files in AGENTS.md state inventory

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* no-mistakes: apply CI fixes

* no-mistakes(ci): make fm-status-bar.test.sh executable

CI runs test scripts directly; the file was committed with mode 100644,
so the Behavior tests job failed with exit 126 (Permission denied).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
fritznoff pushed a commit to fritznoff/starship that referenced this pull request Nov 2, 2026
…h public Starship (kunchenguid#12)

* feat(bin): refuse new names and customer data shapes before they reach public Starship

* no-mistakes(review): Check commit messages, branch words, Dutch phones; drop fallbacks

* no-mistakes(review): Skip unborn caller checkouts; share one deadline across hook calls

* no-mistakes(document): Align leak guard header and hook doc with new checks
ghazni101 pushed a commit to ghazni101/firstmate-dsh that referenced this pull request Nov 19, 2026
…dular spawn' (kunchenguid#12) from fm/spawn-task-copy-acquisition into main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants