Skip to content

refactor(headless): use opencode SDK for threads - #4191

Merged
benjaminshafii merged 2 commits into
devfrom
thin/headless-threads-opencode-sdk
Aug 28, 2026
Merged

benjaminshafii merged 2 commits into
devfrom
thin/headless-threads-opencode-sdk

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Stack

Stacked on #4190 → #4189 → #4188. Review only commit 0f7589f2 / the diff against thin/automation-runner-opencode-sdk.

Why

@openwork/headless-threads is the stable programmatic thread API used by Den Automations and MCP remote-session capabilities. It still called OpenWork’s duplicate session create/messages/snapshot/abort endpoints. This migrates its transport to the official OpenCode SDK through the workspace-scoped proxy while preserving the package’s public API and transcript/wait semantics.

What changed

  • Added @opencode-ai/sdk as a direct package dependency (3-line importer-only lockfile change; trusted xlsx integrity preserved and frozen install verified).
  • Native SDK operations:
    • session.create, then optional session.promptAsync
    • session.messages for admission/idempotency checks
    • parallel session.get + messages + todo + status snapshots
    • session.promptAsync for turns
    • session.abort with native boolean acceptance
  • Preserved:
    • client + host bearer headers
    • redirect rejection
    • injected fetch
    • global/per-call/timeout signal merging
    • stable HeadlessThreadError fields
    • pre-turn message count and stable message-ID idempotency
    • idle-before-busy wait correctness
    • transcript and public result types
    • old wrapper validation/normalization for title and initial prompt (trim, empty prompt not started, whitespace rejection, 120/100000 limits)
  • Removed only obsolete wrapper envelope schemas; raw OpenCode payload validation remains permissive and explicit.
  • Updated the remote-session capability’s real HTTP witness to native mounted proxy paths and raw SDK shapes.
  • Server wrapper routes remain until all app/plugin consumers migrate.

Verification

  • pnpm --filter @openwork/headless-threads test — 36 pass / 0 fail
  • pnpm --filter @openwork/headless-threads typecheck — pass
  • pnpm --filter @openwork/headless-threads build — pass
  • bun ... apps/server/src/headless-threads.e2e.test.ts — 2 pass / 0 fail
  • Remote-session capability real-wire eval — 1 pass / 0 fail
  • pnpm install --frozen-lockfile --prefer-offline — pass; supply-chain policy verified 1718 entries
  • Clean full server suite — 757 pass / 8 skip / 1 fail / 1 error. The sole local failure/error is the baseline bun 1.3.5 inability to resolve node:sqlite in workspace-kv-store.node.test.ts; file untouched, and hosted parent CI is green on Linux/macOS.
  • git diff --check — pass

Coverage added

  • create→prompt ordering and native payload casing
  • explicitly empty, whitespace-only, oversized, and trimmed title/prompt compatibility
  • both worker credentials and optional host token
  • redirect protection
  • URL-encoded workspace/session IDs
  • parallel four-part snapshots and idle fallback
  • global + per-call AbortSignal merging and timeout mapping
  • stable native error status/message/body/path
  • native false abort result
  • duplicate stable message ID admission
  • remote-session capability create/send/read/scoping over the native wire

@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:39pm
openwork-den Ready Ready Preview Aug 28, 2026 6:39pm
openwork-diagnostics Ready Ready Preview Aug 28, 2026 6:39pm
openwork-landing Ready Ready Preview, v0 Aug 28, 2026 6:39pm

@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 (d89e63cb62f7a629013175d72d6e25230f25a719). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Deploying openwork with  Cloudflare Pages  Cloudflare Pages

Latest commit: 21bdf8e
Status: ✅  Deploy successful!
Preview URL: https://be686005.openwork.pages.dev
Branch Preview URL: https://thin-headless-threads-openco.openwork.pages.dev

View logs

diff-warden[bot]
diff-warden Bot previously approved these changes Aug 28, 2026

@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 (d5c78a46b12219b1fcdabd7edd7985c1fddb051e). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

Base automatically changed from thin/automation-runner-opencode-sdk to dev August 28, 2026 18:38

@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 (21bdf8e4fad2240e37479969bb771416380e4bf6). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit dad264e into dev Aug 28, 2026
27 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-den — 21bdf8e4 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-landing — 21bdf8e4 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-app — 21bdf8e4 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-diagnostics — 21bdf8e4 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