Skip to content

Surface AWF steering counters in compact audit usage data - #63664

Merged
pelikhan merged 5 commits into
mainfrom
copilot/update-audit-command-steering-events
Sep 26, 2026
Merged

pelikhan merged 5 commits into
mainfrom
copilot/update-audit-command-steering-events

Conversation

Copilot AI commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Audit required full firewall artifacts to inspect AWF steering behavior. Compact usage artifacts now expose aggregate counters for each steering event type.

  • Usage payload

    • Parse AWF API proxy event logs across supported filenames and schema variants.
    • Add normalized steering totals and per-type counters to usage/activity/summary.json.
  • Audit reporting

    • Backfill steering metrics into firewall_token_usage for usage-only audits.
    • Preserve detailed firewall analysis when available.
  • Contract

    • Extend the audit schema and artifact documentation.
    • Add regression coverage for event aggregation and usage-summary backfill.
{
  "total_steering_events": 3,
  "steering_event_counts": {
    "token_steering": 2,
    "timeout_steering": 1
  }
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan September 26, 2026 19:21
@pelikhan
pelikhan marked this pull request as ready for review September 26, 2026 19:45
Copilot AI balanced review requested due to automatic review settings September 26, 2026 19:45
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Lean already. Ship.

Generated by Ponytail Reviewer for #63664

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer failed during the skills-based review.

Warning

Threat Detection Engine Failure — The analysis engine could not complete. This is a tooling failure, not a security finding.

What happened

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Event-file selection and typed payload decoding can silently omit valid steering events.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds per-type AWF steering counters to compact usage artifacts and exposes them through audit token-usage reporting.

Changes:

  • Aggregates steering events across supported filenames and schemas.
  • Backfills usage-only audit results with steering totals and counters.
  • Extends schemas, documentation, and regression coverage.
File Description
.changeset/​minor-audit-gateway-steering.md Updates the release note.
actions/​setup/​js/​generate_usage_activity_summary.cjs Adds steering aggregation to usage summaries.
actions/​setup/​js/​generate_usage_activity_summary.test.cjs Tests summary steering aggregation.
actions/​setup/​js/​steering_helpers.cjs Adds per-type event counting.
actions/​setup/​js/​steering_helpers.test.cjs Tests schema variants and counters.
docs/​src/​content/​docs/​reference/​artifacts.md Documents compact steering data.
pkg/​cli/​audit_analysis_fanout.go Backfills usage-only audit results.
pkg/​cli/​logs_usage_activity.go Parses and applies compact steering summaries.
pkg/​cli/​logs_usage_activity_test.go Tests backfill and preservation behavior.
pkg/​cli/​token_usage_analyze.go Applies steering summaries during analysis.
pkg/​cli/​token_usage_find.go Adds alternate event-log discovery.
pkg/​cli/​token_usage_steering.go Aggregates normalized steering event types.
pkg/​cli/​token_usage_test.go Tests discovery and aggregation.
pkg/​cli/​token_usage_types.go Extends token usage and event structures.
schemas/​audit.schema.json Adds steering counters to the audit contract.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +157 to +160
for _, relativePath := range relativePaths {
candidate := filepath.Join(root, relativePath)
if fileutil.FileExists(candidate) {
return candidate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d66cd7e: event-log discovery skips empty candidates and continues through supported roots, including legacy layouts, until it finds steering data. Regression tests cover the empty preferred file and legacy fallback.

Comment thread pkg/cli/token_usage_types.go Outdated
Comment on lines +137 to +140
Payload *struct {
Event string `json:"event"`
Type string `json:"type"`
} `json:"payload,omitempty"`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4235a13: payload decoding is flexible, and nested event/type fields are read only from object payloads. Regression cases cover non-object string and array payloads.

@github-actions

Copy link
Copy Markdown
Contributor

ADR required

This PR introduces an architectural decision that is not currently recorded in docs/adr/ on the branch, so I added a draft ADR at docs/adr/63664-surface-awf-steering-counters-in-compact-usage-data.md.

Evidence reviewed

  • actions/setup/js/generate_usage_activity_summary.cjs now aggregates steering events into compact usage artifacts.
  • pkg/cli/logs_usage_activity.go and pkg/cli/token_usage_steering.go backfill steering counts into audit/token-usage paths, including per-event counters.
  • schemas/audit.schema.json and docs/src/content/docs/reference/artifacts.md extend the public contract and documentation.

Next action

Please review and refine the draft ADR, then keep it in the PR as the explicit record of this design decision.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · gpt54 · 17.8 AIC · ⌖ 8.1 AIC · ⊞ 10.1K · ◷
Comment /review to run again

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-09-26T19:51:11.817Z
review_event: REQUEST_CHANGES
top_themes:
  - steering counter fallback stops at first readable proxy-event file
  - compact usage and CLI audit can both under-report steering metrics
files_reviewed:
  - .changeset/minor-audit-gateway-steering.md
  - actions/setup/js/generate_usage_activity_summary.cjs
  - actions/setup/js/generate_usage_activity_summary.test.cjs
  - actions/setup/js/steering_helpers.cjs
  - actions/setup/js/steering_helpers.test.cjs
  - docs/src/content/docs/reference/artifacts.md
  - pkg/cli/audit_analysis_fanout.go
  - pkg/cli/logs_usage_activity.go
  - pkg/cli/logs_usage_activity_test.go
  - pkg/cli/token_usage_analyze.go
  - pkg/cli/token_usage_find.go
  - pkg/cli/token_usage_steering.go
  - pkg/cli/token_usage_test.go
  - pkg/cli/token_usage_types.go
  - schemas/audit.schema.json
comment_count: 2

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 49.5 AIC · ⌖ 9.14 AIC · ⊞ 20.2K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES

The new steering-counter paths short-circuit on the first candidate proxy-event file. In mixed-version or partially populated artifacts, that drops real steering data instead of falling through to the later events.jsonl/audit fallback that actually contains it.

Blocking themes
  • generate_usage_activity_summary.cjs now returns null as soon as the first readable candidate has zero steering entries, so compact usage artifacts can silently omit counters.
  • findAPIProxyEventsFile still resolves by file existence alone, which lets an empty or steering-free preferred filename mask a later populated fallback and undercount firewall_token_usage.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 49.5 AIC · ⌖ 9.14 AIC · ⊞ 20.2K
Comment /review to run again

}
const eventCounts = countSteeringEventsByTypeInApiProxyJsonl(fs.readFileSync(eventLogPath, "utf-8"));
const totalEvents = Object.values(eventCounts).reduce((total, count) => total + count, 0);
return totalEvents > 0 ? { total_events: totalEvents, event_counts: eventCounts } : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This short-circuits on the first readable candidate file, so a present event-logs.jsonl with no steering entries prevents fallback to events.jsonl and silently drops real steering counters from usage/activity/summary.json.

💡 Why this blocks the change

The rest of the codebase treats event-logs.jsonl and events.jsonl as fallbacks for the same signal source, but this helper returns null as soon as the first non-empty file parses to zero steering events. That means mixed-version artifacts can lose steering metrics even though a later candidate file has them.

Please keep iterating when totalEvents === 0 and only return once you find a candidate with steering events, or after every candidate has been checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4235a13: the compact collector continues to later event-log candidates unless it finds steering events. The regression test covers empty and steering-free candidates before the populated fallback.

Comment thread pkg/cli/token_usage_find.go Outdated
} {
for _, relativePath := range relativePaths {
candidate := filepath.Join(root, relativePath)
if fileutil.FileExists(candidate) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns the first existing proxy log path, so a steering-free event-logs.jsonl in sandbox/firewall/logs will mask a populated events.jsonl or audit fallback and under-report firewall_token_usage.

💡 Why this blocks the change

The new logic added a second filename variant, but the resolver still exits on existence alone. If both variants are present during a transition, analyzeTokenUsage() will parse whichever file happens to exist first, even when that file contains no steering events and a later candidate does.

Please mirror the fallback behavior used elsewhere for proxy-event reads: keep searching until you find a candidate that actually carries steering data, or make the downstream parser try the ordered candidate list instead of a single path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d66cd7e: Go event-log discovery checks the ordered candidates for steering data before falling back, so an existing steering-free file no longer masks a populated logs, audit, or legacy candidate. Regression coverage exercises fallback across layouts.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impeccable Skills Review — PR #63664

This PR is a backend/data-plumbing change (steering-event counters surfaced in usage/audit JSON), not a UI change, so the UI-focused Impeccable modes (critique, harden, distill, extract, clarify) don't apply directly. I reviewed it as mixed_unclear using correctness/reliability/maintainability criteria instead.

Findings: none blocking.

  • Go (token_usage_steering.go, logs_usage_activity.go, audit_analysis_fanout.go) and JS (steering_helpers.cjs, generate_usage_activity_summary.cjs) implementations are consistent: both normalize event names to lowercase, match "steering" or *_steering suffix, and aggregate per-type counts the same way.
  • applyUsageActivitySteeringSummary correctly guards against overwriting a TotalSteeringEvents that's already populated from detailed firewall analysis (verified by TestApplyUsageActivitySteeringSummaryPreservesDetailedAnalysis).
  • New multi-path file discovery (event-logs.jsonl / events.jsonl, logs/audit roots, legacy firewall-audit-logs) is covered by table-driven tests.
  • Schema (audit.schema.json) and docs (artifacts.md) were updated alongside the code.
  • go build, go vet, and the targeted Go test suite (TestApplyUsageActivity*, TestLoadUsageActivitySummary*, TestFindAPIProxyEventsFile, TestAnalyzeTokenUsage*) all pass locally.
  • JS vitest suite could not be executed in this sandbox (network-restricted npm install failure unrelated to the PR), but the added JS tests mirror the passing Go equivalents and the logic is straightforward.

No actionable changes requested.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · copilot · sonnet50 · 106 AIC · ⌖ 13.1 AIC · ⊞ 8.1K

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Copilot AI and others added 3 commits September 26, 2026 20:10
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Ran the PR finisher. Fixed steering-log fallback and non-object payload handling, added regression tests, and committed generated schemas in 7a9e4fc, 4235a13, and d66cd7e. Local build, lint, and tests pass. CI must be re-triggered by a maintainer after the agent push; review-thread resolution and human approval remain outstanding.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

pr-sous-chef
@copilot There is still forward progress needed on this PR.

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 24.6 AIC · ⌖ 8.94 AIC · ⊞ 9.7K · ◷
Comment /souschef to run again

Copilot AI requested a review from gh-aw-bot September 26, 2026 20:44
@pelikhan
pelikhan merged commit 4d1d3ec into main Sep 26, 2026
46 checks passed
@pelikhan
pelikhan deleted the copilot/update-audit-command-steering-events branch September 26, 2026 20:49
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.89.22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants