Repository navigation
Persist compaction token savings as per-run policy stats (#18) - #19
Merged
Merged
Conversation
…and exposed (#18) step events carrying compaction were silently dropped. Aggregate them into run_policy_stats (tenant_id, run_id, policy, stats_json), in the same transaction and behind the same idempotency check as the step. Expose as policy_stats on GET /v1/run-records/{run_id} and in the run detail UI. Also drop the stale has_hook default from the admin policy template. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Closes #18 (Phase 1).
Problem
stepevents carryingcompactionwere dropped by_apply_step's key whitelist, so tokens saved never reached storage, the API or the UI.Change
run_policy_stats(tenant_id, run_id, policy, stats_json): additive, created by_SCHEMA,user_versionunchanged. Numeric fields are summed andcallscounted, so other policies can report metrics without a schema change.runsis untouched._apply_step, in the batch transaction and after the idempotency check, so replays do not double count. Independent of the 64-steprun_statering.GET /v1/run-records/{run_id}returnspolicy_stats, scoped to the caller's tenant. The run detail UI shows tokens saved.has_hookdefault from the admincontext_compactiontemplate.Notes
tokens_afteris summed across calls (total sent after compaction).policy_stats.Tests
52 pass, including new cases for aggregation, replay dedupe, more than 64 steps, the read path and no-compaction.
🤖 Generated with Claude Code