Skip to content

[self-care:calesi-design-principles] Keep memory token-bucket refill time monotonic - #20372

Merged
mnkiefer merged 2 commits into
mainfrom
self-care/calesi-memory-limiter-clock-4dcef442d710045a
Nov 7, 2026
Merged

mnkiefer merged 2 commits into
mainfrom
self-care/calesi-memory-limiter-clock-4dcef442d710045a

Conversation

@mnkiefer

@mnkiefer mnkiefer commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

The in-memory operational adapter could refill a rate-limit bucket twice for the same elapsed interval if its clock moved backwards. The PostgreSQL adapter already avoids this. This PR proposes aligning the memory adapter with it. It is not deployed or accepted.

Action: A server maintainer should review and confirm that go test ./internal/operational/... passes, including the new regression test.

Finding

  • Principle: interchangeable implementations (Add create-ops-bundle skill #4). Frozen SHA: caf079a1ed1644fdbb65d20d8f9544a461c5cb83.
  • Contract: operational.RequestLimiter.TakeRateLimitTokens in server/internal/operational/store.go.
  • Memory adapter: memory/limiter.go set updated = now unconditionally.
  • Postgres adapter: postgres/limiter.go advanceTokenBucket only advances the timestamp when now.After(b.At).
  • Before: the regression test failed, with a backward then forward clock step refilling the same interval twice.
  • After: the test passes.
  • Counter-evidence: the clock is injectable and normally time.Now. This only matters for wall-clock steps or injected clocks. No intentional backend limitation covers this.
Validation
  • go test -race ./internal/operational/... passed.
  • TestAdapters passed against an isolated local PostgreSQL 18 for memory and postgres. The redis subtest was skipped because no Redis was available, so Redis conformance is unreviewed.
  • go vet ./... clean, golangci-lint fmt --diff clean, and golangci-lint run ./internal/operational/... reported 0 issues.
  • The full golangci-lint run ./... was not run.
  • Other principles were not exhaustively reviewed in this bounded pass.

Control Plane

Generated by SelfCare / Calesi Principles · copilot · auto · ~37 AIC · ⌖ ~1 AIC · ⊞ 16.1K · ◷

  • expires on Nov 14, 2026, 2:39 PM UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@mnkiefer
mnkiefer merged commit 2dd8726 into main Nov 7, 2026
30 checks passed
@mnkiefer
mnkiefer deleted the self-care/calesi-memory-limiter-clock-4dcef442d710045a branch November 7, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant