Skip to content

feat: parent-child session linking and resumable subagents #87

Description

@ezynda3

Feature Description

Link subagent sessions to their parent session, and allow resuming an existing subagent session for multi-turn collaboration.

1. Parent-child session linking

Subagent runs currently create disconnected child sessions — the parent link is only set in TreeManager.ForkToNewSession, not in the Kit.Subagent() path (pkg/kit/kit.go). The extension config has a ParentSessionID field (internal/extensions/subagent.go) but it is not propagated into the child session header in the SDK path.

Proposed: record parent_session_id in the child session's session entry whenever a subagent is spawned from a session-backed parent. The parent already receives subagent_session_id as tool-response metadata, so linking both directions enables session-tree navigation of delegated work (e.g. a future session browser showing subagent runs nested under the parent turn).

2. Resumable subagents

Each subagent invocation is one-shot: context is re-established from scratch for every follow-up question. opencode's task tool accepts a task_id that reuses the existing child session, enabling cheap multi-turn subagent collaboration.

Proposed: add an optional session_id parameter to the subagent tool (internal/core/subagent.go) and SubagentConfig. When provided, the child Kit loads that existing session instead of starting fresh, so the parent agent can ask follow-ups without paying the context-rebuilding cost. The tool description should mention that the returned subagent_session_id can be passed back for follow-up tasks.

Motivation / Use Case

  • Observability: users can't currently trace which session a subagent run belongs to, or find subagent transcripts from the parent session. Bidirectional links fix that and unlock future UI (nested session trees).
  • Cost/latency: research-style delegation is often iterative ("now check how X handles errors" after an initial exploration). Re-spawning from scratch re-reads the same files and re-burns tokens; resuming the child session reuses its accumulated context.
  • Cancellation semantics: an explicit parent link also gives a natural place to hang parent-abort → child-cancel propagation.

Proposed Implementation

  • internal/session/tree_manager.go: add ParentSessionID to the session header entry; write it when creating subagent-backed sessions.
  • pkg/kit/kit.go (Kit.Subagent): accept SessionID in SubagentConfig; when set, open the existing session instead of creating one; always stamp the parent session ID when the parent is session-backed.
  • internal/core/subagent.go: add optional session_id to subagentArgs; document the resume workflow in the tool description.
  • internal/extbridge/extbridge.go: propagate the existing ParentSessionID field (currently unused in this path).

Related: #84 (named agents), #86 (background subagent handle) touch the same code paths and could share plumbing.

Checklist

  • I've searched existing issues and this hasn't been requested yet
  • This feature aligns with Kit's design philosophy (TUI-first, extension-based)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions