Skip to content

fix(pi-subagents): model inheritance and fatal-error lifecycle - #43

Merged
tasercake merged 1 commit into
mainfrom
fix/pi-subagents-model-inheritance-and-fatal-error
Jul 25, 2026
Merged

fix(pi-subagents): model inheritance and fatal-error lifecycle#43
tasercake merged 1 commit into
mainfrom
fix/pi-subagents-model-inheritance-and-fatal-error

Conversation

@tasercake

Copy link
Copy Markdown
Owner

Summary

Fixes two lifecycle/model-selection bugs in the pi-subagents extension.

Bug 1 — Model inheritance

spawn_subagent accepts an optional model. When omitted, the child previously used ~/.pi/agent/settings.json's global default rather than the parent session's active model. Now reads ctx.model from ExtensionContext and passes the canonical provider/id string 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

  • schemas.ts: model description documents inheritance
  • index.ts: model inheritance in makeRecord, stdout error monitoring + graceful kill in startChild, (error) result fallback
  • pi-args.ts: --mode json for machine-parseable child output
  • SKILL.md: model inheritance docs
  • mock-pi-script.mjs: stopReason/errorMessage support
  • tests: 7 new tests (model inheritance, error lifecycle, dedup, timeout, normal success, lifeline)

Test results

42 pass, 1 fail (pre-existing: integration test uses t.skip() unsupported by Bun)

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
tasercake force-pushed the fix/pi-subagents-model-inheritance-and-fatal-error branch from 3a2cd5f to 5deb747 Compare July 25, 2026 14:34
@tasercake
tasercake merged commit 03f78fa into main Jul 25, 2026
1 check passed
@tasercake
tasercake deleted the fix/pi-subagents-model-inheritance-and-fatal-error branch July 25, 2026 14:35
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.

1 participant