fix(harness): correct OpenCode v2 errors and command handling

Closed
TB
9d ago
+184-19

Summary

Follow-up fixes for https://github.com/dagucloud/dagu/pull/3367. This PR targets your codex/opencode-v2-compatibility branch so it can be merged into the existing contribution without duplicating its changes upstream.

Based on 85e9c8b; one additional commit, four changed files. You can merge this PR or cherry-pick ca66e59161c405aa508fe38b2f47ce42937a77dd.

Changes

  • Decode v2 404 error tags instead of treating every session-scoped 404 as a missing session. Unknown commands/models and missing locations now remain execution errors; actual missing sessions retain the unavailable state, including interaction and message-history requests. V1 mapping is unchanged.
  • Preserve assistant snapshot.files as a stable patch event for the existing timeline and changed-file previews.
  • Let v2 command preparation use the workflow context deadline instead of the generic 30-second HTTP timeout, matching the v1 command path.
  • Add regressions for typed and malformed 404 responses, changed-file metadata, slow commands, and cancellation after command acknowledgement.
  • Extend real-v2 verification with a command containing a 31-second shell substitution and an unknown command that fails while its session remains available.
  • Link managed OpenCode documentation from the README action table.

Related Issues

Related to dagucloud/dagu#3367; this is not a replacement for or closure of that PR.

Validation

The snapshot, error-classification, and slow-command regression tests failed against the original implementation before applying the fixes.

Passed locally:

go test -race ./internal/opencodehost ./internal/runtime/builtin/harness ./internal/cmn/config
go test -race ./internal/runtime/builtin/harness -run '^TestV2(Snapshot|NotFound|SlowCommand|AdmittedCancellation|CommandCancellation)$' -count=10
go vet ./internal/opencodehost ./internal/runtime/builtin/harness ./internal/cmn/config
go fix -embedlit=false -diff ./internal/opencodehost ./internal/runtime/builtin/harness ./internal/cmn/config
git diff --check

Formatting checks for the three modified Go files produced no differences.

Real OpenCode v2.1.4 verification, including prompt, template command, slow command, unknown command, permission approval, question answer/resume, and deletion, passed with race detection:

npm ci --prefix .github/opencode --no-audit --no-fund
DAGU_TEST_OPENCODE_V2_EXECUTABLE="$PWD/.github/opencode/node_modules/@opencode/cli-linux-x64-baseline/bin/opencode" \
  go test -race ./internal/runtime/builtin/harness -run '^TestRealV2Run$' -count=1 -v

Latest result: PASS, package time 43.827s.

Validation limits: repository-wide make fmt timed out during go fix; broad lint was not completed. Harness conformance timed out building the binary before running tests. Real v1.18.11 verification repeatedly failed during startup/preflight before adapter execution; its root cause remains unresolved. No full-suite or real-v1 compatibility claim is made.

Checklist

  • Repository-wide style/lint validation completed
  • Self-review of the code has been performed
  • Tests have been added or updated as needed
  • Documentation has been updated as needed
  • Changes have been tested locally with the scoped checks above