fix(app): ignore stale assistant messages for running state#109
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 14 minutes and 47 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis change consolidates session "running" state logic from three UI components into a single, tested helper function Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request centralizes the logic for determining if a session is active by introducing a new utility function, isSessionRunning, and applying it across several components including the sidebar, session page, and message timeline. Comprehensive unit tests were also added for this new utility. Feedback was provided regarding potential TypeScript errors when accessing message completion times, suggesting the use of optional chaining for better type safety.
8faf1bb to
8ca5931
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
总体逻辑正确,测试覆盖充分。几点 inline 供参考(无阻塞问题)。
Astro-Han
left a comment
There was a problem hiding this comment.
Overall: Clean fix with good test coverage. One edge case suggestion.
Core Logic Review
The new isSessionRunning helper consolidates duplicate logic across 3 files — good refactor. The logic is:
if ((status ?? idle).type !== "idle") return true
const latest = messages?.at(-1)
return latest?.role === "assistant" && typeof latest.time?.completed !== "number"Key insight: Trust live session_status over message history. Only fallback to checking the latest message, not scanning all history. This correctly fixes the stale-incomplete-assistant bug.
Edge Case: Empty Message Array
When messages is an empty array []:
messages?.at(-1)returnsundefinedundefined?.role === "assistant"isfalse- Returns
false✓ (idle state)
This is correct behavior, but worth adding a test case for clarity.
Minor Nits
-
Test file import path:
import { isSessionRunning } from "./session-running-state"— works, but explicit extension would be clearer for future tooling. -
Test helper naming: The
userandassistantfactory functions are minimal. Consider adding JSDoc or renaming tomakeUserMessage/makeAssistantMessagefor discoverability.
These are nits; not blocking.
Suggestion: Add Empty Array Test
test("returns false when messages array is empty", () => {
expect(isSessionRunning(idle, [])).toBe(false)
})This documents the edge case and ensures future refactorers don't accidentally change behavior.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/app/src/pages/session/session-running-state.test.ts`:
- Around line 64-70: Add explicit tests calling isSessionRunning with undefined
inputs to lock the helper contract: add assertions in
session-running-state.test.ts that isSessionRunning(undefined, undefined)
returns false, isSessionRunning(undefined, []) returns false, and
isSessionRunning(undefined, [user("msg_user",1)]) behaves like the idle-case
expectation; reference the isSessionRunning helper to implement these new test
cases so callers passing undefined status or messages are covered.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 2c11aa1a-f426-497b-b23d-51c709408429
📒 Files selected for processing (5)
packages/app/src/pages/layout/sidebar-items.tsxpackages/app/src/pages/session.tsxpackages/app/src/pages/session/message-timeline.tsxpackages/app/src/pages/session/session-running-state.test.tspackages/app/src/pages/session/session-running-state.ts
de0bffb to
7b44979
Compare
Summary
isSessionRunninghelper for app session running-state checks.session_statusas authoritative, and only fall back to message history when the latest message is an incomplete assistant message.Why
A stale incomplete assistant message from an older turn can remain in session history even after later turns complete. The previous UI checks treated any historical incomplete assistant message as current work, which kept completed sessions showing progress/spinners.
Related Issue
Fixes #95
How To Verify
Screenshots or Recordings
Not included. This is a state-derivation fix covered by unit tests, with no intentional visual design change.
Checklist
devbranchSummary by CodeRabbit
Refactor
Tests