Repository navigation
fix(sandbox): bound runtime text output, registry cycles and the backend log - #232
Merged
Merged
Conversation
…end log Sketch code controls the simulation's stdout and stderr. Every plain text line was logged twice and sent as its own WebSocket message, and every spoofed I/O-registry cycle sent, logged and persisted a registry, so one sketch could saturate the event loop and fill the host log. - RuntimeTextLimiter per run: burst 200, 50 lines/s, excess dropped and counted; the client is told once, drops are logged aggregated. - Docker and local runs share one stream delegate and thus the budget. - No log entry per runtime diagnostic line or ignored pin record. - At most 4 I/O-registry cycles per run (the generated main() emits one). - Compose rotates the backend's json-file log (5 x 10 MB by default). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Root cause (verified)
Sketch code fully controls the simulation's stdout and stderr. Before this change:
fputs("x\n", stderr),printf) passed through the parser, was logged twice as WARN ([STDERR] diagnostic received,[Client WS][ERR] diagnostic received) and sent as its own WebSocket message. Only the 100 MB output budget bounded it.[[IO_REGISTRY_START]]…[[IO_REGISTRY_END]]cycle with changed content sent, INFO-logged and wrote (io-registry-*.json) a registry. Each[[IO_PIN]]outside a collection logged a WARN.json-filedefault without rotation, so the host log grew without bound.Proof on the old code: the new real-Docker test (
tests/integration/runtime-output-storm.test.ts) forwarded 1,240,000 lines in 2 s, oneonErrorand two log calls each. The new unit tests were red with 10,000 WARNs for 10,000 diagnostics, 1,000 registry sends for 1,000 spoofed cycles and 1,000 WARNs for stray pin records.Fix
RuntimeTextLimiter, one per run inExecutionState:Runtime output rate limit exceeded …);delegateParsedLineToStreamHandler), so both get the budget. This removes the duplicated stream-state builder inSandboxRunner.onErroris nowdebug) nor ignored pin records are logged per line.RegistryManagerprocesses at mostMAX_REGISTRY_COLLECTIONS_PER_RUN = 4registry cycles per run (the generatedmain()emits exactly one). Further cycles are ignored and logged once.reset()starts a fresh budget. RuntimepinModesends were already bounded by the existing fingerprint dedup.logging: json-filewithmax-size ${UNOSIM_LOG_MAX_SIZE:-10m}andmax-file ${UNOSIM_LOG_MAX_FILE:-5}.SECURITY.md,INSTALL_SERVER.md.Serial output (
SERIAL_EVENT) is unchanged; it was already baud-limited by the batcher.Tests
tests/integration/runtime-output-storm.test.ts(integration-docker): a real sandbox floods stderr for 2 s. The test expects fewer than 1,000 forwarded lines, exactly one notice, no per-lineSTDERRlog and fewer than 200 log calls in total.tests/server/services/runtime-output-bounds.test.ts:tests/server/routes/simulation-runtime-diagnostics.test.ts: 10,000 diagnostics through the real WS route produce no per-line log.tests/server/compose-log-rotation.test.ts: Compose rotates the backend log.docker compose configwas also validated.Existing tests are unchanged.
npm run check,npm run test:unit,npm run check:docs, Knip,git diff --check, the full./run-tests.sh(incl. toolchain, Docker, E2E, build, audit, Sonar) and the pre-push gate are green.🤖 Generated with Claude Code