Repository navigation
Gate SSE : connected on the daemon watch bridge actually being attached - #2587
Conversation
…ched (closes #2584) The dev-proxy's HTTP server (and thus /health) comes up before startWatchBridge()'s async gRPC connect finishes, since Bun.serve() never waits on it. Under a loaded machine that connect can still be in flight when a browser client hits /api/events, gets registered in sseClients, and is told `: connected` — with no upstream listener yet attached to relay events. A write racing that window is never delivered, because dev-proxy's own client bookkeeping has no gap (the prior evidence-driven hypothesis) but the bridge's own readiness does. Track bridge attachment with a promise resolved once the gRPC stream's data/error/end listeners are wired, reset on every reconnect, and have /api/events await it before registering a client or flushing `: connected`. Add a deterministic regression test using the existing startDeferred() harness path (proxy healthy, daemon not yet reachable) that fails reliably against the old code and passes reliably against the fix — no reliance on an idle machine either way. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017sppvEt8PWpk92zQMYjc4W
Code Review SummaryThis is a well-targeted, minimal fix for a genuine race condition: the dev-proxy's HTTP server accepted SSE connections and announced FindingsCritical IssuesNone. Suggested Improvements
Nitpicks
Acceptance Criteria Verification (issue #2584)
Code Quality
Test CoverageAdequate for the bug being fixed. The new test complements the existing three (create/update/delete) by covering the one dimension they didn't: client connection racing bridge (re)attachment rather than racing client registration alone. No additional coverage is needed for this fix's scope. |
malibio
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Self-authored PR — verdict recorded via --comment since GitHub rejects self-approval. Full findings posted above. Summary: sound fix for a genuine race, correctly synchronized reconnect/reset logic (verified no overlapping connect() invocations, no stale-closure resolve, no stuck-forever path), all 3 acceptance criteria met, all 4 e2e tests pass, atomic diff, no lint/quality issues. Net positive — approving with only non-blocking nits/suggestions noted in the review comment.
Two non-blocking nits from the pragmatic-code-review of PR #2587: - The comment above `await bridgeAttached` restated the rationale already documented on `bridgeAttached` itself; trimmed to a pointer. - The new describe/it titles read redundantly against the file's existing describe block; renamed for a clearer, non-overlapping name. Skipped: consolidating bridge-attachment state into an object/class — reviewer flagged this as "not warranted at current size, noting for future growth only," not an actionable recommendation. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_017sppvEt8PWpk92zQMYjc4W
Address Review SummaryAddressed the two non-blocking nits from the pragmatic-code-review (which returned APPROVE with no critical/important findings):
⏭️ Skipped: consolidating Verified after the edits: Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Both changes are cosmetic (comment trimming, test naming) with zero logic changes — no code paths, control flow, or test assertions were touched. The one skipped item was the reviewer's own explicit "not warranted now" note, not a recommendation requiring re-verification. The prior review's correctness analysis (synchronization of Ready for merge pending final approval. |
Summary
Fixes #2584 —
WatchNodes SSE stream > delivers nodeCreated event when a node is writtenwas failing deterministically under the pre-push gate.The prior investigation in the issue correctly showed the dev-proxy's own SSE client bookkeeping (
sseClients.add()before the: connectedflush) has no gap. The actual race is one level up:packages/dev-tools/src/dev-proxy.ts'sBun.serve()starts immediately and does not wait forstartWatchBridge()'s asyncconnect()(which doesawait ready(watchClient)before attaching the gRPC stream'sdata/error/endlisteners). So/health— and/api/events— can be live before the daemon-side relay is actually attached. Under a loaded machine, a client can connect, get registered, and be told: connectedinside that window; a write racing it is never delivered because nothing is listening upstream yet to broadcast it.Changes
packages/dev-tools/src/dev-proxy.ts: track watch-bridge attachment with a resolvable promise, resolved once the gRPC stream's listeners are wired and reset on every reconnect (error/end)./api/eventsnow awaits this before registering a client or flushing: connected.packages/desktop-app/src/tests/e2e/watch-nodes.e2e.ts: added a deterministic regression test using the existingDaemonTestHarness.startDeferred()path (proxy healthy, daemon not yet reachable) — this reproduces the race without depending on machine load. Verified it fails reliably against the pre-fix code and passes reliably with the fix.Test plan
bun run test:e2e -- watch-nodes— all 4 tests pass, repeated 4x with no flakesAbortError: This operation was abortedafter 20s) and passes against the fixbun run test:all— no new failures vs baselinebun run quality:fix— cleangit pushpre-push gate (test:all + cargo build + test:e2e) passed🤖 Generated with Claude Code