Skip to content

Fix native chat completion sorting and restored activity timestamps - #19144

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-agent-activity-sort
Sep 7, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-agent-activity-sort

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​154
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

ELI5

Completed Claude and Codex native chats could sort like idle workspaces, and restored chats could all show the time since startup. They now count as completed turns and retain the journal activity timestamp used for ranking and elapsed ages.

Relationship to fixes already on main

PR What it fixes
#18776 (merged) Status delivery. The host publishes working/attention/idle changes even when a chat is hidden or unopened, so the sidebar does not stay stuck on Working until the chat is reopened. Restored sessions receive status without opening each chat.
#19137 (merged) Sidebar details. The host includes the model, current tool/input, and assistant-response preview. Host and renderer equality checks include these fields so detail changes reach the row.
This PR (#19144) Completion ranking and elapsed ages. Completed native turns count as real completions for Sort by agent activity, and their timestamps come from durable journal activity rather than host publication or renderer observation time. Ordering and distinct ages survive reload.

The fixes on main make status and detail updates reach the sidebar, but main still marks idle native-chat summaries as session boundaries, which completion ranking excludes, and assigns publication time to restored summaries. A row can therefore correctly show Done and the response preview while still sorting as idle or showing an age measured from startup.

This PR preserves both merged fixes and adds the missing completion/timing behavior. It also publishes settled timestamp-only changes, preserves the elapsed start of an unchanged active state, and accepts authoritative clock corrections after a host upgrade without clearing read state or history. Timestamp-only updates during an active turn remain deduplicated; model/tool/response-preview changes introduced by #19137 continue to publish.

What Changed

  • Project settled structured chats as real done entries, with host timestamps and a separate local evidence-observation clock.
  • Retain journal activity timestamps, including revisions and completion tombstones, through replay.
  • Add regression coverage for restored completions, repeated turns, both providers, and host/journal reopening.

Why

The bridge marked every idle projection as a session boundary, which completion sorting deliberately excludes. Both the host and renderer also substituted publication time for durable activity time.

Linked Issue

Fixes #19143

Visual Proof

Before: user-reported Claude native chats show matching ages and incorrect completion ordering. This is the reported screenshot, not the isolated QA setup.

Reported before state

After: real Claude and Codex native chats in isolated git worktrees. Codex moved above Claude when its turn completed; a subsequent Claude completion moved Claude back above Codex. The screenshot is after renderer reload, with that order and the original timestamps preserved.

After reload

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

macOS background Electron, attached to this worktree through Playwright CDP: real Claude and Codex completions, Claude working state, completion order in both directions, and renderer reload. All three native session completion timestamps were unchanged after reload. Real Claude completion was also exercised in a folder workspace.

75 targeted tests passed across the status bridge, host feed, journal reducer, and smart-sort suites. pnpm tc passed; the renderer typecheck was repeated after the final test changes. Changed-code quality and commit lint/format hooks passed. Full build and remaining CI checks are left to CI.

Review

Self-reviewed the status mapping and timestamp flow. The execution host remains authoritative; no new RPC field or opcode is introduced. Linux, Windows, SSH, permission requests, waiting-for-input, and interrupted turns were not manually validated.

Agent skill upstream boundary

  • Not applicable: no skill-sharing implementation changes.

Notes

This fixes completion status metadata, sorting, and elapsed ages. It does not add assistant-response previews or model labels to structured native chat sidebar rows.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots attached with their different capture contexts identified
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Full lint, tests, and build pass (remaining coverage delegated to CI)

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Durable activity timestamp — JournalReducerState gains lastActivityAt (max row ts across every non-epoch row, so revisions and completion tombstones count), exposed via AgentSessionJournal.lastActivityAt(), and the status feed uses it as updatedAt in place of publication time.
  • Real completion projection — StructuredAgentSessionStatusBridge no longer marks idle sessions sessionBoundary: true, and forwards the host summary.updatedAt as the store's updatedAt/stateStartedAt with a local evidenceObservedAt; the no-op guard now keys on updatedAt equality.
  • Regression coverage — tests for restored completion timestamps, repeated identical turns, both claude and codex, and journal/host reopen.

The root-cause mapping is right: sessionBoundary: true made agentEntryCompletionAt resolve to an empty history and drop completed native chats to class 5. The Math.max fold in the reducer also gives lastActivityAt a useful monotonicity guarantee that survives compaction and replay.

ℹ️ Remote clock-skew on completion age

summary.updatedAt (the journal's host clock) now flows into stateStartedAt, which resolveAttention's class-2 gate and lastEnteredDoneAt compare against the renderer's now. For local sessions the clocks coincide, but for SSH/remote sessions with skew the 30-minute freshness window and the displayed "N since it finished" age are computed cross-machine — the same class of skew the evidenceObservedAt/mirroredEvidenceReceivedAt mechanism exists to avoid. The host-authoritative timestamp is the right call for durability; flagging only because remote validation was scoped out in the description and is the one place this would surface.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 6c924731-cf80-43a8-bf64-d9381e4fa7ed

📥 Commits

Reviewing files that changed from the base of the PR and between 135f03f and 9c2fbfb.

📒 Files selected for processing (8)
  • src/main/native-chat/agent-session-journal/journal-reducer.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx
  • src/renderer/src/store/slices/agent-status-contract.ts
  • src/renderer/src/store/slices/agent-status-live-entry-builder.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The journal reducer now tracks the latest non-epoch activity timestamp and preserves original Orca user message bodies during revisions. The journal store exposes this timestamp. The status feed uses it for updatedAt and preserves completion times across reopening. The renderer compares status metadata, preserves working state timing, accepts authoritative older timestamps, and validates model and tool-line propagation.

Merge Risk: ⚪ Minimal · up to 9c2fb

Completed native chats now retain their actual activity age and sorting position after updates and reloads. The timestamp propagation and completion behavior are covered across the journal, status feed, and renderer paths, with no remaining merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes propagation and comparison of model, tool-line, and last-assistant-message fields in the status bridge. These changes are separate from the linked issue, which identifies response … Remove the model, tool-line, and last-assistant-message changes from this PR, or provide clear evidence that they are required to implement completion sorting and timestamp preservation. Move unrelated behavior and tests to a separate PR if…
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. Analyzed 9 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #19143 by treating settled turns as completed entries and preserving journal activity timestamps across replay, host reopening, and renderer reloads. Regression tests cover t…
Title check ✅ Passed The title clearly and concisely describes the main changes: corrected native chat completion sorting and preserved activity timestamps.
Description check ✅ Passed The description is complete and focused. It includes the required ELI5, change summary, rationale, linked issue, visual proof, testing details, review notes, boundary check, notes, and checklist. The …
Full details: Out of Scope Changes check

Explanation

The PR also changes propagation and comparison of model, tool-line, and last-assistant-message fields in the status bridge. These changes are separate from the linked issue, which identifies response previews and model labels as separate concerns.

Resolution

Remove the model, tool-line, and last-assistant-message changes from this PR, or provide clear evidence that they are required to implement completion sorting and timestamp preservation. Move unrelated behavior and tests to a separate PR if needed.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

Caution

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

⚠️ Outside diff range comments (1)
src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts (1)

39-46: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Include updatedAt in summariesEqual.

A journal revision can advance updatedAt without changing the projected status fields. publish() then returns early at Line 88 and does not send the new durable activity time. The renderer retains the older timestamp for sorting and elapsed-age display.

Add a.updatedAt === b.updatedAt to this comparison. Add a regression test that publishes two otherwise identical summaries with different activity timestamps.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 73a29260-fe8b-4eaf-b079-531d79b70381

📥 Commits

Reviewing files that changed from the base of the PR and between 5a46703 and 135f03f.

📒 Files selected for processing (6)
  • src/main/native-chat/agent-session-journal/journal-reducer.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.ts
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Settled-activity dedupe — summariesEqual now compares updatedAt for idle summaries only, so a completed turn's durable timestamp republishes (closing the prior gap where an updatedAt advance alone was swallowed) while streaming working turns stay quiet.
  • Authoritative older timestamps — a new AgentStatusTiming.allowOlderTimestamp flag relaxes the updatedAt < existing.updatedAt staleness gate, letting the ordered host feed correct a legacy publication clock after a host upgrade reconnect.
  • Working-age preservation — the bridge's stateStartedAt is now pinned across same-state non-done metadata changes so a streaming turn's age survives host-metadata advances, while completion still stamps the durable summary.updatedAt.
  • Test harness + regression coverage — bridge tests moved onto the real createTestStore() reducer and added reopened completion, host reopen, working-age, and older-timestamp reconnect cases.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Grok QA evidence (PR #19144 / #19143)

FINAL HEAD 8206dbdb08d349848a163ebfd5f658706528061a. Reused reviewer Electron CDP 9341; getIdentity() = bowhead @ brennanb2025/fix-agent-activity-sort. Reviewer remains cleanup owner of the app.

Visible native Claude/Codex git-worktree completions: both sort directions, repeated Claude turn, neighboring Working, renderer reload ages retained (Claude 1m vs Codex 4m, not identical). Store sessionBoundary: false; host updatedAt matched journal.db max ts. 73 targeted tests passed.

Full report: /tmp/pr19144-grok-qa.md

Screenshots (uncropped real app)

Folder catalog existed but sidebar empty (parentPath: null setup):

empty

Claude Done first:

claude first

Codex Working under Claude Done:

working

Codex Done above Claude:

codex above

Claude second turn above Codex:

claude second

After reload (ages kept distinct):

reload

SSH

Throwaway Linux Docker + /work/demo-project connected (remotePlatform: linux, relay deployed). agentSession.createSupport for that SSH worktree: {supported:false, reason:"remote"} for claude and codex. Pre-existing topology; no fake SSH native-chat completion UI.

Gaps

blocked/waiting/interrupted not exercised. Windows: no Windows-specific diff. Mobile: no mobile UI diff (optional follow-up on persisted smart ranks).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Folder UI addendum

updateProjectGroup cannot persist parentPath (allowed fields are name/collapse/order/color). Used the normal create API: projectGroups.create({ name: 'Activity QA', parentPath: '/tmp', createdFrom: 'folder-scan' }), then createFolderWorkspace at the reviewer paths /tmp/pr19144-qa-claude and /tmp/pr19144-qa-codex.

After renderer reload, folder cards are visible with distinct Done ages: Codex completion 1m above Claude completion 2m. Host timestamps unchanged (codex 1788737371976, claude 1788737280883), sessionBoundary: false.

folder cards after reload

Updated /tmp/pr19144-grok-qa.md. Reviewer Electron left running.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Folder addendum re-verify (dispatch ctx_f9586f3f653e)

HEAD 8206dbdb08. Reattached CDP 9341; identity bowhead @ brennanb2025/fix-agent-activity-sort. Opened Claude completion from the sidebar, then reloaded.

After reload, folder cards remain visible with distinct Done ages: Codex completion 4m above Claude completion 6m. Host timestamps unchanged (claude 1788737280883, codex 1788737371976) and match journal.db max ts. sessionBoundary: false.

updateProjectGroup still cannot set parentPath; the visible cards come from projectGroups.create({ parentPath: '/tmp', createdFrom: 'folder-scan' }) plus folder workspaces at /tmp/pr19144-qa-claude and /tmp/pr19144-qa-codex.

after reload

Updated /tmp/pr19144-grok-qa.md. Reviewer Electron left running.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review complete at 8206dbd. Two GPT-6 Astra / medium review rounds finished clean; focused fixes were committed and pushed without expanding #19143's scope.

Fixed four issues found during review:

  • Settled timestamp-only activity was suppressed by host deduplication.
  • Metadata updates reset an active turn's elapsed start time.
  • Corrected journal timestamps after host upgrade were rejected as stale; the ordered native feed now corrects them while preserving read state/history and ordinary terminal stale rejection.
  • The status-subscription RPC fixture lacked the new journal accessor, causing CI failure.

Validation: 330 focused tests passed, plus Grok's 73-test QA selection (overlapping coverage); node/CLI/web typechecks and changed-code quality passed. All current CI checks are successful or skipped. Performance regression tests verify 20 active streaming revisions produce zero extra status publications and repeated identical snapshots preserve store identity. Initial and final readiness checklists completed; final audit has zero remaining candidate findings. Initial four-seat severity review agreed on P2 findings; two blind-rating seats completed, with the others unavailable due to terminal dispatch errors.

Grok exercised real Claude/Codex completions, ordering in both directions, repeated turns, neighboring Working state, and renderer reload in background Electron. Git and folder workspace ages stayed distinct and matched durable journal timestamps. Main screenshots and evidence · Folder-workspace reload proof. The folder addendum supersedes the earlier setup-only hidden-folder gap.

A real throwaway Linux SSH demo repository connected and deployed the relay; both native providers returned the existing supported:false, reason:remote result. SSH native-chat completion is therefore unsupported, not claimed as tested. Live blocked/waiting/interrupted states, native Windows/Linux/mobile UI, and adverse-network/live mixed-version runs remain untested.

No remaining in-scope code finding. The PR is not merged. Test app/container/profile cleanup completed and the worktree is clean; some auxiliary counsel terminals have unresolved close/idle/ownership evidence and were left untouched rather than forcibly stopped.

…t-activity-sort

# Conflicts:
#	src/main/native-chat/agent-session-wire/structured-agent-session-status-feed.test.ts
#	src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.tsx

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Merged origin/main — brought the branch current with main, resolving the two conflicts in structured-agent-session-status-feed.test.ts and StructuredAgentSessionStatusBridge.tsx; the PR's core behavior (sessionBoundary: false, the updatedAt gate, lastActivityAt, and allowOlderTimestamp) is preserved intact.
  • Summary-field reconciliation — summariesEqual and the bridge now carry main's new model / toolName / toolInput / lastAssistantMessage fields alongside the previously-reviewed updatedAt gate, so settled activity still republishes while streaming turns stay quiet.
  • Test fixture alignment — the feed tests now drive working state through TURN_IDENTITY status rows and pass a deterministic now into openJournal, matching main's journal fixtures without weakening the regression coverage.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit c49345d into main Sep 7, 2026
28 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#19144)

* Fix structured native chat completion sorting and timestamps

* Preserve native chat activity across settled updates and host upgrades

---------

Co-authored-by: Merge Sim <sim@local>
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.

Native chat completions sort as idle and lose activity timestamps on reload

1 participant