Skip to content

fix(dashboard): sync live usage audit status#338

Merged
SantiagoDePolonia merged 3 commits into
mainfrom
fix/live-preview-usage-audit-status
May 17, 2026
Merged

fix(dashboard): sync live usage audit status#338
SantiagoDePolonia merged 3 commits into
mainfrom
fix/live-preview-usage-audit-status

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented May 17, 2026

Summary

  • mark Usage and Audit Logs independently as pending in live workflow previews
  • enrich audit live rows from cached usage events before and after audit previews arrive
  • add dashboard JS tests for cached usage/audit pending and flushed states

Tests

  • node --test internal/admin/dashboard/static/js/modules/live-logs.test.cjs
  • node --test internal/admin/dashboard/static/js/modules/workflows.test.cjs
  • node --test internal/admin/dashboard/static/js/modules/*.test.cjs

Summary by CodeRabbit

  • New Features

    • Audit rows now attach live usage details (token counts, normalized summaries, estimated cached characters) and live-state flags even when usage events were previously hidden or cached.
  • Improvements

    • Formalized handling of hidden/cached usage so previews still enrich audits; skipped cached usage is tracked to preserve enrichment.
    • Workflow dashboard distinguishes pending/completed states separately for usage and audit.
  • Tests

    • Expanded tests for cached-preview behavior, enrichment timing, pending/flushed state transitions, and normalized usage summaries.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5f5c57a8-bd94-4dc0-9cc7-c128f2b01447

📥 Commits

Reviewing files that changed from the base of the PR and between 533bf9d and 410e6de.

📒 Files selected for processing (2)
  • internal/admin/dashboard/static/js/modules/live-logs.js
  • internal/admin/dashboard/static/js/modules/live-logs.test.cjs

📝 Walkthrough

Walkthrough

Live-logs now cache skipped usage by request_id, merge matching usage into audit entries at insert/merge points, refactor usage merge lifecycle and summary helpers, and update tests. Workflows add helpers to detect usage/audit pending state and use them in the chart model.

Changes

Live Logs and Workflows Usage-to-Audit Integration

Layer / File(s) Summary
Module state init and audit insertion merge
internal/admin/dashboard/static/js/modules/live-logs.js
Initialize skippedLiveUsageByRequestId; audit insertion paths call mergeLiveAuditUsagePatch(...) and use liveUsageEntryForAudit(...) to attach matching usage by request_id.
mergeLiveUsageEntry and mergeLiveUsagePatch
internal/admin/dashboard/static/js/modules/live-logs.js
mergeLiveUsageEntry(...) refactored to handle existing-by-id updates and new entries from skipped cache; mergeLiveUsagePatch(...) computes _live, _live_state, _live_pending, and _usage_flushed for merged usage entries and centralizes hide/insert decisions.
Apply live usage to audit & summary helpers
internal/admin/dashboard/static/js/modules/live-logs.js
applyLiveUsageToAudit(...) now replaces audit entries with auditEntryWithLiveUsage(...); adds liveUsageSummary(...) and liveNumber(...) to derive normalized token counts, cached ratios, and estimated cached characters.
Workflow pending-state helpers and chart integration
internal/admin/dashboard/static/js/modules/workflows.js
New exported helpers workflowLiveUsagePending(entry) and workflowLiveAuditPending(entry, runtime); chart model computes usagePending/auditPending via helpers and uses them for usageNodeClass/auditNodeClass; workflowLiveCurrentStep refactored to use helpers.
Test updates for live usage attachment and workflow styling
internal/admin/dashboard/static/js/modules/live-logs.test.cjs, internal/admin/dashboard/static/js/modules/workflows.test.cjs
Tests extended to assert audit-row enrichment with usage.total_tokens and lifecycle flags (_usage_live_state, _usage_live_pending, _usage_flushed), deferred attachment behavior, hide-cached toggle behavior, and workflow chart current-step expectation for pending usage.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I’m a rabbit in the logs tonight,
Hiding tokens, making audits bright,
I patch skipped usage with a gentle hop,
Pending states wait until flushes stop,
🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: synchronizing live usage with audit status tracking in the dashboard.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/live-preview-usage-audit-status

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR updates live dashboard previews for usage and audit workflow status. The main changes are:

  • Audit live rows can be enriched from matching live usage entries.
  • Cached usage events now update audit previews in more cases.
  • Workflow charts track usage and audit pending states independently.
  • Dashboard JavaScript tests cover cached, pending, flushed, and failed live states.

Confidence Score: 3/5

I would fix the live usage merge bugs before merging.

  • Hidden cached usage can be lost when it arrives before the audit preview.
  • Live audit usage summaries can show incorrect token totals for split cache accounting.
  • The workflow chart changes look contained.

internal/admin/dashboard/static/js/modules/live-logs.js

Important Files Changed

Filename Overview
internal/admin/dashboard/static/js/modules/live-logs.js Adds audit enrichment from live usage events, but drops hidden cached usage before late audit rows can use it and undercounts split cache token fields.
internal/admin/dashboard/static/js/modules/workflows.js Separates live usage and audit pending states for workflow node classes.

Reviews (1): Last reviewed commit: "fix(dashboard): sync live usage audit st..." | Re-trigger Greptile

}, ...currentEntries].slice(0, this.usageLog.limit || 50);
};
this.applyLiveUsageToAudit(liveEntry);
if (this.usageLogHideCached && this.liveUsageEntryCached(liveEntry)) return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Hidden usage is dropped

When usageLogHideCached is enabled and a cached usage.completed event arrives before its audit row, applyLiveUsageToAudit(liveEntry) has no matching audit entry and this branch returns before storing the usage event anywhere. When the later audit.completed event arrives, mergeLiveAuditUsagePatch can only look in usageLog.entries, so the audit row never gets the cached usage summary or pending usage state.

if (inputTokens > 0 && uncachedInputTokens + cachedInputTokens + cacheWriteInputTokens === 0) {
uncachedInputTokens = inputTokens;
}
const normalizedInputTokens = inputTokens || uncachedInputTokens + cachedInputTokens + cacheWriteInputTokens;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Cached tokens are undercounted

This uses input_tokens whenever it is nonzero, but split prompt-cache accounting reports cached reads and cache writes in separate fields. For a live usage event with input_tokens: 100 and cached_input_tokens: 50, the audit summary shows input_tokens: 100 instead of the normalized 150, which also makes the fallback total and cached ratio inconsistent with the server-side request summary.

Suggested change
const normalizedInputTokens = inputTokens || uncachedInputTokens + cachedInputTokens + cacheWriteInputTokens;
const segmentedInputTokens = uncachedInputTokens + cachedInputTokens + cacheWriteInputTokens;
const normalizedInputTokens = segmentedInputTokens || inputTokens;

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/admin/dashboard/static/js/modules/live-logs.js`:
- Around line 233-239: The current liveUsageEntryForAudit(…) only searches
this.usageLog.entries and misses live usage events that were received but
filtered/skipped (see early return around lines 329-330); add a persistent map
(e.g., this.skippedLiveUsageByRequestId or this.cachedLiveUsage) on the same
object/class to store any live usage rows that were not inserted into the
visible table, populate that map where the code currently returns early for
filtered/cached entries, and then update liveUsageEntryForAudit to check this
map in addition to this.usageLog.entries (and remove entries from the map when
the row is later inserted/merged) so audits can be enriched by previously
skipped live usage events.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 806ee715-aa93-4e18-8ebf-54daddbe71ff

📥 Commits

Reviewing files that changed from the base of the PR and between 4490b73 and 9fbcb1e.

📒 Files selected for processing (4)
  • internal/admin/dashboard/static/js/modules/live-logs.js
  • internal/admin/dashboard/static/js/modules/live-logs.test.cjs
  • internal/admin/dashboard/static/js/modules/workflows.js
  • internal/admin/dashboard/static/js/modules/workflows.test.cjs

Comment thread internal/admin/dashboard/static/js/modules/live-logs.js
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/admin/dashboard/static/js/modules/live-logs.js`:
- Around line 229-231: mergeLiveAuditUsagePatch currently reads a skipped usage
from skippedLiveUsageByRequestId (via liveUsageEntryForAudit) and merges it into
the audit entry with auditEntryWithLiveUsage but never removes that skipped
entry, causing retained stale entries; update mergeLiveAuditUsagePatch to, after
creating the merged entry, delete the corresponding key from
skippedLiveUsageByRequestId (or call the component method that evicts that
entry) so the skipped usage is evicted once attached, and apply the same
eviction change to the other similar function(s) handling live usage merging
around the other block referenced (the 349-362 region) to avoid cache growth and
stale summaries.
- Around line 306-323: When an existing usage row is updated (the branch that
uses mergeLiveUsagePatch(previous, incoming) and returns early after
applyLiveUsageToAudit), re-run the same hide/caching checks used for new rows:
after calling applyLiveUsageToAudit(merged) call the same conditional logic that
checks usageLogHideCached && liveUsageEntryCached(merged) and
usageLiveInsertAllowed(), and if either indicates the entry should be skipped
call storeSkippedLiveUsage(merged) and remove the merged entry from
this.usageLog.entries (and call removeSkippedLiveUsage(merged) as needed) so an
updated row that becomes cached is moved to skipped just like a newly inserted
row.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ccae2dc9-9b4d-460b-84f0-ee824c4adeea

📥 Commits

Reviewing files that changed from the base of the PR and between 9fbcb1e and 533bf9d.

📒 Files selected for processing (2)
  • internal/admin/dashboard/static/js/modules/live-logs.js
  • internal/admin/dashboard/static/js/modules/live-logs.test.cjs

Comment thread internal/admin/dashboard/static/js/modules/live-logs.js Outdated
Comment thread internal/admin/dashboard/static/js/modules/live-logs.js
@SantiagoDePolonia SantiagoDePolonia merged commit 430b2ca into main May 17, 2026
19 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.

2 participants