Skip to content

fix(ai): meta quota key-endpoint path publishes phantom all-null windows for figure-less subs_usage objects #1907

Closed

Description

@dezren39

Problem

packages/ai/src/quota/providers/meta.ts — keyUsageResult (the Meta key-endpoint cross-check, module-private) publishes a window for every subs_usage.window / subs_usage.weekly object that is present, even when the object carries no usable figure at all. An empty window object mints a phantom all-null window, violating window-contract rule 4 (types.ts: "No figure, no window — an empty/all-null/zero-limit window-shaped object publishes no window") and diverging from the codex #1762 disposition for the identical shape ("a window without a usable used_percent carries no quota figure, so it is dropped — an empty window object used to mint a phantom all-null window") and from claude's addWindow guard (percent === null && !valueLabel → no window).

Evidence (verified this run, main 69016ea)

Probe probe-meta-keyusage.ts in laptop worktree ~/git/fleet/probe-2026-11-06-meta-keyusage/wt (detached origin/main), driving the real provider.fetchQuota with a stubbed key-endpoint response and an unreachable CDP base (portal path fails closed, key endpoint answers):

  • subs_usage: { window: {}, weekly: { used_percent: 25, resets_at: 1893456000 } } → ok: true with two windows: a phantom rolling window (usedPercent: null, remainingPercent: null, windowSeconds: null, resetAt: null, no label) beside the real weekly window. The CLI renderer prints this as rolling: unknown next to real data.
  • subs_usage: { window: {}, weekly: {} } → ok: true with two all-null windows and no figure anywhere — the result's own no-data branch (Object.keys(windows).length === 0 → no-data failure / post-roll empty state) is bypassed because the phantom keys make the map non-empty.
  • Control, both windows carrying used_percent → both publish normally (unchanged by the fix).

Site: meta.ts keyUsageResult — the rolling block adds windows[...] unconditionally when asObject(subsUsage?.window) is non-null; the weekly block does the same. toUsedPercent already returns null for a missing/unusable percent; the result is never checked.

Why it matters

The key endpoint is the cross-check/fallback for the portal read (session-expired and portal-failure paths): a phantom window there reads as a real (empty) rolling window to the CLI renderer and to downstream quota consumers that group windows by provider, and an all-phantom answer masquerades as a successful quota read instead of the honest no-data/post-roll states the same function already implements.

Acceptance criteria

  • A subs_usage window object with no usable used_percent publishes no window (per window: a missing-figure rolling window drops while a real weekly window still publishes, and vice versa).
  • When neither window carries a figure, the existing dispositions apply unchanged: is_subs_active !== true → the no-data failure; active → the post-roll empty state.
  • Windows carrying a figure publish byte-for-byte as today (percent clamping, duration-derived key, reset handling unchanged; the fix(ai): meta quota rolling window keyed only by derived label — a weekly-length rolling window is silently overwritten by the weekly window #1777 key-collision behaviour is out of scope).
  • Tests in packages/ai/test/quota.test.ts drive provider.fetchQuota for the key-endpoint path (empty window + real weekly, both empty, control) and pass; ai typecheck clean.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/aiPackage: ai (pkgs/ or apps/ in this repo)
    work/self-assignedAn agent grabbed this item directly, outside the queue
    effort/xsTrivial: expected under 30 minutes of work
    on Nov 7, 2026
  2. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    🤖 Agent note · filed

  3. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    🤖 Agent note · picked up

    • Agent: new-issue-creator job (new-issue-creator-opencode)
    • Session / ID: cron new-issue-creator-opencode, run 2026-11-07T02:35:00Z
    • Found via: self-assigned during new-issue-creator-opencode run (guarded self-solve, lifecycle protocol §4: filed this run, trivial, no safety labels)
    • Task: Implementing the fix on branch creator/1907-meta-keyusage-phantom-window: drop each key-endpoint window whose used_percent is unusable, add fetch-path pins to quota.test.ts.
    • Expectation: effort xs; done = PR merged with quota tests + ai typecheck green on the laptop, negative control failing on stashed fix.
    • Links: branch creator/1907-meta-keyusage-phantom-window (PR to follow)
  4. added a commit that references this issue on Nov 7, 2026
  5. dezren39 commented on Nov 7, 2026

    @dezren39
    Author

    🤖 Agent note · done

  6. removed
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    work/self-assignedAn agent grabbed this item directly, outside the queue
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/aiPackage: ai (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator job

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions