Skip to content

write usage cache entry even for AIC = 0#39066

Merged
pelikhan merged 2 commits into
mainfrom
copilot/write-usage-entry-in-cache
Jun 13, 2026
Merged

write usage cache entry even for AIC = 0#39066
pelikhan merged 2 commits into
mainfrom
copilot/write-usage-entry-in-cache

Conversation

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

When the daily AIC guardrail blocks a run, the agent never executes and no usage files are produced — AIC is legitimately 0. The old guard (aic <= 0 → skip) treated this the same as a computation error, leaving the run uncached. Every subsequent activation then wasted a getRunAIC artifact-download round-trip for that run, finding nothing and getting 0 anyway.

Changes

  • write_daily_aic_usage_cache.cjs: relax skip condition from aic <= 0 to aic < 0 — zero is a valid, writable AIC
  • check_daily_aic_workflow_guardrail.cjs (loadAICUsageCache): accept aic >= 0 so aic=0 entries land in the Map as cache hits; the guardrail loop already skips runAIC <= 0 runs correctly
  • check_daily_aic_workflow_guardrail.test.cjs: update assertion — aic=0 entries are now loaded; negative/non-finite still rejected

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review June 13, 2026 11:36
Copilot AI review requested due to automatic review settings June 13, 2026 11:36

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.

Pull request overview

This PR updates the daily AI Credits (AIC) usage caching flow so that AIC = 0 (e.g., when a run is blocked by the daily guardrail and produces no usage artifact) is treated as a valid cached value, avoiding repeated artifact-download retries on subsequent activations.

Changes:

  • Write cache entries when computed AIC is 0 (skip only negative/non-finite).
  • Load cached entries with aic >= 0 so 0 becomes a cache hit.
  • Update the guardrail cache-loading test to assert aic = 0 is loaded.
Show a summary per file
File Description
actions/setup/js/write_daily_aic_usage_cache.cjs Allows writing cache entries for aic = 0 to prevent repeated artifact download attempts for blocked runs.
actions/setup/js/check_daily_aic_workflow_guardrail.cjs Adjusts cache-load filtering to accept aic >= 0 so zero-valued entries become cache hits.
actions/setup/js/check_daily_aic_workflow_guardrail.test.cjs Updates expectations to reflect that aic = 0 entries are now loaded into the cache.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment on lines 122 to +125
const entry = JSON.parse(line);
const runId = Number(entry?.run_id);
const aic = Number(entry?.aic);
if (Number.isFinite(runId) && runId > 0 && Number.isFinite(aic) && aic > 0) {
if (Number.isFinite(runId) && runId > 0 && Number.isFinite(aic) && aic >= 0) {
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

…coercion

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Done. Fixed in commit 1f7b2c3 — loadAICUsageCache now checks typeof rawAic === "number" before coercing, so null/""/true are rejected outright rather than coerced to 0/1. All 21 tests pass including the aic=null boundary assertion.

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.

3 participants