Skip to content

fix(quota): cover all history instead of crashing on an unrepresentable window - #8682

Open
Duang777 wants to merge 1 commit into
loopx-project:mainfrom
Duang777:codex/quota-unrepresentable-window-20261113
Open

Duang777 wants to merge 1 commit into
loopx-project:mainfrom
Duang777:codex/quota-unrepresentable-window-20261113

Conversation

@Duang777

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: self-found core defect. No public issue; the request in this PR is the basis.
  • Goal/source and gap: goal_quota_with_spend_ledger in loopx/quota.py computed current_time - timedelta(hours=int(window_hours)) with no overflow handling. configure-goal --quota-window-hours accepts any finite positive number and a registry can hold any number. collect_history evaluates every registered goal in one pass.
  • Observable before → after, with the validation row that proves it: A goal with window_hours of 1e8 or more raised OverflowError (date value out of range, or from timedelta itself at 1e12), and collect_history failed for the whole registry including goals with a 24-hour window. After: such a window covers all history, the goal keeps its configured window and counts all of its spends, and the other goals are unaffected. Rows: regression_parity, unit.
  • Issue/task and intended base: none. Base is main at 7bb1b01.

Author Declaration

  • Written by: agent, Claude Sonnet 5.5, for @Duang777

Implemented against

  • Specification and revision: no written specification; the request in this PR is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
One goal's configuration must not break reads for other goals implemented goal_quota_with_spend_ledger in loopx/quota.py tests/control_plane/test_quota_rolling_window_projection.py::test_unrepresentable_window_covers_all_history_without_crashing
  • Self-check before submission: reproduced the defect on the unfixed code, then confirmed the new test fails before and passes after. Did not run the full suite or CI-equivalent gates locally. Fixed at the read rather than clamping at configure time so a hand-edited registry is covered too. Severity is medium: it needs an extreme configured value.

Scope And Continuation

  • Completed scope and remaining work: complete within this scope. No limit is added to --quota-window-hours.
  • Slice boundary / successor: N/A, one independent defect.

Validation

  • Tested revision: b0d57936c2eb202f0697777fa04e07ac3200ab15 for the diff; local runs used a working tree whose touched files were blob-identical to main 7bb1b01 before the change.
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
regression_parity passed The test, parametrized over 10**8, 10**12 and 1e12, fails 3 of 6 cases on the unfixed code and passes with the fix.
unit passed Also test_quota_ledger_integrity.py, test_quota_paused_precedence.py and test_quota_plan_policy.py: 62 passed; ruff check clean.
  • Coverage and gaps: configure_goal could not be driven end to end on the local tree, so the repro went through collect_history and a hand-written registry.

Frontend / Visual Evidence

  • UI impact: none

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening.

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check passes, or no paired RFC changed. No RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

🤖 Generated with Claude Code

…le window

goal_quota_with_spend_ledger subtracts timedelta(hours=window_hours) from the
current time. configure-goal accepts any finite positive --quota-window-hours,
and a registry can carry any number, so a value of 1e8 hours or more makes the
subtraction raise OverflowError (and 1e12 overflows the timedelta itself).
collect_history evaluates every registered Goal in one pass, so one Goal with
such a window made `status` and every quota read fail for the whole registry,
including Goals with a normal 24 hour window.

An unrepresentably long window covers every representable event, so the window
start is now the earliest datetime in the current time's zone. The Goal keeps
its configured window_hours and still counts all of its spends.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: duang777 <duangjl007@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant