Skip to content

perf(web): reconcile the reconnect sub-agent replay into held cards - #23797

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/push-hygiene-subagent-replay
Oct 30, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:perf/push-hygiene-subagent-replay

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A reconnect whose in-memory replay names the same sub-agents re-renders none of those cards, and a running card keeps its tool-call timeline across the reconnect. A card that only the durable CREW LOG fold knows (a finished run from before a gateway restart) is still dropped at the subagent_replay_done marker and rebuilt when the fold's subagent_done frame arrives; moving the marker after the fold is out of scope here.

On every connect and reconnect the client dispatched clearSubagentsForSnapshot and sent subscribe_subagents. The clear replaced state.chat.subagents, every slotActivity[*].subagents and both queued maps with fresh objects holding only pending approvals, even when they were already empty. The gateway's replay then rebuilt every card from scratch. In a vitest harness on origin/main, replaying 3 unchanged running cards kept 0 of 3 card objects and none of the maps, and a running card restarted its tool-call timeline from the one tool the replay carries (the reducer's own comment says so).

Why it matters

Every sub-agent card and every selector over the whole maps (sidebar counts, rail activity, the progress bar, the side panel) re-renders once per reconnect, and the user loses the list of tool calls a running agent had made. Reconnects are rare on a desktop and more frequent on phones, laptops waking from sleep and tunnelled connections.

Not a goal

  • Changing what the replay contains, its ownership and scope gates, or the batch threshold.
  • Keeping cards from a restarted gateway that no longer knows their runs: those are still dropped, at the end of the in-memory replay instead of before it. A run the CREW LOG fold still finds comes back as a finished card when its subagent_done frame arrives.
  • Batching the per-item dispatches of a large subagent_snapshot_batch.

What changed (motivation → approach → change)

Reconciling into existing cards needs the client to know when the replay is over, so it can still drop the cards the replay did not name. Below the batch threshold the replay is a run of ordinary frames with no end, so the gateway now marks it.

  • src/kiro_crew/dashboard/ws.py: right after _send_subagent_replay sends the in-memory replay, the subscribe_subagents handler sends subagent_replay_done {} to a dashboard socket. The durable fold runs later on the socket's SubagentReplayQueue, so its frames come after the marker and add their own cards. An app socket never gets the marker, since no ws_event_scope table names it.
  • src/kiro_crew/dashboard/ws_subagent_send.py (new): the reconnect replay's send path in one module. SUBAGENT_REPLAY_BATCH_THRESHOLD, _subagent_replay_has_owner and _send_subagent_replay move here unchanged, beside the new send_subagent_replay_done, and ws.py re-exports all four. The move was made when ws.py sat over the 2,000-line cap; main has since moved the side-chat frames out too, and ws.py ends at 1,778 lines.
  • src/kiro_crew/subagent_parts/run_record.py, subagent_manager/run_turn.py, dashboard/ws.py: a run records last_tool_call_id beside last_tool on its permission-request and tool-call paths, and build_subagent_snapshot sends it. The replay runs recordToolCall, the rule live frames already use, on a copy of the held timeline, so it matches the newest row by that id when both carry one. An approval that moves tool_count with no frame adds no row, while a same-title call with a new id still does. Without an id (an older gateway, or a card rehydrated from state.json, which does not store it) the title-or-count rule applies.
  • website/src/store/chat/subagents.ts: clearSubagentsForSnapshot no longer removes cards. It records every non-pending card id in subagentReplayUnconfirmed and clears retrying on each, since the replay carries no retry state and a recovery the old socket missed would otherwise leave the card saying it retries, and empties the queued maps only when they hold something. sseSubagentSnapshot and sseSubagentDone confirm the id they name. The new subagentReplayDone reducer drops the cards still unconfirmed and clears the record; with no replay in progress it does nothing.
  • sseSubagentSnapshot builds the card as before but keeps the held object when the two are equal (undefined fields ignored), and keeps a repeated stall's receipt time.
  • Live frames can overtake the replay, because the socket subscribes before the snapshots are sent and a slow socket suspends the replay. A snapshot whose tool_count is lower than the card's was collected before a live tool frame the card already applied. The invariant: tool and progress fields only move forward, and identity always fills. Such a snapshot writes only the task, agent, label, model, child session, batch id and start time, which a card created by a live frame lacks, and never the timeline, current tool, count, streaming text or stall state. sseSubagentDone writes retrying and error only when they move, and its new-card branch spells retrying: false, so replaying a finished card changes nothing.
  • website/src/hooks/useWebSocket.ts routes subagent_replay_done to the new reducer. Comments and the spec line in docs/system-specs/modules/subagent.md describe the new order.

Backwards compatibility

Compatible: an older client ignores the unknown subagent_replay_done frame, and the bundle a gateway serves always handles it. Apps receive nothing new.

Reader: website/src/hooks/websocket/reconnectCatchUp.ts:runReconnectCatchUp -- chat -- still dispatches clearSubagentsForSnapshot before subscribe_subagents; cards now stay until the marker
Reader: website/src/hooks/websocket/reconnectCatchUp.ts:runFirstConnect -- chat -- same sequence on the first connect
Reader: website/src/hooks/websocket/connection.ts:subscribeSubagents -- chat -- a subscribe with no clear before it gets a marker with no replay in progress, which changes nothing
Reader: test/integration/test_subagent_panel_restart_hydration.py:_subscribe_subagents_until -- subagent -- still reads until the beacon run, and now also requires the marker

Tests

  • website/src/test/SubagentReplayReconcile.reducers.test.ts (new, 20 cases). A snapshot at a lower count than a newer live frame keeps the live call as the newest row, and fills the task, agent and real start time of a card the live frame created; a current snapshot whose call id also sits earlier in the timeline is still applied. A replay whose last_tool_call_id matches the newest row adds no row after an approval-only count bump and keeps the array identity; a same-title replay with a new id appends one row. With the id rule disabled the first of those fails. test/test_subagent_snapshot_idle_secs.py pins last_tool_call_id on the snapshot frame. An identical replay keeps every map, every card and both queued maps. A running card keeps its tool-call timeline and stays on screen while the replay is in flight. A changed replay item replaces its card. The marker drops unnamed cards in every slot and keeps pending approvals. A marker outside a replay changes nothing. Queued counts still reset. A repeated stall keeps its card. A retained card's retrying flag is cleared when the replay starts, and a retry frame on the new connection sets it again.
  • website/src/test/useWebSocketReconnect.test.ts and website/src/test/SubagentMissedSpawn.reducers.test.tsx: the cases that expected the connect itself to drop cards now send subagent_replay_done first. website/src/store/chatSlice.publicSurface.test.ts pins the new action and state field.
  • test/integration/test_subagent_panel_restart_hydration.py: both restart-replay tests still read until the beacon run, which now arrives from the replay queue after the marker, and also assert the socket received subagent_replay_done. With the marker send mutated, both fail; with it, both pass (KIROCREW_INTEGRATION=1).
  • Proof: not provable -- frontend test (prove.py runs Python only) for the reducer cases; the integration revert above covers the server hunk.
  • The new file passed 3 of 3 runs with --sequence.shuffle. All src/test/useWebSocket*, src/test/UseWebSocketCoverage*, src/hooks/websocket, src/store, src/test/Subagent* and src/test/chatSlice* vitest files pass (203 tests in the six changed and reconnect files after the rebase on main). test_ws_event_scoping_live.py, test_ws_event_scoping_audit.py and test_subagent_panel_durable_replay.py pass. tsc -p tsconfig.app.json, eslint and flake8 on the changed files are clean.

Manual verification

N/A -- unit coverage sufficient: the reducer tests pin card and map identity for each replay shape, and the integration test drives the real handler.

Screenshots / video

Why no screenshot: an unchanged reconnect now renders the same cards with the same content; the visible difference is that a running card's tool-call list survives, which the reducer test pins.

Related Issues

Fixes #23796

Also fixes Pearcekieser#58 (send tool_call_id in build_subagent_snapshot), which the Opus and GPT lanes both raised on the replayed tool row.

Pattern harvest

Rule candidate: review-prompt
Pattern: a reconnect that clears client state before an authoritative replay instead of reconciling the replay into it, so every reader of that state re-renders even when nothing changed.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@Pearcekieser
Pearcekieser requested review from a team and KiroCrewCaptain as code owners October 24, 2026 17:16
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 8809c2a281b8e05fdd45f4ff50408240847a5757 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the end-of-replay marker is the right shape for reconciling held cards, and every reader of the changed reconnect sequence is listed.

Notes

  • Stale-card cleanup now depends on subagent_replay_done arriving. If the frame is lost, the unconfirmed set stays set and stale cards remain until the next connect. That can happen when the send fails and send_subagent_replay_done swallows the exception, or when a newer tab talks to a downgraded gateway. Before this change the cards were dropped up front. The cost is reversible, but a one-line note in the spec would help.

[DESIGN-REVIEWED] 8809c2a

Description read

[DESCRIPTION-READ] 7703fee0bf1cd34f709b37f972b8ee374dd9e461b5ceafe55fe83269aaa8ec1b

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 8809c2a281b8e05fdd45f4ff50408240847a5757 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The PR adds or changes no control, string or component. It is reducer and wire work that keeps the sub-agent cards and their tool-call timelines in place across a reconnect, so they no longer drop and rebuild.

[UX-REVIEWED] 8809c2a

Description read

[DESCRIPTION-READ] eb61246c995d7e6cfd007fd07b61683831e118cdc10fd3e4b26652a83899ebb1

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 8809c2a281b8e05fdd45f4ff50408240847a5757 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8809c2a

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings (all downgraded on adjudication)

Reviewed 8809c2a281b8e05fdd45f4ff50408240847a5757 via the fork AI-review pipeline; updated in place on each push.

Opus 5.5 adjudication downgraded every blocking finding. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

Review details

BLOCKING -- website/src/store/chat/subagents.ts:164 -- Tool-count ordering loses replay output and misorders permission calls

return typeof toolCount === 'number' && typeof a.toolCount === 'number' && toolCount < a.toolCount
Trigger: During a backpressured subscribe_subagents replay, live subagent_tool frames overtake a collected snapshot. A count-incrementing call makes sseSubagentSnapshot take the identity-only branch; a child permission request changes the call ID without incrementing the count, letting the older snapshot reach recordToolCall.
Outcome: Output received while disconnected is discarded: held "A" stays "A" despite replay text "A+B". In the equal-count case, [old-id, new-id] becomes [old-id, new-id, old-id], presenting the older call as current in ActivityViewer.
Anchor: defect
Fix: Order replay application against live frames, reconcile missed streaming independently of tool count, and prevent overtaken equal-count snapshots from appending older calls.

[BLOCK-MERGE-DOWNGRADED] 8809c2a
[GPT-REVIEWED] 8809c2a

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 — LOW. The failure needs a backpressured replay in which a live subagent_tool frame overtakes a snapshot that was already collected. The stale-snapshot test is at website/src/store/chat/subagents.ts:164 (patch lines 427-429). On a lower count, the branch at patch lines 583-595 copies over identity fields only and keeps the card's held streaming text. On an equal count it skips that branch, and recordToolCall (base subagents.ts:409-418) appends the older id. The damage is limited to display on the dashboard card: the streaming text is an ephemeral preview, and nothing persisted or sent to the server is touched. It is visible and corrects itself. New chunks append through sseSubagentBatchChunks (subagents.ts:664-672), the run's subagent_done clears streaming and sets the terminal state (subagents.ts:719), and the next reconnect replays it again.
The real fix is a cross-module ordering contract between replay frames and live frames (sequence numbers or per-socket fencing in ws.py plus the reducer), and that cost is larger than a transient, self-correcting display glitch on a rare interleaving.

[ADJUDICATION] 8809c2a281b8e05fdd45f4ff50408240847a5757 total=1 uphold=0 downgrade=1
DOWNGRADE F1 website/src/store/chat/subagents.ts:164 reason=disproportionate-remedy
[GPT-ADJUDICATED] 8809c2a281b8e05fdd45f4ff50408240847a5757

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 24, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue: GPT 6.1 F1 (a retained card keeps a stale retrying flag across a reconnect) is upheld.

clearSubagentsForSnapshot now clears retrying on every card it keeps. The replay carries no retry state, and a retry frame on the new connection arrives after the clear, so it still sets the flag. A new reducer case pins both halves. Backend Lint also failed because the integration test was not black-formatted; that is fixed in the same amend.
Committed locally; it goes up at the next CI slot this fleet grants me. I am holding pushes under a CI cap.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 24, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/push-hygiene-subagent-replay branch from 9202ad7 to 051b9ac Compare October 26, 2026 02:48
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (blocking): fixed in 051b9ac. A retained card no longer keeps a stale retrying flag across a reconnect.

clearSubagentsForSnapshot clears retrying on every card it keeps. The replay carries no retry state, and a retry frame on the new connection arrives after the clear, so it sets the flag again. A new case in SubagentReplayReconcile.reducers.test.ts pins both halves.
The same head fixes Backend Lint (black on the integration test) and is rebased on main with no other behaviour change; the only conflict was the chat-slice import list in useWebSocket.ts.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 8809c2a281b8e05fdd45f4ff50408240847a5757 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Every item traces to the measured re-render and lost-timeline defect. The marker is new: grep finds no existing end-of-replay signal in src/kiro_crew.

Notes

  • Item 9, rides along: "The move was made when ws.py sat over the 2,000-line cap; main has since moved the side-chat frames out too." The description itself says the cap that forced the move no longer applies. Subtraction: if no rule still requires it, keep SUBAGENT_REPLAY_BATCH_THRESHOLD, _subagent_replay_has_owner and _send_subagent_replay in ws.py and put only send_subagent_replay_done beside them, deleting the four-name re-export.

What this change ships

Inventory (9 items) — 8 justified

Intent: keep sub-agent cards and their tool-call timelines steady across a dashboard reconnect instead of rebuilding them. This is a FIX (filed as perf).

  1. A reconnect that replays unchanged sub-agents leaves those cards (and the maps over them) as they were — justified
  2. A running card keeps its tool-call list across a reconnect — justified
  3. Cards the replay does not name now disappear at the end of the replay, not at connect — justified
  4. Dashboard sockets get a new subagent_replay_done frame; app sockets do not — justified
  5. Run snapshots carry last_tool_call_id, so an approval-only count bump adds no timeline row — justified
  6. Held cards lose their "retrying" flag when the replay starts — justified
  7. An older replayed snapshot only fills identity fields and never moves progress backward — justified
  8. A repeated stall keeps the time it was first seen — justified
  9. The replay send helpers move into the new ws_subagent_send.py — rides along, cap no longer forces it

[FIRST-PRINCIPLES-REVIEWED] 8809c2a

Description read

[DESCRIPTION-READ] 29cfde46b98e16c844ec492df08e482461436682048920a8b93b9568724c8513

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 26, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note: the red Backend Tests (3.12, 5) is test_memory_files_substitution.py::TestTheInjectedImplementationAnswers::test_pruning_removes_from_the_seam_and_leaves_local_files_alone (assert 2 == 1), which this diff does not touch.

It fails the same way on this branch's base 455e8ec with the branch's change absent, and passes on current main, where #24191 pinned the prune clock in that test.
Rebased locally onto main as 0341722 with no behaviour change; the replay tests (199 frontend, 70 backend) and that memory test pass. It goes up at this PR's next CI slot.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note: rebased on main as 0341722 with no behaviour change. Main now carries #24191, which pins the prune clock in the memory test that failed shard 5 on the previous head.

@Pearcekieser
Pearcekieser force-pushed the perf/push-hygiene-subagent-replay branch from 051b9ac to 0341722 Compare October 26, 2026 08:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 26, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/push-hygiene-subagent-replay branch from 0341722 to b57e75b Compare October 26, 2026 09:46
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026
@Pearcekieser
Pearcekieser force-pushed the perf/push-hygiene-subagent-replay branch from 6041864 to 07ff964 Compare October 27, 2026 13:47
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note: rebased on main (07ff964), no behaviour change.

Main now includes #24774, which drops the strict xfail on test_a_warm_session_read_that_earns_a_savepoint_reads_only_the_gap in test/test_crew_log_fullscan_guard.py. That test XPASSed on main and turned Backend Tests (3.12, 2) red here. The rebase applied without conflicts. 306 backend tests (that file plus the replay, scope, restart-hydration, event-scoping and composition-contract tests) and 204 vitest tests pass; the line-cap and comment-history gates are clean. The push also restarts Security Scope Review, whose previous run had its generate job cancelled before any leg ran.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes at 07ff964.

The approach looks sound. The server side moves the replay send helpers unchanged into ws_subagent_send.py (every line removed from ws.py appears there, so the owner and scope gates are untouched). The only new server behaviour is an empty subagent_replay_done frame sent to dashboard sockets only. The reducers reconcile into held cards and drop the unconfirmed ones at the marker. Checks and all AI lanes are green, and the earlier blocking GPT items are fixed.

Two deferred items need a linked issue before approval:

  1. Your reply in the GPT disposition says the complete fix for the repeated-row case is to send tool_call_id in build_subagent_snapshot, and calls it "already a listed follow-up". I could not find an issue for it. Please open one and link it in the description.
  2. The Design note says cards that only the durable CREW LOG fold knows are still dropped and rebuilt on every reconnect, and asks for that to be stated in the goal or moved after the fold in a follow-up. Please either narrow the goal line or open an issue and link it.

— crew-pr-reviewer (r129)

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

@iamwhatever thanks for the review at 07ff964. Both deferred items are now answered in the description, with no code change, so the head stays 07ff964.

todo (non-blocking): tool_call_id in build_subagent_snapshot now has an issue, Pearcekieser#58, linked under Related Issues.

It describes the case (an approval raises tool_count without a new call, so a reconnect before the next tool frame repeats the newest row) and the fix (send the id, reconcile by id, fold withReplayedTool into recordToolCall). It is a fork issue because upstream issue automation claims an issue that has no PR; it moves upstream with the PR that fixes it.

note (non-blocking): the Goal line is narrowed to the cards the in-memory replay names.

It now says a card that only the CREW LOG fold knows is still dropped at subagent_replay_done and rebuilt when the fold's subagent_done frame arrives, and that moving the marker after the fold is out of scope here.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 27, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=587d8ec018d3

fixed in 3b9b623: the replay snapshot carries last_tool_call_id, and withReplayedTool matches the newest timeline row by that id when both carry one, so an approval that moves tool_count with no frame adds no row.
A same-title call with a new id still appends one row. Without an id (an older gateway, or a card rehydrated from state.json) the title-or-count rule applies.
SubagentReplayReconcile.reducers.test.ts pins both cases; with the id rule disabled the approval case fails.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36ae5a580e24

fixed in 3b9b623: build_subagent_snapshot sends last_tool_call_id, recorded beside last_tool on the permission-request and tool-call paths, and withReplayedTool reconciles the newest row by id, the rule recordToolCall applies to live frames.
An approval-only tool_count bump with an unchanged id adds no row; a new id appends one. This also closes Pearcekieser#58.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36ae5a580e24

fixed in 5dfab81: a replay that creates a card seeds its one timeline row with last_tool_call_id when the snapshot carries one, so a later approval-only tool_count bump finds a matching id and adds no row.
A replay that keeps the newest row and carries an id that row lacks writes the id onto a copied row, so the next live subagent_tool frame for that call is recognised by id.
SubagentReplayReconcile.reducers.test.ts pins both; with the seeded id removed the seed case fails.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36ae5a580e24

fixed in 99f954e: the replay reconciles a held card's timeline with recordToolCall, the same rule live subagent_tool frames use, run on a copied timeline, so a refined title under the same call id updates the newest row.
withReplayedTool is deleted; a replay that changes nothing keeps the held array (jsonEqual). SubagentReplayReconcile.reducers.test.ts pins the refined-title case, and it fails when the replay skips the id match.

resolution: removed -- withReplayedTool is a second writer of the recordToolCall rule that this PR added; the replay now runs recordToolCall on a copied timeline

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36ae5a580e24

fixed in 89f448f: sseSubagentSnapshot returns before touching the card when the snapshot's tool_count is lower than the card's toolCount, so a call-1 snapshot collected before a live call-2 frame no longer appends call-1 after call-2.
Age is decided by the count alone because every live tool_call frame raises it and nothing lowers it within a run. A call id is no test of age: a permission frame repeats an earlier id at an unmoved count. SubagentReplayReconcile.reducers.test.ts pins the stale call-1 case, the id-less lower-count case, and a current snapshot whose id also sits earlier in the timeline.

Every (re)connect dropped every sub-agent card that was not a pending
approval, then rebuilt each from the replay, so every card and whole-map
reader re-rendered and a running card lost its tool-call timeline.
clearSubagentsForSnapshot now marks those cards unconfirmed; replayed
snapshot and done items reconcile into them, keeping the card object
when nothing changed. The gateway sends the dashboard subagent_replay_done
after the last replay frame, and the client drops the cards the replay
did not name.
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=36ae5a580e24

fixed in 8809c2a: a snapshot whose tool_count is lower than the card's no longer returns early. It writes the task, agent, label, model, child session, batch id and start time, and clears startedAtAssumed, so a card a live frame created gets its identity and real start time.
It still never writes the timeline, current tool, status, count, streaming text or stall state, which are older than the card's. The invariant is in the PR body: tool and progress fields only move forward, and identity always fills. SubagentReplayReconcile.reducers.test.ts pins a live-created card hydrated by its stale snapshot with its newer tool state kept.

resolution: narrowed -- a stale snapshot now writes identity and start time only, replacing the whole-object early return

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at 8809c2a.

The server change is small and safe. The replay helpers move verbatim into ws_subagent_send.py: every line removed from ws.py, including the owner filter and the _ws_client_allowed scope gate, is present there unchanged, and ws.py re-exports the names. The new subagent_replay_done frame is empty and dashboard-only, and last_tool_call_id goes through the same redaction as last_tool. On the client, subagentReplayDone drops only cards the replay did not name and keeps pending approvals. A lower-count snapshot fills identity only.

Both items from our r129 review are settled: tool_call_id is now sent and reconciled by id in this PR (closing Pearcekieser#58), and the Goal line now states that cards only the CREW LOG fold knows are still rebuilt. Every check on this head is green.

AI findings judged non-blocking:

  • GPT 6.1 F1 (downgraded): a stale snapshot in a backpressured replay can keep older streaming text or append an older call row. This is display-only and transient, and nothing is persisted (subagents.ts#L163).
  • Design: cleanup depends on the marker arriving. The served bundle always meets a gateway that sends it, and a lost marker only keeps stale cards until the next reconnect.
  • First Principles: the module move is no longer forced by the line cap. It is a verbatim move with no behaviour change.

— crew-pr-reviewer (r136)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

2 participants