fix: harden the run relay + workspace sandbox against resource exhaustion#284
Merged
Conversation
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.
Closes #283.
A hardening pass over the code shipped this session (relay #230, sandbox #229), cross-checked by an independent adversarial review. Four real resource issues fixed; the first two are remote memory-exhaustion vectors since the relay is unauthenticated and binds 0.0.0.0.
GET /r/<id>/eventsandPOST .../publishused to lazily create a per-runEventStreamthat was never freed, so an anonymous caller looping over random ids exhausted memory. Now bounded bymaxRuns(default 200) with least-recently-used eviction (evicted runs close their stream and drop viewers).EventStreamiterators gained areturn()that drops the waiter and settles a pendingnext();serveSSEcalls it onreqclose. Previously a dropped viewer's waiter lingered on the stream until the next event (never, for an idle run). This also fixes the same latent leak on the localhost dashboard.snapshotWorkspacenowstats a file and skips it if oversized, instead of reading the whole thing into memory first (avoids an OOM on a large workspace asset during--sandbox dockersync).relayPublisheraddsAbortSignal.timeout, so a relay that accepts but never responds can't hangflush()and block CLI exit.Tests: EventStream
return()cancellation (ai-autopilot); relay LRU eviction + publisher no-hang-on-stall (framework). ai-autopilot 340 + framework 152 green, including the real Docker serve-gate e2e.Deferred (noted in #283, not this PR): SSE write backpressure; a per-run history cap (conflicts with full-history replay, needs a design call).
Two patch changesets (@gemstack/framework + @gemstack/ai-autopilot).