Skip to content

feat(settings): opt in to Code Mode for new tasks - #5219

Open
Astro-Han wants to merge 9 commits into
apache:mainfrom
Astro-Han:feat/code-mode-global-setting
Open

feat(settings): opt in to Code Mode for new tasks#5219
Astro-Han wants to merge 9 commits into
apache:mainfrom
Astro-Han:feat/code-mode-global-setting

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an opt-in Code Mode switch under Settings → General → Task defaults. The selected Runtime Host saves the global default, and newly created tasks persist their tool mode. Changing the switch leaves existing tasks unchanged; copies and child tasks inherit their source task's mode. Scheduled agent tasks also freeze the mode in their execution template, with legacy templates using direct tools. There is no per-task UI switch.

When enabled, the model receives only exec, with the current callable tool catalog in its description. Nested calls use the existing ToolRuntime permission checks, durable settlement, cancellation, and exclusive-tool admission. Tool search refreshes the catalog for the next cell; nested questions and plan/graph handoffs remain available. Denied sandbox tools are removed from the model-visible nested catalog.

Execution boundary

Keep @ai-sdk/code-mode, upgrading 1.0.42 → 1.0.56 and aligning the AI SDK family and provider-utils patch. Pin its run dependency to 2.1.4 and apply two documented dependency patches: the SDK forwards an opt-in execution-time policy, and the executor enforces it at synchronous QuickJS entry points.

Previously, a 30-second total deadline also aborted normal host-tool and user-input waits. Maka now uses a cumulative 30-second VM execution budget. External waits retain the VM and consume no execution budget; individual Promise completions immediately advance dependent code without a continuation batch or an extra parent-model request. Default SDK wall-time behavior remains available and unchanged.

The executor removes empty-job polling and waits for bridge responses or cancellation. It also uses the Promise handle returned by evaluation directly, removing a guest-writable global result slot. Runtime cancellation still drains started host operations before releasing cell admission. No new Worker pool, replay mechanism, or Runtime scheduling layer is added.

The patched run manifest uses Maka's Node >=22.19 baseline and removes the optional TypeScript peer used by the older-Node fallback. Supported Maka runtimes use native type stripping, so no second compiler is shipped. Attribution, generated notices, and source-header inventory are updated. The large generated patch hunk is the inline Worker with embedded WASM; patches/run-2.1.4-source.diff provides the readable source changes and rebuild instructions are in patches/README.md.

Host protocol compatibility epoch moves from 142 to 143.

Verification

  • 292 relevant Runtime tests passed, including dependent Promise.race progress across long waits, cumulative computation across awaits, computation while a host call is pending, cancellation/drain, and resource limits.
  • The 58 Code Mode/backend tests also passed on the minimum supported Node 22.19.0.
  • 69 scheduled-task and Session catalog tests passed; 196 release checks passed.
  • Patched upstream run: 364 tests, build, and typecheck passed.
  • A real 31-second host wait crossed the previous default deadline, returned its answer exactly once, and kept its signal live. Independent review also tested a 15-second wait under a 12ms execution budget and cancellation followed by reuse of a single Worker slot.
  • Independent clean npm ci, dependency patch application, production dependency inspection, and SDK smoke passed. Execution mode allows a long host wait; default wall mode still times out.
  • Real Electron settings test passed: enable/disable persists across reopening, with a screenshot attached to the test result.
  • Workspace test build, rebuilt desktop renderer, formatting, lint, license-header checks, and whitespace checks passed.

Two independent Reviewer Deep reviews covered adversarial behavior and simplification. No P0/P1 remains. Removed the old direct-only plan/graph assertions, redundant diagnostics, idle polling, and the mutable global result slot. Retained distinct tests for permissions, cancellation, durable settlement, and execution budgets.

Known limits

Waiting invocations retain their VM and Worker/memory quota until completion or cancellation. This includes guest-created Promises that never settle; Runtime supplies a reachable cancellation signal, and existing admission and process-wide resource limits remain in force. There is no automatic liveness deadline or deadlock detector. Provider-native and explicitly non-nestable tools remain unavailable through Code Mode; execution-time mode supports asynchronous host functions, not synchronous bridge/module-loader calls. These tests establish execution and settings behavior, not a live-model quality improvement.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex implemented dependency alignment, executor patches, settings/runtime integration, and tests. Two Reviewer Deep agents performed independent reviews.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described above
  • No

@github-actions github-actions Bot added the effort/L Under 1000 readable lines label Sep 12, 2026
@Astro-Han
Astro-Han marked this pull request as draft September 12, 2026 06:23
isLabelHidden
value={props.codeModeEnabled}
isDisabled={savingRows["code-mode"] || !props.settingsInteractive}
onChange={(enabled) => void persistCodeMode(enabled)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion (non-blocking): Switch already supports an async changeAction and manages its optimistic/pending state internally. Passing persistCodeMode through that prop would let this row drop its savingRows["code-mode"] entry and keyed guard lifecycle (begin/set/reset/release), while preserving the existing error toast. That keeps the new setting from adding another copy of the manual save state machine.

Keep the VM alive during host waits and resume through the existing Promise bridge. Patch the executor at its synchronous VM boundary, remove idle polling and the guest-writable result slot, and preserve cancellation and resource limits.

Generated-by: Codex
@Astro-Han
Astro-Han marked this pull request as ready for review September 12, 2026 07:39
@github-actions github-actions Bot added effort/XL Under 2500 readable lines and removed effort/L Under 1000 readable lines labels Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XL Under 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants