fix(kap-server): carry the live subagent roster in the session snapshot - #1623
fix(kap-server): carry the live subagent roster in the session snapshot#1623wbxl2000 wants to merge 11 commits into
Conversation
🦋 Changeset detectedLatest commit: 5991a4b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Accumulate the per-session live subagent roster in the broadcaster's dispatch queue and expose it via getSnapshotState, so the web client can rebuild swarm cards after a page refresh. Both snapshot assembly paths (SnapshotReader and the legacy resume path) pass it through as the optional subagents field.
be6a123 to
0217112
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be6a123a14
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
commit: |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95b12c30d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bef5c98c79
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0552bbc38a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8fae3d8fc9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c5e10015b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2d8e2f778
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| sessionId, | ||
| journal, | ||
| tracker: new InFlightTurnTracker(), | ||
| roster: new SubagentRosterTracker(), |
There was a problem hiding this comment.
Seed the roster on first activation
When the first v1 WS/snapshot activation for an already-running session happens after subagent.spawned has fired (for example, a prompt was started via REST/TUI before the web UI subscribes), this initializes an empty roster and only then attaches the agent event listeners. The missed spawn metadata is not replayed into SubagentRosterTracker, and later lifecycle/progress events ignore unknown subagent IDs, so /snapshot still returns subagents: [] for the live swarm until a new spawn occurs. Seed the tracker from an already-active run or activate the broadcaster before prompt execution starts.
Useful? React with 👍 / 👎.
Related Issue
No linked issue — the problem is explained below.
Problem
Refreshing the web UI while subagents are still running lost the AgentSwarm card's member list on the kap-server backend. The swarm identity metadata (
description/parentToolCallId/swarmIndex) only rode thesubagent.spawnedWS event, which is not replayed after a refresh, and REST/tasksdid not provide the live foreground swarm roster. The protocol already defines an optionalsubagentssnapshot field, but kap-server did not populate it.The initial roster implementation also had lifecycle gaps. A child agent's
turn.endedcould clear every sibling; Ctrl+B detach and its later terminal event were not reflected in the durable snapshot; and late ordinary lifecycle events could overwrite a terminal status. On the Web side, the client collapsed an omitted legacy field and an authoritativesubagents: []into the same value, so a resync could retain a stale running member after the main turn had cleared the roster. Detached Agent tasks also need their real task identity so REST and WS cannot create duplicate or mismatched cards.What changed
SessionEventBroadcaster, updated inside its existing dispatch queue.agent_idalongside a detached task's canonicalid.turn.endedno longer clears sibling entries.task.startedandtask.terminatedinto the matching member so detach and its final state survive refresh, with exact task binding preventing an old run from terminating a respawned run.task.startedonly update a running member;task.terminatedremains authoritative in either event order; onlysubagent.spawnedstarts a new run for the same agent.subagentsroster through both kap-server snapshot assembly paths.[], removes stale foreground roster members while preserving Bash/tool tasks and REST-owned detached Agent tasks (run_in_background: true); a non-empty roster replaces unknown foreground members.The branch includes current
main@5d1f9049cthrough an ordinary merge commit. This only refreshes the test/DI baseline; no downstream stop or foreground-task branch is copied into this PR. #1648 remains the separate stacked foreground REST projection change.Verification
check:style: baseline mode, 29 existing findings, no failure.agent-core-v2 lint:domain: passed (848 files).git diff --check: passed.changeset status --since=origin/main:@moonshot-ai/kimi-codepatch.gen-changesetsand thegen-docsimpact check. No user guide change is needed for restoring this existing behavior; the skill's changelog sync prerequisite is absent in this checkout (docs/scripts/sync-changelog.mjs), so no changelog sync was claimed.Checklist