fix(sandbox): accumulate canonical stdout from polled deltas, not final re-read (#1850)#1915
fix(sandbox): accumulate canonical stdout from polled deltas, not final re-read (#1850)#1915larryro wants to merge 1 commit into
Conversation
…al re-read (#1850) Kubelet rotates container logs at containerLogMaxSize (default 10Mi) and readNamespacedPodLog serves only the current file. A final re-read after rotation returned a mid-stream window instead of the deterministic first-N bytes that docker's drainAndCap produces. Fix: maintain canonicalChunks/canonicalByteCount accumulators inside pollRunnerStdout. Each delta is appended up to stdoutMaxBytes. On rotation (logs.length < lastLogLen), reset lastLogLen=0 so post-rotation bytes are picked up from byte 0 of the new file; logShrunk=true ensures truncated.stdout is set regardless. The final readPodLog call is replaced by Buffer.concat(canonicalChunks).toString('utf8'). Two regression tests added: (1) pre-rotation head bytes are preserved when rotation is detected in the final poll, (2) post-rotation deltas are appended correctly when the cap has not yet been reached.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Desk Review: fix(sandbox) — accumulate canonical stdout from polled deltas (#1850)Verdict: READY TO MERGE CI Status — ALL REQUIRED CHECKS PASS
Test RunThe two new tests in Correctness ReviewRoot cause correctly targeted. The old code's final Happy path (no rotation): Deltas are computed correctly as Rotation path: When Cap path: Once Truncation flag:
Minor Observations (non-blocking)
SummaryThe fix is correct on all paths (happy, rotation, cap, multiple rotation). The new tests pin both primary scenarios. All 327 sandbox tests pass locally and all required CI checks are green. No blocking findings. |
Summary
Fixes #1850:
sandbox/k8sstdout beyond kubelet log rotation returns a mid-stream window.Root cause
In
KubernetesBackend.execute(), after the polling loop ends, the code performed a finalreadPodLog()call to get the canonical stdout. When kubelet had rotated the container log (due to output exceedingcontainerLogMaxSize, default 10Mi), this final read returned only the content of the current rotated file — a window from the middle of the stream rather than the deterministic first-N bytes that the docker backend'sdrainAndCapproduces.The previous fix PR detected log shrinkage and set
truncated.stdout = true, but the content itself was still wrong.Fix
Accumulate canonical stdout incrementally from polled deltas in
pollRunnerStdout, capped atstdoutMaxBytes, instead of re-reading the full log at the end:canonicalChunks: Buffer[]andcanonicalByteCountaccumulators inside the closure.logs.slice(lastLogLen)) is appended to the accumulator up to the cap.logs.length < lastLogLen): setlogShrunk = trueand resetlastLogLen = 0so subsequent polls pick up post-rotation content from byte 0 of the new file.readPodLog()call withBuffer.concat(canonicalChunks).toString('utf8').This gives deterministic first-N-bytes semantics regardless of when kubelet rotates the container log.
Tests
Two regression tests added to
k8s-backend.test.ts:truncated.stdoutis set.Test plan
bun testinservices/sandbox— 327 pass, 0 failbunx tsc --noEmit— no type errorsbunx oxlint --type-aware— 0 warnings, 0 errorsSummary by CodeRabbit
Bug Fixes
Tests