Skip to content

fix(native-chat): settle sidebar agent status while the chat pane is hidden - #18713

Closed
brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/chatui-5-sidebar-working-stuck
Closed

brennanb2025 wants to merge 4 commits into
mainfrom
brennanb2025/chatui-5-sidebar-working-stuck

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​322 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​317
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​255 $\color{#cf222e}{\Huge{\mathbf{−}}}$​55 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​200

Item 5: "Sometimes the sidebar agent status won't stop 'working' status until I click into the Chat UI view, even it's done working."

Reported by Jinjing in the Chat UI UI/UX feedback thread: https://stablygroup.slack.com/archives/C0BV03ZK1KN/p1788474468997739

ELI5

Every agent chat has a "listener" that watches for the message "I'm finished." That listener was only switched on while the chat was on screen. As soon as you looked at a different workspace, the listener went to sleep, so the sidebar kept showing the last thing it had heard: "working." It only woke up again when you opened the chat, which is why clicking into the Chat UI "fixed" it. Now the listener stays on whenever the agent is mid-reply, even when the chat is off screen, and goes back to sleep once the reply lands.

Before / After (user-facing)

Before

  • Start a Codex chat reply, then switch to another workspace.
  • The sidebar row for that chat stays on the "working" spinner after the reply has finished.
  • It only flips to Done when you click back into that Chat UI.

After

  • Start a Codex chat reply, then switch to another workspace.
  • The sidebar row flips from "working" to Done on its own when the reply finishes.
  • No need to reopen the chat; the row already reflects the real state when you come back.

Root cause

The structured status bridge subscribed to the session read owner without ever activating it. Hiding the last visible reader stopped transport before the turn-completion tombstone arrived, so the projection kept reporting an active turn until the pane was reopened.

Fix

Retain read-owner activation while the cached projection still has an active turn, so settlement is observed with the pane hidden.

Validation

15/15 targeted tests including a new regression test for hidden-pane settlement; oxlint; pnpm tc:web. Electron CDP evidence shows the sidebar going Working -> Done in the background without reopening the Chat UI.

Reproduced in the real Electron app over CDP before the fix and verified after.

@brennanb2025
brennanb2025 marked this pull request as ready for review September 4, 2026 21:34
@coderabbitai

coderabbitai Bot commented Sep 4, 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: 58941d8c-3077-4522-8d1d-85a7735a4b6d

📥 Commits

Reviewing files that changed from the base of the PR and between bf6c562 and 1b1a645.

📒 Files selected for processing (2)
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
  • src/renderer/src/components/native-chat/structured-agent-session-pending-turn-retentions.ts

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


📝 Walkthrough

Walkthrough

The structured session read owner now tracks pending-turn retentions and exposes retain/release callbacks. The outbox retains turns during dispatch and retry, and releases them after refusal, rejection, or send failure. Retry preparation now handles operation ID rotation and retry state. Tests cover hidden-turn settlement and retention across send and unmount.

Merge Risk: 🔵 Low · up to 1b1a6

The production fix appears functional, but the regression test does not fully guard its retention behavior. This is bounded test-coverage risk rather than a demonstrated runtime defect.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing sidebar agent status settlement while the chat pane is hidden.
Description check ✅ Passed The description is mostly complete and explains the user impact, root cause, fix, before/after behavior, linked report, and validation. It does not include the template's exact "Fixes #" issue referen…
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.
  • 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.

@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

  • Retain read-owner activation during hidden active turns — useStructuredAgentSessionReadObservation now activates the shared session read owner while the projection has a running turn, so the turn-completion tombstone is still observed after the chat pane hides.
  • Hidden-pane settlement regression test — a new StructuredAgentSessionStatusBridge test drives a running turn, hides the pane, delivers a removal batch, and asserts the sidebar flips working → done and the subscription is released only after settlement.

The activation predicate (activeStructuredAgentSessionTurnId) is deliberately scoped to the working state, which settles autonomously; the attention/blocked state settles through pane interaction and correctly needs no hidden-pane observation.

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

@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/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx (1)

290-292: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert retainPendingTurn is captured before you call it.

retainPendingTurn?.('client-1') skips the call silently when the capture at line 141 does not run. The batch at lines 297-331 still settles to done and still triggers one unsubscribe, so this regression test passes without exercising retention at all. Test 1 already guards this at lines 238-239. Mirror that assertion here.

💚 Proposed fix
     act(() => {
+      expect(retainPendingTurn).not.toBeNull()
       retainPendingTurn?.('client-1')
     })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 39e96240-f5a9-4d05-a3a6-c8204c7f283e

📥 Commits

Reviewing files that changed from the base of the PR and between 7624c11 and bf6c562.

📒 Files selected for processing (8)
  • src/renderer/src/components/native-chat/StructuredAgentSessionStatusBridge.test.tsx
  • src/renderer/src/components/native-chat/structured-agent-session-outbox-retry.ts
  • src/renderer/src/components/native-chat/structured-agent-session-pending-turn-retentions.ts
  • src/renderer/src/components/native-chat/structured-agent-session-read-owner.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-outbox.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session-outbox.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-read.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/native-chat/use-structured-agent-session-read.ts

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.

Important

The new pending-turn retention heuristic can release a queued send's retention before that send's turn ever starts when two sends land in the same pre-running window, leaving a hidden pane's second turn unobserved (see the inline comment).

Reviewed changes

  • Added a pending-turn retention subsystem — structured-agent-session-pending-turn-retentions.ts keeps the session read owner activated from the moment a send is queued until its turn's lifecycle settles, closing the gap between the send handoff and the running status the prior commit's activation predicate relied on.
  • Threaded retainPendingTurn/releasePendingTurn through the read path — the read owner, read hook, and session hook now expose retention/release, and the outbox retains on queue/dispatch and releases on refusal, rejection, and failure.
  • Extracted prepareStructuredAgentSessionOutboxRetry — the outbox retry operation-id rotation is factored into a pure, behavior-preserving helper.
  • Added hidden-pane handoff regression tests — StructuredAgentSessionStatusBridge tests cover an immediate hidden send before its running event and a batch where running and settled lifecycles arrive together.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron visual proof at bf6c5627b6945caef401d17814c30dd325df179b

Validated the live structured Codex chat scenario on this worktree's Electron dev app (Orca: brennanb2025/chatui-5-sidebar-working-stuck, PID 51175, CDP 9335). This is rendered-UI proof, not store-only.

Actions: opened New tab → Codex (structured agent-session), sent a real composer turn (Read README.md with a tool, then write a 150-word explanation of git…), hid the chat by switching to workspace B while the sidebar still showed Working, then waited for completion without reopening that chat.

Visible evidence: center pane stayed on B's Terminal 1. A's sidebar row went Working → Done on its own.

Before — Working while chat hidden

Working while chat hidden

After — Done while chat still hidden

Done while chat still hidden

Backing evidence: agentStatusByPaneKey was working with the live prompt while B was active, then done / agentType: 'codex' / sessionBoundary: true still on B. Snapshot text: A option Working then Done; selected B Active; visible tab Terminal 1.

Logs: no structured-session renderer errors. Unrelated: tooltip controlled/uncontrolled warning, xterm deadline, B-terminal input while document.visibilityState hidden, FileListingCancelledError on workspace switch, startup MaxListenersExceededWarning. Codex app-server trust grant succeeded.

Gaps: a first trivial ping turn finished while the chat was still visible; the hidden Working→Done proof is the second live turn. Hide on that turn used setActiveWorktree(B) after Working appeared (UI did switch to B/Terminal 1). Did not reopen the chat after Done. attention/blocked not exercised. Desktop renderer-only; no mobile QA.

Screenshots show local username brennanbenson in B's terminal prompt and temp QA paths. No tokens/keys.

@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

  • Fenced the completing turn out of the settlement scan — the !activeTurnId branch in createStructuredAgentSessionPendingTurnRetentions now seeds claimedTurnIds with observedActiveTurnId, so a turn's completion no longer releases a still-pending send's retention before that send's own turn starts.
  • Added a concurrent-send regression test — does not settle a pending hidden send when the previous turn completes retains a second send while a first turn is running, completes the first turn, and asserts the pending retention survives until its own turn settles.

The new test fails against the prior version (empty claimedTurnIds) and passes with the seed in place, and the change leaves the other settlement paths (claim-on-running, release-on-removal, refusal/rejection) untouched.

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

@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

  • Retained turn-ownership history — createStructuredAgentSessionPendingTurnRetentions now tracks every observed active turn in a persistent observedTurnIds set (seeded on first retain, accumulated per observe, cleared when retentions empty) instead of fencing only the single observedActiveTurnId. The !activeTurnId settlement scan therefore excludes all prior turns, not just the most recent one, so a stale completion item from an earlier turn can no longer release a still-pending send's retention on a later snapshot.
  • Extended the regression test to three turns — the test now retains two pending sends (client-b, client-c) and asserts unsubscribe is still unissued after the first turn settles, then drives the second turn through running → done before the subscription releases.

The persistent-set change closes the residual window in the prior commit (where observedActiveTurnId reset to null after the completing observe, re-exposing an earlier turn's completion). The extended test fails against the single-id version and passes here.

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron visual proof at 1b1a645382463bef832552fa1b56ae12eac67d69

Revalidated the live structured Codex chat scenario on this worktree's Electron dev app (Orca: brennanb2025/chatui-5-sidebar-working-stuck, Electron PID 12858, CDP 9337, renderer 5178). This is rendered-UI proof, not store-only. No source edits.

Actions: opened New tab → Codex (structured agent-session), sent a real composer turn (Use a tool to read README.md. Then write a 500-word essay…), hid the chat by switching to workspace qa-b while the sidebar still showed Working, then waited for completion without reopening that chat.

Visible evidence: center pane stayed on qa-b's Terminal 1. A's sidebar row went Working → Done on its own.

Before — Working while chat hidden

Working while chat hidden

After — Done while chat still hidden

Done while chat still hidden

Backing evidence: After hide, agentStatusByPaneKey was working / agentType: 'codex' / sessionBoundary: false with the live 500-word prompt while qa-b was active and the center tab was terminal. Poll samples stayed working + visible Working for several seconds, then flipped to done / sessionBoundary: true / visible Done with hasCodexChatTab: false and Terminal 1 still selected. Snapshot text: A option Working then Done; selected B Active; visible tab Terminal 1.

Overlap: the product UI can queue extra sends while a turn is active (Enter still calls send(); the button is Stop). Two earlier live sequences queued additional accepted user bubbles during Working (DONE-OVERLAP, then OVERLAP-STILL-WORKING). Those overlapping turns completed and the hidden row ended Done after the last reply. We did not capture a screenshot of the in-between window where the first overlapping turn had settled but later queued turns were still pending, because those sequences finished too quickly.

Logs: no structured-session renderer errors. Unrelated: tooltip controlled/uncontrolled warning, xterm deadline, FileListingCancelledError on workspace switch, startup MaxListenersExceededWarning. Codex app-server trust grant succeeded.

Gaps: hide used setActiveWorktree(qa-b) after Working appeared (UI did switch to B / Terminal 1). Did not reopen the chat after the proof Done screenshot. attention / blocked not exercised. Overlap intermediate (older settlement must not flip hidden Done early) is covered by the accepted queued sends + final Done, but not by a dedicated mid-overlap screenshot. Desktop renderer-only; no mobile QA.

Screenshots show local username brennanbenson in B's terminal prompt and temp QA paths. No tokens/keys.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review status: clean — recommend landing at 1b1a645382463bef832552fa1b56ae12eac67d69.

  • The same-model review/fix loop found and fixed the immediate-hide read-handoff race, then two overlapping/queued-turn ownership variants that could release the hidden reader on an older turn's completion. Fixes were pushed in bf6c5627, c8c45ab6, and 1b1a6453.
  • The solution remains focused on structured native-chat lifecycle ownership. Precedent review supports the shared-reader lease/handoff design; no ad hoc polling, provider fanout, wire change, or platform-specific path was added.
  • Start- and end-of-session readiness audits completed. Final audit found no P0/P1/P2, security, persistence, cross-platform, SSH-boundary, folder-workspace, mobile, or remote-wire issues.
  • Local verification: 28/28 final targeted tests, pnpm tc:web, changed-file oxlint/code-quality, formatting, and git diff --check.
  • Final-head CI is green: static analysis, typecheck, macOS and Windows packaging, all 8 test shards, LoC/root guards, and verify.
  • Performance/resource review is clean: event-driven only; retained turn IDs are bounded to an active retention epoch and clear when the final retention releases.
  • Grok Electron/CDP proof at the exact final HEAD: Working → Done while the structured Codex chat remained hidden. The rendered sidebar, backing store, and accessibility snapshot agreed; overlapping Enter sends were also accepted and settled to Done.

Residual QA gaps: attention/blocked were not manually exercised, and the intermediate settlement between multiple queued turns was too brief for a screenshot; that ownership sequence is covered by the regression test. Desktop renderer-only, so mobile QA was not applicable.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #18776, which moves the status projection to the host (one status stream per client) instead of retaining the renderer's transcript reader. That also covers the unopened-tab and window-reload cases this change could not reach. Closing this one.

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.

1 participant