Repository navigation
fix: restore swarm members from persisted lifecycle events - #3970
Conversation
🦋 Changeset detectedLatest commit: fab6751 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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Cold reconstruction can produce stale or duplicate task state and does not reliably identify members lost from earlier turns.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 3
Open (3)
What changed in this PR
Persists subagent lifecycle events so cold transcript reads can reconstruct Swarm members after restarts.
Changes:
- Makes subagent lifecycle events durable and replayable.
- Rebuilds member tasks/references and marks interrupted foreground members lost.
- Adds persistence and cold-reconstruction coverage.
| File | Description |
|---|---|
.changeset/restore-swarm-members.md |
Records the user-visible fix. |
packages/agent-core-v2/src/session/subagent/mirrorAgentRun.ts |
Makes lifecycle events durable. |
packages/agent-core-v2/test/state/eventDispatcher.test.ts |
Tests persistence and replay. |
packages/transcript/src/history/foldFacts.ts |
Reconstructs tasks and member references. |
packages/transcript/test/layers.test.ts |
Tests lifecycle folding. |
packages/kap-server/src/services/transcript/transcriptService.ts |
Reconciles restored task liveness. |
packages/kap-server/test/services/transcript.test.ts |
Tests cold Swarm restoration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d306f9fec
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ycle records The manifest inventory drives the vis wire-renderer coverage check, so vis gains a renderer for each new record type and treats them as timeline-neutral in the context projector.
… after its spawn Some emitters register the task after publishing the spawn, so the durable spawn record carries no task id and the cold fold keyed the member by its agent id. A later task.started then created a second task that no subagent terminal event ever reached, leaving a duplicate stuck in the running state. Folding task.started now records the agent-to-task association the live projector keeps, and terminal subagent records update both representations when both are retained.
…d member The durable subagent.completed record carries the member's token usage and the live projector copies it onto the task, but the cold fold dropped it, so a reopened conversation showed a completed member without usage metadata. The fold now validates the payload's four counters and restores them.
…ed it The cold snapshot only terminalised an unfinished foreground member when the parent agent was idle, so a member left behind by a restart stayed marked as running forever once the user started a new parent turn before backfill. The restored agent refs already name the tool call that spawned each member, so the decision now uses the turn owning that call: a member is lost when its own loop is not running and its spawning turn is not the turn the parent is running now.
…ored-swarm-members
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e1201cf02
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… afterwards A spawn published before its task is registered — the Tower worker path — carries no task id, so the fold created a placeholder keyed by the agent id and the later task.started added a second task under the registered id. Only the registered task was ever terminalised, and the detached placeholder was skipped by the lost-member pass, so a restored transcript kept a duplicate worker shown as running forever. task.started now folds the placeholder into the registered task instead of leaving it behind.
The append log buffers records and writes them in batches, which is why its own reader flushes the log first. The cold transcript reads the wire file directly and skipped that drain, so a snapshot could stop on a stale prefix. When the transcript binding is created after a turn has already ended, the whole store is built from that snapshot and nothing repairs it afterwards, leaving the turn's last tool call without its result and its member marked lost. Reading now drains the live agent's wire first, as session export already does before it reads the same files.
…ored-swarm-members
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Step 9 of the incremental sync to 2.1.1: 24 upstream commits over 321 files. The step brings the TUI mode setting, the jump-to-bottom indicator, click-to-toggle transcript folds, banner audience targeting and the workspace-trust hardening. Upstream's changes in this step, all absorbed: - add a TUI mode setting for the fullscreen layout (MoonshotAI#4004) - add a jump-to-bottom indicator and a steady status row (MoonshotAI#3989) - toggle one transcript fold block with a click (MoonshotAI#3990) - support audience targeting for startup banners (MoonshotAI#3868) - harden workspace trust boundaries across git, file tools and the local web server (MoonshotAI#3964) - turn off filesystem watch by default (MoonshotAI#3931) - add the auto_session_title config option (MoonshotAI#3962) - prepend a wall-time header to persisted tool results (MoonshotAI#3966) - report enabled plugins and plugin toggles in telemetry (MoonshotAI#3963) - include step timing and usage in cold-folded steps (MoonshotAI#3938) - restore swarm members from persisted lifecycle events (MoonshotAI#3970) - enforce tower protocol invariants and deny AgentSwarm (MoonshotAI#3976) - inherit titleKind for default fork titles (MoonshotAI#3974) - request offline_access in MCP OAuth when the authorization server advertises it (MoonshotAI#3979) - cut CLI startup time and memory in the native binary and config reads (MoonshotAI#3975) - avoid a stack overflow when caching large wire files (MoonshotAI#3957) - reject non-ASCII mission titles and record token usage (MoonshotAI#3847) - pick the credential slot and relay from the login region (MoonshotAI#3969) - add the KIMI_CODE_REPEAT_BREAKER env switch (MoonshotAI#3995) - update the kimi-webbridge plugin to the 2.0.11 skill (MoonshotAI#3961) - restructure the PR template and add the write-pr and review-pr skills (MoonshotAI#3992) Fork behaviour that had to survive: - the TUI controller split: upstream's rewritten activity-pane logic (braille thinking/composing spinners, the shared loading-tip kind) was ported into the fork's ActivityPaneController, and KimiTUI keeps delegating to it - the i18n layer: the new TUI mode setting, its picker, the restart notice and the settings entry all go through `t()` with en/zh entries - the fork's node-local → host rename: the upstream test files that still imported `#/os/backends/node-local/hostFsService` now point at `#/os/backends/host/hostFsService` - the fork's inline media reading: upstream's realpath guard for the media tool is covered by a ReadTool-based symlink-escape test - the fork's removePlugin deletes the plugin root from disk, so the new toggle-telemetry fixture keeps its root inside the managed directory - the Bun toolchain: the retired Node SEA chain stays retired Verified: typecheck clean across every package and app; full suite 17831 passed / 0 failed / 81 skipped / 1 todo, plus kimi-inspect's own 115 tests; lint 0 errors.

Related Issue
Reported during testing of the Swarm member list in the desktop client; no separate issue.
Problem
After restarting the server with a foreground Swarm still in progress, reopening the conversation shows no members. The child conversations remain on disk, but their spawn and completion events were transient, so the cold transcript cannot reconstruct the member tasks or their parent tool calls.
What changed
Existing conversations recorded before this fix do not contain the required association facts and cannot be reconstructed reliably. This change preserves new runs; it does not infer associations from child names or creation order.
Checklist
gen-changesetsskill.