Skip to content

fix(sidebar): keep agent rows ordered by their session start once state history wraps - #14654

Merged
brennanb2025 merged 11 commits into
mainfrom
brennanb2025/sidebar-row-order-13847
Oct 29, 2026
Merged

brennanb2025 merged 11 commits into
mainfrom
brennanb2025/sidebar-row-order-13847

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​640 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​639
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​104

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

Case Before After
A busy agent changes status more than 20 times (e.g. Pi working through many tool calls) while a quieter agent sits below it Once its 20-entry history wraps, its sort time jumps forward and the row drops below the quieter agent; it keeps shuffling as more changes arrive The row stays where it was, ordered by when its session started
An agent finishes and its terminal closes, so the sidebar or Dashboard keeps a retained "done" row The retained row could jump to a new position when the live row disappeared The retained row stays in the same position
Viewing a paired desktop's agents Rows jumped the same way as local ones, and a retained row could move when the same session came back Rows keep the host's order; a session that comes back returns to its old place
Orca learns more about the same session: the agent type gets detected after the row appears, Pi's transcript path becomes available, an equivalent WSL route is used, or the pane is moved to another tab Moved only through the history wrap above Treated as the same session and keeps its place
A genuinely new session in the same pane (a different agent, a different provider session, or a move to another worktree or host) Took a new position Unchanged: it still takes a new position, dated from when the new session started

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 firstStateStartedAt on 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:

Sidebar before history overflow

After 24 transitions:

Sidebar after history overflow

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.

…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.
@coderabbitai

coderabbitai Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 6d03763e-c481-4a59-b97b-a814287e7a77
Commits

Reviewing files that changed from the base of the PR and between 33b0224 and 1bce4de.

Files selected for processing: 1
  • mobile/src/session/mobile-session-tab-status-clock.test.ts
Walkthrough

Agent status entries now retain a session start timestamp when recent history no longer contains the first state. Live and mirrored status updates resolve that timestamp, and row ordering, fallback tabs, and retained-agent timestamps use it. Tests cover history truncation, session replacement, enrichment, stale updates, and frame decoding.

Priority: Pending latest changes

Merge Risk: Moderate · previous review 46af6

The mobile test suite fails on the new assertion. Correct its expected chat value before merging.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description gives detailed behavior, rationale, testing results, and visual proof, but it does not follow the required template structure. It omits the required section headings and checklist resp… Reformat the description using all required template sections. Add actual issue links under Linked Issue, complete the Testing and Checklist items, provide the required AI Disclosure when applicable, and state N/A with a reason where a sect…
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: preserving agent-row ordering by session start after state history wraps.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description gives detailed behavior, rationale, testing results, and visual proof, but it does not follow the required template structure. It omits the required section headings and checklist responses, and it lists issue IDs without actual issue links.

Resolution

Reformat the description using all required template sections. Add actual issue links under Linked Issue, complete the Testing and Checklist items, provide the required AI Disclosure when applicable, and state N/A with a reason where a section does not apply.

Full details: Docstring Coverage

Explanation

Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 14 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 2
📝 Generate docstrings: 💡
- [ ] Create stacked PR - [ ] Commit on current branch
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/shared/agent-session-start-time.ts (1)

13-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shorten 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

📥 Commits

Reviewing files that changed from the base of the PR and between 78d5920 and c66bfd7.

📒 Files selected for processing (6)
  • src/renderer/src/components/sidebar/worktree-agent-row-fallback-tab.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-order.test.ts
  • src/renderer/src/store/slices/agent-status-session-start-latch.test.ts
  • src/renderer/src/store/slices/agent-status.ts
  • src/shared/agent-session-start-time.ts
  • src/shared/agent-status-types.ts

@blade035

Copy link
Copy Markdown
Contributor

Rebased #14284 onto main (post-#14486) — the WorktreeList.tsx conflict is resolved and the diff now sits on the reorganized call sites. The corrected PR body already documents the gating you flagged: the sort-order persist effect only rewrites while sortBy === 'smart', so in Manual the fallback bites after a Smart round trip, meta-row minting, or a remote persistSortOrder push — filtered-out-at-drag rows remain documented as out of scope.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

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 win

Use the retained row origin when the mirrored patch rebuilds a pane entry.

buildMirroredAgentStatusPatch stores a remapped host entry for every host surface, even when no live entry exists for its pane key. Its origin resolver receives only previous: existing. When existing is undefined, the resolver ignores any retained row for that pane key. If the host entry omits firstStateStartedAt and its stateHistory no longer contains the session start, the resolver falls back to the current stateStartedAt. 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 previous and the retained startedAt as previousStartedAt. 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
Commits

Reviewing files that changed from the base of the PR and between 239d9db and f229c1c.

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.

@brennanb2025

brennanb2025 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

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 08d3179e9c88b636d343bca3fd02ccdadd200b06 after the one main sync; that merge changed none of the PR’s reviewed diff.

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:

Sidebar before history overflow

After 24 transitions:

Sidebar after history overflow

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.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR introduces a session-scoped ordering origin so sidebar and dashboard agent rows remain stable after rolling state history wraps.

  • Adds firstStateStartedAt to agent status entries and centralizes origin derivation.
  • Preserves or resets the origin according to accepted session and terminal-owner identity.
  • Uses the origin consistently for local, paired-host, fallback-tab, and retained-row ordering.
  • Adds regression and transport-compatibility coverage for history overflow, replacements, pane transfers, retention, and legacy peers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  O[Agent status observation] --> I{Same accepted session identity?}
  I -->|Yes| P[Preserve firstStateStartedAt]
  I -->|No| R[Set replacement session origin]
  P --> S[Store or paired snapshot]
  R --> S
  S --> L[Live sidebar and dashboard rows]
  S --> T[Retained completed rows]
  L --> K[Sort by stable session origin]
  T --> K
Loading

Reviews (3) · Last reviewed commit: "test(mobile): expect sessionLive in the ..." · Reviewed by Greptile

@coderabbitai coderabbitai Bot 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.

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
Commits

Reviewing files that changed from the base of the PR and between f229c1c and 46af6c1.

Files selected for processing: 9
  • mobile/src/session/mobile-session-tab-status-clock.test.ts
  • src/renderer/src/components/dashboard/useRetainedAgents.test.ts
  • src/renderer/src/components/sidebar/worktree-agent-row-fallback-tab.ts
  • src/renderer/src/runtime/sync-runtime-graph-terminal-surface-projection.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync-agent-status.test.ts
  • src/renderer/src/runtime/web-session-tabs-sync/agent-status-patch.ts
  • src/renderer/src/store/slices/agent-status/agent-status-live-entry-builder.ts
  • src/renderer/src/store/slices/agent-status/agent-status-row-order-origin.test.ts
  • src/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.

@brennanb2025
brennanb2025 merged commit 004907e into main Oct 29, 2026
57 checks passed
Fartown pushed a commit to Fartown/orca that referenced this pull request Nov 3, 2026
…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]>
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