Repository navigation
fix(sidebar): keep agent rows ordered by their session start once state history wraps - #14654
Conversation
…tory wraps Sidebar agent rows are ordered by the session's first reported state, read as `stateHistory[0].startedAt`. `stateHistory` is a rolling window capped at AGENT_STATE_HISTORY_MAX that trims oldest-first, so past ~20 transitions that row is a recent turn: the row's identity clock silently becomes an activity clock and busy agents re-sort themselves on every turn. Latch the session origin in `firstStateStartedAt` when the entry is built and read it through `agentEntrySessionStartedAt`, keeping the history lookup as a fallback for entries that predate the field.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Walkthrough
Priority: Merge Risk:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/agent-session-start-time.ts (1)
13-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winShorten the helper documentation.
The block repeats behavior that the type and function body show. Keep one concise sentence that states the fallback order.
Proposed change
-/** - * When this pane's agent session first reported a state — the stable identity clock the - * sidebar orders agent rows by. - * - * Why not `stateHistory[0].startedAt` alone: `stateHistory` is a rolling window capped at - * `AGENT_STATE_HISTORY_MAX` that trims oldest-first, so once a session passes the cap its - * first *retained* row advances on every transition. Reading it directly turns a stable - * identity clock into an activity clock, and the row re-sorts on each new turn. - * `firstStateStartedAt` is latched at session start and never moves; history remains the - * fallback for entries that predate it (rehydrated from disk, derived rows). - */ +/** Returns the latched session start, then the oldest retained or current state start. */As per coding guidelines, comments must be concise, non-obvious, and brief; prefer one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9b677b0f-fc7b-4ad2-9292-194fa5a5eeeb
📒 Files selected for processing (6)
src/renderer/src/components/sidebar/worktree-agent-row-fallback-tab.tssrc/renderer/src/components/sidebar/worktree-agent-row-order.test.tssrc/renderer/src/store/slices/agent-status-session-start-latch.test.tssrc/renderer/src/store/slices/agent-status.tssrc/shared/agent-session-start-time.tssrc/shared/agent-status-types.ts
|
Rebased #14284 onto main (post-#14486) — the |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

Major · Use the retained row origin when the mirrored patch rebuilds a… · agent-status-patch.ts:127-134
src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts:127-134
🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse the retained row origin when the mirrored patch rebuilds a pane entry.
buildMirroredAgentStatusPatchstores a remapped host entry for every host surface, even when no live entry exists for its pane key. Its origin resolver receives onlyprevious: existing. Whenexistingis undefined, the resolver ignores any retained row for that pane key. If the host entry omitsfirstStateStartedAtand itsstateHistoryno longer contains the session start, the resolver falls back to the currentstateStartedAt. The rebuilt row then sorts by that later value instead of the retained origin.The live builder already handles this case. It passes the retained entry as
previousand the retainedstartedAtaspreviousStartedAt. The mirrored path should do the same.Suggested fix
firstStateStartedAt: resolveAgentSessionStartedAt({ entry: accepted, - previous: existing, + previous: existing ?? state.retainedAgentsByPaneKey?.[entry.paneKey]?.entry, + previousStartedAt: existing + ? undefined + : state.retainedAgentsByPaneKey?.[entry.paneKey]?.startedAt, replacementStartedAt: accepted.stateStartedAt })Limit: The fix changes only the resolver call. The sidebar comparator was not inspected. The rest of the chain is supported by source, so no separate row-consumer edit is indicated.

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
24f04ba0-571c-4290-80d3-472c60e65037
Files selected for processing: 1-
src/renderer/src/runtime/web-session-tabs-sync-agent-status.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
|
Agent rows could cross each other while an agent worked: their order came from the oldest item in a rolling 20-transition history, so that timestamp advanced as activity continued. The same moving clock affected completed rows when they were retained. The change gives each observed session one ordering origin and uses it for live and retained rows. Known replacement sessions get a new origin; metadata enrichment and equivalent routes preserve it. The existing paired payload carries the optional origin, and receivers support hosts that omit it. Review found and repaired two remaining paths: a replacement session could inherit the previous session’s state clock, and a paired row returning after a temporary observation gap could discard its retained origin. Two review rounds finished with no open findings. The repair regressions failed before the fix, then 39 tests passed across four named suites. A final 27-check run additionally verifies bounded N/10N work through the real paired update, no-op snapshots, optional-field publication and old/new payload parity through phone status, send and Stop consumers (suite counts overlap). CI is green on Coverage is row position only. In-place blinking remains unconfirmed. A fresh renderer cannot recover history that was already discarded, so identical historical order across clients or restarts is not promised. No agents were run for this tests-row UI change. For Brennan’s review Branch-only screenshot on the reviewed head, using synthetic observations through the production status action; no agents were run. Pi stays above Codex at y=365.5 and y=391.5 before and after 24 transitions, even though Pi’s oldest retained history timestamp advances past Codex’s start. Its session ordering origin stays unchanged. Before overflow: After 24 transitions:
Whole-mechanism reference comparison is complete. Stable ordering follows the common pattern; per-observed-session origins, optional paired payload compatibility and the fresh-renderer fallback are intended differences for multi-host, mixed-version observations. Since the QA head 08d3179: two main merges (46af6c1, 33b0224; the first resolved an import-only conflict in agent-status-live-entry-builder.ts) and one test-only commit (1bce4de: the phone codec test expects main's new chat sessionLive field). No shipped file changed by this PR since QA; CI green on 1bce4de. |
[Medium impact] The PR appears safe to merge. SummaryThe PR introduces a session-scoped ordering origin so sidebar and dashboard agent rows remain stable after rolling state history wraps.
|
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: Unavailable
- Branch: Unavailable
- File: No configuration file from this repository applied
- Commit: Unavailable
- Layers: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
4e8f9e6a-e08c-4184-b1f2-8bdcb6aae8cb
Files selected for processing: 9-
mobile/src/session/mobile-session-tab-status-clock.test.tssrc/renderer/src/components/dashboard/useRetainedAgents.test.tssrc/renderer/src/components/sidebar/worktree-agent-row-fallback-tab.tssrc/renderer/src/runtime/sync-runtime-graph-terminal-surface-projection.test.tssrc/renderer/src/runtime/web-session-tabs-sync-agent-status.test.tssrc/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.tssrc/renderer/src/store/slices/agent-status/agent-status-live-entry-builder.tssrc/renderer/src/store/slices/agent-status/agent-status-row-order-origin.test.tssrc/shared/agent-session-start-time.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
…n's start-a-chat change
…am's row-order test Upstream stablyai#14654's test expects session B to inherit A's stateStartedAt when the host replays it. session-names deliberately resets the clock on a session switch (activity-session-history.test.ts pins the same rule) so Activity does not merge two sessions' events. The test now expects B's clock; the sidebar ordering assertions upstream cares about are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Agent rows can move while an agent works because their primary sort key comes from the oldest entry in a rolling activity history. That history keeps only 20 transitions, so its oldest timestamp advances and a busy agent crosses quieter rows. The same moving timestamp can change the row again when a completed terminal disappears and its row is retained.
Keep each observed session's ordering start separate from recent activity. Local updates and paired desktop snapshots preserve that start through activity, identity enrichment, equivalent WSL routing and pane transfers. A known session or owner replacement gets a new start. Sidebar rows and both retained-row paths read the same value.
Before / after
Not covered: keeping the same historical order across an app restart or on a client that connected later (it uses the oldest evidence still available), the separate report of a row blinking in place (needs a repro), and phone rows, which never had a history to wrap.
Plan: store one optional
firstStateStartedAton the existing status entry and derive its lifetime from accepted session identity. This replaces the old PR's unconditional inheritance without changing state-history retention or status authority. The optional member also travels in the existing whole-entry session-tab payload; old hosts can omit it. There is no saved schema migration or new wire operation. A fresh renderer can only recover the oldest evidence still available, so this does not promise identical historical order across clients or restarts.Validation: the initial production-flow regressions ran before the fix (8 failed / 18 passed), then 86 tests passed across eight named suites through tc-gate. Review added red/green regressions for same-state replacement and paired retained revival (4 failed before repair; 39 passed across four named suites after repair). The final 27-check contract run covers N/10N resolver counts through the real paired patch, unchanged-snapshot no-op behavior, real replacement publication, and optional-origin legacy/current codec parity through phone status, send and Stop consumers; counts overlap the previous suites. Two review rounds, dedicated readiness/performance review and fresh whole-mechanism reference comparison finished with no open findings. Final CI is green on 08d3179, after the one main sync. Branch-only screenshot on this head passed: synthetic production-action observations kept Pi above Codex at unchanged row positions after 24 state transitions overflowed its 20-entry history. No agents were run; paired/older-peer behavior is covered by the contract tests.
Branch-only screenshot on the reviewed head, using synthetic observations through the production status action; no agents were run. Pi stays above Codex at y=365.5 and y=391.5 before and after 24 transitions, even though Pi’s oldest retained history timestamp advances past Codex’s start. Its session ordering origin stays unchanged.
Before overflow:
After 24 transitions:
Tracked in STA-4085 — Pi rows move during activity.
Tracked in STA-3816 — agent rows move up and down during activity.
Coverage is position shifting only. The separate in-place blinking report still needs reproduction. Phone entries already have empty history, so their pre-existing ordering key is outside this change.