Skip to content

Fix #108: Per-execution CodeMode WalkCache and comparator sort write-back preflight - #134

Merged
shuv1337 merged 2 commits into
v2from
t3/codemode-walk-cache-sort-preflight
Nov 27, 2026
Merged

shuv1337 merged 2 commits into
v2from
t3/codemode-walk-cache-sort-preflight

Conversation

@shuv1337

Copy link
Copy Markdown
Owner

Closes #108 (remaining slices: M2, M3, and N4; N3 deferred as planned).

Summary

  • M2 — Per-execution WalkCache isolation (patches/@opencode-ai%[email protected]):
    • Replaced module-level walked, insideWalked, walkEpoch, and isWalked in dist/interpreter/references.{js,d.ts} with an exported WalkCache class (WeakMap, WeakSet, epoch, isWalked).
    • Owned this.walkCache on Interpreter (dist/interpreter/runtime.{js,d.ts}), forwarded it across invokeFunction, exposed it on CallbackRunner via closure walkCache: () => this.walkCache, and threaded it through dist/interpreter/methods.{js,d.ts} (push, unshift, splice, fill, sort, invokeGlobalMethod) and dist/stdlib/object.{js,d.ts} (Object.assign).
  • M3 — Comparator Array.prototype.sort write-back preflight (dist/interpreter/methods.js):
    • When args[0] !== undefined, captures the live own object elements of target via Object.keys(target) and preflights every object in sorted.slice(0, itemCount) not currently present in target via rejectCircularInsertion(target, item, "Array.sort result", node, seen, meter, cache) with a shared seen set and meter before mutating target or deleting trailing holes.
    • Preserves all-or-nothing write-back, sparse holes vs. explicit undefined, and zero step-budget overhead on no-comparator or legitimate large-object comparator sorts.
  • N4 + E2E + Docs + Fork CI:
    • Added self-host E2E scenario mcpExecuteWalkCache in e2e/tests/mcp-execute-step-budget.spec.ts and e2e/test-plan.ts, and wired it into .github/workflows/fork-ci.yml (security-e2e).
    • Updated patches/codemode-step-budget.md to document WalkCache, comparator sort write-back validation, and remove the stale shared-records bullet.
mcp-execute-step-budget.spec.ts

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)

  • M2 quiet control: passed (ok: true, value: 20000, 407 ms).
  • M2 concurrent victim under noise (noisyBursts: 5, overlapObserved: true): FAILED (ok: false, 2018 ms) with TimeoutExceeded: Execution exceeded its compute budget of 5000000 interpreter steps and was stopped... (line 17, col 5).
  • M3 direct cycle: FAILED ({ err: "", len: 2 }, allowed live cycle and mutated t).
  • M3 leaf-cache cycle: FAILED ("", x.k = { t } skipped cached leaf t).
  • M3 ancestor-cache cycle: FAILED ("", x.o = outer skipped cached ancestor outer).
  • N4 seeded fuzz: FAILED (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: PASSED
    • M2 quiet control: 403 ms, ok: true, value: 20000.
    • M2 concurrent victim under noise: 663 ms, ok: true, value: 20000 (noisyBursts: 5, overlapObserved: true).
    • M3 direct cycle: { err: "Error: Array.sort result contains a circular value.", len: 0 }.
    • M3 leaf-cache cycle: "Error: Object assignment result contains a circular value.".
    • M3 ancestor-cache cycle: "Error: Object assignment result contains a circular value.".
    • M3 controls: sparse "4,1,2,true,true,false", 5,000-object comparator sort 5000 (502 ms).
    • N4 seeded fuzz: 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:check 24/24, format:check, lint 0 warnings / 0 errors, e2e boundary, typecheck 9/9 projects).

…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.
@shuv1337
shuv1337 merged commit f22924e into v2 Nov 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-ups from #107 review: touch() byte drift, shared walk epoch, sort write-back

1 participant