Repository navigation
Conversation
Models keep writing tools.x(...).catch(() => null) despite a prompt rule against it, and the sandbox rejected every such program. Chained promises now run like JS: handlers run once when the promise is first observed, Promise.all/allSettled start every member's handler before joining so second-stage calls overlap, and race races each chain's root call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
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.
The agent's code sandbox now runs programs that use
.then(),.catch()or.finally()on a tool call instead of rejecting them. When a customer asks Replo's agent for store data, the agent writes a short JavaScript program that calls integrations such as Shopify; about 70 of those calls from about 50 people failed in Nov 3–30 only because the model wrote.catch(() => null), which the sandbox refused. A prompt rule against it has been in the agent's instructions since Sep 27 and the model still writes it, so the sandbox should accept it.Context
OPENCODE_VERSIONpins in andytown (.agents/skills/agent-tooling/release-opencode.md). A companion andytown PR makes the daily product report stop hiding this error so any return shows up.How it works
A
.then/.catch/.finallycall returns a derived promise: a promise whose handler runs once, when something first waits on it (await,Promise.all, or the end-of-program drain that already waits for fire-and-forget calls). Handlers do not get their own fibers (the Effect library's lightweight threads), because the interpreter keeps one shared stack of variable scopes and two handlers interleaving would read each other's variables. Tool calls a handler starts still run in parallel on their own fibers.await tools.x().catch(() => null)UnsupportedSyntaxerrornullon failurePromise.all(items.map(i => tools.a(i).then(r => tools.b(r))))bcalls overlapPromise.raceover chains.catchon an un-awaited callReview closely:
chainPromiseand the race change inpackages/codemode/src/interpreter/runtime.ts. Known gap: handlers run when awaited rather than on a microtask, so a program that reads a variable a never-awaited.thenwrites, before the program ends, sees the old value. Real JS has the same race in practice since the tool call is asynchronous.Testing Done
bun testinpackages/codemode: 285 pass, including 15 new tests for.then,.catch,.finally, chains, assimilation of a returned tool call, run-once memoization,Promise.all/allSettled/race, fire-and-forget chains, and a non-function handler.bun typecheckacross the repo (pre-push hook) passes;oxlint packages/codemodereports 0 errors.🤖 Generated with Claude Code
Summary by cubic
The agent's code sandbox now runs programs that use
.then(),.catch()and.finally()on tool‑call promises instead of rejecting them with anUnsupportedSyntaxerror.Promises chained this way behave like JS: handlers run once when the promise is first awaited or joined,
Promise.all/allSettledstart every chain's handler before joining so second‑stage tool calls overlap, andPromise.raceraces each chain's root call, running only the winner's handlers. A handler that returns a tool call is assimilated, missing handlers pass the settlement through, and a.catchattached to an un‑awaited call counts as handled. This addresses REPL-36898, the widest app integration failure in the Nov 30 MCP & API report.Known gap
Written for commit 63ad5ab. Summary will update on new commits.