Skip to content

Persist compaction token savings as per-run policy stats (#18) - #19

Merged
susheem-k merged 1 commit into
mainfrom
fix/18-compaction-policy-stats
Sep 19, 2026
Merged

susheem-k merged 1 commit into
mainfrom
fix/18-compaction-policy-stats

Conversation

@susheem-k

Copy link
Copy Markdown
Contributor

Closes #18 (Phase 1).

Problem

step events carrying compaction were dropped by _apply_step's key whitelist, so tokens saved never reached storage, the API or the UI.

Change

  • New table run_policy_stats(tenant_id, run_id, policy, stats_json): additive, created by _SCHEMA, user_version unchanged. Numeric fields are summed and calls counted, so other policies can report metrics without a schema change. runs is untouched.
  • Written in _apply_step, in the batch transaction and after the idempotency check, so replays do not double count. Independent of the 64-step run_state ring.
  • GET /v1/run-records/{run_id} returns policy_stats, scoped to the caller's tenant. The run detail UI shows tokens saved.
  • Contract §5 and §13 updated. Removed the stale has_hook default from the admin context_compaction template.

Notes

  • Values are chars/4 estimates.
  • tokens_after is summed across calls (total sent after compaction).
  • The list endpoint does not include policy_stats.
  • Contract version label "0.2.2" in the doc is a placeholder; no version bump or CHANGELOG entry yet.

Tests

52 pass, including new cases for aggregation, replay dedupe, more than 64 steps, the read path and no-compaction.

🤖 Generated with Claude Code

…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>
@susheem-k
susheem-k merged commit d39f82e into main Sep 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction token savings are dropped by the control plane: step events carry them, nothing stores or exposes them

1 participant