Skip to content

remove OpenCode serve+attach workaround for stateless CLI#326

Open
AdityaNair-jpg wants to merge 1 commit intoAgent-Field:mainfrom
AdityaNair-jpg:refactor/opencode-stateless-cli
Open

remove OpenCode serve+attach workaround for stateless CLI#326
AdityaNair-jpg wants to merge 1 commit intoAgent-Field:mainfrom
AdityaNair-jpg:refactor/opencode-stateless-cli

Conversation

@AdityaNair-jpg
Copy link
Copy Markdown
Contributor

@AdityaNair-jpg AdityaNair-jpg commented Apr 1, 2026

Summary

This PR refactors the OpenCode harness provider to use a simple, stateless CLI subprocess pattern. This change removes the previous "serve+attach" workaround which was required to bypass a "Session not found" bug in headless mode (upstream issue opencode#13851).

Key improvements include:

  • Architectural Cleanup: Deleted ~120 lines of fragile process management code (port hunting, background server spawning, and cleanup hooks).
  • Stateless Execution: Reverted to direct opencode run calls, aligning with the pattern used by Gemini and Codex providers.
  • API Purity: Removed the opencode_server field from HarnessConfig and simplified directory routing in the core runner.
  • Preserved Features: Maintained the concurrency limiter and --dir project isolation support.

Testing

  • ./scripts/test-all.sh
  • Additional verification:
    • Verified 8/8 unit tests in sdk/python/tests/test_harness_provider_opencode.py pass using new mocks.
    • Verified tests/debug_complex_json.py correctly reaches execution phase.
    • Manually verified that opencode run without a temp subdirectory correctly writes to the target project_dir.

Checklist

  • I updated documentation where applicable.
  • I added or updated tests (or none were needed).
  • I updated CHANGELOG.md (or this change does not warrant a changelog entry).

Screenshots (if UI-related)

No UI changes; logic refactor only.

Closes #221

Related issues

Fixes #206
References #210, #220

@AdityaNair-jpg AdityaNair-jpg requested review from a team and AbirAbbas as code owners April 1, 2026 19:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

Performance

SDK Memory Δ Latency Δ Tests Status
Python 9.3 KB +4% 0.23 µs -34%

✓ No regressions detected

@AbirAbbas
Copy link
Copy Markdown
Contributor

Manual Testing Failed — CLI Interface Mismatch

Tested locally against OpenCode v0.0.55 (latest release as of 2026-04-01). The provider builds commands using opencode run --model <model>, but the installed CLI doesn't support the run subcommand or --model flag.

Reproduction

from dotenv import load_dotenv
load_dotenv()

import asyncio
from agentfield.harness.providers.opencode import OpenCodeProvider

async def test():
    p = OpenCodeProvider()
    r = await p.execute('say hello', {'model': 'openai/gpt-4o'})
    print('error:', r.is_error)
    print('failure_type:', r.failure_type)
    print('output:', (r.result or '')[:200])
    print('error_msg:', (r.error_message or '')[:200])

asyncio.run(test())

Output

error: True
failure_type: FailureType.CRASH
output: 
error_msg: Error: unknown flag: --model
Usage:
  opencode [flags]

Examples:

  # Run in interactive mode
  opencode

  # Run with debug logging
  opencode -d

  # Run a single non-interactive prompt
  opencode -p "Explain the use of context in Go"

Flags:
  -c, --cwd string             Current working directory
  -d, --debug
  -p, --prompt string          Run a single non-interactive prompt
  -f, --format string          Output format (text, json)
  -v, --version                Print version

Details

  • Installed version: v0.0.55 (latest release, confirmed via gh api repos/opencode-ai/opencode/releases/latest)
  • Installed via: go install github.com/opencode-ai/opencode@latest
  • The current CLI uses -p for prompts and -c for cwd — no run subcommand, no --model or --dir flags.

The refactor itself is structurally clean, but the target CLI interface (opencode run --model X --dir Y <prompt>) doesn't exist in any released version. Could you clarify which version this targets?

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.

Simplify OpenCode provider once upstream fixes headless mode (opencode#13851) [SDK] OpenCode provider for .harness()

2 participants