Skip to content

fix(cli): attribute step events to their model in run json output - #44462

Closed
Enough1122 wants to merge 1 commit into
anomalyco:v2from
Enough1122:run-json-model-attribution
Closed

fix(cli): attribute step events to their model in run json output#44462
Enough1122 wants to merge 1 commit into
anomalyco:v2from
Enough1122:run-json-model-attribution

Conversation

@Enough1122

Copy link
Copy Markdown

Issue for this PR

Closes#40544

Type of change

  • Bug fix

What does this PR do?

opencode run --format json emitted step_start/step_finish without any model reference, so a headless consumer could not attribute tokens or cost - especially across mid-session model switches or subagents running a different model. The core session.step.started event already carries the model (the human output prints it), so the JSON path now stamps providerID/modelID onto step_start from the event and onto step_finish from the in-flight capture, clearing it when the step ends.

How did you verify your code works?

  • bun run typecheck (packages/cli): clean
  • additive keys on JSON events; the v1-compatibility pendingStep path inherits them through the same part object

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

opencode run --format json emitted step_start/step_finish without any model reference, so headless consumers could not attribute tokens or cost across model switches or subagents. The core session.step.started event already carries the model; capture it and stamp providerID/modelID onto both JSON parts, clearing it when the step ends.
Fixesanomalyco#40544
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #40545: fix(opencode): add model attribution to run --format json events
#40545

This PR appears to be directly related to the current PR #44462. Both are focused on adding model attribution (providerID/modelID) to run --format json output. PR #40545 specifically addresses model attribution to events, which is exactly what the current PR is doing for step events.

Since the current PR (#44462) closes issue #40544 and is also about attributing step events to their model in JSON output, you should verify whether #40545 already addresses this or if they're complementary changes to different aspects of the same feature.

@Enough1122

Copy link
Copy Markdown
Author

Heads up that #40545 (fix(opencode): add model attribution to run --format json events) opened earlier covers the same issue. Not attached to landing this separately - happy to consolidate or close in favor of it if the maintainers prefer that approach; leaving this up because it ships with its own tests that could be salvaged either way.

@Enough1122

Copy link
Copy Markdown
Author

Similar work landed in #40545 against packages/opencode/src/cli/cmd/run.ts, which no longer exists on v2 (the noninteractive runner lives in packages/cli/src/run/noninteractive.ts now). This PR carries the same attribution over to the current tree.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@Enough1122