Repository navigation
feat: add typed turn results and session usage totals - #171
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #150.
Callers can now inspect JSON command output through
CodexWrapper.Turn.from_result/1without parsing stdout themselves or requiring the final answer to be JSON. The projection exposes status, exit code, thread ID, final agent message, normalized usage, native error data, and parsed events.%Result{}is unchanged.session.last_turnandSession.last_turn/1, plusSession.total_usage/1. SessionServer provides both accessors. Session sends and history retain their existing raw Result contract.turn; nativeparsed_resultremains a raw terminal event independent of process status. Final evidence replacing streamed stdout no longer leaves a stale terminal event.Validation
Ran the complete local check matrix before both pushes:
Both runtimes passed
mix deps.get,mix deps.unlock --check-unused,mix hex.audit,mix compile --warnings-as-errors,mix format --check-formatted,mix credo --strict,mix dialyzer,mix test, andmix docs --warnings-as-errors.mix codex.contractpassed with Node 22.23.4 for CLI 0.149.0, 0.164.0, and latest 0.166.0. The contracts do not invoke inference. The 91 targeted projection, structured, session and evidence tests also passed;git diff --checkpassed.Final GitHub CI for
cd602af95f5096a19504ec8d1d60227a4f7eaf73: all five jobs passed, including both runtime jobs, Docs, and both pinned CLI contracts. CI run.Acceptance
Compatibility and limits
Structured.decode/2intentionally changes error precedence for existing callers. Giventurn.completedfollowed by a top-levelerrorwith no later terminal event, it returns{:error, {:turn_failed, detail}}at both zero and nonzero process exits. Previously, a zero exit could decode successfully, while a nonzero exit returned{:error, {:process_failed, detail}}. This follows the documented event-order rule and issue #150. A later terminal event still supersedes an earlier error. The follow-up commit message also records this compatibility change.The existing Session error and history rules are preserved: rejected nonzero exits do not update the session or contribute to recorded usage totals. A total field remains nil when no recorded turn reports a valid value; partially reported totals cover only known values. ExecutionObservation.parsed_result remains native evidence rather than a success assertion.
All new fixtures are synthetic. Live provider inference was not run; the four opt-in integration tests remain excluded as in CI. Release publication steps were not run because they publish artifacts and are not PR checks.
Review follow-up
PR #173 documents and tests the stream-wide versus last-turn field scopes and caches session usage totals during sends so reads do not reparse retained stdout. #171 was already merged when those follow-up changes were applied.