fix(pi-subagents): model inheritance and fatal-error lifecycle - #43
Merged
tasercake merged 1 commit intoJul 25, 2026
Merged
Conversation
Bug 1 — Model inheritance: When spawn_subagent is called without an explicit model, the child previously used ~/.pi/agent/settings.json's global default instead of the parent session's active model. Fix: makeRecord now reads ctx.model from the ExtensionContext and populates the canonical provider/id string. Explicit model still wins. Bug 2 — Fatal-error lifecycle: When a child Pi receives a stopReason:"error" response (e.g. HTTP 402), the child may stay alive indefinitely. The parent only considers a child complete after OS process close, so the record remains running forever. Fix: monitor child stdout for "stopReason":"error" in JSONL output (enabled via --mode json). On detection, record the error immediately and kill the hung child after a 1-second grace period (SIGTERM then SIGKILL). This triggers the normal close handler which finalizes the record with error text and fires exactly one completion notification. Changes: - schemas.ts: update model description to document inheritance - index.ts (extension): model inheritance in makeRecord, stdout error monitoring + graceful kill in startChild, result.log (error) fallback when provider error captured, fix code!=null check to not overwrite signal-killed errors - pi-args.ts: pass --mode json for machine-parseable child output - SKILL.md: document model inheritance behavior - mock-pi-script.mjs: support stopReason/errorMessage in responses - tests: 7 new tests covering model inheritance, error lifecycle, dedup, timeout-preservation, normal success, lifeline cleanup
tasercake
force-pushed
the
fix/pi-subagents-model-inheritance-and-fatal-error
branch
from
July 25, 2026 14:34
3a2cd5f to
5deb747
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two lifecycle/model-selection bugs in the pi-subagents extension.
Bug 1 — Model inheritance
spawn_subagentaccepts an optionalmodel. When omitted, the child previously used~/.pi/agent/settings.json's global default rather than the parent session's active model. Now readsctx.modelfromExtensionContextand passes the canonicalprovider/idstring to the child.Bug 2 — Fatal-error lifecycle
When a child Pi receives
stopReason: "error"(e.g. HTTP 402), the process may stay alive indefinitely. The parent only considers a child complete after OS process close, so the record remains running forever. Now monitors child stdout in real-time for terminal error events, records the error immediately, and kills the hung child after a 1-second grace period.Changes
makeRecord, stdout error monitoring + graceful kill instartChild,(error)result fallback--mode jsonfor machine-parseable child outputstopReason/errorMessagesupportTest results