Skip to content

OpenCode: parse usage, cost and finish reason from step_finish.part #1433

Description

@pauravhp

Summary

Cyrus does not currently parse OpenCode usage, cost and finish-reason information from the event fields where OpenCode emits them.

Current behavior

Cyrus reads these values from the top level of a step_finish event.

OpenCode's current event shape places them inside step_finish.part, causing Cyrus to record missing or inaccurate session accounting.

Expected behavior

Cyrus should parse the current OpenCode event shape and record usage, cost and finish reason accurately.

Why this matters

Incorrect accounting makes OpenCode sessions harder to observe and can produce inaccurate usage and cost reporting.

Acceptance criteria

  • Usage is read from the current step_finish.part fields.
  • Cost is recorded accurately.
  • The actual finish reason is preserved.
  • Missing optional values are handled safely.
  • A single event is not counted more than once.
  • Top-level fields can remain as a backwards-compatible fallback if needed.
  • Test fixtures reflect real OpenCode JSON output.

Validation

Add tests using a representative real OpenCode step_finish event.

The tests should cover:

  • Successful completion.
  • Interrupted or stopped completion.
  • Usage and cost values.
  • Cache-token values where present.
  • Missing optional fields.
  • Protection against duplicate accounting.

Include a live smoke test showing that a completed OpenCode session records non-empty usage and the correct finish reason.

Related

Identified while validating #1263.

Observed on main at b936752.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions