opencode icon indicating copy to clipboard operation
opencode copied to clipboard

cli: opencode stats reports no tool calls when all calls are still running

Open 521ox opened this issue 1 week ago • 4 comments

Description

When the only tool call in the selected range is still running, the default opencode stats card says no tool calls. The detailed and JSON views correctly count that call. A success rate is not available yet, but that is different from zero calls.

Steps to reproduce

  1. Use a fresh project that has a single pending tool call, for example a question waiting for a reply, and no completed or failed calls in the range.
  2. Before the call finishes, compare opencode stats --project . --days 1, the same command with --tools, and with --json.
  3. The card says no tool calls; the detail view says 0 finished calls · 1 unfinished; JSON reports calls: 1 and unfinished: 1.

Verified with the production Core projector and stats collector in an in-memory database. A loopback fixture replayed their outputs to the unmodified CLI, which printed the same discrepancy in 3/3 runs. Controls: before the call the card correctly reported no calls; after successful completion it reported 100.0% tool success. No live provider or user database was involved.

OpenCode version

V2 dev at 22377659a8ed223f3eebc86660dd1a5bc2b33ca5 (2.3.0).

Operating System

Windows 11 x64, Bun 1.4.4.

Terminal

CLI subprocess with captured stdout; no TUI or third-party plugins.

521ox avatar Nov 18 '26 10:11 521ox

Thanks for the detailed report. I tried this on opencode v2.3.0 with a simulated model. I started a session whose only tool call was a shell command (in a second run, an unanswered question), then ran opencode stats --project . --days 1, the same with --tools, and with --json, while the call should have been pending. In my runs all three views agreed: the card and --tools both said no tool calls, and the JSON had calls: 0 and unfinished: 0. I couldn't confirm the pending call had actually started, though, so this attempt doesn't rule out the problem.

From reading the code, the default card does print no tool calls whenever no call has succeeded or failed yet, without checking the unfinished count. The --tools view does show the unfinished count. This logic looks the same on the latest dev (d412042), so your description of the rendering matches the code. What I couldn't see myself is a live session where the server reports an unfinished call and nothing finished.

These would help:

  • Can you reproduce it with your normal opencode and a real session (no fixture)? For example, ask something that makes the agent ask a question, leave it unanswered, and run the three commands from the same project directory.
  • If so, please paste the three outputs, the tools section of the JSON included.
  • Does it still happen on a newer release (2.3.2)?

opencodejr[bot] avatar Nov 18 '26 10:11 opencodejr[bot]

I pushed a focused fix in e45e416: the card shows 1 unfinished tool call (or its plural) when calls exist but none has finished. The success rate still uses only completed/failed outcomes.

Automated local checks: 16 CLI stats tests pass (the two unfinished cases fail on the base), 48 adjacent collector/projector tests pass, and the root bun run check passes all 35 tasks. A separate proof publishes synthetic tool events through the real Bus/projector and in-memory SQLite collector into the CLI renderer: the base says no tool calls; the candidate reports the unfinished call and then 100.0% tool success after completion. This is local production-boundary evidence, not a live provider session.

Diff against dev. PR creation remains unavailable to this account, so I am sharing the tested branch here.

1052326311 avatar Nov 18 '26 12:11 1052326311

Thanks, @521ox, and thanks @1052326311 for the patch. I'm closing this for now because we still can't reproduce it in a real session. The rendering logic you describe is real: the default opencode stats card shows no tool calls whenever no call has succeeded or failed, even if one is still unfinished. But in my runs on opencode v2.3.0, the stats command saw zero calls in every view while the call was pending, and both the original report and the proposed fix rely on synthetic or replayed events. What's still missing is the output of opencode stats --project . --days 1, with --tools and with --json, from a real session that has an unanswered tool call (for example a pending question). If you can share that, or it still happens on 2.3.2, replying here reopens the issue.

opencodejr[bot] avatar Nov 18 '26 16:11 opencodejr[bot]

I reproduced this with a normal server and session, using a local scripted OpenAI-compatible model, not an external provider. This executes the real runner and question tool; it does not inject events or edit the database. The unanswered form and persisted message both show question in running state. Current dev's stats renderer is unchanged from my tested baseline (blob b6507ab4).

While that one question remained unanswered, the CLI commands against the same server/project returned:

opencode stats --project . --days 1
1 session
1 prompt · 1 step · 0 tokens
no tool calls · 1 active day · best streak 1 day

opencode stats --project . --days 1 --tools
question   1   -   -
0 finished calls · 1 unfinished

opencode stats --project . --days 1 --json
"tools": {
  "mode": "detail",
  "totals": {"calls": 1, "succeeded": 0, "failed": 0, "unfinished": 1},
  "usage": [{"name": "question", "calls": 1, "succeeded": 0, "failed": 0, "unfinished": 1}]
}

With e45e4169, the default card reads 1 unfinished tool call; the other two outputs are unchanged. The commands use an explicit --server connection to an isolated source CLI server. Only the model response is simulated; no live-provider test is claimed.

1052326311 avatar Nov 19 '26 01:11 1052326311