Repository navigation
fix(pi): gate first provider call on startup context - #3158
kunchenguid merged 9 commits into
Conversation
… failure fallback
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code failure remaining after review. The generation owner gates provider startup on the matching result, suppresses stale delivery, retires supervised process groups across lifecycle transitions, and preserves intentional silence separately from failure fallback. Reviews (1): Last reviewed commit: "no-mistakes(document): docs: clarify Pi ..." | Re-trigger Greptile |
|
Speaking as Kun's firstmate: Reviewed HEAD Class: corrective. Immediate VISION (per rule, inspected evidence):
First-time fork CI: after that full-diff review I approved workflow runs Not merging. Merge-eligible: NO (waiting-ci). Captain-flag NOW: NO. |
|
@kunchenguid Thanks for reviewing and approving the workflow runs. All 14 checks are now green on the same reviewed HEAD |
|
Any updates on this? |
Intent
Fix the reproducible Pi
/newstartup-context race on the fetched currentorigin/mainimplementation base and publish one PR whose canonical base is exactlygithub.com/kunchenguid/firstmate, without merging it. The user-visible failure is triggered by submitting the first prompt immediately after/newwhile native startup digest generation is still running: the first provider call can occur before native delivery, lacks startup context, causes the documented manual fallback to run, and a later call then contains both manual and native startup digests. Preserve the comparison with the proven path where native startup completes before prompt submission, retain the deterministic local-provider reproduction as the regression basis, and seek disconfirming evidence for the ownership fix.Implement the smallest current-code-aligned generation-bound owner in
.pi/extensions/fm-primary-turnend-guard.ts: activate one generation onsession_start, bind it to the Pi session and monotonic generation, makebefore_agent_startawait that matching startup result and return the persistent context message immediately upstream of the first provider call, prevent asynchronous native delivery from racing that call, ignore stale generations, and terminate the matching child process group with no late delivery on shutdown or replacement. If an eligible native attempt fails or yields no digest, let that exact attempt settle before injecting the existing exact manual fallback instruction so native and manual generation never run concurrently. Preserve conservative full-start behavior, lock/refusal behavior, loud truncation and direct-inspection guidance, context-preserving source behavior, compaction behavior, and every supported Pi and pi-signed source route. Do not implement the investigation report's unrelated context-efficiency items 1-7.Acceptance requires an end-to-end immediate-
/newregression proving no provider call occurs before the matching prerequisite settles; exactly one startup execution and one model-visible startup context for each generation; the first provider payload contains that context; and deterministic executable coverage for interruption, shutdown, child/grandchild retirement, two rapid replacements, stale completion, empty output, spawn error, nonzero failure, intentional ineligibility, timeout, and truncation with no stale delivery. Keep existing startup, supervision, wake, and harness behavior passing across applicable Pi and pi-signed surfaces. Correct maintained documentation that previously claimed race-free delivery, keep one sentence per Markdown line, and route evidence to its proper owner. Run repository-prescribed syntax and lint checks,bin/fm-doc-audience-check.sh, documentation validation, applicable startup suites, and the real no-network Pi 0.84.0 regression using an isolated home, barrier-controlled digest, and deterministic local provider.The preserved read-only investigation at
/Users/cmagana/cerebro/data/firstmate-public-head-context-plan-v1-s6/report.mdmust remain unchanged. A later bounded base-vs-branch counterfactual established that the unchanged bootstrap-parallelism overlap assertion fails identically on exactorigin/mainunder equivalent conditions, with byte-identical normalized timelines and no task diff touching its owners; preserve that as a pre-existing or environment-sensitive limitation and do not weaken, skip, or edit the unrelated bootstrap regression merely to obtain green. Publish only the task branch through the full no-mistakes pipeline, use GitHub author and committer identity exactlyM00NLIG7 <[email protected]>with no agent co-author, verify that identity again before publication, open the authorized upstream PR against exactlygithub.com/kunchenguid/firstmate, and stop when its required CI is green. Never merge the PR.What Changed
/new, lifecycle and failure paths, and update documentation to reflect prerequisite-based delivery.Risk Assessment
✅ Low: Captain, the generation-bound prerequisite, supervised process-group lifecycle, failure fallback, and fixture dependency changes are coherent and no material source risk remains.
Testing
With no prior baseline results supplied, I verified the required runtime, passed the targeted executable lifecycle/failure regression, and passed the real isolated no-network Pi 0.84.0
/newreproduction; the saved transcript demonstrates prompt blocking, exactly one native context per generation, and no manual fallback for both immediate and completed-before-prompt paths.Evidence: Offline Pi `/new` race transcript
Source: Offline Pi
/newrace transcriptPi 0.84.0: immediate and completed-before-prompt/newpaths each made one first provider call with exactly one native startup context and no manual execution.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (6) ✅
.pi/extensions/fm-primary-turnend-guard.ts:189- Retirement treats the direct child'scloseas proof that the entire process group exited. If a descendant ignores SIGTERM and has redirected/closed stdio, the leader can close first,childClosedbecomes true, and SIGKILL is skipped, leaving that descendant running after replacement or shutdown. After the grace period, probe/kill the captured process group independently of the leader's close state, and cover a TERM-resistant descendant with closed stdio.🔧 Fix: Captain, fix startup process-group retirement after leader exit
1 warning still open:
.pi/extensions/fm-primary-turnend-guard.ts:395- The module-level exit listener is never removed. Pi clears and reloads extension modules on/reload, so each reload adds another retainedprocess.once("exit")callback holding that module generation and potentially its 512 KiB result. Repeated reloads cause memory growth and eventuallyMaxListenersExceededWarning. Register cleanup per bound extension instance and remove it duringsession_shutdownso the replacement instance owns the sole exit fallback.🔧 Fix: Captain, release reload exit listeners on shutdown
2 errors still open:
.pi/extensions/fm-primary-turnend-guard.ts:484- Pi supports same-bound-instancesession_shutdown→session_startreplacement, but shutdown permanently removes this instance's exit listener and session start never restores it. After/new,/resume, or/fork, a later active startup generation therefore lacks process-exit cleanup. Re-register the listener idempotently when each session activates, and add same-instance replacement coverage..pi/extensions/fm-primary-turnend-guard.ts:439- The process-exit fallback still depends ongeneration.child. If the leader closes while a TERM-resistant descendant with closed stdio remains,markClosed()clears that field, so exit cleanup skips the captured process group and orphans the descendant. On non-Windows platforms, signal the retainedprocessGroupIddirectly even after leader close; preserve the current Windows path and cover this sequence.🔧 Fix: Captain, complete startup exit lifecycle ownership
1 error still open:
.pi/extensions/fm-primary-turnend-guard.ts:445- A completed generation retains its numeric process-group ID indefinitely. After the child closes and that ID is reused,/new, shutdown, or process-exit cleanup can send TERM/SIGKILL to an unrelated process group. Monitor the retained group after leader close and clearprocessGroupIdas soon as the group becomes empty, while preserving it for verified surviving descendants.🔧 Fix: Captain, release empty startup process-group ownership promptly
2 errors still open:
.pi/extensions/fm-primary-turnend-guard.ts:392- The required criterion says, “If an eligible native attempt fails or yields no digest ... inject[] the existing exact manual fallback instruction,” but this allowlist suppresses fallback forresumeandforkeven when their child has a spawn error or nonzero exit. Preserve intentional context-restored silence for expected empty results, but return the exact fallback for failed eligible attempts on every source..pi/extensions/fm-primary-turnend-guard.ts:193- The 10 ms existence polling still retains only a reusable numeric process-group ID: after a successful probe, the matching group can empty and its ID can be reused before the next tick; the monitor then accepts the unrelated group as alive, and later replacement or process-exit cleanup sends it SIGTERM/SIGKILL. This leaves the previously reported unrelated-process termination reachable. Move retained ownership to a stable launch boundary—such as a supervisor that remains the group leader until ownership is released—rather than retaining an unidentifiable bare PGID after the leader closes.🔧 Fix: Captain, supervise startup ownership and restore failure fallback
1 error still open:
tests/fm-sessionstart-hook-live-e2e.test.sh:354- Both isolated Pi fixture builders in this file copy the extension without its newlib/fm-sessionstart-supervisor.mjsruntime dependency (also see line 179). Node therefore exits with a missing-module error, and the required/newregression reaches fallback instead of producingRACE_NATIVEcontext. Copy the supervisor into each fixture’slibdirectory so the live tests exercise the production path.🔧 Fix: Captain, restore live Pi supervisor execution
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
pi --versionandtmux -Vconfirmed Pi 0.84.0 and tmux 3.6a.tests/fm-sessionstart-nudge.test.shFM_PI_SESSIONSTART_RACE_LIVE_E2E=1 tests/fm-sessionstart-hook-live-e2e.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.