fix(message): preserve active chat lanes - #1045
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughChat-lane queue entries now retain a per-lane guard while processing. Cache eviction checks that guard, message handlers use the new queue payload, and an integration test verifies active lanes survive capacity pressure before becoming evictable when idle. ChangesChat lane eviction protection
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
| Filename | Overview |
|---|---|
| src/client.rs | Introduces QueuedChatMessage (node + lane_liveness Arc) and ChatLane::try_enqueue; cleanly encapsulates strong-count bump at enqueue time. |
| src/client/lifecycle.rs | Adds evict_guard to chat_lanes cache consistent with the existing session_locks guard; one-line change with no other side effects. |
| src/handlers/message.rs | Worker loop destructures QueuedChatMessage with an explicit lane_liveness binding and an explicit drop after processing; intent is anchored by a comment. |
| src/client/tests.rs | Adds active_chat_lane_survives_capacity_pressure regression test covering enqueue, in-flight eviction blocking, and post-processing evictability with a capacity-1 cache. |
Reviews (3): Last reviewed commit: "refactor(message): make lane liveness ex..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/handlers/message.rs`:
- Around line 88-92: Add a concise comment directly above or beside the
`lane_guard: _lane_guard` binding in the `QueuedChatMessage` destructuring
within the receive loop, documenting that the named binding must remain alive
through the worker body to preserve cache-eviction protection; do not change the
binding behavior.
🪄 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: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 88529a47-20c0-4c1b-ae30-7dafcf4e844a
📒 Files selected for processing (4)
src/client.rssrc/client/lifecycle.rssrc/client/tests.rssrc/handlers/message.rs
📦 Binary size report
.text per crate
Baseline: |
1ec3ba2 to
1a2a20b
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/client.rs`:
- Around line 195-198: Add a Debug derive to the QueuedChatMessage struct while
preserving its existing fields and behavior.
🪄 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: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 736042e1-242a-4bda-8a34-2aee162aeeaa
📒 Files selected for processing (4)
src/client.rssrc/client/lifecycle.rssrc/client/tests.rssrc/handlers/message.rs
Closes #1039.
An active chat lane could be capacity-evicted after its worker dequeued a message. A later message for the same chat would then create a second worker, allowing post-decryption dispatch to run out of order.
This keeps the cached lane alive from enqueue through processing by carrying a clone of its existing lock with each queued message. The cache now skips lanes with live references, while idle lanes remain evictable on the next capacity check. The token is an
Arcclone, so it adds no heap allocation.The capacity-1 regression test reproduces the old eviction, verifies that consecutive messages stay on the original channel, and confirms the lane becomes evictable after processing.
Performance validation on 50,000-message ping-pong runs:
Validated with
cargo fmt --all --check,cargo clippy --all --tests, the non-E2E workspace test suite, and the release WASM build.