feat(junior): Add deferred subagent handoff for Pi task delegation#73
feat(junior): Add deferred subagent handoff for Pi task delegation#73
Conversation
Synthesize a new integration-documentation skill for consumers that use @mariozechner/pi-agent-core as their agent abstraction. Document API contracts, common downstream integration patterns, and failure-mode troubleshooting focused on streaming bridges, queue/continue semantics, and migration-safe usage. Co-Authored-By: Codex <noreply@openai.com>
Add queued subagent delegation with child-task processing and parent turn continuation so long-running delegated work can complete safely in serverless. Also reduce interface slop by collapsing queue handoff fields into a typed queue context object, removing unused model override plumbing, and gating subagent runs from spawning subagents or using Slack tools. Fixes #71 Co-Authored-By: GPT-5 Codex <noreply@openai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| messageTs: payload.queueContext.message.id, | ||
| threadTs: payload.queueContext.message.threadId, | ||
| requesterId: payload.queueContext.message.author?.userId | ||
| }, |
There was a problem hiding this comment.
Subagent reuses parent session checkpoint key, corrupting state
High Severity
The subagent passes the parent's conversationId and sessionId (as turnId) into generateAssistantReply's correlation. Since getSessionIdentifiers derives the checkpoint key from correlation.conversationId and correlation.turnId, the subagent's turn session checkpoint key is identical to the parent's. This causes two critical problems: (1) the subagent finds the parent's "awaiting_resume" checkpoint, treats it as its own, and calls continue() on the parent's message history instead of running prompt() with the delegated task; (2) upon completion, the subagent overwrites the parent's checkpoint with state: "completed", preventing the parent from ever resuming properly.


Add deferred subagent execution so long-running delegated work can complete without requiring the parent turn to stay active in one serverless slice.
This introduces a taskSubagent tool that enqueues a child subagent task, persists task state, and resumes the parent turn once the child finishes. Parent turns checkpoint and defer via retryable turn semantics instead of hard-failing on pending child work.
Subagent execution now uses the same generateAssistantReply runtime path as the parent, so it has equivalent non-Slack/non-recursive tooling behavior and prompt/runtime conventions. As guardrails, subagent turns do not register Slack tools and cannot invoke taskSubagent recursively.
I also deslopped the new interface by collapsing multiple queue handoff fields into one typed queueContext contract and removing unused delegated model override plumbing.
Fixes #71