refactor(core): decompose SessionBridge and harden transport/persistence#115
refactor(core): decompose SessionBridge and harden transport/persistence#115
Conversation
Summary of ChangesHello @teng-lin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant refactoring of the core Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The refactoring of SessionBridge into dedicated plane composers significantly improves the modularity and testability of the core logic. The introduction of BufferedWebSocket provides a robust solution for handling early CLI messages, and the addition of the flush() contract to SessionStorage ensures data durability during shutdown. The documentation updates accurately reflect these architectural changes. The suggested change for BufferedWebSocket is valid and addresses potential race conditions.
| socket.on("message", handler as (data: string | Buffer) => void); | ||
| if (!this.replayed && !this.closedOrErrored) { | ||
| this.replayed = true; | ||
| for (const message of this.bufferedMessages) { | ||
| handler(message); | ||
| } | ||
| this.bufferedMessages.length = 0; | ||
| this.buffering = false; | ||
| } |
There was a problem hiding this comment.
To prevent any potential race conditions or duplicate message delivery if the underlying socket emits synchronously during listener registration, it is safer to disable buffering and capture the current buffer before registering the new handler on the socket. This ensures that the order of messages is strictly preserved and no message is both replayed and delivered via the live listener.
| socket.on("message", handler as (data: string | Buffer) => void); | |
| if (!this.replayed && !this.closedOrErrored) { | |
| this.replayed = true; | |
| for (const message of this.bufferedMessages) { | |
| handler(message); | |
| } | |
| this.bufferedMessages.length = 0; | |
| this.buffering = false; | |
| } | |
| if (!this.replayed && !this.closedOrErrored) { | |
| this.replayed = true; | |
| this.buffering = false; | |
| const toReplay = [...this.bufferedMessages]; | |
| this.bufferedMessages.length = 0; | |
| socket.on("message", handler as (data: string | Buffer) => void); | |
| for (const message of toReplay) handler(message); | |
| } else { | |
| socket.on("message", handler as (data: string | Buffer) => void); | |
| } |
Summary
SessionBridgecomposition into dedicated plane composers undersrc/core/session-bridge/BufferedWebSocketand migrateCliGatewayflush()contract and wire flush-on-bridge-close for shutdown durabilityValidation
pnpm typecheckpnpm vitest run src/adapters/file-storage.test.ts src/core/session-bridge.integration.test.ts src/core/session-bridge.adapter-consumer.integration.test.ts src/core/session/buffered-websocket.test.ts src/core/session/cli-gateway.test.ts src/core/session/session-transport-hub.test.ts src/core/session-bridge/compose-*.test.ts src/core/session-coordinator.wiring.test.ts