Repository navigation
fix(emergent): QuickJSExecutor follow-ups from the cold read of #160 - #178
Conversation
- An infinite memoryMB runs at the build's 2,048 MiB maximum, as the documentation says, instead of the 16 MiB floor. - A room probe stopped by the interrupt handler (the deadline or the call's signal) ends the call as timed out, not out of memory. - String's toLocaleLowerCase and toLocaleUpperCase convert through the host with the locale, as the in-process context does; QuickJS ignored the locale. - A regression test for the symbol a guest hands a host function, which #168 refuses: it was dumped into the host's global symbol registry.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
This review includes 4 billable files and costs up to $1.00.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 40 minutes for your next included review. View limit detailsLimit details: You’ve used all 4 included reviews currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (4)
Comment |
Reviewer's GuideFixes QuickJS executor edge cases by honoring infinite memory budgets, preserving timeout semantics when interrupted memory probes fail, and delegating locale-sensitive string case conversion to the host; integration tests cover memory growth, cross-boundary symbol rejection, and locale parity. Sequence diagram for interrupted QuickJS memory probessequenceDiagram
participant Executor
participant GuestRun
participant QuickJS
participant InterruptHandler
Executor->>GuestRun: allocateGuest(bytes)
GuestRun->>QuickJS: Run memory probe
QuickJS->>InterruptHandler: Check deadline or call signal
InterruptHandler-->>GuestRun: Mark interrupted
QuickJS-->>GuestRun: Probe fails
GuestRun->>GuestRun: noRoom()
GuestRun-->>Executor: status: timeout
Sequence diagram for locale-sensitive QuickJS string case conversionsequenceDiagram
participant GuestCode
participant GuestPrelude
participant HostBindings
participant HostContext
GuestCode->>GuestPrelude: toLocaleUpperCase(locales)
GuestPrelude->>HostBindings: string_case(method, text, locales)
HostBindings->>HostContext: String.toLocaleUpperCase(locales)
HostContext-->>HostBindings: Locale-sensitive result
HostBindings-->>GuestPrelude: Result
GuestPrelude-->>GuestCode: Converted string
Flow diagram for QuickJS memory budget selectionflowchart TD
A[memoryMB] --> B{memoryMB is Infinity?}
B -->|Yes| C[MAXIMUM_PAGES]
B -->|No| D{Positive finite value?}
D -->|Yes| E[Ceil memoryMB to pages]
D -->|No| F[INITIAL_PAGES]
C --> G[Clamp between INITIAL_PAGES and MAXIMUM_PAGES]
E --> G
F --> G
G --> H[Guest memory limit]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR Summary by QodoFix QuickJS memory limits, interrupt reporting, and locale casing
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1. Probe timeouts lack regression coverage
|
| if (this.interrupted) { | ||
| return { status: 'timeout', memoryUsedBytes }; |
There was a problem hiding this comment.
1. Probe timeouts lack regression coverage 📘 Rule violation ☼ Reliability
The new noRoom() branch that returns timeout when this.interrupted is set has no real-path integration test. The memory tests exercise allocation exhaustion, while the deadline tests spin or await without entering a failed room probe, so the suite would not catch this path returning memory_exceeded instead.
Agent Prompt
## Issue description
The new timeout classification for an interrupted room probe is not covered through the real executor path.
## Fix Focus Areas
- src/cognition/emergent/executor/QuickJSExecutor.ts[479-486]
- tests/emergent/quickjs-executor.integration.spec.ts[140-230]
## Recommended Fix
Add a deterministic test hook or equivalent harness that interrupts a room probe during an executor run. Assert that the result is `timeout`, and retain a separate assertion that ordinary allocation exhaustion returns `memory_exceeded`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // QuickJS converts case without the locale; the in-process context's ICU uses it. | ||
| for (const method of ['toLocaleLowerCase', 'toLocaleUpperCase']) { | ||
| define(String.prototype, method, function (locales) { | ||
| return host.string_case(method, String(this), localesArg(locales)); |
There was a problem hiding this comment.
2. Invalid locales silently change case 🐞 Bug ≡ Correctness
localesArg turns a symbol locale into an empty array before string_case receives it, rather than letting the locale method reject it. When forged code calls a locale-case method with a symbol, the QuickJS path uses default casing while the in-process method throws a TypeError.
Agent Prompt
## Issue description
A symbol passed as the locale is converted into an empty array, so locale-case methods return a result instead of throwing.
## Fix Focus Areas
- src/cognition/emergent/executor/guest-prelude.ts[292-297]
- src/cognition/emergent/executor/guest-prelude.ts[372-376]
## Recommended Fix
Add case-method-specific locale validation before converting values to bridge data. Reject symbol locales with `TypeError`, preserve valid locale strings and lists, and add a parity test against the in-process context.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| define(String.prototype, method, function (locales) { | ||
| return host.string_case(method, String(this), localesArg(locales)); |
There was a problem hiding this comment.
3. Null receivers become text 🐞 Bug ≡ Correctness
The new wrapper applies String(this) without checking whether its receiver is null or undefined. Calling either locale-case method with .call(null) or .call(undefined) therefore sends the text "null" or "undefined" to the host instead of throwing as the in-process method does.
Agent Prompt
## Issue description
The case-method wrappers stringify null and undefined receivers even though native String locale-case methods reject them.
## Fix Focus Areas
- src/cognition/emergent/executor/guest-prelude.ts[373-376]
## Recommended Fix
Check the receiver before coercion and throw `TypeError` for null or undefined. Add parity tests for explicit `.call` invocations against the in-process context.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| // QuickJS converts case without the locale; the in-process context's ICU uses it. | ||
| for (const method of ['toLocaleLowerCase', 'toLocaleUpperCase']) { | ||
| define(String.prototype, method, function (locales) { | ||
| return host.string_case(method, String(this), localesArg(locales)); |
There was a problem hiding this comment.
4. Forged code can alter locale case results 🐞 Bug ≡ Correctness
The wrappers look up the mutable global String when converting their receiver, rather than using a captured coercion function. If forged code replaces String, subsequent locale-case calls send the replacement's result to the host; native locale-case methods do not consult that global.
Agent Prompt
## Issue description
Replacing the guest's global `String` changes the text processed by the new locale-case wrappers.
## Fix Focus Areas
- src/cognition/emergent/executor/guest-prelude.ts[372-376]
## Recommended Fix
Capture a suitable intrinsic coercion function while installing the prelude and use it after validating the receiver, rather than looking up global `String` on each call. Test a locale-case call after forged code replaces `String`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Follow-ups to #160 from its cold read (one reader, one skeptic per finding; four confirmed, two refuted). #168 fixed a fifth (a guest symbol copied into the host's global symbol registry through
dump); this adds its regression test.What changes
memoryMB: Infinityruns at the build's 2,048 MiB maximum, asdocs/architecture/EMERGENT_CAPABILITIES.mdsays.maximumPagesForsent every non-finite value to the 16 MiB floor, so a host that set an unlimited budget got the smallest guest.timeout. The probe runs guest code, so the handler can stop it at the deadline or on the call's signal; every failed probe was read as "no room" and the call endedmemory_exceeded, which the forge reports as a memory failure. The handler marks the interrupt before QuickJS throws, andnoRoom()reads that mark.String.prototype.toLocaleLowerCaseandtoLocaleUpperCaseconvert through the host with the locale. QuickJS ignores the locale ('i'.toLocaleUpperCase('tr')gaveI, the in-process contextİ).Tests
tests/emergent/quickjs-executor.integration.spec.ts: an infinite budget grows the guest past 40 MiB; a symbol handed to anIntlmethod is refused withTypeError; the Intl parity tool gains Turkish and German case conversions, compared with the in-process context. The interrupt race has no test: it needs QuickJS's interrupt counter to reach zero inside the probe, which a test cannot place.🤖 Generated with Claude Code
Summary by Sourcery
Align QuickJS guest execution with documented memory limits, interruption semantics, and host locale behavior.
Bug Fixes: