Repository navigation
Fix #108: Per-execution CodeMode WalkCache and comparator sort write-back preflight - #134
Merged
Merged
Conversation
…rt write-back Implements slices M2, M3, and N4 for #108: - Move CodeMode cycle-walk cache (walked, insideWalked, epoch) into a per-execution WalkCache on Interpreter so concurrent executions cannot invalidate each other's cache or push another program over its step budget. - Preflight comparator Array.prototype.sort write-back against live own object elements via rejectCircularInsertion with a shared seen set and meter before mutating target. - Add self-host E2E scenario mcpExecuteWalkCache covering concurrent walk-cache isolation, comparator sort cycle/cache/control cases, and a seeded differential graph-mutation fuzz against an independent BFS oracle, and wire it into fork-ci.yml. Release-note: Fix: Isolate CodeMode walk caches per execution and validate comparator sort write-back against cycles.
Tighten E2E overlap verification and coverage per round-1 reviews: - Replace client-side wall-clock overlap check with a server-observed loopback HTTP barrier app so the concurrent execution test fails if runs are serialized. - Place a valid object ahead of the cyclic object in the direct sort cycle test to verify zero partial write-back on later item rejection. - Use high-bit LCG extraction and mix partial-removal comparator sorts into the seeded graph fuzz, and decode the fuzz result with Schema. - Clarify the shared skip-walk rule and reflow prose in patches/codemode-step-budget.md. Release-note: Fix: Programs running at the same time no longer exhaust each other's step budget, and sorting with a comparator can no longer create a circular value.
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 #108 (remaining slices: M2, M3, and N4; N3 deferred as planned).
Summary
WalkCacheisolation (patches/@opencode-ai%[email protected]):walked,insideWalked,walkEpoch, andisWalkedindist/interpreter/references.{js,d.ts}with an exportedWalkCacheclass (WeakMap,WeakSet,epoch,isWalked).this.walkCacheonInterpreter(dist/interpreter/runtime.{js,d.ts}), forwarded it acrossinvokeFunction, exposed it onCallbackRunnervia closurewalkCache: () => this.walkCache, and threaded it throughdist/interpreter/methods.{js,d.ts}(push,unshift,splice,fill,sort,invokeGlobalMethod) anddist/stdlib/object.{js,d.ts}(Object.assign).Array.prototype.sortwrite-back preflight (dist/interpreter/methods.js):args[0] !== undefined, captures the live own object elements oftargetviaObject.keys(target)and preflights every object insorted.slice(0, itemCount)not currently present intargetviarejectCircularInsertion(target, item, "Array.sort result", node, seen, meter, cache)with a sharedseenset andmeterbefore mutatingtargetor deleting trailing holes.undefined, and zero step-budget overhead on no-comparator or legitimate large-object comparator sorts.mcpExecuteWalkCacheine2e/tests/mcp-execute-step-budget.spec.tsande2e/test-plan.ts, and wired it into.github/workflows/fork-ci.yml(security-e2e).patches/codemode-step-budget.mdto documentWalkCache, comparatorsortwrite-back validation, and remove the stale shared-records bullet.RED / GREEN Verification
RED (before patch change,
nice -n 19 bun run e2e:self-host --test-name '^Hosted MCP execute isolates walk budgets' --workers 1, Node 24)ok: true,value: 20000,407 ms).noisyBursts: 5,overlapObserved: true): FAILED (ok: false,2018 ms) withTimeoutExceeded:Execution exceeded its compute budget of 5000000 interpreter steps and was stopped... (line 17, col 5).{ err: "", len: 2 }, allowed live cycle and mutatedt)."",x.k = { t }skipped cached leaft)."",x.o = outerskipped cached ancestorouter).mismatch: "seed 101 step 31 sort write-back expected=true threw=false").GREEN (after patch change +
e2e:prepare, Node 24,--workers 1)^Hosted MCP execute isolates walk budgets: PASSED403 ms,ok: true,value: 20000.663 ms,ok: true,value: 20000(noisyBursts: 5,overlapObserved: true).{ err: "Error: Array.sort result contains a circular value.", len: 0 }."Error: Object assignment result contains a circular value."."Error: Object assignment result contains a circular value."."4,1,2,true,true,false", 5,000-object comparator sort5000(502 ms).mismatch: "",accepted: 1292,cyclesRejected: 612,sortOps: 144,jsonChecks: 42.^Hosted MCP execute stops a program(regression check): PASSED (36.5s, all step-budget assertions green).bun run check: 17 of 17 checks passed (patches:check24/24,format:check,lint0 warnings / 0 errors,e2e boundary,typecheck9/9 projects).