Repository navigation
Attribute friction costs to audit sources - #64338
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation matches the stated behavior and includes appropriate coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Adds source-attributed friction costs to audit console output and documents their JSON representation.
Changes:
- Labels friction drivers and events with their source and available costs.
- Tests console rendering and JSON source attribution.
- Documents friction driver and event fields.
| File | Description |
|---|---|
pkg/cli/audit_report_render.go |
Renders source-attributed friction details. |
pkg/cli/friction_cost_test.go |
Verifies console and JSON output. |
docs/src/content/docs/reference/audit.md |
Documents friction reporting. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
No ADR enforcement needed: PR does not have the implementation label and has ≤100 new lines of code in business logic directories.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
Comment MemoryNote This comment is managed by comment memory.It stores persistent context for this thread in the code block at the top of this comment.
|
There was a problem hiding this comment.
Verdict
No blocking correctness or maintainability issue stood out in the changed lines.
What I checked
The renderer/docs/tests move together: source attribution is visible on both driver and event rows, unavailable AIC stays omitted instead of being printed as a misleading zero, and the JSON round-trip coverage still exercises the source-attributed fields.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 26.9 AIC · ⌖ 7.23 AIC · ⊞ 19.3K
Comment /review to run again
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /codebase-design and /tdd — 2 non-blocking suggestions, no correctness bugs found.
📋 Key Themes & Highlights
Key Themes
- Duplicated formatting logic:
frictionCostDetails(new,audit_report_render.go) mirrors the dimension-formatting conditionals already infrictionSummaryLine(friction_cost.go). Extracting a shared helper would prevent the two from drifting as new cost dimensions are added. - Driver vs. event AIC-gating asymmetry: the event renderer correctly consults
event.DimensionStates["aic"]to overrideevent.Statewhen deciding whether to showaic=, but the driver renderer only looks atdriver.State, which is currently hardcoded tounavailableinderiveFrictionFromLogs's aggregation loop and never revisited. Not a bug today (aggregated derived-driver costs are ToolCalls-only), but there's no test pinning this behavior, so a future change to driver aggregation could silently regress AIC visibility.
Positive Highlights
- ✅ New behavior is well covered:
TestRenderConsoleFrictionAttributesCostsToSourceand theTestAuditDataSerializesFrictionsource/cost assertions directly validate the PR's stated goal (source attribution surviving both console and JSON output). - ✅ Docs updated in lockstep with the JSON/console schema changes (
audit.md), and existing tests (TestRenderConsoleFrictionShowsAggregateAndEvents) were updated rather than left stale. - ✅
frictionSourceLabelcleanly handles the empty-source case ("unknown") rather than printing a blanksource=.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 59.7 AIC · ⌖ 14.5 AIC · ⊞ 10K
Comment /matt to run again
| return source | ||
| } | ||
|
|
||
| func frictionCostDetails(cost FrictionCost, aicState string) string { |
There was a problem hiding this comment.
[/codebase-design] frictionCostDetails re-implements the same dimension formatting already present in frictionSummaryLine (friction_cost.go:161-190) — same tokens/turns/tool-calls/latency conditionals, duplicated verbatim across two files.
💡 Suggested fix
Extract a single shared helper (e.g. formatFrictionCostParts(cost FrictionCost, aicState string) []string) that both frictionSummaryLine and frictionCostDetails call, so future dimension additions (e.g. a new cost axis) only need one edit site instead of two that can drift apart.
@copilot please address this.
There was a problem hiding this comment.
Shared the token, turn, tool-call, and latency formatting between aggregate and driver/event output in pkg/cli/friction_cost.go (d15f9cd). The existing AIC, ratio, and uncertainty ordering is preserved.
There was a problem hiding this comment.
Reviewed with a standard correctness/maintainability pass (this is Go CLI console-output formatting, not a UI/frontend change, so Impeccable audit/critique/harden modes don't directly apply).
Findings: none blocking.
frictionSourceLabeldefaulting to"unknown"matches existing codebase conventions (seeaudit_diff.go,gateway_logs_types.go, etc.).- Driver-level
frictionCostDetailsgates AIC display offdriver.Statewhile event-level gates offevent.DimensionStates["aic"]when present — this is intentional sinceFrictionDriverSummaryhas no per-dimension state map, and behavior matches new/updated tests. - New tests (
TestRenderConsoleFrictionAttributesCostsToSource, JSON source-attribution assertions inTestAuditDataSerializesFriction) directly cover the new behavior and pass. go build ./pkg/cli/...,go vet ./pkg/cli/..., andgo test ./pkg/cli/... -run Frictionall pass;gofmt -lreports no issues.- Docs update in
audit.mdaccurately describes the newfriction.drivers[]/friction.events[]fields and console format.
No actionable issues found.
🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet50 · 53.4 AIC · ⌖ 13.1 AIC · ⊞ 8.1K
|
@copilot run pr-finisher skill |
|
@copilot please review the latest comments, refresh the branch if needed, and run the pr-finisher skill before handing this back for maintainer review.
|
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…on-cost-identification Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Ran the PR finisher pass: addressed the review suggestion in d15f9cd, merged current |
PR #64338 was merged by a maintainer at 21:43 UTC before this pass. The prior finisher changes and branch refresh are included in the merged head (eadce86); no further branch changes are appropriate. |
|
🎉 This pull request is included in a new release. Release: |
Audit friction totals don’t show which source incurred the cost. This change makes source- and driver-level costs visible in console and JSON output.
friction.drivers[]andfriction.events[].