Skip to content

fix(sdk-python): count opencode turns from JSON step events#546

Merged
AbirAbbas merged 2 commits intoAgent-Field:mainfrom
ivasuy:fix/opencode-num-turns-518
May 7, 2026
Merged

fix(sdk-python): count opencode turns from JSON step events#546
AbirAbbas merged 2 commits intoAgent-Field:mainfrom
ivasuy:fix/opencode-num-turns-518

Conversation

@ivasuy
Copy link
Copy Markdown
Contributor

@ivasuy ivasuy commented May 7, 2026

Summary

Fixes HarnessResult.num_turns for provider="opencode" in the Python SDK.
Instead of reporting 1 whenever text output exists, the provider now parses OpenCode JSON events and counts actual turns from step_start events (with fallback behavior). Added regression coverage to ensure multi-step runs report num_turns > 1. This PR also hardens the newer JSON-stream path so OpenCode-specific output is handled correctly: assistant text is extracted from type:"text" part.text events, multi-part text within a step is accumulated, per-step stream cost is preferred over prompt/completion estimation when available, and in-band type:"error" events are surfaced as real failures instead of falling through as empty success.

Testing

  • ./scripts/test-all.sh

  • Additional verification (please describe):

    • python3 -m venv .venv && .venv/bin/python -m pip install -r sdk/python/requirements-dev.txt
    • .venv/bin/python -m pytest sdk/python/tests/test_harness_provider_opencode.py -v

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)

Not applicable (no UI changes).

Related issues

Fixes #518

@ivasuy ivasuy requested review from a team and AbirAbbas as code owners May 7, 2026 03:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Performance

SDK Memory Δ Latency Δ Tests Status
Python 9.4 KB +4% 0.32 µs -9%

✓ No regressions detected

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 86%, aggregate ≥ 88%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 87.40% 87.30% ↑ +0.10 pp 🟡
sdk-go 91.90% 90.70% ↑ +1.20 pp 🟢
sdk-python 93.66% 93.63% ↑ +0.03 pp 🟢
sdk-typescript 92.68% 92.56% ↑ +0.12 pp 🟢
web-ui 89.81% 90.01% ↓ -0.20 pp 🟡
aggregate 88.92% 89.01% ↓ -0.09 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 ➖ no changes
sdk-go 0 ➖ no changes
sdk-python 0 ➖ no changes
sdk-typescript 0 ➖ no changes
web-ui 0 ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b10731bdb4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/python/agentfield/harness/providers/opencode.py
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6e38e231a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/python/agentfield/harness/_cli.py
@ivasuy ivasuy force-pushed the fix/opencode-num-turns-518 branch from f6e38e2 to 804d189 Compare May 7, 2026 09:47
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 804d1896da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread sdk/python/agentfield/harness/providers/opencode.py
@ivasuy ivasuy force-pushed the fix/opencode-num-turns-518 branch from 804d189 to 2aad82f Compare May 7, 2026 10:09
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@AbirAbbas AbirAbbas enabled auto-merge May 7, 2026 12:44
@AbirAbbas AbirAbbas added this pull request to the merge queue May 7, 2026
Merged via the queue into Agent-Field:main with commit d134751 May 7, 2026
27 checks passed
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.

HarnessResult.num_turns hard-coded to 1 for opencode provider

2 participants