GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(codemode): suspend only durable work, resume with host outcomes, and save fetch responses by jlongster · Pull Request #62086 · anomalyco/opencode

Conversation

@jlongster

@jlongster jlongster commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Stacked on #61856 (base: resumable-codemode).

Summary

This changes how a Code Mode run is suspended and resumed. execute now returns a running execution you can suspend. A suspend succeeds only while every running call is a durable tool call that has its handle. On resume, the host supplies those calls' results. Extensions can make their returned values survive a suspend, and core's fetch uses that, so a response the program holds still works after a resume.

Nothing in OpenCode suspends runs yet. Core treats a suspended outcome as an unsupported failure.

API

const execution = yield* runtime.execute(code, bindings?)   // Effect<Execution, never, R | Scope>: starts the program in the current scope
yield* execution.suspend    // Effect<Result | Suspended, SuspendError>
yield* execution.result     // Effect<Result | Suspended>
const next = yield* runtime.resume(state | bytes, { [key]: { ok: true, value } | { ok: false, error } })
  • execute replaces start. CodeMode.execute({ code, ... }) returns an Execution too. Closing the scope interrupts the run and cancels pending durable work.
  • SuspendError { running: [{ key, path }] } is returned when anything other than a durable call that has its handle is in progress. That covers normal tools, search, fetch, extension calls (including queued ones and methods on extension results), and a durable call still in start. The run carries on untouched.
  • Suspending is immediate and synchronous: check the running calls, encode the state and check its size, and only then detach the durable fibers. A failed encode or a state over suspend.maxBytes also leaves the run untouched.
  • ctx.suspend() is on durable tools' start and attach context. A durable tool can use it to suspend its run, under the same rule. A non-durable tool gets a SuspendError.
  • Resume requires an outcome for every pending durable call; a missing or unknown key is a SnapshotError. Outcomes are copied as JSON. Saved limits (timeoutMs, maxToolCalls, maxOutputBytes) are restored.
  • Extension.make({ ..., snapshot?: { encode, decode } }): functions inside a hooked extension's results are saved as their path within the value encode returned, and rebuilt with decode. The host-globals check covers each extension's name and whether it has hooks.
  • Removed: start, the tool retry option, suspend.graceMs, the "may have partially run" rejection, and reattaching through attach/lookup on resume. durable.lookup is optional.
  • Fixed: a snapshot holding a lost non-function host value couldn't be decoded, because encode and decode disagreed on the record shape.

Core

  • The execute tool runs Effect.scoped(execute(code) → result) and reports ok: "suspended" as an unsupported failure instead of an empty success.
  • fetch builds its response from plain data and adds snapshot hooks. What programs see is unchanged, and a fetch still in flight blocks a suspend.

Verification

  • Code Mode suite: 14,892 pass. test262: 13,329 pass, 1,678 skip, 1 fail (language/global-code/import.js, which also fails on dev). Typecheck clean.
  • Core Code Mode tests: 40 pass (2 new for fetch). Core typecheck clean.
  • Save-and-restore test mode: clean when test262 and the other files run separately. Run as one process, it shows order-dependent test262 failures that predate this branch. Those are being fixed separately by sealing the frame-kind registry (see the review comment on feat(codemode): make Code Mode runs suspendable and resumable #61856).
  • Benchmarks: within noise of feat(codemode): make Code Mode runs suspendable and resumable #61856.
  • 25 real Code Mode scripts, suspended at 50% and 90% of their steps: all 50 points resume to the correct result. 43 suspended at the exact step. 7 were refused with a SuspendError naming the running fetch calls, then suspended successfully a few steps later. Before this change, those 7 crashed on resume.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added the contributor label Nov 5, 2026
@jlongster
jlongster force-pushed the durable-suspend branch from 4ee230e to 55abbef Compare November 5, 2026 15:10
jlongster added 8 commits November 5, 2026 18:26
@jlongster
fix(codemode): decode every lost value the way it was encoded
4c128aa
@jlongster
feat(codemode): start programs with execute in the current scope, rep…
e31430d
…lacing start
@jlongster
feat(codemode): suspend only while durable work runs, at once, failin…
e630b43
…g with SuspendError otherwise
@jlongster
feat(codemode): resume with an outcome for every pending durable call…
56a7a04
…, under the saved limits
@jlongster
feat(codemode): let a durable tool suspend its run from start or atta…
1b170a9
…ch with ctx.suspend
@jlongster
feat(codemode): save functions inside extension results through the e…
bc4367e
…xtension's snapshot hooks
@jlongster
feat(core): save fetch responses across a suspended Code Mode run wit…
e3ddb76
…h snapshot hooks
@jlongster
docs(codemode): describe durable-only suspends, resume outcomes, and …
d8169ce
…extension snapshot hooks
@jlongster
jlongster force-pushed the durable-suspend branch from 55abbef to d8169ce Compare November 5, 2026 18:28
@jlongster

jlongster commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Closing: superseded by a new bytecode VM engine that lands side by side with dev's original interpreter behind CodeMode.make({ engine: "vm" }), plus the OpenCode integration behind an experimental flag. Links to follow. The branch is kept for reference.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jlongster jlongster closed this Nov 6, 2026
This was referenced Nov 6, 2026
feat(codemode): add a bytecode VM engine behind CodeMode.make({ engine: "vm" }) #62357
Merged
feat(core): run Code Mode on the bytecode VM behind experimental.codemodeVm #62358
Merged
@jlongster

jlongster commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #62357 (bytecode VM engine side by side with dev's interpreter, CodeMode.make({ engine: "vm" })) and #62358 (OpenCode integration behind experimental.codemode_vm).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jlongster
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.