Skip to content

refactor(desktop): use opencode SDK in automation runner - #4190

Merged
benjaminshafii merged 1 commit into
devfrom
thin/automation-runner-opencode-sdk
Aug 28, 2026
Merged

benjaminshafii merged 1 commit into
devfrom
thin/automation-runner-opencode-sdk

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Stack

Stacked on #4189, which is stacked on #4188. Review only commit 26f2a4f3 / the diff against thin/proxy-scope-hardening.

Why

The desktop Automation/remote-session runner still used OpenWork’s duplicate session create/abort/snapshot endpoints. This migrates that trusted consumer to the official @opencode-ai/sdk/v2/client through the workspace-mounted, scope-hardened proxy from #4189.

What changed

  • Keep OpenWork HTTP only for /workspaces discovery and Den runner APIs.
  • Build a workspace-bound SDK client at /workspace/:id/opencode.
  • Preserve local OpenWork bearer authentication in the SDK transport.
  • Create sessions with native session.create.
  • Submit initial work with native session.promptAsync, preserving provider/model/variant/text semantics.
  • Poll a snapshot in parallel from native session.get, session.messages(limit: 200), session.todo, and session.status.
  • Preserve idle status fallback, assistant output/usage aggregation, provider failure handling, timeout behavior, and Den completion context.
  • Abort with native session.abort. The cleanup call intentionally does not reuse the already-aborted assignment signal, so it can actually reach OpenCode.
  • Preserve useful native upstream status/message on failures.
  • No fallback to the old wrapper endpoints.

Server session wrappers remain for other consumers and are removed only after the rest of the stack migrates.

Verification

Branch-specific

  • node --test apps/desktop/electron/automation-runner.test.mjs — 34 pass / 0 fail
  • ./node_modules/.bin/tsc -p apps/desktop/tsconfig.electron.json --noEmit — pass
  • pnpm --filter @openwork/desktop check:electron — pass (52 renderer methods covered)
  • pnpm --filter @openwork/desktop typecheck:electron — pass
  • vitest ... specs/automation-runner-reconnect-backoff.test.ts — 1 pass / 0 fail
  • git diff --check — pass

Broader local matrix

  • Full desktop suite executes 276 tests; runner’s 34 tests all pass. Its sole assertion failure is the unrelated local runtime CA fixture; two subsequent chain-repair tests are cancelled by that parent failure. Files untouched by this PR.
  • Full PR eval project: 91 pass / 3 fail / 2 skipped before the witness-count fix. The only branch-related failure was its expected runner count (33→34); after updating, that spec passes in isolation. The other two failures are unrelated local build-state issues: concurrent Den DB asset copy EEXIST, and Node 22 loading an unbuilt workspace .ts export.
  • Hosted CI is the authoritative clean-environment lane and must be fully green before merge.

Contract coverage added/updated

  • native create → prompt ordering and exact payloads
  • encoded workspace ids
  • nullable prompt/model omission
  • four snapshot endpoints launched in parallel
  • message limit=200
  • status fallback when status map omits the session
  • bearer auth and AbortSignal propagation
  • cleanup abort uses a live signal
  • upstream status/message + workspace context preservation
  • cancellation, lease rotation, wake/double-claim protection, tool-only completion, provider failure, and pinned model loss

@vercel

vercel Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Aug 28, 2026 6:06pm
openwork-den Ready Ready Preview Aug 28, 2026 6:06pm
openwork-diagnostics Ready Ready Preview Aug 28, 2026 6:06pm
openwork-landing Ready Ready Preview, v0 Aug 28, 2026 6:06pm

@diff-warden diff-warden 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.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (a806a929e698c4fd66f736e3981f5d194677acaa). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

Base automatically changed from thin/proxy-scope-hardening to dev August 28, 2026 18:05
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying openwork with  Cloudflare Pages  Cloudflare Pages

Latest commit: c4e61dd
Status: ✅  Deploy successful!
Preview URL: https://b3bea335.openwork.pages.dev
Branch Preview URL: https://thin-automation-runner-openc.openwork.pages.dev

View logs

@diff-warden diff-warden 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.

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (c4e61dd61085519bca9943e3cacbde3b40f601fb). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit a3bcd17 into dev Aug 28, 2026
19 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — c4e61dd6 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-app — c4e61dd6 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-den — c4e61dd6 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-diagnostics — c4e61dd6 Deployed Aug 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant