Skip to content

[Feature] Add background subagent lifecycle v1.1 #341

@Astro-Han

Description

@Astro-Han

What task are you trying to do?

We want PawWork to add the background half of the agent lifecycle now that #283 v1 has shipped through PR #287. The current v1 is intentionally foreground-only: agent blocks until terminal, lifecycle state is persisted through SubagentRun, and the model can inspect owned runs through agent_list and agent_output. This issue scopes the next step: background subagents that can keep running after the parent turn returns, then notify and resume safely when they finish.

What happens today?

PR #287 implemented the foreground lifecycle foundation: explicit running, completed, completed_empty, failed, and canceled_by_user states; a per-parent concurrency cap; agent_list; agent_output; resume validation; and parent-owned lifecycle persistence. The deferred pieces from #283 are still not present: run_in_background, parent-session completion notifications, safe auto-resume, agent_stop, blocking output reads, and restart cleanup for stranded running rows.

What would a good result look like?

agent supports run_in_background?: boolean while preserving the existing foreground default. A background subagent returns quickly with a clear running status and enough identity for later inspection. Terminal background states inject a parent-session notification and trigger safe auto-resume only when the parent can continue without surprising the user. The model can inspect background progress through the existing agent_list / agent_output tools. Any new stop or blocking-read tool surface must be justified by the background lifecycle, not added speculatively.

Scope

  • Add run_in_background?: boolean to agent, default false.
  • Reuse the existing SubagentRun lifecycle vocabulary and parent-owned state.
  • Preserve agent as the spawn entry point; keep agent_list and agent_output as narrow lifecycle query tools.
  • Add parent-session terminal notification for background completion, failure, cancellation, and empty output.
  • Define safe auto-resume rules so the parent can react to background completion without continuing blindly.
  • Decide whether agent_output needs block?: boolean / timeout_ms?: number once background reads exist.
  • Add agent_stop only if background execution gives the model a real re-entrant point where stopping a child is useful.
  • Add an abandoned or equivalent startup sweep for persisted running rows left behind by host restart.

Non-goals

  • Do not replace the current three-tool model with agent({ action: ... }). The current shape matches Claude Code-style best practice: spawn is one tool, lifecycle inspection is handled by narrow companion tools.
  • Do not add a new task panel, global background-task UI, or full task system.
  • Do not add nested subagents.
  • Do not add automatic backgrounding heuristics in this issue.
  • Do not mix in worktree/session execution-context changes; those belong to [Feature] Agent session lacks worktree isolation — worktree is a project concept, not a session context #278.
  • Do not add cross-parent session management.
  • Do not implement full transcript pagination.

Acceptance criteria

  • agent({ run_in_background: true }) starts a background subagent and returns a clear running result without blocking the parent until terminal.
  • Foreground agent behavior remains the default and stays backward-compatible with PR feat(agent): subagent lifecycle v1 (foreground-only) #287.
  • Background and foreground runs share the same persisted lifecycle states and authorization model.
  • agent_list includes running background runs and unread terminal background runs under the existing all_active behavior.
  • agent_output can inspect running background runs without consuming them, and consumes only terminal rows on first read.
  • Background terminal states notify the parent session with enough structured context for the model to continue safely.
  • Safe auto-resume behavior is specified and tested, including cases where the parent should not resume.
  • User cancellation and model/tool failure finalize background runs as explicit lifecycle states, never empty output.
  • Host restart does not leave old persisted running rows looking live forever; the startup sweep marks them with a clear terminal or abandoned state.
  • If agent_stop is added, it can stop only subagents owned by the current parent session and returns the same lifecycle vocabulary.
  • Tests cover foreground compatibility, background launch, notification, auto-resume gating, output reads, cancellation, failure, restart cleanup, and authorization.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priorityenhancementNew feature or requestharnessModel harness, prompts, tool descriptions, and session mechanics

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions