Skip to content

fix(core): live recordQuota pruning loses quota events for a Location that registers later with a wider demotion window (PR #1605 CodeRabbit follow-up unaddressed) #1699

Open

Description

@dezren39

Finding (from PR review)

CodeRabbit (coderabbitai[bot]) raised this finding as a follow-up in its review of merged PR #1605 and it was never fixed or responded to:

No-response evidence

Still live on current main (verified 2026-11-05 by two independent gh api raw reads)

packages/core/src/model-route.ts:

  • recordQuota (lines 1183–1192): retentionMs = retainedDemotionWindow() and the stored events are filtered to now - at <= retentionMs at record time, then capped with .slice(-50).
  • retainedDemotionWindow (lines 1124–1139) unions only the readers registered at that moment (demotionReaders + settingsReaders); a Location whose graph activates later is not — and cannot be — in that union.
  • Contrast with the restore path in the same file: seedDemotion (lines 2396–2405) deliberately replays ledger rows with ModelRouteLog.MAX_DEMOTION_WINDOW_MS (7,776,000,000 ms ≈ 90 days, model-route-log.ts:501) precisely because "a Location with a longer demotion window can activate after the restore, and pruning the replay against the then-current retention … would discard failures its policy still counts, unrecoverably". The live recording path has no equivalent protection, so in a long-running process the same loss happens for live events: they survive in the durable ledger but are gone from the in-memory quotaEvents cache until a restart re-seeds them, and demoted() for the later Location under-counts in the meantime.

Acceptance criteria

  • Live quota-event retention preserves events that a later-registering Location could still count under the widest supported demotion window (e.g. record with the MAX_DEMOTION_WINDOW_MS horizon, as seedDemotion already does), or another documented retention policy with the same guarantee; demoted() keeps applying each judging Location's own window over what is retained.
  • A regression test covers the scenario: quota events recorded while only a narrow-window Location is registered still count toward demotion for a wider-window Location that registers afterwards, without a restart.
  • Or: the finding is resolved on this issue by a documented decision with reasoning recorded (e.g. an argued case that later registration cannot occur in-process, or that restart reseeding bounds the impact acceptably).

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/lowNice to have; do when convenient
    queue/queuedHas a queued task in the Supabase agent queue
    app/corePackage: core (pkgs/ or apps/ in this repo)
    on Nov 5, 2026
  2. dezren39 commented on Nov 5, 2026

    @dezren39
    Author

    🤖 Agent note · filed

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/corePackage: core (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientqueue/queuedHas a queued task in the Supabase agent queuesource/pr-comment-reviewFiled by the pr-comment-review jobstatus/needs-triageNot yet triaged; needs a first looktask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions