Repository navigation
fix(console): dedupe current_strategies KV writes (Cloudflare free-tier quota) - #1013
Merged
Merged
Conversation
…under the free-tier daily quota The 5s SWR freshness window re-put the GitHub-derived strategies cache to KV on every refresh (unconditional, ~500-600 writes/day, pushing the account past Cloudflare's 1,000 writes/day free KV limit). Writes now happen only when the payload actually changed, plus at most one ts keep-alive bump per 10 minutes so cold isolates keep serving from the KV stale window. Fresh memo window raised 5s -> 60s to cut KV read and GitHub load proportionally. scheduled() now uses the same dedup helper.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
…on window The cross-day rotation case pinned yesterday at 10:00 UTC, which leaves the Worker's 36h window at 22:00 UTC, so the sync was rejected as account_facts_observation_window (400) instead of reaching the binding mismatch (409) between 22:00 and 24:00 UTC every day.
This was referenced Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI assistance
Qoder Desktop agent (session of 2026-11-01, SGT) drafted the fix, the new test and this description. Measurements (Cloudflare GraphQL usage, log scans) were done with the owner's wrangler credentials, read-only. Human owner directed the work and approved push/PR/deploy.
Governance note: the
owner-approvedlabel required by the risk-gate was applied by the agent withghon the owner's explicit instruction in this session, using the owner's ownPigbibicredentials. It is the owner's approval, not an agent self-approval, but it was not clicked manually in the GitHub UI.What changed
The Cloudflare account hit the Workers KV free-tier limit of 1,000 writes/day. Full-day measurement for 2026-10-31 (GraphQL
kvOperationsAdaptiveGroups): 1,053 writes / 51,155 reads account-wide, split asworker-STRATEGY_SWITCH_CONFIG616,quant-ai-oauth240,pigbibi-personal-ai-oauth186,FORWARDED_KV11.Root cause for the console namespace:
readCurrentStrategieskept a 5-second SWR freshness window (a development-era value) and re-putthe GitHub-derivedcurrent_strategies_cacheon every background refresh unconditionally — thetsfield always changes, so every refresh cost a KV write.web/strategy-switch-console/worker.js: newwriteCurrentStrategiesCachehelper — writes only when the payload actually changed, plus at most one ts keep-alive bump per 10 minutes (preserves the existing "cold isolate serves stale from KV without waiting on GitHub" semantics). Fresh memo window 5s -> 60s, which also cuts KV reads and GitHub fetches ~12x.scheduled()now goes through the same helper (wrangler.toml.exampledocuments a*/5cron path that would otherwise add 288 writes/day).tests/console_current_strategies_kv_dedup_validation.mjs: cold miss = 1 write; fresh-window request = 0 writes; unchanged payload inside the bump interval = 0 writes; aged entry = exactly 1 keep-alive write; post-bump requests = 0 writes.tests/account_facts_validation.mjs(second commit, one line + comment): the cross-day rotation fixture pinned "yesterday" at 10:00 UTC, which falls outside the Worker's 36hACCOUNT_FACTS_OBSERVATION_WINDOW_MS, so the case failed between 22:00 and 24:00 UTC every day onmaintoo. Moved to 23:00 UTC so the row stays inside the window at any run hour. Unrelated to the quota fix; included because it is the only thing blocking this PR'sjscheck.How verified
node tests/console_current_strategies_kv_dedup_validation.mjs— PASSjsCI step replayed locally in CI order (~90 test files, Node 22.23.1, same env flags, incl. frontend build,sync:v2-assets,tsc,git diff --exit-codegates): exit 0, no assertion failures, withaccount_facts_validation.mjsskipped only to get past the 22:00-24:00 UTC fixture window.jsfailure is pre-existing and time-based, not caused by this diff:maintipd52804apassedjson CI at 21:28 UTC and failed at 22:56 UTC;mainalso fails locally at 23:06 UTC on both Node 22 and Node 26; this branch passesaccount_facts_validation.mjswhen the clock is shifted 2h back, and passes at real time with the fixture hour corrected.console_deploy_safety_validation.mjscould run as it does in CI.worker-STRATEGY_SWITCH_CONFIG616 -> ~150 and account total ~560-620, i.e. under the 1,000/day limit; the two*-oauthnamespaces (426/day combined) stay the next target.