Skip to content

fix(emergent): QuickJSExecutor follow-ups from the cold read of #160 - #178

Merged
jddunn merged 1 commit into
masterfrom
fix/quickjs-cold-read
Oct 8, 2026
Merged

jddunn merged 1 commit into
masterfrom
fix/quickjs-cold-read

Conversation

@jddunn

@jddunn jddunn commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

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: Infinity runs at the build's 2,048 MiB maximum, as docs/architecture/EMERGENT_CAPABILITIES.md says. maximumPagesFor sent every non-finite value to the 16 MiB floor, so a host that set an unlimited budget got the smallest guest.
  • A room probe stopped by the interrupt handler ends the call as 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 ended memory_exceeded, which the forge reports as a memory failure. The handler marks the interrupt before QuickJS throws, and noRoom() reads that mark.
  • String.prototype.toLocaleLowerCase and toLocaleUpperCase convert through the host with the locale. QuickJS ignores the locale ('i'.toLocaleUpperCase('tr') gave I, 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 an Intl method is refused with TypeError; 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:

  • Correct infinite memory budgets so they use the configured 2,048 MiB maximum instead of the minimum guest memory.
  • Report interrupted memory probes as timeouts rather than memory-limit failures.
  • Preserve locale-sensitive behavior for String.prototype.toLocaleLowerCase and toLocaleUpperCase in QuickJS guests.
  • Add regression coverage for infinite memory budgets, cross-boundary symbols, and locale-sensitive case conversion.

- 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.
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 8, 2026 22:10
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 8 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 4 billable files and costs up to $1.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 7254fc14-eb39-441c-a481-a25f27e1aa3d
📥 Commits

Reviewing files that changed from the base of the PR and between 338e321 and b64a19c.

📒 Files selected for processing (4)
  • src/cognition/emergent/executor/QuickJSExecutor.ts
  • src/cognition/emergent/executor/guest-prelude.ts
  • src/cognition/emergent/executor/guest-surface.ts
  • tests/emergent/quickjs-executor.integration.spec.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes 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 probes

sequenceDiagram
    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
Loading

Sequence diagram for locale-sensitive QuickJS string case conversion

sequenceDiagram
    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
Loading

Flow diagram for QuickJS memory budget selection

flowchart 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]
Loading

File-Level Changes

Change Details Files
Treat an infinite memory budget as the configured maximum instead of falling back to the minimum allocation.
  • Map positive infinity directly to the maximum QuickJS page count.
  • Add an integration test proving a guest can allocate beyond 40 MiB with an infinite budget.
src/cognition/emergent/executor/QuickJSExecutor.ts
tests/emergent/quickjs-executor.integration.spec.ts
Preserve timeout and cancellation outcomes when memory probes are interrupted during guest execution.
  • Centralize failed-probe handling to distinguish interruption from genuine memory exhaustion.
  • Propagate the resulting timeout status through copy, string, and result-handling paths.
src/cognition/emergent/executor/QuickJSExecutor.ts
Route locale-sensitive string case conversion through the host runtime for parity with the in-process context.
  • Override both locale case methods in the guest prelude.
  • Validate supported methods and invoke host locale-aware conversions.
  • Extend Intl parity coverage with Turkish and German case examples.
src/cognition/emergent/executor/guest-prelude.ts
src/cognition/emergent/executor/guest-surface.ts
tests/emergent/quickjs-executor.integration.spec.ts
Add regression coverage for rejecting guest symbols passed to host Intl functions.
  • Verify a guest-created registry symbol is rejected at the host boundary with the expected TypeError.
tests/emergent/quickjs-executor.integration.spec.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fix QuickJS memory limits, interrupt reporting, and locale casing

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Honor infinite memory budgets up to QuickJS’s 2,048 MiB ceiling.
• Report allocation probes stopped by an interrupt as timeouts, not memory failures.
• Use host locale casing and add memory, symbol-boundary, and Intl parity regressions.
Diagram

graph TD
  E["QuickJS executor"] --> P["Allocation probe"] --> D{"Interrupted?"} -->|Yes| T["Timeout status"]
  D -->|No| M["Memory status"]
  E --> L["Guest prelude"] --> B["Host bindings"] --> I["Host ICU"]
Loading
High-Level Assessment

The changes fit the existing per-call memory handling and data-only guest-to-host binding architecture. Keeping QuickJS’s native locale methods would preserve the parity bug; a separate locale implementation would duplicate the host’s ICU behavior.

Files changed (4) +70 / -7

Bug fix (3) +46 / -7
QuickJSExecutor.tsCap infinite memory budgets and classify interrupted probes +30/-7

Cap infinite memory budgets and classify interrupted probes

• Treats positive infinity as the build’s maximum memory rather than its minimum. Centralizes failed allocation-probe classification so a probe stopped by the interrupt handler yields a timeout instead of a memory failure.

src/cognition/emergent/executor/QuickJSExecutor.ts

guest-prelude.tsForward locale-aware string casing to the host +6/-0

Forward locale-aware string casing to the host

• Overrides the guest’s locale-aware upper- and lowercase methods to pass strings and locales through the host binding, matching in-process locale behavior.

src/cognition/emergent/executor/guest-prelude.ts

guest-surface.tsAdd a validated host binding for locale casing +10/-0

Add a validated host binding for locale casing

• Adds a binding that accepts only the two locale-aware string case methods and performs the conversion using the host’s string methods.

src/cognition/emergent/executor/guest-surface.ts

Tests (1) +24 / -0
quickjs-executor.integration.spec.tsCover infinite budgets, symbol rejection, and locale parity +24/-0

Cover infinite budgets, symbol rejection, and locale parity

• Verifies that an infinite budget permits guest memory growth beyond 40 MiB and that an Intl call rejects a guest symbol at the host boundary. Extends the in-process parity comparison with Turkish casing and an unqualified German uppercase conversion; the interrupt-probe race has no test.

tests/emergent/quickjs-executor.integration.spec.ts

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Probe timeouts lack regression coverage 📘 Rule violation ☼ Reliability
Description
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.
Code

src/cognition/emergent/executor/QuickJSExecutor.ts[R481-482]

+    if (this.interrupted) {
+      return { status: 'timeout', memoryUsedBytes };
Evidence
Rule 6 requires real-path integration coverage for observable behavior. The changed branch
distinguishes two externally reported statuses, but the existing integration cases cover memory
exhaustion and deadlines separately rather than interruption during a failed probe.

AGENTS.md: Test Observable Behavior Through Real Paths: AGENTS.md: Test Observable Behavior Through Real Paths
src/cognition/emergent/executor/QuickJSExecutor.ts[479-486]
tests/emergent/quickjs-executor.integration.spec.ts[140-230]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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



Remediation recommended

2. Invalid locales silently change case 🐞 Bug ≡ Correctness
Description
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.
Code

src/cognition/emergent/executor/guest-prelude.ts[375]

+      return host.string_case(method, String(this), localesArg(locales));
Evidence
The new method passes its locale through localesArg, which calls Array.from for non-string
values; a symbol becomes an empty array. The host then receives only that array and invokes the
native locale-case method with it, so it cannot reject the original symbol.

src/cognition/emergent/executor/guest-prelude.ts[292-297]
src/cognition/emergent/executor/guest-prelude.ts[372-376]
src/cognition/emergent/executor/guest-surface.ts[223-230]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


3. Null receivers become text 🐞 Bug ≡ Correctness
Description
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.
Code

src/cognition/emergent/executor/guest-prelude.ts[R374-375]

+    define(String.prototype, method, function (locales) {
+      return host.string_case(method, String(this), localesArg(locales));
Evidence
The wrapper is a strict function and sends String(this) across the bridge. The host binding
receives only that resulting text, so it cannot distinguish an invalid original receiver from an
ordinary string.

src/cognition/emergent/executor/guest-prelude.ts[18-20]
src/cognition/emergent/executor/guest-prelude.ts[373-376]
src/cognition/emergent/executor/guest-surface.ts[223-230]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


4. Forged code can alter locale case results 🐞 Bug ≡ Correctness
Description
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.
Code

src/cognition/emergent/executor/guest-prelude.ts[375]

+      return host.string_case(method, String(this), localesArg(locales));
Evidence
The prelude installs the wrapper before evaluating forged code, but its String(this) expression is
evaluated at call time. The binding trusts the resulting text and applies host casing to it.

src/cognition/emergent/executor/QuickJSExecutor.ts[375-405]
src/cognition/emergent/executor/guest-prelude.ts[373-376]
src/cognition/emergent/executor/guest-surface.ts[223-230]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +481 to +482
if (this.interrupted) {
return { status: 'timeout', memoryUsedBytes };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

Comment on lines +374 to +375
define(String.prototype, method, function (locales) {
return host.string_case(method, String(this), localesArg(locales));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

@jddunn
jddunn merged commit 2ec4535 into master Oct 8, 2026
8 checks passed
@jddunn
jddunn deleted the fix/quickjs-cold-read branch October 8, 2026 22:14
github-actions Bot pushed a commit that referenced this pull request Oct 8, 2026
## [0.13.3](v0.13.2...v0.13.3) (2026-10-08)

### feat

* **guardrails:** required guards, hold-until-final output, phrase lists and hard limits (#169) ([032fcbf](032fcbf))

### fix

* **emergent:** QuickJSExecutor follow-ups from the cold read of #160 (#178) ([2ec4535](2ec4535))
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.

1 participant