Slice A (reuse program #150): reset-aware quota state + Z.ai reset plausibility #151
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
P1
P2
P3
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Creatidy/scarcity-router#151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Child of #150 (reuse-first reconstruction program). Slice A: quota correctness and reset mechanics.
Problem
State layer (
resource_state.py): freshness is TTL-only.classify_freshnesscompares observation age againstfreshness_ttl_seconds;refresh_due/_entry_refresh_duecompare age againstpoll_interval_seconds. A window's normalizedresets_atis carried as explanation data but never consumed: an observation taken one minute before a five-hour window reset staysfreshfor its whole TTL even after the reset moment passes, and a 0%-exhausted window pins its scarcity asunavailableuntil the next poll even when its reset time is already in the past. Stale quota facts can therefore outlive the window they describe.Parser (
providers/zai.py):nextResetTimeis validated only as a 13-digit epoch-ms band. A five-hour window whose reset claims to be days away (timezone-shifted or drifted provider value) is accepted verbatim; the evidenced five-hour duration is never cross-checked against the claimed reset.Change (state mechanics only — no ranking-policy change)
classify_freshnessgains an optional earliest-window-reset input; when the evaluation instant has reached any observed window'sresets_at, the observation isstaleregardless of TTL age.refresh_due(registry + entry) additionally report a reset-crossed observation as due even when younger than the poll interval. Exhausted (0%) windows are covered by the same rule: after reset crossing they stop pinning scarcity via obsolete facts. TheFRESHNESS_STATESvocabulary is unchanged (staleis an existing value); observation classes, health statuses and serialized contracts are unchanged.nextResetTimemore than duration + 60s ahead of the retrieval instant is implausible:resets_atis omitted and the existingreset_unknownwindow diagnostic is emitted (no new diagnostic vocabulary). Resets at or before the retrieval instant are preserved as-is; obsolescence is the state layer's reset-crossing rule.Frozen semantics untouched
D-026 penalty (no reset-proximity term), D-037 role blend, capacity v3 vocabularies,
_DIAGNOSTIC_CODES, health statuses, reason codes. The change only makes staleness truthful; scoring inputs are unchanged.Required regressions (new tests)
classify_freshness: reset crossed →staledespite age < TTL; reset in future →fresh; reset exactly atnow→stale; no resets → TTL-only behavior unchanged; malformed reset rejected.registry_snapshot: entry freshness reflects a crossed reset; multi-window observation (weekly future + five-hour crossed) →stale.refresh_due(both forms): reset-crossed observation is due despite young poll interval; no polling cadence → never due even when reset crossed (freshness still evaluatesstale).stale(no longer treated as trustworthy capacity).apply_worker_reportthen evaluated read shows the reset-crossing rule.reset_unknown; boundary at exactly 5h+60s → kept; weekly window bounded by 7d+60s; unknown-kind window (no evidenced duration) → no plausibility check; normal near-future reset kept; past reset kept (state layer owns obsolescence).Scope
scarcity_router/resource_state.py,scarcity_router/providers/zai.py, focused doc updates (docs/capacity-model.mdfreshness prose;providers/zai.pymodule docstring; Codex evidence re-pin note per #150), tests intests/test_resource_state.py+tests/test_zai_parser.py. No selector/policy/contract changes.Evidence / complexity boundary
Upstream evidence: weave-os/router
usagepackage @e5133a6(Apache-2.0) —ExhaustedAsOfreset semantics andTestObserver_ResetAtExpiresBeforeWindowLengthinvariant, PORTed as state mechanics with its test invariants reused as specifications; CodexBarzai.js@491ae68(MIT) — five-hour reset plausibility pattern ("a five-hour Coding Plan reset cannot be ten hours away; never guess a timezone correction"). Attribution via this issue; no source vendored, no NOTICE change required (no code copied).Budget: 120 min wall clock. Full gate before PR; PR targets
develop, left open for human review.Security classification
Not security-critical (no credentials, transport, or execution-surface changes). Independent exact-head review mandatory; UX impact assessment mandatory.