Skip to content

feat: add native Cloudflare Workflows executor for OpenCode Go tasks - #2

Merged
Pigbibi merged 1 commit into
mainfrom
feat/cloudflare-workflow-opencode
Dec 2, 2026
Merged

Pigbibi merged 1 commit into
mainfrom
feat/cloudflare-workflow-opencode

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

AI assistance

Antigravity (Gemini 4 Neon).

What changed

  • Added src/opencode-workflow-core.mjs and src/opencode-workflow.mjs (OpenCodeTaskWorkflow extends WorkflowEntrypoint) to run long OpenCode Go tasks natively inside Cloudflare Workflows using direct Durable Object stubs.
  • Added cloudflare_workflow adapter in src/agent-adapters.mjs and src/routing.mjs, eliminating external GitHub Actions triggers, duplicated API keys, and OAuth MCP token rotation for OpenCode Go async tasks.
  • Exported OpenCodeTaskWorkflow from src/index.mjs and src/worker.mjs.
  • Added unit tests covering cloudflare_workflow readiness/dispatch, 429 model fallback, Draft 2020-12 schema repair, and Durable Object claim/commit loop.

How verified

  • node --test test/routing.mjs (38/38 passed)
  • npm run build (passed)

@Pigbibi
Pigbibi merged commit 0e317cb into main Dec 2, 2026
@Pigbibi
Pigbibi deleted the feat/cloudflare-workflow-opencode branch December 2, 2026 18:40
@cgl-opencode-reviewer

Copy link
Copy Markdown

AI Code Review (opencode / glm-5.3)

The PR adds a Cloudflare Workflows-based executor for OpenCode Go agent tasks with reasonable security posture (untrusted-data framing of materials, manual redirects, no secrets in workflow params, store-side claim/commit with worker/attempt identifiers). The happy path works, but the dispatch is not idempotent, several critical control-flow paths (cancel, failure, contention, terminal-skip) are untested and depend on unverified TaskStore semantics, and the diff ships no Workers configuration registering the workflow class/binding, so the feature cannot run as submitted. There is also duplicated base-URL logic and some dead/redundant code in the inference loop.

Reviewed commit: ce118d2ba2 · Coverage: complete · Unresolved findings: true

Findings

  • [MEDIUM] src/agent-adapters.mjs: wakeAgent's cloudflare_workflow path is not idempotent: env[binding].create({id}) throws when an instance with the deterministic id already exists, so any event redelivery, submission retry, or re-wake of the same task/revision fails the whole wake request instead of being treated as already-dispatched. Additionally, stripping non-[A-Za-z0-9_-] chars and slicing to 64 chars can map two distinct task_ids to the same instance id (e.g. 'task.a' vs 'task/a'), permanently blocking the second task's workflow. Wrap create() with duplicate-instance handling and use a collision-free id derivation (or validate task_id charset upstream).
  • [MEDIUM] test/routing.mjs: Only the happy path is tested, and the TaskStore is fully mocked, so the real getCanonical/claim/commitReport signatures and post-claim status semantics are unverified. Untested critical paths: initial.status === 'cancel_requested' branch (dead code if claim() transitions status to 'running' — unverifiable with the mock), report-failed-* on inference exhaustion, terminal-status skip in claim/commit, the revision-changed contention loop ending in 'revision_kept_changing', stale-attempt commitReport behavior when another worker reclaimed the task, duplicate create() errors, and validateAgentTrigger cloudflare rejection paths (missing binding, base_url with query string, bad key_env). Add tests against the real store or a contract-accurate fake.
  • [MEDIUM] src/worker.mjs: The diff contains no wrangler/workers configuration change registering OpenCodeTaskWorkflow ([[workflows]] with class_name and the OPENCODE_WORKFLOW binding). Without it, env.OPENCODE_WORKFLOW is undefined in deployment, readiness permanently returns 'missing_workflow_binding', and the advertised feature is dead as shipped. The PR also claims 'Draft 2020-12 schema repair' is covered, but no schema-compatibility/repair code exists — the raw stored schema is sent verbatim under response_format strict:true, which many OpenAI-compatible endpoints reject with 400; that error just burns all fallback models and fails the task.
  • [LOW] src/opencode-workflow-core.mjs: Repair-loop defects: on failures that occur before content extraction (model_mismatch, incomplete_response, receipt parse errors) rawText is still '' yet is pushed as an assistant message, producing a degenerate repair prompt and wasted rounds for errors retrying cannot fix; and 'if (rateLimited) continue;' is redundant since the outer for-loop continues to the next model regardless of how the inner loop exited.
  • [LOW] src/opencode-workflow-core.mjs: resolveBaseUrl plus DEFAULT_OPENCODE_GO_BASE_URL duplicate resolveOpenCodeBaseURL and the same constant in src/api.mjs (same default URL, query-string rejection, trailing-slash strip). Extract a shared helper so the two validation paths cannot drift apart.
  • [LOW] src/agent-adapters.mjs: The cloudflare_workflow wake path performs no validation of event fields: an undefined/empty event.task_id silently produces instance id 't-undefined-r1' and a workflow bound to a nonexistent task, and remainingSeconds is silently ignored. Validate task_id/project/revision before create(), and document/handle the ignored timeout parameter.
  • [LOW] src/opencode-workflow-core.mjs: request.reasoning_effort is forwarded to the provider without the REASONING_EFFORTS allowlist that src/api.mjs enforces for direct API calls; the workflow path relies entirely on admission-time validation of the stored request_json. Apply the same allowlist (or reject unknown values) for defense in depth.

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