Repository navigation
fix: cache session usage and clarify turn field scopes - #173
Merged
Merged
Conversation
Accumulate usage when Session.send/3 records a turn so repeated Session
and SessionServer reads do not parse retained stdout. Preserve unknown
values, explicit zero, and exclusion of rejected turns.
Document that status, error and terminal_event cover the event stream,
while final_message and usage reset at turn.started. Test completion,
failure and top-level errors followed by a new turn start.
This PR changes Structured.decode/2 error precedence: turn.completed
followed by error now returns {:turn_failed, detail}. Previously a zero
exit could decode successfully and a nonzero exit returned
{:process_failed, detail}. A later terminal still supersedes an earlier
error.
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
Follow-up to #171, which was already merged when these review changes were applied. This branch includes current main, including #170, and the diff is limited to the six follow-up files.
Compatibility
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.For example, turn.started, turn.completed, turn.started still yields status :completed and the earlier terminal_event, but nil final_message and usage. Status reports the last terminal outcome in the stream, not completion of the last started turn. The module and README now describe this distinction explicitly.
Validation
Before the first follow-up push, both runtime matrices passed with 734 tests each. After syncing with current main, repeated every local CI check before the final push:
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.With Node 22.23.4,
mix codex.contractpassed for CLI 0.149.0, 0.164.0, and latest 0.166.0. The 95 focused projection, structured, session and evidence tests passed before syncing main.git diff --checkpassed. No live provider inference was invoked; the repository's four opt-in integration tests remain excluded. Release publication steps are main-only side effects and were not run.Final GitHub CI passed all five jobs on
00e9d57adaa2af8abe0b6aacf5500aa492fd921b: both Elixir/OTP jobs, Docs, and both pinned CLI contracts. CI run.