Skip to content

fix(agents): upgrade opencode to 2.4.2 - #3246

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
gardener/upstream/opencode-2.4.2
Open

github-actions[bot] wants to merge 1 commit into
mainfrom
gardener/upstream/opencode-2.4.2

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Moves agents/harness/opencode and agents/models/opencode from opencode 2.0.24 to 2.4.2, and raises the peer floor to 2.2.3.

Package From To
@opencode/sdk (dev, packages/agents) 2.0.24 2.4.2
@opencode/plugin (dev, packages/agents) 2.0.24 2.4.2
@opencode/sdk / @opencode/plugin (examples/next/harnesses/opencode) 2.0.24 2.4.2
@opencode/sdk / @opencode/plugin peer range ^2.0.24 ^2.2.3

OpenCode has shipped 2.0.25 through 2.4.2 since our pin. All of them fall inside our ^2.0.24 peer range, so users can already install them, and from 2.2.1 on agents/models/opencode doesn't work for them: every prompt comes back unanswered. This PR carries over the source, config and docs changes from #3102 (2.4.1), which only github-actions[bot] committed to, applies them to current main (where harness-opencode now runs on @cloudflare/vitest-plugin), and moves on to 2.4.2. Nothing from 2.4.1 to 2.4.2 needed a code change. 2.4.2 installed without a minimumReleaseAge hold.

What changed upstream that affects us

  • high · breaking: "chore(core): remove bundled cohere, vercel and perplexity AI SDK packages (#59771)" (fc6922f6b8, in @opencode/core 2.2.1, a dependency of @opencode/sdk). agents/models/opencode told OpenCode its provider used aisdk:@ai-sdk/vercel (packages/agents/src/models/opencode/index.ts:60 on main). OpenCode loaded that bundled package in-process and our language hook swapped in the model. Now the package isn't bundled, so OpenCode hands the provider to its npm installer, which can't run in workerd. At 2.4.2 with the old carrier, 14 of the 35 harness-opencode tests fail with status: "unanswered". The fix relies on "fix(core): run dynamic provider npm fallback after external sdk hooks (#60380)" (b5c223182c, 2.2.3), which runs a plugin's aisdk.hook("sdk") before that loader. Our plugin now answers the sdk step itself, under a package name that doesn't exist, and keeps its language hook:
    -const CARRIER_PACKAGE = "aisdk:@ai-sdk/vercel";
    -const UNREACHABLE_BASE_URL = "https://workers-ai.binding.invalid/v1";
    +const CARRIER_PACKAGE = "aisdk:agents/models/opencode";
    ...
    -            package: CARRIER_PACKAGE,
    -            settings: { baseURL: UNREACHABLE_BASE_URL, apiKey: "binding" }
    +            package: CARRIER_PACKAGE
    ...
    -      const hook = await ctx.aisdk.hook(
    +      const sdk = await ctx.aisdk.hook(
    +        "sdk",
    +        (event) => {
    +          event.sdk = { provider: CLOUDFLARE_PROVIDER_ID };
    +        },
    +        { providerID }
    +      );
    +      const language = await ctx.aisdk.hook(
             "language",
    The cleanup disposes both hooks (index.ts:165-166). The doc comment above CARRIER_PACKAGE (index.ts:50-58) now explains the sdk hook.
  • medium · breaking: "refactor(client): group experimental SDK methods under client.experimental (#59072)" (9a9386edbc, 2.2.1). opencode.sessions.wait and opencode.sessions.log became aliases marked @deprecated Use `client.experimental.session.wait`. Removed in the next minor. (log carries the same note). The harness calls them at packages/agents/src/harness/opencode/harness.ts:536, :670 and :1242, and OpenCodeLogEvent is derived from sessions.log at packages/agents/src/harness/opencode/types.ts:45. Our caret range admits the release that removes them.
    -              opencode.sessions.wait(
    +              opencode.experimental.session.wait(
    ...
    -      yield* opencode.sessions.log(
    +      yield* opencode.experimental.session.log(
    ...
    -  ReturnType<OpenCode["sessions"]["log"]> extends AsyncIterable<infer E>
    +  ReturnType<OpenCode["experimental"]["session"]["log"]> extends AsyncIterable<
    +    infer E
    +  >
  • low · breaking (test and example build): "chore: upgrade Effect to rc.118 (#50231)" (1aae67e853). OpenCode's Effect moved effect/unstable/httpapi to effect/http-api, and 2.4.2 depends on effect 4.1.0, so the empty-httpapi-scalar stub at packages/agents/src/harness/opencode/tests/vitest.config.ts:17 and examples/next/harnesses/opencode/vite.config.ts:16 no longer matched any file.
    -        id.includes("/effect/dist/unstable/httpapi/internal/httpApiScalar.js")
    +        id.includes("/effect/dist/http-api/internal/httpApiScalar.js")
  • low · breaking (tests only): @opencode/core now inlines models.dev's catalog as one 8 MB string literal (marked // src/models-dev/snapshot.txt), which its release build fetches at publish time: "feat(build): fetch the models.dev catalog once per release and verify the bundled copy (#59173)" (d5bb993278, 2.2.0). The module is too large for the test runtime's module transfer, so harness.test.ts crashes with WebSocket 1009 "Message is too large". The tests set models: { fetch: false } and use only the Cloudflare provider, so packages/agents/src/harness/opencode/tests/vitest.config.ts:21-25 gains an empty-models-dev-snapshot transform, implemented in the new tests/models-dev-snapshot.ts, that replaces the literal with '{}'. It throws a named error if the marker is present but the literal changed shape, or if an @opencode/core module over 1 MB has no marker. The new tests/models-dev-snapshot.test.ts (4 tests) covers these cases. The example's production build keeps the catalog.
  • low · docs: the same growth makes examples/next/harnesses/opencode/README.md:83 ("OpenCode adds about 3.7 MB (gzip) to the Worker") out of date. At 2.4.2, wrangler deploy --dry-run on the example's vite build output reports Total Upload: 28051.95 KiB / gzip: 4567.84 KiB.
    -about 3.7 MB (gzip) to the Worker, so deploying needs the Workers Paid plan.
    +about 4.5 MB (gzip) to the Worker, so deploying needs the Workers Paid plan.
  • low · new feature: "feat(sdk,core,server): wire OpenCodeWorkerd alarm(), WorkspaceDriver Identity, and WorkerClient.fromWebSocket (#66240)" (6f6c193006, 2.4.2). OpenCodeWorkerd.Interface (our OpenCode type, packages/agents/src/harness/opencode/types.ts:11) gains alarm(), which runs workspace.suspendIdle() for remote workspaces, and the workerd profile now schedules idle deadlines through storage.setAlarm. That only happens once a remote workspace connection opens. The Promise OpenCodeWorkerd.create takes no workspaceProviders, and the harness and example create no OpenCode workspaces (the example's /workspace is an @cloudflare/computer plugin tool), so OpenCode never arms an alarm in our objects and alarm() has nothing to suspend. Not adopted: nothing to forward today, and if OpenCode remote workspaces are ever supported, its setAlarm calls would have to go through Lifecycle, which owns the object's single alarm (docs/agents/agent-class.md:83); possible follow-up.
No effect on us: 2.4.1 → 2.4.2 (14)
  • "release: v2.4.2" (fc31a48531) and "release: v2.4.1 (#65848)" (472d9f8e2e, the version bump merged back to dev): package.json versions only.
  • "test: isolate home and XDG directories across core preload, server, and sdk (#66417)" (ac1bab2ffc): the SDK's test script only.
  • "feat(core): add push notifications for the mobile apps (#66130)" (4c2977b82e), "fix(core): refuse plugin automation creates before configured permissions load (#66109)" (af54caef70), "fix(core): wait for the automation target's plugin registry (#66104)" (f84258d3b6): SDK tests only in packages/sdk.
  • "fix(core): let plugins create automations during setup (#65987)" (01bf9f0d65), "fix(plugin): preserve completed errors on late abort (#66102)" (71324e2063) and "chore(core): revert niche fixes from the daily review job (#66140)" (9964772701): the revert undoes both, and git diff v2.4.1 v2.4.2 -- packages/sdk/src/internal/instances.ts is empty.
  • "fix(plugin): honor abort signals in Promise plugin API calls (#65980)" (57f83d690d) and "fix(plugin): reject aborted Promise plugin calls with the signal's reason (#66041)" (883c871683): Promise plugin API methods take an optional { signal }. Additive; our plugin passes none.
  • 6f6c193006 also drops OpenCode.create's second (embed) argument in favour of createWithHost. We only call OpenCodeWorkerd.create, whose options are unchanged.
  • GUI plugin work in packages/plugin/src/gui: "fix(app): redesign the add extension dialog (#66355)" (5050225a09), "docs(plugin): describe the new quote text in ComposerQuote (#66248)" (a4bea47aa5), "feat(app): move the file tree to the right from its context menu (#66012)" (f25b09005e), "feat(app): pin inbox sessions and list archived ones in the sidebar (#65961)" (b5948e5229). We don't use @opencode/plugin/gui*.
No effect on us: 2.0.24 → 2.4.1 (as reviewed in #2907, #3040 and #3102)

I checked every commit in git log v2.0.24..v2.4.1 -- packages/sdk packages/plugin (139) against the hashes below and in the entries above, and none is missing.

  • "release: v2.4.1" (6f0514052a) and "release: v2.4.0 (#65753)" (d6379ff0e1), "release: v2.4.0" (44aed4fd14), "docs: add the v2.3.1 and v2.3.2 changelog entries to dev (#65701)" (406fd32698): package.json versions only.
  • "fix(plugin): lower the @OpenTui peer floor to 0.8.0 and stop raising it on upgrades (#65819)" (698800f59c): optional TUI peers. We don't use @opencode/plugin/tui.
  • "feat(plugin): let plugins create, list and delete automations (#65747)" (26f4041911): adds ctx.experimental.automation. Additive; we create no automations.
  • GUI plugin work in packages/plugin/src/gui: 176db8d456, 34411562e4, 3bc82a19b3, 80d7c17d8e, cd0d037d68, 723e0a9105, d412042beb, 22377659a8, 363217b2c4. We don't use @opencode/plugin/gui*.
  • "feat(tui): add a Scripts tab to the composer picker" (b9a2dc32cb) and "Opentui 0.9.0" (4c5298bce4): plugin/src/tui and its optional peers.
  • "feat(core): revoke ChatGPT sign-in on logout" (53212a6125): optional revoke on integration OAuth methods. We register no integrations.
  • "feat(core): add an experimental video generation tool" (49cbcd8c0c): video kind in the idle hook's background list. We don't register the idle hook.
  • "feat(core): choose tools and Code Mode placement from the session's model" (007afb1b0c): tool.add gains defaulted type parameters, tool hook events gain info and codemode. We register no tool hooks; the example's workspace.ts tool.transform still typechecks.
  • "feat(core): add Bun.file, Bun.write and Bun.Glob to Code Mode behind full_codemode" (2f20ba65b7): SDK packaging script only.
  • Release and version-sync commits: c0ad18b402, a554d70499, 8aa00e805e, 5f76acb125, 4878a0e30f, 872f694b05, b44b7164ba, 4efad23dd8, f74b1416a8, 86976449c4, 2a3e7c0f34, e965774fa0, 4b50f5cc6c, 133b1ebfaf, d30e990c69, 4e95dacd81, 83c5abbbe3, f40dc433cb, 34d8ded0c5, c5aabae288, 03cb9b9946, 8059cdcbdf, 62e087ff7b, bd55d4895f.
  • Merge commits with no changes of their own: be315b1db8, 15d4afd089, 3a58a0c9cf, bcd713e2b7, 4b83402a29, 316a688fe9, fd0efe30f2.
  • OpenTUI bumps in @opencode/plugin's optional TUI peers: 8db3d852cc, 13e8186410, ab4d1f3ab1, c9c1dc04f7, c7ddff776c, def5d948ef, d0a2ce32de, 65f8907708, da40b8fbe3, fcad1319bf, c4bf172532.
  • Desktop GUI plugin work: dae4077a96, 758cf5adbe, 19d87a72e6, 5792c3e63b, 4ba064f653, b3de41a572, 2fc371657b, a88d3ca0bc, 8fdf2e5875, 4dd7b2662c, 69ef55f02b, 3fcdcb35e8, 27dd925604, 9a7f22a776, 605e912fda, 4a6067d85c, 3343941f16, 6469454d35, e23d54ca75, ffcaeec36c, b268a4e8b0, 1cb0633c8b.
  • plugin/src/tui only: de284dc1bc, 4cba1b7f5d.
  • SDK tests and scripts only: 33ba535c9f, bcaf561d94, 0f1ddb4643, 9a3f03e5c5, 7a82f3aed2, 17229d24f5, f2323623c4.
  • Build and tooling, no runtime change for us: 36f559b0c6, 6996bbcd6d, fa5b4bd618, 1dab9ae99e, 23359e9fe6, 84578e123f, 41b03dea0f (plugin README), 50ae4bd4db.
  • Hooks and plugin APIs we don't register or call: 30654dae6c (Code Mode background kind), 9f807c7777 (ctx.experimental.generate drops video), b81c5f3465 (Effect entry point Tool), 2f886a2a5e (session request hook metadata), 2ef38b2172 (provider sign-in), e56eff2bc0 (fork field on session hooks; sessions.fork unchanged), 53f2d631df (freeform tool input), 64bd35afa9 and 05d347d750 (Promise tool signals), 37729b1df1 and b88b867b6e (experimental.model.resolve), 8f0fc21e71, f29e281322, 89f3ac108f, 8de0323975 (new artifact, provider, tool and goal domains), 2a0639a11f (ctx.generate deprecated), 1438073271 and 73517183b3 (Promise tool hook errors), 6c74e11e95, bc5fa1ccf3, 6a7cedcbf1, d78267503d, 70c6c8cbc5 (new plugin methods), 21ed6e4103 (VCS type field).
  • "fix(tui): identify config-defined providers" (cc4faf46bf) and its revert (cd15a6a38b): cancel out.
  • "fix(core): keep plugin swaps going when a cleanup fails" (ec263d62b6): our plugin's cleanup is an async function.
  • "feat(plugin): filter event subscriptions by type" (1434464f7e): plugin ctx.event.subscribe gains types; the harness subscribes through the client, which still delivers every event.
  • c8cf3a544f, 946c331fce (form polling): internal, no API change.
  • dad29a8991 (Effect moved to @opencode/ai/effect): import paths inside the plugin package.
  • 7a62a46695 (cast and helper cleanup): DeepMutable keeps its shape and we don't name it.
  • "refactor: v2.1 minor breaking changes" (acdcdb8dd9): providerState renamed native on a session hook event. We don't register session hooks; the shapes the harness reads typecheck and pass the tests.
  • "feat(sdk): seed host plugins before recovery and harden workerd defaults" (55dde8810d): OpenCodeWorkerd.create({ plugins }) registers our plugin before restart recovery. Same API; the crash-recovery tests pass.
  • c50e39b72b (@opencode/sdk/effect file overrides), c28e9ec311 (Bun CLI plugin runtime): not used.
  • "fix(sdk): release completed embedded request signals" (9ee97d87a2): per-request abort controllers; close() still aborts in-flight requests.

Decisions

  • Carry over fix(agents): upgrade opencode to 2.4.1 #3102 rather than starting over. Its source, config and docs changes apply cleanly to current main; the only overlap is packages/agents/src/harness/opencode/tests/vitest.config.ts, where main now imports cloudflareTest from @cloudflare/vitest-plugin, and the http-api path and empty-models-dev-snapshot transform sit alongside it. I regenerated the lockfile for 2.4.2, re-measured the example's Worker size, and wrote a new changeset that says "tested with 2.4.2". fix(agents): upgrade opencode to 2.4.1 #3102 is closed as superseded.
  • Peer floor ^2.2.3, not ^2.4.2. The sdk-hook carrier needs 2.2.3, the first release that runs plugin sdk hooks before the npm loader. experimental.session.wait/log exist from 2.2.1. Nothing we use needs a newer release. Releases before 2.2.3 can't work with the new carrier: 2.2.1 and 2.2.2 lack @ai-sdk/vercel, and on 2.2.0 and earlier the carrier would reach the npm loader first.
  • patch changeset. The peer floor moves within major 2, and the source change fixes a provider that's broken on in-range releases.
  • Answer the sdk hook rather than borrow another bundled package. fix(agents): upgrade opencode to 2.2.1 #2776 used gitlab-ai-provider as a stand-in carrier. Since 2.2.3 a plugin's sdk hook answers before the loader, so we no longer depend on which AI SDK packages OpenCode bundles. The sdk value is a placeholder object, because our language hook always supplies the model.
  • Stub the models.dev catalog in the test config only. The harness tests never read the catalog (models: { fetch: false }). Shipped code and the example's production build are unchanged.
  • Don't forward alarm() to OpenCode. See the new-feature entry above: with no remote workspaces it is a no-op, and wiring it would mean letting OpenCode share the alarm Lifecycle owns.

Needs a maintainer

None.

Affected open PRs

  • fix(agents): upgrade opencode to 2.4.1 #3102 fix(agents): upgrade opencode to 2.4.1: made obsolete. This PR contains its changes and moves on to 2.4.2. Only github-actions[bot] committed to it, so it gets a "Superseded by" comment and is closed. Its two open review threads (no 2.0.24-database upgrade test; @number0/iroh as an optional native dependency of @opencode/core) apply here unchanged.
  • fix(agents): upgrade opencode to 2.2.1 #2776 fix(agents): upgrade opencode to 2.2.1 (draft): made obsolete. It waits for "a proper way to supply the Cloudflare provider" in place of the gitlab-ai-provider carrier, and this PR uses the sdk-hook route that 2.2.3 added.
  • fix(opencode): stop pausing wait() and prompt() after every run #2785 fix(opencode): stop pausing wait() and prompt() after every run: needs updating. It rewrites the block around opencode.sessions.wait( at harness.ts:536, which this PR changes to opencode.experimental.session.wait(, so the two conflict textually. It should keep the new call when rebased.

No other open PR changes @opencode/* versions: I read packages/agents/package.json on the heads of #3223, #3057, #2929, #2511, #2421, #2416, #2273, #2250 and #2203.

Other changes

  • packages/agents/package.json: dev pins 2.0.24 → 2.4.2 and peer range ^2.0.24 → ^2.2.3 for both packages.
  • examples/next/harnesses/opencode/package.json: pins 2.0.24 → 2.4.2.
  • pnpm-lock.yaml: regenerated with pnpm install. It now resolves only @opencode/* 2.4.2. The other entries that changed belong to OpenCode's dependency tree, for example effect and @effect/* 4.0.0-rc.112 → 4.1.0, @opentui/core 0.5.14 → 0.9.9, @opencode-ai/pty 0.2.0 → @opencode/pty 0.6.0, gitlab-ai-provider 6.19.0 → 6.24.0, @ai-sdk/vercel/cohere/perplexity removed, and @number0/iroh 1.2.0 added. Through pnpm's peer resolution, ws 8.21.3 → 8.23.0 and zod 4.1.8 → 4.6.7 appear in the peer suffixes of a few unrelated packages (OpenCode's @effect/platform-node-shared 4.1.0 needs ws ^8.22.0).
  • .changeset/opencode-2-4-2.md: agents patch describing the new peer floor, the provider and harness changes, and the one-way door.

Evidence

  • Before: at 2.0.24 on main: harness-opencode 31/31, workers src/tests/models/opencode 5/5. At 2.4.2 with main's agents/models/opencode (all other changes in place): harness-opencode 14 of 35 fail with status: "unanswered".
  • After: harness-opencode 35/35 (31 existing plus the 4 models-dev-snapshot.test.ts tests). workers src/tests/models/opencode 5/5. pnpm run build and pnpm run check pass: sherif, the exports check, the public API check, the instance-names check, oxfmt, oxlint, and typecheck (134 projects). The example's vite build succeeds.

Merge Danger

Door: one-way

Blast Radius: OpenCode harness users

Users of agents/harness/opencode or agents/models/opencode on opencode below 2.2.3 get a peer-dependency warning and need to upgrade @opencode/sdk and @opencode/plugin to 2.2.3 or later (2.4.2 tested). Users on 2.2.1–2.2.2 are already broken. Once a Durable Object has run opencode 2.2.0 or later, OpenCode's migrations can't be rolled back:

  • From 2.2.0, session media is stored as media:<hash> references into a new blob table.
  • From 2.2.4, background job markers move out of kv into a new job table, and the kv rows are deleted.
  • Assistant replies are stored in a session_part table with the message row's inline content left empty, which older releases don't read.
  • 2.4.0 adds a machine table, and its automation migration drops run-limited schedules. Our harness never creates schedules.

An older opencode release can't read those sessions. 2.4.2 adds no migrations. Our own code stores nothing new.


Opened by Gardener's opencode-upgrade task. Commits pushed by Gardener don't start CI: close and reopen this pull request, or push to it, to run it. Review comments are handled by Gardener's pr-review-fix task.


Devin Review

Move @opencode/sdk and @opencode/plugin to 2.4.2, with a peer range of ^2.2.3.
OpenCode 2.2.1 stopped bundling @ai-sdk/vercel, which agents/models/opencode
named as its carrier package, so every prompt came back unanswered. Since
2.2.3 OpenCode runs its npm loader after plugin sdk hooks, so the provider
now answers the sdk hook itself. Move the harness off the deprecated
sessions.wait and sessions.log to experimental.session, update the test and
example Vite configs for effect's new http-api path, stub the 8 MB models.dev
snapshot in the harness tests (failing loudly if its shape changes), and
correct the example's Worker size. Carries over the changes from #3102
(2.4.1), rebased on the current harness test config.

Gardener-Operation: op_9d1d38ebdd927411a2f09ed1b844538b53770bc4e994f77e9094aa2417616500:3a43ca8202b50d66d9888941b2cf1e6f1b9ec4a5878b5eae4dab35aa8336cff6
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Nov 26, 2026
@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: edd8990

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 3 potential issues.

Devin Review

"@opencode/plugin": "2.0.24",
"@opencode/sdk": "2.0.24",
"@opencode/plugin": "2.4.2",
"@opencode/sdk": "2.4.2",

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.

🔍 Existing session upgrades lack coverage

The test worker creates and reopens databases with 2.4.2. Add a 2.0.24 fixture to verify that the one-way migration preserves transcripts and queued prompts under opencode_.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +89 to +90
"@opencode/plugin": "^2.2.3",
"@opencode/sdk": "^2.2.3",

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.

🔍 Advertised peer floor lacks coverage

The tests pin 2.4.2. Run a Workers AI prompt on 2.2.3 to exercise the two-hook provider at the advertised minimum.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread pnpm-lock.yaml
zod: 4.1.8
zod: 4.6.7
optionalDependencies:
'@number0/iroh': 1.2.0

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.

🔍 New optional native dependency

OpenCode adds the @number0/iroh Node-API package and its platform binaries to the install graph. Resolve the conflict with the native dependency rule before merging.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants