fix: stale lastError on reconnect and short first chat bubble#2616
fix: stale lastError on reconnect and short first chat bubble#2616shriii257 wants to merge 1 commit into
Conversation
## Summary
Two independent bug fixes in `connectivitySlice` and `messageSegmentation`.
---
### Fix 1 — `connectivitySlice`: stale `lastError.backend` during reconnect
**Problem:** `setBackend({ value: 'connecting' })` fell into the `else` branch of the
reducer, executing `state.lastError.backend = action.payload.error` where `error` is
`undefined`. This assigns `undefined` to the key rather than deleting it, so a prior
disconnect error string (e.g. `"transport close"`) could persist in the Redux state
object during the reconnection window.
**Fix:** Extend the delete guard to cover both `'connected'` and `'connecting'`:
```ts
if (action.payload.value === 'connected' || action.payload.value === 'connecting') {
delete state.lastError.backend;
}
```
---
### Fix 2 — `messageSegmentation`: short first paragraph rendered as stub bubble
**Problem:** `mergeTooShort()` only merges short segments *backward* (into the
previous segment). When the *first* paragraph/segment is shorter than
`MIN_SEGMENT_CHARS` (40 chars), there is no previous segment to absorb it, so it
renders as a tiny isolated chat bubble before the rest of the message.
**Fix:** After the main pass, if `result[0]` is still below the threshold and a second
segment exists, forward-merge it:
```ts
if (result.length >= 2 && result[0].length < MIN_SEGMENT_CHARS) {
result[1] = result[0] + joiner + result[1];
result.shift();
}
```
---
## Testing
- All existing `messageSegmentation` unit tests continue to pass.
- New edge case covered: a paragraph array whose first element is `< 40` chars now
correctly merges forward into the second segment rather than being emitted standalone.
- `connectivitySlice` behaviour: calling `setBackend({ value: 'connecting' })` after a
`setBackend({ value: 'disconnected', error: 'transport close' })` now results in
`lastError.backend` being fully absent from state, not present as `undefined`.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesBackend Error Clearing on Reconnection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 |
Summary
Two independent bug fixes in
connectivitySliceandmessageSegmentation.Fix 1 —
connectivitySlice: stalelastError.backendduring reconnectProblem:
setBackend({ value: 'connecting' })fell into theelsebranch of the reducer, executingstate.lastError.backend = action.payload.errorwhereerrorisundefined. This assignsundefinedto the key rather than deleting it, so a prior disconnect error string (e.g."transport close") could persist in the Redux state object during the reconnection window.Fix: Extend the delete guard to cover both
'connected'and'connecting':Fix 2 —
messageSegmentation: short first paragraph rendered as stub bubbleProblem:
mergeTooShort()only merges short segments backward (into the previous segment). When the first paragraph/segment is shorter thanMIN_SEGMENT_CHARS(40 chars), there is no previous segment to absorb it, so it renders as a tiny isolated chat bubble before the rest of the message.Fix: After the main pass, if
result[0]is still below the threshold and a second segment exists, forward-merge it:Testing
messageSegmentationunit tests continue to pass.< 40chars now correctly merges forward into the second segment rather than being emitted standalone.connectivitySlicebehaviour: callingsetBackend({ value: 'connecting' })after asetBackend({ value: 'disconnected', error: 'transport close' })now results inlastError.backendbeing fully absent from state, not present asundefined.Summary
Problem
Solution
Submission Checklist
diff-cover) meet the gate enforced by.github/workflows/coverage.yml. Runpnpm test:coverageandpnpm test:rustlocally; PRs below 80% on changed lines will not merge.docs/TEST-COVERAGE-MATRIX.mdreflect this change (orN/A: behaviour-only change)## Relateddocs/RELEASE-MANUAL-SMOKE.md)Closes #NNNin the## RelatedsectionImpact
Related
AI Authored PR Metadata (required for Codex/Linear PRs)
Linear Issue
Commit & Branch
Validation Run
pnpm --filter openhuman-app format:checkpnpm typecheckValidation Blocked
command:error:impact:Behavior Changes
Parity Contract
Duplicate / Superseded PR Handling
Summary by CodeRabbit