Repository navigation
fix(sandbox): restore port-sniffer phrase gate + cross-chunk carry - #5676
Merged
Merged
Conversation
The Go daemon's port sniffer (default since #5568, TS daemon deleted in #5575) was an incomplete port of the TypeScript one: it dropped two safeguards, so a Vite dev server that binds a non-config port (e.g. 5173) is no longer detected. `getDevPort()` then falls back to the configured `application.port` (3000) — the daemon proxies/probes 127.0.0.1:3000, gets connection-refused forever, serves "Server is starting…" and never leaves the `starting` lifecycle phase. The preview is stuck on the boot skeleton even though `vite dev` is ready. Restore both safeguards from the TS sniffer: - **Phrase gate.** The bind URL must be preceded by `Local:` / `Listening on` on the same line. Without it, a bare `http://localhost:3000` line (a framework echoing the injected PORT, a proxied fetch, a sibling process) hijacks the lock before Vite's real `Local: http://localhost:5173/`. - **Cross-chunk carry.** PTY reads aren't line-buffered, so the bind line can split across chunks. Carry a bounded, ANSI-stripped tail per source and match the concatenation. Also require a `/` or whitespace after the port so a split mid-number ("...:51" | "73/") waits instead of locking the truncated "51". Tests cover both failure modes (bare-3000 hijack, split bind line). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Review of the previous commit found the `[/\s]` trailing requirement regressed the no-trailing-slash frameworks (next, bun) it claimed to support: the ANSI stripper matches the bracket body but not the ESC, so a colored `http://localhost:3000\x1b[0m\n` strips to `...:3000\x1b\n` — the ESC sits between the port and the newline, `[/\s]` rejects it, and the port is never sniffed (silently falling back to the wrong configured port — the exact failure the sniffer exists to prevent). - Require a non-digit terminator (`[^\d]`) instead of `[/\s]`. Still fixes the mid-number split (a buffer ending on digits has no following char → waits), but locks on any non-digit — `/`, `)`, `,`, whitespace, newline, or a leftover ESC — matching the eager TS behavior for the frameworks a strict `[/\s]` would have dropped. - Make ansiPattern consume the ESC when present (`\x1b?`) so a stripped color code leaves nothing between the port and its terminator. Tests: colored no-trailing-slash, non-slash terminator, Reset clears carry, sibling URL before the banner (line-bound `[^\n]*?`), and per-source carry isolation. Co-Authored-By: Claude Opus 4.8 <[email protected]>
decocms Bot
pushed a commit
that referenced
this pull request
Aug 4, 2026
PR: #5676 fix(sandbox): restore port-sniffer phrase gate + cross-chunk carry Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.37.0 -> 1.37.1 - deploy/helm/sandbox-env (chart 0.10.9) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.37.1 Deploy-Scope: both
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TanStack/Vite migration previews (e.g.
granadobr-tanstack) are stuck on the boot skeleton / "Server is starting…" even though thedevterminal showsVITE readyonhttp://localhost:5173/.Reading the daemon log directly (
fetch("/_sandbox/events")on the preview host, bypassing the Studio/api/.../eventsproxy) shows the smoking gun:The daemon dials 3000 while Vite serves 5173.
Root cause — a regression in the TS→Go daemon rewrite
The Go port sniffer became the default in #5568 and the TS daemon was deleted in #5575. The Go
portsniffer.gowas an incomplete port of the TSport-sniffer.ts— it dropped two safeguards:Local:/Listening onon the URL line)http://localhost:NmatchesEither gap makes the sniffer miss Vite's
5173.getDevPort()then falls back to the configuredapplication.port(DEFAULT_DEV_PORT = 3000) → the proxy (proxy.go) and probe (probe.go) dial a dead port →StartingHTML+ lifecycle stuck atstarting. Apps that bind the injectedPORT(e.g.casaevideo-tanstack, which serves on 3000) were unaffected; apps relying on the sniffer to learn a dynamic port broke.Fix
Restore both safeguards in
portsniffer.go:Local:/Listening onon the same line, so an early barelocalhost:3000(a framework echoingPORT, a proxied fetch, a sibling process) can't hijack the lock./or whitespace, so a chunk splitting mid-number (...:51|73/) waits for its continuation instead of locking the truncated51.Tests
proc_test.gogains coverage for both failure modes:TestPortSnifferIgnoresBareURLBeforeBanner— an early barelocalhost:3000does not lock; the laterLocal: …:5173/does.TestPortSnifferSpansChunkBoundary— a split bind line locks once completed.Regex + carry logic validated against all cases (existing lock-in, phrase gate, mid-port split, colon split, casaevideo
Local:3000).Testing notes
Go isn't installed locally, so I couldn't run
go testhere — relying on thesandbox-daemonCI (go vet/go test -race/go build). Logic was validated with an equivalent-regex simulation covering every scenario.🤖 Generated with Claude Code
Summary by cubic
Fixes dev previews getting stuck by restoring safeguards in the Go port sniffer. It now reliably detects the real dev server port (e.g., Vite 5173 and Next/Bun without a trailing slash) instead of falling back to 3000.
portsniffer.goand expanded tests inproc_test.go(colored no-slash, non-slash terminator, reset carry, sibling-before-banner, per-source isolation).Written for commit eb8b7f5. Summary will update on new commits.