Repository navigation
Conversation
…on.decode from the hot path startTransitionScript decoded the full sandbox JSON on Redis's single-threaded event loop for every call with ExpectExecutionID set (the evictor path), and after the lifecycle-hold work it decodes unconditionally for is_held too. Under concurrent expiry (400+ sandboxes/node, many API replicas) that serialises O(JSON) CPU on the main thread and stalls every other command (e2b-dev#3602). Store the two fields the hot path needs -- executionID and the lifecycle hold (token + until) -- in a dedicated meta key beside the record, in the same slot. Every script that writes KEYS[1] (add, start_transition, fenced_set, restore) now writes the meta key in the same atomic script, and remove deletes it with the record, so meta can never drift from the record. startTransitionScript reads the meta key with one GET and a string split instead of cjson.decode. Migration: a record written before this change has no meta key; the hot path then falls back to decoding the record exactly as before, so pre-deploy sandboxes stay correct until they are next written (which sets the meta key) or expire. add/remove keep decoding the record for their gone-set logic, which is not the storm path. Supersedes the stale single-key approach in e2b-dev#3603, which no longer applied because is_held forced a decode regardless.
AdaAibaby
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
November 12, 2026 03:50
This branch has not been deployed
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 (#3602)
startTransitionScriptrunscjson.decodeon the full sandbox JSON on Redis's single-threaded event loop. WithExpectExecutionIDset (the evictor path) it decodes to compare the execution ID, and since the lifecycle-hold work it decodes unconditionally for theis_heldcheck too. Under concurrent expiry (400+ sandboxes/node, multiple API replicas each running the 50 ms evictor loop) this serialises O(JSON) CPU on the main thread and stalls every other command.#3603 proposed externalising only
executionID. That no longer suffices:is_held(decoded)forces a decode regardless, so the win is cancelled. This PR supersedes #3603 by externalising both fields.Change
A dedicated meta key beside each record, in the same slot, holds the two fields the hot path needs —
executionIDand the lifecycle hold (lifecycleHold+lifecycleHoldUntil), US-separated (packMeta).add,start_transition,fenced_set,restore) writes the meta key in the same atomic script;removedeletes it with the record. The record writers are a closed set (verified: no Go-sideSet/Delbypasses the scripts), so meta can never drift.startTransitionScriptreads the meta key with oneGET+ a string split instead ofcjson.decode.add/removekeep decoding the record for their gone-set/return-value logic — not the storm path.Testing
Full
packages/api/internal/sandbox/storage/redissuite passes on Linux with Redis, includingTestDifferentialAgainstModel(model-based differential test — the strongest guard against meta/record incoherence),execution_pin,lifecycle_hold,scripts_remove,update_write_retry.go vetclean.Fixes #3602. Supersedes #3603.