Skip to content

Crashes: count the daily limits on the clock that stamps the event - #414

Merged
widgetii merged 1 commit into
masterfrom
crashes-limit-clock
Oct 8, 2026
Merged

widgetii merged 1 commit into
masterfrom
crashes-limit-clock

Conversation

@widgetii

@widgetii widgetii commented Oct 8, 2026

Copy link
Copy Markdown
Member

Master's CI is failing TestMonthCap (internal/crashes, #411) since 17:00 UTC today, on master's own code and on every branch.

Cause: Store.Insert counted a client's and a camera's crashes since a.now() - 24h, but stamped each event with the database's now(). When the API's clock and the database's differ, the window counts the wrong events. In TestMonthCap the clock is fixed at 2026-10-08 12:00 UTC and steps 5 hours per send. From 17:00 UTC that day, the test's earlier sends all fall inside the window, so the sixth is refused with 429. From then on it fails on every day.

Fix: Insert takes the event's time, stamps received_at with it, and counts the 24 hours before it. The window and what it counts now come from one clock. In production both clocks are the server's, so behaviour is unchanged.

Tests: TestMonthCap fails on ce684af at 18:07 UTC and passes with this change at 18:09 UTC. The full service/run.sh test passes (23 packages), and gofmt is clean.

Insert counted a client's and a camera's crashes since a.now() - 24h, but
stamped each event with the database's now(). With the API's clock and
the database's apart -- as in TestMonthCap, whose clock is fixed at
2026-10-08 12:00 UTC -- the window counted the wrong events: from 17:00
UTC that day the test's earlier sends all fell inside it and the sixth
was refused 429, so master's CI fails from then on, on every day.

Insert now takes the event's time, stamps received_at with it, and counts
the day before it: the window and what it counts come from one clock.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Align crash quota windows with event timestamps

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Use one clock for crash timestamps and 24-hour quota windows.
• Prevent clock differences between the API and database from causing incorrect quota refusals.
Diagram

graph TD
  API["Crash API"] -->|event time| STORE["Store Insert"] -->|count prior day| DB[("Crash events")] -->|counts| CHECK{"Below quota?"}
  CHECK -->|yes| SAVE["Stamp event"] -->|received_at| DB
  CHECK -->|no| REJECT["HTTP 429"]
  subgraph Legend
    direction LR
    _step["Processing step"] ~~~ _data[("Stored data")] ~~~ _decision{"Decision"}
  end
Loading
High-Level Assessment

Passing one timestamp into Insert is the smallest change that keeps quota counts and event timestamps on the same clock. Using the database clock for both was considered, but would bypass the API's injectable clock used by tests. No test files change in this PR.

Files changed (2) +10 / -8

Bug fix (2) +10 / -8
api.goPass the event time to crash insertion +1/-1

Pass the event time to crash insertion

• Submit now passes the API's current time rather than a precomputed 24-hour cutoff. This lets storage use the same time for quota checks and the event timestamp.

service/internal/crashes/api.go

store.goCount and stamp crashes using one time +9/-7

Count and stamp crashes using one time

• Insert derives the quota cutoff from the supplied event time and explicitly writes that time to crash_events.received_at. Its contract now documents the shared clock.

service/internal/crashes/store.go

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@widgetii
widgetii merged commit e04f0ef into master Oct 8, 2026
2 checks passed
@widgetii
widgetii deleted the crashes-limit-clock branch October 8, 2026 18:17
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.

2 participants