Skip to content

feat(core): expose subagent task tracker for delegated runs#35

Merged
ZhiXiao-Lin merged 1 commit into
mainfrom
feat/subagent-task-tracker
May 23, 2026
Merged

feat(core): expose subagent task tracker for delegated runs#35
ZhiXiao-Lin merged 1 commit into
mainfrom
feat/subagent-task-tracker

Conversation

@ZhiXiao-Lin
Copy link
Copy Markdown
Contributor

Summary

Adds a queryable materialized view of delegated subagent task lifecycles so callers can introspect automatically-triggered parallel sub-agent runs like a task dashboard — without parsing run_events().

  • New subagent_task_tracker module: SubagentTaskSnapshot + InMemorySubagentTaskTracker, populated from the existing SubagentStart/Progress/End event stream via RuntimeEventSink::observe.
  • New public APIs on AgentSession: subagent_task(id), subagent_tasks(), pending_subagent_tasks() — all scoped to the parent session.
  • Fixes two pre-existing bugs in TaskExecutor:
    1. SubagentStart now carries the real parent_session_id (was String::new()).
    2. execute_background returns the same task_id used in emitted events (was returning a throwaway id), and pre-emits SubagentStart synchronously so callers querying the tracker right after scheduling don't hit a race.

The event stream remains the authoritative record; the tracker is a read-side projection.

API surface

session.subagent_task("task-abc").await   // Option<SubagentTaskSnapshot>
session.subagent_tasks().await            // Vec<SubagentTaskSnapshot> (this session)
session.pending_subagent_tasks().await    // only Running entries

SubagentTaskSnapshot carries task_id, parent_session_id, child_session_id, agent, description, status, started_ms, updated_ms, finished_ms, output, success, progress (currently empty — wired in PR #2).

Test plan

  • 6 unit tests in subagent_task_tracker.rs cover lifecycle, failed-end, pending filter, parent-session filter, end-before-start, and non-subagent events.
  • 2 integration tests in agent_api/tests.rs cover end-to-end propagation through RuntimeEventSink and parent-session isolation.
  • cargo test --lib -p a3s-code-core: 1651 passed / 0 failed.
  • cargo test --tests -p a3s-code-core: all integration binaries green.
  • cargo clippy --lib --tests -p a3s-code-core: no new warnings (3 pre-existing warnings in extra_agent_tests.rs / test_auto_delegation_real_parallel.rs are untouched).
  • cargo fmt clean (pre-commit hook passed).

Out of scope (follow-ups)

Adds a materialized view over the existing SubagentStart/Progress/End
event stream so callers can query the lifecycle of delegated child runs
by task id — without scanning run_events() — making automatic parallel
delegation observable like a task dashboard.

- New `subagent_task_tracker` module with `SubagentTaskSnapshot` +
  `InMemorySubagentTaskTracker`; populated from runtime events via the
  existing `RuntimeEventSink::observe` path.
- `AgentSession` gains `subagent_task(id)`, `subagent_tasks()`, and
  `pending_subagent_tasks()` query APIs, scoped to the parent session.
- Fixes two pre-existing bugs in `TaskExecutor`:
  1. `SubagentStart` now carries the real parent session id instead of
     `String::new()`, so tracker entries are correctly associated with
     the originating session.
  2. `execute_background` now returns the same task id used in emitted
     events (previously it generated a throwaway id and `execute`
     internally generated a different one), and pre-emits `SubagentStart`
     synchronously so callers can query the tracker immediately after
     the background task is scheduled.

Event stream remains the authoritative record; the tracker is a
read-side projection that can be rebuilt by replaying events.
@ZhiXiao-Lin ZhiXiao-Lin merged commit 57cd9a3 into main May 23, 2026
1 check passed
@ZhiXiao-Lin ZhiXiao-Lin deleted the feat/subagent-task-tracker branch May 23, 2026 15:47
ZhiXiao-Lin pushed a commit that referenced this pull request May 23, 2026
Bumps Rust core, Node SDK, and Python SDK to 3.2.0 and documents the
subagent task tracker work that landed across #35#41 + #38.

Changes
- Bump all five version files (core/sdk Cargo.toml, sdk/node/package.json,
  sdk/python/pyproject.toml) plus Node lockfiles and Cargo.lock.
- Mark SubagentStatus #[non_exhaustive] so future variants are non-
  breaking. The Cancelled variant added in this release still counts as
  a breaking change for exhaustive matchers — flagged in the CHANGELOG.
- Add a [3.2.0] section to CHANGELOG.md covering: the tracker query
  API, SubagentProgress emission, the Cancelled status and
  cancel_subagent_task entry point, Node + Python SDK exposure of all
  of the above, the regen-stable Node .d.ts split, and the
  TaskExecutor / register_task_with_mcp signature additions.
- Extend README with a "What's new in 3.2" block and a Delegation
  table that lays out the observe + cancel API across Rust, Node, and
  Python.

Preflight done locally
- cargo fmt --all --check
- cargo test -p a3s-code-core --lib  (1661 passed)
- cargo test -p a3s-code-core --tests (all green)
- scripts/check_release_versions.sh  (consistent at 3.2.0)
- (cd sdk/node && npm run build:debug && npm test && npm run test:types)

Not run here: release.sh / git tag. This commit is for review only;
tagging + publishing happens after the PR lands.
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.

2 participants