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

  3. added
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    Author

    🤖 Agent note · picked_up

  5. dezren39 commented on Nov 6, 2026

    @dezren39
    Author

    🤖 Agent note · picked up

  6. added
    queue/queuedHas a queued task in the Supabase agent queue
    task/fixQueued scoped fix task
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    on Nov 6, 2026
  7. dezren39 commented on Nov 6, 2026

    @dezren39
    Author

    Triage verdict — finding confirmed on current main

    Fresh GitHub API and raw reads on 2026-11-06 confirm issue #1699 is still open and source PR #1605 is merged at . at prunes by , which only sees currently registered readers (); already passes the full horizon (, 7,776,000,000 ms). No competing open PR or active fix task was found. This confirms the later-activation retention gap.

    Routed a scoped fix packet as task 10865 (): preserve the supported retention horizon, keep per-Location judgment windows, and add a no-restart regression test. The primary clone's existing uncommitted changes were left untouched.

    🤖 Agent note · handed off

  8. dezren39 commented on Nov 6, 2026

    @dezren39
    Author

    Triage verdict — finding confirmed on current main

    Fresh GitHub API and raw main reads on 2026-11-06 confirm issue #1699 is open and source PR #1605 is merged at 9748389. In packages/core/src/model-route.ts, recordQuota (lines 1183-1192) prunes by retainedDemotionWindow(), whose readers are those registered at record time (lines 1124-1137); seedDemotion (lines 2392-2405) already passes MAX_DEMOTION_WINDOW_MS (7,776,000,000 ms). No competing open PR or active fix task was found. The later-activation retention gap is confirmed.

    Routed the scoped follow-up as task 10865 with dedupe key repo-health:v1:fix:developing-today/opencode:issue:1699. It preserves the supported retention horizon, keeps per-Location judgment windows, and adds a no-restart regression test. The primary clone's pre-existing uncommitted changes remain untouched.

    🤖 Agent note · handed off

  9. added
    queue/claimedA queue worker has claimed the task for this item
    work/assignedAn agent holds this item via the queue (claimed task)
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 6, 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/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/claimedA queue worker has claimed the task for this itemsource/pr-comment-reviewFiled by the pr-comment-review jobstatus/in-progressActively being workedtask/fixQueued scoped fix taskwork/assignedAn agent holds this item via the queue (claimed task)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions