Repository navigation
feat(emergent): forged code runs through an executor interface; a CI run measures QuickJS - #148
Conversation
…e in-process executor The library's own forge test fixtures, copied verbatim, and a written set (computational models, language features, built-in globals, each capability), each with the result the in-process executor returns. Capability fixtures run under a ceiling through the broker against a local server and a directory of files.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (21)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideIntroduces a reusable forged-tool corpus and deterministic HTTP/filesystem environment, then adds an integration suite that executes every fixture in-process, routing capability-enabled tools through the broker and checking declared outcomes. The corpus is also documented as the shared input for a separate executor evidence run measuring QuickJS. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
SandboxedToolForge validates, pre-parses and builds the granted functions, then hands each run to a ForgedCodeExecutor (name, isolates, run). The default InProcessExecutor is the CodeSandbox path moved behind the interface with every message unchanged; it declares isolates: false. A host may pass its own executor (SandboxedToolForgeConfig.executor); forge.executor names the one in use.
…xt hands forged code Exports InProcessExecutor, ForgedCodeExecutor, ExecutorRunRequest and ExecutorRunResult. The guide gains an Executors section; the memory row and the configuration reference name the executor; the Safety Invariants line says that codeGeneration applies to the context's own intrinsics and that the host's constructors handed to the context carry the host's Function. The documentation word check reads the two executor files.
… an executor for forged code A job on pull requests that touch the forge, the sandbox or the corpus. It runs a prototype QuickJS executor (quickjs-emscripten 0.32.0, installed only by the job) through the same forge as the in-process executor, and reports: awaiting host functions, the forged-tool corpus, start-up and per-call time, the memory limit, a guest that spins after a yield, and escape probes. Verdicts are evidence; only a harness error fails the job.
…d an instance per call The first run found that QuickJS's own memory limit does not bound a guest under Emscripten: it counts only each allocation's overhead, so a guest under a 16 MB limit grew the host by about 2 GB before an allocation failed. The build imports its memory and grows it only to that memory's maximum, so the run now also measures a shared module on a capped memory and an instance per call, compiled once, on a memory capped at the call's limit. Q4 now bounds the host's RSS growth (garbage collection forced), every question runs on the per-call instance too, a new section tries QuickJS stack limits of 1 MiB, 256 KiB and 64 KiB, and each section reports the teardowns that failed.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
PR Summary by QodoAdd a forged-code executor interface and QuickJS evidence job
AI Description
Diagram
High-Level Assessment
Files changed (20)
|
Code Review by Qodo
1. Benchmarks land in the source repository
|
| const measure = async (set: ForgeSet, fixture: CorpusFixture, n: number) => { | ||
| const times: number[] = []; | ||
| for (let i = 0; i < n + 10; i++) { | ||
| const outcome = await set.run(fixture.code, fixture.input, fixture.allowlist); |
There was a problem hiding this comment.
1. Benchmarks land in the source repository 📘 Rule violation ⚙ Maintainability
questionTime in evidence/forge-executors/run.ts warms up the executors, repeatedly times forged calls, and calculates latency statistics. The new workflow runs it on relevant pull requests and uploads the results, keeping a benchmark implementation in this repository.
Agent Prompt
## Issue description
The evidence runner implements repeatable executor latency benchmarks in the AgentOS source repository.
## Fix Focus Areas
- evidence/forge-executors/run.ts[308-364]
- .github/workflows/forge-executor-evidence.yml[43-48]
## Recommended Fix
Move the timing benchmark and its CI execution to agentos-bench. Keep any non-benchmark compatibility or safety checks needed here separate from the timing measurements.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| input, | ||
| init === null ? undefined : init, | ||
| )) as Response; | ||
| const body = new Uint8Array(await response.arrayBuffer()); |
There was a problem hiding this comment.
2. Large fetches bypass the guest memory cap 🐞 Bug ☼ Reliability
guestSurface reads a granted fetch response completely into host memory before QuickJSExecutor copies it into the memory-limited guest. Without a ceiling, the forge's fetch wrapper imposes no response-size limit, so a large response can exhaust host memory before the guest's limit takes effect.
Agent Prompt
## Issue description
The prototype buffers an entire fetched response on the host before the guest memory cap can apply.
## Fix Focus Areas
- evidence/forge-executors/guest-surface.ts[73-91]
- evidence/forge-executors/quickjs-executor.ts[332-343]
## Recommended Fix
Enforce a per-call response byte limit while streaming the body, cancel oversized responses, and include this case in the memory evidence.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| const id = next; | ||
| next += 1; | ||
| digests.set(id, digest); | ||
| return id; |
There was a problem hiding this comment.
3. Guest hashes grow uncapped host state 🐞 Bug ☼ Reliability
guestSurface stores every new hash or keyed-hash object in a host-side Map until forged code calls digest(). A tool granted crypto can repeatedly create objects without digesting them, growing host memory independently of the QuickJS memory limit for the duration of its call.
Agent Prompt
## Issue description
Guest-created digest objects accumulate in a host Map outside the guest memory budget.
## Fix Focus Areas
- evidence/forge-executors/guest-surface.ts[100-135]
- evidence/forge-executors/quickjs-executor.ts[185-190]
## Recommended Fix
Bound outstanding digest objects per call, reject creation beyond that bound, and add a memory probe that creates hashes without digesting them.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
## [0.12.10](v0.12.9...v0.12.10) (2026-10-08) ### feat * **emergent:** forged code runs through an executor interface, and a CI run measures QuickJS (#148) ([3c5832a](3c5832a)) ### docs * audit follow-ups to the GMI step contract and gateway docs (#147) ([000547a](000547a)) * **gmi:** correct the step contract and document completion options, history and the gateway (#145) ([ff883a4](ff883a4)) ### ci * check that package exports point at built files (#146) ([fee43be](fee43be))
What this changes
SandboxedToolForgevalidates the source, pre-parses it and builds the granted functions, then hands each run to aForgedCodeExecutor(name,isolates,run). The default,InProcessExecutor, is the CodeSandbox path moved behind the interface; every message a host sees is unchanged, and it declaresisolates: false. A host may pass its own executor (new SandboxedToolForge({ executor }));forge.executornames the one in use. Exported:InProcessExecutor,ForgedCodeExecutor,ExecutorRunRequest,ExecutorRunResult.tests/fixtures/forged-tools/: the forged code of the library's own forge tests, verbatim (29), and a written set (32) of computational models, language features, built-in globals and each capability.tests/emergent/forged-corpus.integration.spec.tsruns all of them through the forge on the in-process executor, capability fixtures under a ceiling through the broker..github/workflows/forge-executor-evidence.yml,evidence/forge-executors/) that runs a prototype QuickJS-in-WebAssembly executor through the same forge and reports what follows. Nothing about QuickJS ships;quickjs-emscripten0.32.0 is installed only by the job.codeGenerationapplies to the context's own intrinsics and that the host constructors handed to the in-process context carry the host'sFunction.Evidence (run 37730116146, commit f6398c7)
QuickJS held three ways: one shared module, one shared module on a memory capped at 256 MB, and an instance per call (the module compiled once, each call on a fresh
WebAssembly.Memorywhose maximum is the call'smemoryMB).fetch,fs.readFile, three in parallel, a refused host caught, 20 in sequence)Intlis missing, and string code generation inside the guest is allowed (it reaches only the guest's own realm)A 256 MB cap on a shared module stopped the guest at 248 MB, and the host kept the 248 MB. At QuickJS's 1 MiB stack limit, deep recursion exhausts V8's own stack first. At 256 KiB it ends as the guest's own "stack overflow", and a recursion 1,000 deep still succeeds.
Tests
src/cognition/emergent/__tests__/forge-executor.test.ts: what the executor receives (code, input, granted functions, limits, the call's signal under a ceiling) and how each way a run ends comes back; validation, the pre-parse and a missing call handle never reach it.tests/emergent/forged-corpus.integration.spec.ts: 61 forged tools through the forge on the in-process executor.🤖 Generated with Claude Code