Skip to content

feat(junior): Add deferred subagent handoff for Pi task delegation#73

Draft
dcramer wants to merge 2 commits intomainfrom
feat/subagent-deferred-deslop
Draft

feat(junior): Add deferred subagent handoff for Pi task delegation#73
dcramer wants to merge 2 commits intomainfrom
feat/subagent-deferred-deslop

Conversation

@dcramer
Copy link
Member

@dcramer dcramer commented Mar 6, 2026

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

dcramer and others added 2 commits March 5, 2026 14:42
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>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

Evaluate task subagent capability in Junior via Pi SDK

1 participant