Repository navigation
ENG-1113: -f/--follow for sandbox logs (client-side polling) - #353
Conversation
The sandbox endpoint is a snapshot, so --follow tails by polling on an interval and advancing sinceTime. Correctness details: - per-container de-dup: multiple containers share one sinceTime per request, so each container is de-duped against its own last-printed timestamp and the next poll uses the oldest per-container high-water mark (no lost/repeated lines). - first poll surfaces selector errors (unknown workload/container/etc.); later transient errors (pod not running yet, restarts) are reported once and retried. - graceful stop on SIGINT/SIGTERM. - rejected with -o json|yaml (streamed plain lines only). Job path unchanged (already streams via SSE). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
e908efb to
814d85c
Compare
go-sdk #90 merged (squash) and its branch was deleted, so pin the released main revision instead of the now-non-canonical generate branch commit. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Code ReviewThoughtful, well-scoped change. Follow is implemented client-side by polling the snapshot endpoint every 2s, advancing A few things worth resolving before merge: Correctness / risks1. Dedup can drop lines when timestamps aren't unique (main risk). The boundary filter is At 1 line/sec (as tested) timestamps are distinct so this never fires — but with bursty logs or coarse server-side timestamp precision (second/ms rather than ns) many lines share a timestamp and lines will be lost at every poll boundary. Worth confirming the endpoint's timestamp precision. Robust fix: remember the set/count of messages seen at exactly the max timestamp and only suppress those, rather than everything 2. Catastrophic duplication if 3. First-poll fail-fast also rejects not-yet-running pods. On Minor / style
TestsNo tests added, and the package has no None of these block the happy path that was tested live, but #1 and #2 are the difference between "works in my test" and "correct under load." Also a reminder to retarget/rebase onto 🤖 Generated with Claude Code |
- Boundary dedup: per-container high-water mark + set of messages seen at exactly that timestamp, so distinct lines sharing the boundary timestamp are no longer dropped (was: skip all <= last). - Untimestamped lines: emit only on the first poll, never reprint (guards against infinite re-emit if the watermark can't advance). - --follow first poll fails fast on selector errors but retries transient ones (pod not running yet / restart / gateway) via isTransientFollowErr. - Reject --follow with --job (was silently ignored), matching the other cross-source flag guards. - Latch the multi-container [name] prefix so it can't flap mid-stream. - Trap SIGHUP alongside SIGINT/SIGTERM. - Add table-driven tests for followState.observe (boundary dup, older-than-hwm, empty timestamp, independent containers) and sinceTime (oldest hwm, fallback). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks Scott — all addressed in #1 — dedup dropping distinct same-timestamp lines. Fixed. Each container now keeps its high-water mark plus the set of messages already printed at exactly that timestamp; a line is emitted if it's strictly newer, or shares the boundary timestamp but its exact message hasn't been printed. So a distinct line sharing the boundary ts is no longer dropped. Table-test #2 — catastrophic reprint on empty #3 — first-poll fail-fast vs not-yet-running. Fixed. First poll now fails fast only on non-transient errors;
SIGHUP. Added to Tests. Added Also rebased onto |
|
Below comment is now tracked in https://github.com/signadot/signadot/issues/7271 Follow loop — two gapsThe previous round is well handled: the boundary-set dedup and the "untimestamped lines only on the first poll" rule are the right shapes, and the table tests hit the cases that actually matter. Build and Two things this round didn't reach. Both come from the server side of the contract (
That same 1000-line cap truncates silently. A container emitting more than ~500 lines/s loses everything but the newest 1000 in an interval, the hwm jumps the gap, and nothing tells the user. Since Smaller: the |
|
…ansient guard - isTransientFollowErr now matches the go-sdk *transport.APIError (via errors.As) and its Code/message fields, never err.Error(). The formatted string prefixes the status text and splices in the user's selector + valid names, so a fork/container named connection-pool or timeout-worker made a typo retry forever; 5xx retries, 4xx only for the server's readiness message. - followState.sinceTime clamps the rewind to newestHWM-grace so a container that logs once and goes quiet (startup-only sidecar, completed step pod) doesn't pin the shared sinceTime and re-request its whole capped window every poll indefinitely. - Warn on stderr when a container's fetch hits the server tail cap (serverTailCap=1000) instead of silently dropping older lines under load. - Narrow the followState doc: the boundary-dedup guarantee only covers lines the server re-sends; the container defining sinceTime never receives a same-timestamp line (server filters strict After). - Tests: rewind clamp case + TestIsTransientFollowErr (5xx retry, 4xx readiness retry, connection-pool/timeout-worker selector fail-fast, transport retry). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Thanks — all four addressed in
var apiErr *transport.APIError
if errors.As(err, &apiErr) {
switch {
case apiErr.Code >= 500: return true // gateway/tunnel/k8s hiccup
case apiErr.Code >= 400: return isReadinessMsg(apiErr.ErrorResponse.Error) // clean msg only
default: return false
}
}
return isTransportErr(err.Error()) // only non-API (pre-response) transport failures
Proven live against staging — a fork name containing "timeout" now fails fast instead of looping:
Silent 1000-line truncation. Fixed — when a container's fetch returns Doc claim. Narrowed: the boundary-dedup guarantee is now scoped to "lines the server re-sends," and the comment states the container that defines
|
There was a problem hiding this comment.
Risk: medium. Cursor Bugbot was not present on this PR; evaluated using remaining signals. Approved — sandbox follow-logs changes are bounded with prior review feedback addressed and unit tests present. Reviewers already assigned; no new reviewers added.
Sent by Cursor Approval Agent: Pull Request Approver
foxish
left a comment
There was a problem hiding this comment.
LGTM. Verified at 52a3b82: both rounds of Scott's feedback are addressed in code (boundary-set dedup, first-poll-only untimestamped lines, transient-error fail-fast via errors.As on *transport.APIError, --job/--follow exclusion, latched multi prefix, SIGHUP, rewind clamp, truncation warning, narrowed doc claim). Build, go vet, and go test ./internal/command/logs/ are green locally; go-sdk pin is a merged main revision; confirmed FixAPIErrors wraps *APIError with %w so the typed guard holds in production. Known limitations (server cap mirror, readiness message matching) are commented and tracked in #7271 / ENG-1156 / ENG-1115.
🤖 Reviewed with Claude Code


What
Adds
-f/--followtosignadot logsfor the sandbox path (ENG-1113).Stacked on #351 (ENG-1112) — base is
feat/sandbox-logs; will retarget tomainonce #351 merges.The sandbox-scoped endpoint is a point-in-time snapshot, so follow tails by polling on an interval (2s) and advancing
sinceTime. Native pod-log streaming is a fast-follow (ENG-1115). The job path already streams via SSE and is unchanged.Correctness
sinceTimeper request, so a global high-water mark would drop lines from a lagging container. Instead each container is de-duped against its own last-printed timestamp, and the next poll uses the oldest per-container high-water mark — no lost or repeated lines across multiple containers.-o json|yaml(follow streams plain lines only).Testing (live, local cluster)
Followed a 2-container fork (
app+sidecar, each logging every 1s):-f: 70 lines, 70 unique (0 duplicates), 35[app]+ 35[sidecar], sequential with no gaps.-f -c app→ single container, raw (unprefixed), tails live.-f -o json→Error: --follow cannot be combined with -o json.-f --workload nope→ first poll surfaces400 … workload "nope" not found ….🤖 Generated with Claude Code