Repository navigation
Replace assistant-prose heuristic with explicit turn lifecycle markers - #9121
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAdds provider-specific native-chat turn lifecycle decoding for Claude and Codex, including completion, interruption, and working boundaries. Lifecycle metadata now flows through transcript readers, watchers, IPC frames, runtime validation, web preload adapters, and renderer session state. Renderer logic tracks lifecycle revisions, working subagents, terminal boundaries, interruption rows, and working suppression. Pending-send handling detects glued transcript rows, while PTY sends are serialized with cancellation and idle coordination. Tests cover decoding, transport propagation, pagination ordering, reconnects, pending messages, and UI status behavior. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 6f2b700e-3de9-4922-9463-384108189e8e
📒 Files selected for processing (32)
src/main/ipc/native-chat-subscribe-lifecycle.test.tssrc/main/ipc/native-chat.tssrc/main/native-chat/transcript-incremental-reader.tssrc/main/native-chat/transcript-interruption-message.test.tssrc/main/native-chat/transcript-line-decoders-claude.tssrc/main/native-chat/transcript-line-decoders-codex.tssrc/main/native-chat/transcript-reader.tssrc/main/native-chat/transcript-tail-reader.tssrc/main/native-chat/transcript-turn-lifecycle.test.tssrc/main/native-chat/transcript-turn-lifecycle.tssrc/main/native-chat/transcript-watch-contract.tssrc/main/native-chat/transcript-watch-engine.tssrc/main/native-chat/transcript-watch.test.tssrc/main/native-chat/transcript-watch.tssrc/main/runtime/rpc/methods/native-chat.test.tssrc/main/runtime/rpc/methods/native-chat.tssrc/preload/api-types.tssrc/renderer/src/components/native-chat/NativeChatView.tsxsrc/renderer/src/components/native-chat/native-chat-live-status.tssrc/renderer/src/components/native-chat/native-chat-noise.test.tssrc/renderer/src/components/native-chat/native-chat-runtime-contract.tssrc/renderer/src/components/native-chat/native-chat-session-transport.test.tssrc/renderer/src/components/native-chat/native-chat-session-transport.tssrc/renderer/src/components/native-chat/native-chat-working-suppression.test.tssrc/renderer/src/components/native-chat/native-chat-working-suppression.tssrc/renderer/src/components/native-chat/use-native-chat-hook-status.tssrc/renderer/src/components/native-chat/use-native-chat-live-session.test.tssrc/renderer/src/components/native-chat/use-native-chat-live-session.tssrc/renderer/src/components/native-chat/use-native-chat-transcript-lifecycle.tssrc/renderer/src/web/web-preload-api.test.tssrc/renderer/src/web/web-preload-api.tssrc/shared/native-chat-types.ts
Extract provider-authored turn boundaries (completion, interruption) directly from Claude/Codex transcripts so the chat view knows when work ends without guessing from message presence. Reconciles live hook state with transcript lifecycle: when a terminal boundary lands, it settles a dropped Stop hook instead of letting prose mislead the UI into showing 'working' after done.
Treat max_tokens/stop_sequence/refusal as completed markers so capable hosts do not stay working after a dropped Stop, and assert lifecycle payloads on runtime subscribe/read frames plus mid-turn non-terminal stop_reason cases.
Add type assertion and comment documenting that lifecycle field is optional and can be omitted in truncation-gating test fixtures.
When Claude's turn is explicitly interrupted, the session should show ready immediately — even if background subagents are still running. Add an interruption check before consulting the hook's working-subagents flag so interruptions take precedence. Also normalize omitted lifecycle timestamps to null instead of leaving them undefined, and add test coverage for both cases.
Explicit transcript turn-lifecycle markers now fully replace the prose-fallback settlement path. Remove the now-unused `turnLifecycleCapable` flag and wire lifecycle to suppress spinner even when hook status lingers. Refine Claude lifecycle detection to distinguish terminal stops from mid-turn tool_use rows, exclude harness noise from new-generation detection, and apply clock-skew slack over SSH/relay. Serialize PTY sends per line to prevent rapid prompts from gluing before Enter, clearing unsubmitted input on cancel. Update working suppression to detect epoch rollovers so interrupt+next-turn without a ready gap resets the spinner correctly.
ab0ac05 to
2df2e19
Compare
There was a problem hiding this comment.
Actionable comments posted: 5
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/renderer/src/components/native-chat/native-chat-runtime-send.ts (1)
134-142: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAborted verified sends leave their accepted command body in the composer. Clear that body when the delay aborts or Enter is rejected.
src/renderer/src/components/native-chat/native-chat-runtime-send.ts#L134-L142: perform best-effort cleanup after body acceptance when submission does not complete.src/renderer/src/components/native-chat/native-chat-runtime-send.test.ts#L222-L233: assert both that Enter is suppressed and that the clear write occurs.src/renderer/src/components/native-chat/use-native-chat-session-option-command.ts (1)
51-60: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winSynchronously prevent concurrent option-command dispatches.
setIsDispatching(true)does not guard re-entry before React renders. Two calls can therefore run verified PTY writes and confirmation observers concurrently, concatenating commands or associating output with the wrong observer. CheckactiveSendsRefbefore registering another controller.Proposed fix
async (command, options) => { const target = resolveTarget() if (!target || disabled) { throw new Error('No live terminal is available.') } + if (activeSendsRef.current.size > 0) { + throw new Error('Another native chat option command is already in progress.') + } const sendController = new AbortController()
🧹 Nitpick comments (3)
src/renderer/src/components/native-chat/native-chat-pending.test.ts (1)
154-161: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExercise the glued-prefix branch in this negative test.
With one pending entry, selection returns early at
pending.length < 2, so this test cannot detect prefix-matching regressions. Use at least two fragments.Proposed test adjustment
- const pending = [pendingOf('p1', 'hi')] + const pending = [pendingOf('p1', 'hi'), pendingOf('p2', 'there')]src/renderer/src/components/native-chat/native-chat-runtime-send.test.ts (2)
107-113: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover queue accounting after completed-handle cancellation.
This test only verifies that no PTY write occurs. Keep another send queued, cancel the completed handle, and assert that a newly enqueued handle retains the correct
settleAfterMs.
222-233: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert that abort removes the accepted command body.
The body has already been written when this abort occurs. Verify that cancellation emits the clear sequence as well as suppressing Enter, preventing the next verified command from concatenating with stale input.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f0980522-9620-41c1-86e3-b4192a44222d
📒 Files selected for processing (40)
src/main/ipc/native-chat-subscribe-lifecycle.test.tssrc/main/ipc/native-chat.tssrc/main/native-chat/transcript-incremental-reader.tssrc/main/native-chat/transcript-interruption-message.test.tssrc/main/native-chat/transcript-line-decoders-claude.tssrc/main/native-chat/transcript-line-decoders-codex.tssrc/main/native-chat/transcript-reader.tssrc/main/native-chat/transcript-tail-reader.tssrc/main/native-chat/transcript-turn-lifecycle.test.tssrc/main/native-chat/transcript-turn-lifecycle.tssrc/main/native-chat/transcript-turn-markers.tssrc/main/native-chat/transcript-watch-contract.tssrc/main/native-chat/transcript-watch-engine.tssrc/main/native-chat/transcript-watch.test.tssrc/main/native-chat/transcript-watch.tssrc/main/runtime/rpc/methods/native-chat.test.tssrc/main/runtime/rpc/methods/native-chat.tssrc/preload/api-types.tssrc/renderer/src/components/native-chat/NativeChatView.tsxsrc/renderer/src/components/native-chat/native-chat-live-status.tssrc/renderer/src/components/native-chat/native-chat-noise.test.tssrc/renderer/src/components/native-chat/native-chat-pending-occurrence.tssrc/renderer/src/components/native-chat/native-chat-pending.test.tssrc/renderer/src/components/native-chat/native-chat-pending.tssrc/renderer/src/components/native-chat/native-chat-pty-send-queue.tssrc/renderer/src/components/native-chat/native-chat-runtime-contract.tssrc/renderer/src/components/native-chat/native-chat-runtime-send.test.tssrc/renderer/src/components/native-chat/native-chat-runtime-send.tssrc/renderer/src/components/native-chat/native-chat-session-transport.test.tssrc/renderer/src/components/native-chat/native-chat-session-transport.tssrc/renderer/src/components/native-chat/native-chat-working-suppression.test.tssrc/renderer/src/components/native-chat/native-chat-working-suppression.tssrc/renderer/src/components/native-chat/use-native-chat-hook-status.tssrc/renderer/src/components/native-chat/use-native-chat-live-session.test.tssrc/renderer/src/components/native-chat/use-native-chat-live-session.tssrc/renderer/src/components/native-chat/use-native-chat-session-option-command.tssrc/renderer/src/components/native-chat/use-native-chat-transcript-lifecycle.tssrc/renderer/src/web/web-preload-api.test.tssrc/renderer/src/web/web-preload-api.tssrc/shared/native-chat-types.ts
🚧 Files skipped from review as they are similar to previous changes (17)
- src/main/native-chat/transcript-interruption-message.test.ts
- src/main/native-chat/transcript-watch-contract.ts
- src/renderer/src/components/native-chat/native-chat-noise.test.ts
- src/renderer/src/components/native-chat/use-native-chat-hook-status.ts
- src/main/ipc/native-chat-subscribe-lifecycle.test.ts
- src/main/native-chat/transcript-watch.ts
- src/main/native-chat/transcript-incremental-reader.ts
- src/shared/native-chat-types.ts
- src/renderer/src/components/native-chat/native-chat-session-transport.ts
- src/renderer/src/web/web-preload-api.test.ts
- src/main/native-chat/transcript-line-decoders-codex.ts
- src/main/native-chat/transcript-line-decoders-claude.ts
- src/main/native-chat/transcript-watch.test.ts
- src/main/native-chat/transcript-turn-lifecycle.test.ts
- src/main/native-chat/transcript-tail-reader.ts
- src/main/native-chat/transcript-watch-engine.ts
- src/renderer/src/components/native-chat/NativeChatView.tsx
…hat-still-shows-loading-when-ai-done
stablyai#9121) * Replace assistant-prose heuristic with explicit turn lifecycle markers Extract provider-authored turn boundaries (completion, interruption) directly from Claude/Codex transcripts so the chat view knows when work ends without guessing from message presence. Reconciles live hook state with transcript lifecycle: when a terminal boundary lands, it settles a dropped Stop hook instead of letting prose mislead the UI into showing 'working' after done. * fix(review): cover Claude terminal stop_reasons and RPC lifecycle frames Treat max_tokens/stop_sequence/refusal as completed markers so capable hosts do not stay working after a dropped Stop, and assert lifecycle payloads on runtime subscribe/read frames plus mid-turn non-terminal stop_reason cases. * test(native-chat): clarify that lifecycle field is optional Add type assertion and comment documenting that lifecycle field is optional and can be omitted in truncation-gating test fixtures. * fix(native-chat): settle status on interruption despite working subagent When Claude's turn is explicitly interrupted, the session should show ready immediately — even if background subagents are still running. Add an interruption check before consulting the hook's working-subagents flag so interruptions take precedence. Also normalize omitted lifecycle timestamps to null instead of leaving them undefined, and add test coverage for both cases. * fix(native-chat): settle loading spinner on explicit turn boundaries Explicit transcript turn-lifecycle markers now fully replace the prose-fallback settlement path. Remove the now-unused `turnLifecycleCapable` flag and wire lifecycle to suppress spinner even when hook status lingers. Refine Claude lifecycle detection to distinguish terminal stops from mid-turn tool_use rows, exclude harness noise from new-generation detection, and apply clock-skew slack over SSH/relay. Serialize PTY sends per line to prevent rapid prompts from gluing before Enter, clearing unsubmitted input on cancel. Update working suppression to detect epoch rollovers so interrupt+next-turn without a ready gap resets the spinner correctly.
Summary
Fixes native chat showing 'loading' after AI completion by replacing an unreliable prose-based heuristic with explicit provider-authored turn lifecycle records. Adds support for Claude terminal
stop_reasonevents and Codex task boundaries.Problem
The live-session merge relied on detecting trailing assistant prose (timestamp comparison) to settle a dropped working hook. This failed when:
Solution
Added
NativeChatTurnLifecycle— provider-authored turn boundaries recovered from the transcript itself:stop_reasonfields (end_turn,max_tokens,stop_sequence,refusal) andinterruptedMessageIdrecordstask_started,task_complete, andturn_abortedevent recordsThe merge now reconciles live hook 'working' against these boundaries: hook persists until an explicit terminal marker lands (completion/interruption) or the hook state exits.
Key Changes
transcript-turn-lifecycle.tsmodule with decoders for each providernative-chat-live-status.tsmerge logic to check lifecycle state against hook timinguseNativeChatTranscriptLifecycle()anduseNativeChatHookStatus()for renderer reconciliationTesting
transcript-turn-lifecycle.test.tscovering Claude/Codex decoder logictranscript-interruption-message.test.tsfor interruption normalizationuse-native-chat-live-session.test.tswith lifecycle reconciliation scenariosnative-chat-session-transport.test.tsto validate lifecycle metadata from remotesweb-preload-api.test.tscases for web runtime validationNotes
turnLifecycleCapable: trueso consumers know whether to trust explicit boundaries