You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Medium risk] Adds token usage metrics to turn-end hook events.
No outstanding issue blocks merging.
What we checked:
Executed the referenced sources crates/jcode-compaction-core/src/lib.rs::effective_context_tokens_from_usage and crates/jcode-app-core/src/agent/turn_execution.rs::turn_token_usage_tests to validate the streaming path that stores the derived prompt count and the turn_end emission of PROMPT_TOKENS.
Ran normalization and aggregation tests, and observed that each revision passed 1 normalization test and 2 aggregation tests.
Noted that the only code-change between revisions was reformatting the aggregation expression.
Captured supporting artifacts documenting the run, including a shell script and two test-run logs for review.
Summary
The PR adds prompt-token totals to the turn_end hook and documents the new token fields. No outstanding issue blocks merging.
CI is currently blocked only by the repository code-size ratchet (scripts/check_code_size_budget.py). The substantive checks for this PR are passing (module resolution, formatting, Clippy, warning budget, and Linux build/tests). The guardrail reports unrelated oversized-file regressions across the merge tree, so I’m not changing unrelated code or refreshing the baseline in this scoped hook patch. Please let me know if you want this handled as a repository-level baseline/ratchet update.
Confirmed the guardrail failure is inherited: upstream master at 77f4f9d fails the same check_code_size_budget.py step even without #1700. I opened separate PR #1701 to synchronize the code-size baseline against current master (#692). That keeps this feature PR scoped to turn-end token usage.
Thanks for picking this up so fast. One request: could the hook also export JCODE_HOOK_PROMPT_TOKENS (summed prompt_tokens)?
With only INPUT_TOKENS a consumer can't tell whether cache is included. In my sessions, 292 of 13,916 cached rows under a Claude session have input_tokens == prompt_tokens, so the raw input alone gives the wrong uncached count. prompt - cache_read - cache_write works for every provider.
Implemented the requested JCODE_HOOK_PROMPT_TOKENS export in the existing turn-scoped aggregation path. It sums stored assistant prompt_tokens for the current turn, adds regression coverage, and documents the provider-reported semantics alongside the existing input/cache fields. The change stays scoped to the hook contract; the known repository code-size ratchet issue remains isolated in #1701.
Want your agent to iterate on Greptile's feedback? Try greploops.
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
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
turn_endhookstart_message_indexFixes #1697.
Validation
turn_endenvironment fieldsScope
Observer hook contract only; no changes to provider accounting or persisted session data.