- RemoteCodemodeSandbox ran start() step by step, saving the whole heap after
every step (and failing on a WeakRef). Sandboxes now open a run with its
lifetime (session or saved), and a start() run is one session on the remote,
as on main.
- start()'s tests run on the worker, inline, and remote sandboxes again, with
main's cases for globals numbered with tools and rejections carrying their
properties; a test checks a remote start() takes no steps.
- start()'s fingerprint names the run's actual CPU budget (none, a number, or
remote), not "default" for every sandbox.
- start()'s call records carry the module; the dropped calls are computed once.
- Durable skips a namespace named like a built-in global or a global's
namespace (models) as a module, instead of failing every script; pi-codemode
exports CODEMODE_RESERVED_NAMES from /declarations for it.
- Docs: CodemodeHostCall.id, durable's call keys and schema, the CHANGELOGs
(start()'s jsName, the un-awaited calls rule, /remote, strict mode and UTC in
the coding agent), the README on dropped calls and remote start() runs, and
the coding agent's Bun caveat, which no longer holds (checked on Bun 1.4.4:
a long sort or split stops at the deadline).
- djs's local zone is one fixed offset (the host's current one, no DST), so
dates across a DST change were an hour off. Every run now passes
timeZoneOffset 0: getTimezoneOffset() is 0 and local time is UTC, as it
already was in deterministic runs.
- A store() value JSON cannot hold no longer puts the host's
JSON.stringify stack (absolute host paths) into the script's error; the
reason is name and message only.
Scripts run on djs in a worker of their own, as before with QuickJS: worker admission
and PI_CODEMODE_MAX_WORKERS stay, the bundle and the Bun binary embed djs.wasm and the
codemode worker. A script has a CPU budget of about a minute; TypeScript works.
- Add aspectRatio and size to ImagesOptions
- Forward aspectRatio and size to OpenRouter's image_config in
openrouter-images
- Validate and forward optional { aspectRatio, size } as the third
argument to codemode models.generateImages(); unknown option keys
such as apiKey or aspect_ratio throw
- Document the options in the ai README and the codemode and models
docs, and add tests
Fixes#10585.
## Problem
Bash output past the truncation limit is copied to a temp file in
`$TMPDIR`. The `WriteStream` had no `error` listener, so any open or
write failure became an uncaught exception and killed pi, including the
in-flight turn, subagents and background jobs. Triggers seen in
practice: a full tmpfs `/tmp` (ENOSPC), per-user tmpfs quotas that
systemd sets on `/tmp` (EDQUOT, errno 122), an unwritable `TMPDIR`
(EACCES). Both paths were affected: the agent `bash` tool
(`OutputAccumulator`) and `!` commands (`executeBashWithOperations`).
Only adding a listener is not enough: `end()` on a stream that already
errored never emits `finish` or `error`, so `closeTempFile()` would hang
instead.
## Change
- `createOutputFileStream` returns an `OutputFileStream` wrapper: error
handling from the start, writes ignored after a failure, a partially
written file removed (never a file that was already at the path), and
`close()` that never rejects or hangs and returns `{ kind: "saved", path
} | { kind: "failed", error }`.
- Bash tool: the temp file is closed before the final result is built.
On failure the result keeps the in-memory tail and ends with `[Showing
lines X-Y of N. Could not save the full output: ENOSPC ...]`, without
`fullOutputPath` / `full_output_path`. `readFullOutput()` (structured
output for codemode) falls back to the tail. This matches what codemode
already does for its own output files.
- `!` commands: the executor waits for the file to flush before
returning its path. On failure it returns the tail without a path.
- Other crashes from temp dir failures: opening the external editor
(Ctrl+G) and `/share` now report the error instead of throwing from
key/submit handlers. The TUI width crash keeps its error and restores
the terminal when its debug log cannot be written.
Durable's bash spill handling (kills the command when the spill file
fails) is unchanged; aligning it is left for a separate PR.
## Tests
`test/output-file-failures.test.ts` covers failed open (missing
`TMPDIR`), failed writes (ENOSPC, injected), and `EEXIST` for the
stream, the bash tool and the `!` executor. New cases in
`external-editor.test.ts`, `session-share.test.ts` and
`tui-render.test.ts`.
Scripts wait in arrival order for a free worker instead of failing
immediately. The wait counts toward timeout_ms, honours abort, and is
capped at 60 seconds. PI_CODEMODE_MAX_WORKERS raises the process-wide
limit of two workers for hosts running many sessions in one process.
closes#11184
A misplaced options line was ignored, so its timeout_ms never applied and
the script ran without a deadline. parseCodemodeSource now throws
CodemodeSourceError before the script runs.
fixes#10631
Adds the openai-decisions classifier API with gpt-6-luna on the openai provider. bool questions map to predicates with the criteria in the instructions, refusals fail the result, and gateway timeouts (504) are not retried. The model needs an API key and is hidden from availability while openai uses Sign in with ChatGPT.
Adds optional images to ClassifierContext. Models without image input and APIs that cannot send images return an error result. Codemode's models.classify() accepts images.
Moves the shared classifier HTTP code out of system-one-shared.ts into classifier-shared.ts.
Text items get ==> text N/M <== headers when there are several, and
console output is grouped into one <console_output> block. Console text
items are marked with console: true.
Rules and the tool list follow the declared tools (active minus
hiddenDeclarations). The skills hint names no tool when the reader is
hidden. Codemode shows each tool's prompt guidelines with its
declaration, via the new ToolLoadout.getPromptGuidelines().
closes#10343
image() output is also written to a temp file and the result names the
path before each image, so later turns can reference generated images.
Output files are now created through one helper (still tmpdir()) and
are readable only by the user.
closes#10310
text(), image(), and console.* fail the script with a RangeError past
MAX_OUTPUT_CHARS (16 Mi) characters or MAX_OUTPUT_ITEMS (100000) items.
closes#10283
Move the codemode script reference, including the models API, into
docs/codemode.md and keep only one line per global in the tool
description. Declared tools get a one-line note on how scripts call them,
and the codemode system prompt guidance and MCP server section are shorter.
With the default tools a GPT-5.6 request drops from about 5,300 to 3,300
tokens.
Errors now point the way back: unknown tools and models members name close
matches, models.classify() and models.generateImages() validate their
arguments, unknown or mistyped models point to getAvailableOfType(),
store() overflow explains the store, and unshown generated images get a note.