fix(interactive-subagents): harden parallel lifecycle delivery

This commit is contained in:
jb
2026-09-03 23:40:14 -04:00
parent d99dbce93d
commit 7a1043e5e0
11 changed files with 848 additions and 131 deletions
+2 -16
View File
@@ -20,23 +20,9 @@ Slice 1 found two Nono 0.74 limitations while building behavioral policy proofs.
The strict `workflow` extension repeatedly failed before implementation because planner output and persisted state-machine constraints were too brittle for adaptive subagent orchestration. In a separate session, design a repository-managed skill where the main Pi agent owns the plan, task tree, isolated worktree, explicit user approval gates, verification, and independent review while launching standard `scout` and `worker` subagents directly. Preserve file-ownership boundaries, no inferred approvals, review independence, and resumable repository evidence, but prefer native Pi primitives over a custom orchestration engine. Evaluate a small committed state manifest for crash recovery before retiring or archiving the extension. Use the abandoned `.worktrees/workflow-plan-seed` implementation only as reference; do not integrate it by default.
## Support subagent launches through `multi_tool_use.parallel`
## Support finished-session resume for Claude CLI subagents
A user reported that launching subagents through Pi's `multi_tool_use.parallel` wrapper does not work, although equivalent launches succeed outside the wrapper in another session. The tool surface in the incident below was the harness-provided `functions.subagent` tool wrapped by `multi_tool_use.parallel`; it has not been proven to be the `subagent_spawn`/`subagent_wait` surface from this repository's `@jbcode/pi-subagents` package. Keep those implementations separate until tracing identifies the owner.
A second incident occurred while planning the skill-led development workflow on 03SEP2026. The complete sanitized wrapper payload, prompts, expected lifecycle, observed lifecycle, and direct-launch control are retained in [`docs/fixtures/subagent-parallel-idle-delivery-03SEP2026.json`](./fixtures/subagent-parallel-idle-delivery-03SEP2026.json). Environment evidence captured at `2026-09-03T15:54:57-04:00`:
- Pi `0.84.4`; repository subagent package `0.1.0` was present but is not yet identified as the failing tool implementation.
- Parent session `01a06885-7f00-7cff-bc2f-334984151941`, file `/home/jb/.pi/agent/sessions/--srv-data-code-jb-pi-harness-tools--/2026-09-03T18-26-14-400Z_01a06885-7f00-7cff-bc2f-334984151941.jsonl`.
- Parent backend `openai-codex/gpt-5.6-sol`, reasoning `high`.
- One `multi_tool_use.parallel` call launched `workflow-architecture` (`codebase-analyzer`), `workflow-history` (`precedent-locator`), and `workflow-patterns` (`codebase-pattern-finder`) with cwd `/srv/data/code/jb-pi/harness-tools`. Each wrapped result returned only a successful fire-and-forget acknowledgement; no child task or session ID was exposed.
- The children later appeared completed in the UI, but their automatic result payloads did not wake the idle orchestrator. The orchestrator remained parked until the user intervened.
- Follow-up `subagent_message` calls for all three returned acknowledgements saying the message was delivered to a running subagent, inconsistent with the completed UI state.
- A later direct, unwrapped `subagent` launch named `skill-workflow-plan-review` in the same parent session completed and delivered its result automatically after 14 minutes 9 seconds.
Use the retained three-agent JSON payload as the captured failing fixture. Also reproduce with two minimal independent children, comparing direct calls with one wrapped call. Include a case where the parent performs other work and then becomes idle before both children finish. Preserve exact tool-call payloads, acknowledgement timestamps, child IDs when available, terminal-state timestamps, parent idle transitions, callback queue entries, and delivered steer messages. Capture whether failure occurs during schema validation, dispatch, asynchronous acknowledgement, task registration, terminal-state publication, idle-parent wake-up, or completion delivery.
The wrapper must return promptly for fire-and-forget launches, preserve each subagent's name and working directory, expose enough identity to correlate acknowledgements and terminal results, transition UI and tool-visible status consistently, and deliver each result exactly once without polling or user intervention. Add focused integration coverage for successful parallel launch, staggered completion while the parent is idle, one-child failure, cancellation, late steering of an apparently completed child, and duplicate-delivery prevention before changing either tool.
`subagent_message` can steer a running Claude CLI pane, but a completed Claude launch has no Pi session file and cannot use the existing finished-session resume path. Store the Claude session identifier and original sandbox metadata in the parent registry, then resume with Claude's native session mechanism while retaining the original name and fire-and-forget result delivery. Until implemented, keep the README's finished-session contract explicitly limited to Pi-backed subagents.
## Investigate transient concurrent NeMo benchmark failures