Repository navigation
refactor(gateway): extract source-agnostic desktop relay core - #122455
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 12, 2026, 2:03 AM ET / 06:03 UTC. ClawSweeper reviewWhat this changesThis PR moves the cloud-worker desktop relay into a source-agnostic Gateway desktop module while retaining worker-specific SSH acquisition and app launching. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the extraction introduces a same-owner launch/observe race that can stop a newly created desktop session and fail the observer connection. Priority: P1 Review scores
Verification
How this fits togetherA worker desktop RPC acquires an RFB endpoint and returns a short-lived WebSocket path to Control UI. Gateway upgrades that path, attaches an observer to the desktop lifecycle, and relays RFB traffic with view-only filtering. flowchart LR
A[Control UI desktop request] --> B[Worker desktop RPC]
B --> C[Desktop session registry]
C --> D[Observer token]
D --> E[Gateway WebSocket upgrade]
E --> F[RFB relay]
F --> G[Worker desktop attachment]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +163, Tests +41. Total +204 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Preserve a same-epoch session during fencing and add a regression test for concurrent first launch and observation after an owner advance. Do we have a high-confidence way to reproduce the issue? Yes: start app launch as the first operation for a new owner epoch, begin same-epoch desktop acquisition before its fencing step runs, and observe that the unconditional stop rejects the new acquisition. Is this the best way to solve the issue? No: the shared registry is the right owner, but the worker adapter must retain the prior lower-epoch fence invariant rather than stopping every current entry. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6752f8b4f133. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Split the cloud-worker desktop observer into a reusable core under src/gateway/desktop/ so upcoming desktop sources (gateway host, nodes) plug into one relay pipeline: - attachment.ts: RfbAttachment union (unix socket | loopback TCP) - session-registry.ts: generic observer lifecycle (8-observer cap, controller eviction, 60s linger, owner-epoch fencing) with typed stale-owner/stopped errors - observe-bridge.ts: single-use observe tokens + WS relay, path moves to /desktop/observe (clients consume wsPath verbatim) - rfb-view-only-filter.ts: pure move desktop-tunnel.ts keeps only worker SSH acquisition and app launch, plugged into the shared registry; external API unchanged. Behavior is identical; worker desktop tests pass unmodified apart from import and path renames. Drops the never-used now() option.
The desktop core extraction replaced the owner fence's "stop strictly older owners" check with an unconditional session stop. A launcher that claims an owner epoch first, then reaches its async fencing pass after a same-epoch observe has already created the session, tore that session down and failed the observer with "stopped before connecting". Restore the original invariant in the registry that owns it: stopSuperseded() retires an entry only when its epoch is strictly lower than the claimant's, so peers sharing a generation keep the session. The regression test drives launch-then-observe at one epoch and fails on the pre-fix code inside fenceReplacedOwners.
faa487c to
57bc979
Compare
|
Merged via squash.
|
…aw#122455) * refactor(gateway): extract source-agnostic desktop relay core Split the cloud-worker desktop observer into a reusable core under src/gateway/desktop/ so upcoming desktop sources (gateway host, nodes) plug into one relay pipeline: - attachment.ts: RfbAttachment union (unix socket | loopback TCP) - session-registry.ts: generic observer lifecycle (8-observer cap, controller eviction, 60s linger, owner-epoch fencing) with typed stale-owner/stopped errors - observe-bridge.ts: single-use observe tokens + WS relay, path moves to /desktop/observe (clients consume wsPath verbatim) - rfb-view-only-filter.ts: pure move desktop-tunnel.ts keeps only worker SSH acquisition and app launch, plugged into the shared registry; external API unchanged. Behavior is identical; worker desktop tests pass unmodified apart from import and path renames. Drops the never-used now() option. * fix(gateway): fence only superseded desktop sessions The desktop core extraction replaced the owner fence's "stop strictly older owners" check with an unconditional session stop. A launcher that claims an owner epoch first, then reaches its async fencing pass after a same-epoch observe has already created the session, tore that session down and failed the observer with "stopped before connecting". Restore the original invariant in the registry that owns it: stopSuperseded() retires an entry only when its epoch is strictly lower than the claimant's, so peers sharing a generation keep the session. The regression test drives launch-then-observe at one epoch and fails on the pre-fix code inside fenceReplacedOwners. * refactor(gateway): drop unused WorkerDesktopTunnels type export
What Problem This Solves
The Gateway's remote-desktop observer is hardwired to cloud-worker environments: the observer lifecycle, token minting, WebSocket relay, and view-only enforcement all live inside
src/gateway/worker-environments/and assume an SSH-forwarded unix socket. Upcoming work adds more desktop sources (the Gateway host's own screen, paired nodes), which need the same relay pipeline without the worker coupling.Why This Change Was Made
Pure extraction refactor, zero behavior change: the source-agnostic core moves to
src/gateway/desktop/— anRfbAttachmentunion (unix socket | loopback TCP), a generic desktop session registry (8-observer cap, single controller withcontrol-takeneviction, 60s linger, owner-epoch fencing, typed stale-owner/stopped errors), the observe-token + WS relay bridge, and the RFB view-only filter.desktop-tunnel.tskeeps only worker-specific SSH acquisition and app launch, plugged into the shared registry as start/teardown hooks; its external API is unchanged. The observe WS path moves from/worker-desktop/observeto/desktop/observe— private contract, clients consumewsPathverbatim from theworker.desktop.observeRPC result. Also drops anow()option that was dead code before the refactor.User Impact
No user-visible change. Cloud-worker desktop observers (Labs
cloudWorkers.desktop) behave identically: same RPC surface, same token format and TTL, same observer semantics, same view-only enforcement. This unblocks follow-up PRs that add a Gateway-host desktop source and node desktop streaming.Evidence
stopSuperseded()now fences only strictly older owner epochs, preserving a same-epoch observe session when app launch claimed the epoch first.desktop-tunnel.test.tsreproduces the launch/observe ordering and proves the same-epoch desktop session remains alive.node scripts/run-vitest.mjs src/gateway/desktop src/gateway/worker-environments: 177 files, 2,013 tests passed on head57bc9790217, including the new P1 regression.node --import tsx scripts/check-deadcode-exports.mts: production, full-tree, and script scans passed with 0 entries.31570657246: green.git diff --checkclean.