Skip to content

feat(parser): detect opencode bash tool failures from metadata.exit - #1257

Merged
mjacobs merged 3 commits into
kenn-io:mainfrom
ajinkyajacob:feat/opencode-metadata-exit-failure-detection
Jul 24, 2026
Merged

feat(parser): detect opencode bash tool failures from metadata.exit#1257
mjacobs merged 3 commits into
kenn-io:mainfrom
ajinkyajacob:feat/opencode-metadata-exit-failure-detection

Conversation

@ajinkyajacob

@ajinkyajacob ajinkyajacob commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Problem

OpenCode bash tool failures leave metadata.exit > 0 in the tool state but the output text does NOT contain the exit status N pattern that AgentsView's isBashFailure() checks. This is not Windows-specific: on a Linux opencode.db, all 24 bash parts with a non-zero exit (1, 127, 128) had output text with no exit status marker, while all 81 successful parts recorded exit=0. Example outputs from real sessions:

  • 'choco' is not recognized as an internal or external command - exit=1, no "exit status" text
  • (empty output) - exit=1, no text at all
  • rsync error: some files could not be transferred - exit=1

The exit code is reliably recorded in metadata.exit by the agent, but the parser never reads it.

Impact

On a Windows machine with 273 opencode sessions, 1233 bash tool failures are missed because they lack the exit status output pattern. Only 51 are currently detected (via the tool:"invalid" fix). The remaining ~1200 are invisible to signals, insights, and health scoring.

Fix

In extractOpenCodeToolCall(), after parsing the tool state, check metadata.exit:

if len(state.Metadata) > 0 {
    var m struct { Exit int `json:"exit"` }
    if err := json.Unmarshal(state.Metadata, &m); err == nil && m.Exit > 0 {
        isFailure = true
    }
}

This is opt-in per agent - only opencode records metadata.exit. Other agents are unaffected.

dataVersion moves to 73 so existing opencode rows are re-parsed and historical sessions backfill the failure events, and the format evidence is recorded in docs/internal/session-format-sources.md.

Branch

https://github.com/ajinkyajacob/agentsview/tree/feat/opencode-metadata-exit-failure-detection

Risk

  • Non-zero exit doesn't always mean failure (e.g., grep returns 1 for no match). However, AgentsView's existing exitStatusRe already makes the same assumption via output text. This just adds parity for the metadata path.
  • Only applies when metadata key exists in the tool state (opencode format), so other agents are isolated.

@roborev-ci

roborev-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown

roborev: Combined Review (69274d4)

Verdict: One medium-severity issue must be addressed before merging.

Medium

  • internal/db/db.go:324 — The parser now persists new tool-result events, but dataVersion remains 71. Existing unchanged OpenCode sessions will retain stale parsed data and incorrect failure analytics indefinitely. Increment dataVersion and document that OpenCode sessions require reparsing to backfill failure events.

Reviewers: 2 done | Synthesis: codex, 9s | Total: 3m9s

ajinkyajacob and others added 2 commits July 24, 2026 11:06
Non-zero exit codes in bash tool metadata indicate tool failure,
even when output text lacks Linux-style 'exit status N' pattern.
This is especially important on Windows where cmd.exe and PowerShell
use different error output formats.
The parser now emits errored result events for opencode bash tool calls
whose state metadata records a non-zero exit. Without a dataVersion bump,
unchanged opencode sessions keep their stale parse and never gain the
failure signal, so tool-health analytics stay wrong indefinitely.

Bump dataVersion to 73 so existing rows are re-parsed and historical
sessions backfill the failure events.

Record the format evidence in the provenance doc: the bash tool's
structured output carries the child exit code, that output is persisted
as the tool part's state.metadata, and the output text never carries an
"exit status N" marker, so text matching alone misses these failures on
every platform. Verified against a live opencode.db where all 24 bash
parts with a non-zero exit lacked the marker.

Expand the parser test to a table covering non-zero exit, zero exit,
metadata without an exit key, and absent metadata.
@mjacobs
mjacobs force-pushed the feat/opencode-metadata-exit-failure-detection branch from 69274d4 to 03ade78 Compare July 24, 2026 18:41
@roborev-ci

roborev-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown

roborev: Combined Review (03ade78)

No issues found.


Reviewers: 2 done | Synthesis: codex | Total: 2m51s

@mjacobs

mjacobs commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

found an edge case that should be handled, updating PR soon

@roborev-ci

roborev-ci Bot commented Jul 24, 2026

Copy link
Copy Markdown

roborev: Combined Review (56e82d7)

Code looks clean overall; no Medium, High, or Critical findings were reported.


Reviewers: 2 done | Synthesis: codex, 5s | Total: 4m7s

@mjacobs
mjacobs merged commit 1989908 into kenn-io:main Jul 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants