feat(brain): surface cost_unit aggregation in event_counts#958
Conversation
ADR-103 Amendment 1 (#918) specified batch-scaled cost_unit; PR #927 stamps payload.resource.cost_unit on every successful dispatch's audit event. brain.event_counts never read it. Extend the handler to sum resource.cost_unit into total_cost_unit and cost_unit_by_verb, using the same aggregate-in-handler / omit-when-empty style as counts_by_kind / counts_by_actor / counts_by_work_class. Additive only: no change to existing fields or behavior. Events with no resource.cost_unit (pre-#927 events, or errored/denied dispatches, per Amendment 1's "absence has exactly two meanings" rule) simply do not contribute. Sums saturate on i64 overflow rather than panicking, mirroring cost_unit.rs's own overflow-clamp convention. When the 50k window cap truncates the page, both sums are documented as computed over the fetched page only, same as the other counts_by_* fields. Updates the verb's help description, its doc comment, and the event_counts section of docs/guide/api-reference.md and AGENTS.md's brain-pack verb table. Fixes #955
|
APPROVE-WITH-FIXES Findings: 0 Blocker, 0 High, 0 Medium, 1 Low [Low] Update the stale
|
Successful-dispatch audit rows have written payload.resource.work_class since the cost-unit enrichment landed; the helper doc claimed no producer writes that path. Addresses the review finding. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ky tx-age sweep run_writer_task registers a writer_task_tx handle in the process-wide tx_registry singleton; the checkpoint tx_age_sweep_* tests read that singleton under #[serial(tx_registry)]. The writer_task.rs tests that spawn a writer task were missing from the group, leaking a longer-lived writer_task_tx into the sweep's oldest() read and intermittently failing the assertion on main CI. Join them to the serial group. No prod change.
|
Codex static review: APPROVE at b66fbf6 (0 blocking findings). |
oceanwaves630
left a comment
There was a problem hiding this comment.
Reviewed against the posted review artifacts and CI rollup. Approved.
Summary
payload.resource.cost_uniton every successful verb dispatch's audit event since it merged, butbrain.event_counts(ADR-103 Stage 1, Read surface: windowed event counts (per-actor, per-kind) + section co-usage aggregates #724 Ask A) never read or surfaced it.brain.event_countsto sumpayload.resource.cost_unitinto two new response fields,total_cost_unitandcost_unit_by_verb, following the same aggregate-in-handler / omit-when-empty style already used bycounts_by_kind/counts_by_actor/counts_by_work_class.resource.cost_unit(pre-feat(runtime): emit resource.cost_unit per ADR-103 Amendment 1 #927 events, or errored/denied dispatches, per Amendment 1's "absence has exactly two meanings" rule) simply do not contribute to either sum.event_countssections ofdocs/guide/api-reference.mdandAGENTS.md's brain-pack verb table.Closes #955
Downstream
Flagging for the lambda gate read: #931 (measured per-verb weights table) is the consumer waiting on this read path to validate/calibrate
cost_unitweights against real dispatch volume.Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test -p khive-pack-brain(235 tests, including 5 new/updatedevent_countscost_unit tests: sum + per-verb split, absence handling, window filtering, saturating overflow)cargo test -p khive-runtime(907 tests)RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p khive-pack-brain🤖 Generated with Claude Code