Repository navigation
fix: refetch an aws-control bill fetched in an earlier UTC month - #47905
winnythedev wants to merge 1 commit into
Conversation
The AWS Control bill is a month-to-date figure: fetch_month_costs asks Cost Explorer for the spend since the first of the current UTC month. is_fresh judged a cached copy only by its age (24 hours), so a copy fetched late on the last day of a month was still fresh on the 1st, and Usage & costs showed the finished month's whole bill as "This month", with no cached caption, until the cache aged out. A cached bill fetched in another UTC month than now is no longer fresh, whatever its age; otherwise the 24-hour rule stands. The month is read from the stamp converted to UTC. fetch_month_costs now reads the clock once for the query and the stamp, so a Cost Explorer call that ends past midnight on the last day no longer stamps last month's bill with the new month. This is the wheel copy's half of the app repository's fix for KiroCrewCaptain/kirocrew-app-aws-control#23
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: a small, reversible fix to a real cache bug, landed in the app repository first as the adoption pin requires. Notes
[DESIGN-REVIEWED] a53ef81 Description read[DESCRIPTION-READ] c46fd210458416bb643acc81c86b61854764ae72d57fa11e43b95bf0ac91a58b That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix works. The cache already stores the month in Notes
What this change shipsInventory (3 items) — 2 justifiedIntent: on the 1st of a month, Usage & costs shows this month's spend, not last month's whole bill. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] a53ef81 Description read[DESCRIPTION-READ] e3a95d59cd2418e2b545b8780934223c9a2fedf8e286c42830a4f591bf8e2e2e That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Problem / Motivation
Goal: On the first day of a month, AWS Control's Usage & costs shows this month's spend instead of last month's whole bill.
The AWS Control bill is cached for 24 hours. A copy fetched late on the last day of a month was still served on the 1st with
fresh: true, so "This month" and the Overview's "Month to date" tile showed the finished month's total, with no "Cached figures" caption, for up to a day. The page never asks for a refresh, so the person could not get the right figure.Why it matters
Anyone who opens Usage & costs on the 1st of a month (UTC) after a late fetch the evening before sees a figure that is wrong by a whole month's spend and is labelled as current. This is the wheel copy's half of the fix: the app repository takes the same change first.
Not a goal
?refresh=1route or the page.aws-control.What changed (motivation → approach → change)
fetch_month_costsasks Cost Explorer for the spend since the first of the current UTC month), butcosts.is_freshjudged a cached copy only by its age.src/kiro_crew/apps/builtins/aws_control/backend/costs.py:is_fresh: a cached bill fetched in another UTC month than now is not fresh, whatever its age. Otherwise the 24-hour rule stands. The month is read from the stamp converted to UTC, and a timezone-less stamp is still read as UTC.fetch_month_costsreads the clock once, for both the query's period and thefetchedAtstamp. Before, it read it again after the Cost Explorer call (up to 60 s), so a call ending just past midnight on the last day would stamp last month's bill with the new month, and the new rule would still serve it.The cost is at most one extra Cost Explorer query a month per account (about $0.01, per the module docstring), on the first read after the UTC month turns.
aws-controlis pinned insrc/kiro_crew/apps/adoption-pins.json, so the fix landed in the app repository first (PR #24, merged):App repo: KiroCrewCaptain/kirocrew-app-aws-control@b8efc3f
The two
costs.pyfiles are the same fromis_freshdown. The test is the app's, with two differences: its autouse fixture patches through_floor_monkeypatch(this repository's semgrep rule), and two comments state the stamps in words rather than as ISO dates (the comment-history gate reads a date as history).Backwards compatibility
Compatible: the cache file's shape is unchanged; a cached bill from an earlier month is fetched again once, and every other cached bill is served exactly as before.
Removes nothing: no key, route, field or record is removed; a stale cached bill stays on disk and is overwritten by the next fetch.
Tests
test/test_aws_control_costs_month_rollover.py(new; the clock is frozen through the module's owndtbinding):GET /costs/{account}, is fetched again.fresh: true, with no Cost Explorer call.is_freshon last month's bill is false.On
main5 of the 6 fail (the first withassert 312.4 == 0.5) and the same-month cache case passes; with this change all 6 pass, and so doestest/test_aws_control_routes_costs_library.py.Local gates on Linux x86_64 (Python 3.12): black, isort, flake8, the comment-history, brand, agent-SDK-boundary and file-line-cap checks, the flake and wait ratchets, and
semgrep scan --config semgrep/ --baseline-commit <base> --error(1.78.0) all pass.scripts/local-gate.py --base refs/remotes/upstream/main --tree-scans: 39933 + 6693 related and 31553 + 14273 tree-scan tests pass; 13 fail, all because a child Python started with a stripped environment cannot loadlibffi.so.6on that machine (test_crew_log_*,test_mcp_footprint_stub_probe,test_managed_launcher_restart,test_display_battery_rules_version,test_crew_image_build_plan,test_browser_harness_supervisor). None touch AWS Control.mypy src/kiro_crewreports 6 errors in files this PR does not touch (missing library stubs on that machine,wecom/client.py). The frontend set did not run (nowebsite/node_modules); the diff has no frontend change.Proof: PROVEN test/test_aws_control_costs_month_rollover.py::test_last_months_bill_is_refetched_on_the_first_day, test/test_aws_control_costs_month_rollover.py::test_a_bill_from_last_month_is_stale_for_is_fresh, test/test_aws_control_costs_month_rollover.py::test_the_month_is_read_in_utc_not_in_the_stamp_offset, test/test_aws_control_costs_month_rollover.py::test_the_year_rollover_reads_the_same_way, test/test_aws_control_costs_month_rollover.py::test_a_fetch_that_straddles_the_month_turn_is_stamped_in_the_month_it_asked_for (head a53ef81)
Manual verification
N/A: no gateway was started and no real AWS call was made. Cost Explorer is reached only through the
_checkedseam, which the tests patch.Real-machine verification
Machine: own computer, Linux x86_64, Python 3.12
Before (main d72eba4, the base the fix was written on):
python -m pytest -n0 test/test_aws_control_costs_month_rollover.py-> 5 failed, 1 passedAfter (head a53ef81):
python -m pytest -n0 test/test_aws_control_costs_month_rollover.py test/test_aws_control_routes_costs_library.py-> 44 passedCleanup: own computer, nothing to delete
No live run was done: the fix is verified by pytest on Linux.
Related Issues
KiroCrewCaptain/kirocrew-app-aws-control#23
App PR (merged): KiroCrewCaptain/kirocrew-app-aws-control#24
Sibling sweep
Swept: git grep -n "periodStart|monthToDate|is_fresh" -- src/kiro_crew
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/costs.py -- changed here
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/routes_parts/accounts.py -- not affected -- calls is_fresh and serves what it decides
Pattern harvest
Not generalizable: the defect is one cache that judged a month-to-date figure only by age; no other cache in the tree holds a figure scoped to a calendar period.
Review (multi-model interrogate)
Two independent reviewers read the full diff against CI's own lane contracts and found nothing; a final re-check of the head found nothing in the diff. Two more reviews were not counted because the AGENTS.md line count each stated did not match the file.
App repo:line names its merge commit.fresh: false. That fallback is unchanged code outside this fix, and the page captions it as cached.fetchedAtis now stamped when the query starts, so a cached bill expires up to 60 s sooner. That is the intended trade.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.