Skip to content

fix: server review fixes — suspended tenants, permissions, error mapping, expiry, perf - #301

Merged
amavashev merged 5 commits into
mainfrom
fix/server-review-spec-compliance
Nov 26, 2026
Merged

amavashev merged 5 commits into
mainfrom
fix/server-review-spec-compliance

Conversation

@amavashev

@amavashev amavashev commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes from a review of the server for bugs, spec compliance and performance. Runtime and governance YAML are unchanged.

Suspended tenants (governance spec: "Read-only, no new reservations"; existing reservations can still commit/release)

  • SUSPENDED tenant keys authenticate again (previously 401 for everything).
  • reserve.lua and event.lua refuse new budget claims. Dry runs and /decide return DENY.
  • Reads, commits and releases remain available. Fresh extensions return 403. Retrying a successful pre-suspension extension returns its original expiry. In-flight work can commit or release through the existing expiry plus grace period.

Bugs and spec gaps

  • Spring MVC client errors (unknown path, 405, 415, missing or mistyped parameter) return their 4xx instead of 500.
  • A key-store outage or malformed tenant status during authentication returns 500 INTERNAL_ERROR.
  • API-key permissions are enforced per endpoint with 403 (admin:read satisfies *:read).
  • expire.lua checks that every refund has a distinct scope, an existing ledger with canonical int64 counters, sufficient reserved funds and room to credit remaining. The tenant-close cascade has already credited CLOSED budgets. After expiry plus grace, the sweeper preserves closed budget snapshots and refunds scopes still holding funds. A CLOSED owning tenant yields RELEASED with release_reason=tenant_closed and a release timestamp visible to admin GET. Ordinary expiry still yields EXPIRED. Open budgets with insufficient reserved funds still trigger quarantine before any refund.
  • reservation.denied fires on live 409 reserve denials; /decide denials report the deepest scope; budget.exhausted fires when remaining crosses below zero; event balance events carry the overage policy actually applied.

Performance

  • GET /v1/balances uses SCAN by default so externally seeded budgets remain visible. Set cycles.balances.use-governance-index=true when governance indexes all budgets. Both listing paths skip unreadable rows.
  • Each expiry sweep processes up to cycles.expiry.max-batches-per-sweep batches (default 20). It advances past entries still in grace so later due reservations can settle in the same tick.
  • Reservation ownership is checked inside the commit/release/extend scripts and the GET read, removing the owner-lookup round-trip for tenant keys; auth uses one pooled connection; release.lua uses a single HMGET.

The Maven revision and production Compose image pins are now 0.1.25.60.

Reviewer notes

  • Suspended returns 403 FORBIDDEN: the runtime ErrorCode enum has no suspended code. A dedicated code needs a spec change.
  • Rolling upgrades. The optional TENANT_SUSPENDED decision reason defaults off so v0.1.25.59 replicas can read shared idempotency responses. Enable cycles.decisions.emit-tenant-suspended-reason once all replicas support it. Before rollback, disable it everywhere and allow 24 hours for existing entries to expire.
  • Permission enforcement can break existing keys stored with an empty or partial permission list. Kill switch: cycles.auth.enforce-permissions=false.
  • Assumed mappings where the spec is silent: /decide needs reservations:create; /events needs reservations:create and reservations:commit.
  • budget.exhausted now reports the actual remaining (may be negative) instead of a hardcoded 0.
  • Balances on the index path are ordered by budget key and use a new bi1. cursor; legacy scan cursors keep working.

Not included

  • API-key scope_filter enforcement (semantics underspecified).
  • Webhook subscription caching.
  • Collapsing the three auth GETs into one script.

Testing

  • Local Maven verification passed 1,410 tests, including Redis integration and contract validation, and met both 95% coverage gates. A follow-up run passed all 40 Redis expiry conformance cases, including three additional malformed-owner retry cases.
  • In a two-version HTTP test with shared Redis, v0.1.25.59 replayed byte-identical v0.1.25.60 dry-run and decision denials after tenant reactivation, including the original evidence references.
  • BENCHMARKS.md records three workstation trials on 2399262. The release workflow evaluates its own results, including 200-client throughput, against rolling CI history.

…ng, expiry, perf)

Suspended tenants (governance spec): SUSPENDED keys authenticate again;
reserve.lua/event.lua refuse new budget claims (403 FORBIDDEN), dry_run and
/decide answer DENY TENANT_SUSPENDED, commit/release/extend and reads work.

API-key permissions: controllers enforce the governance Permission values
with 403 (admin:read satisfies *:read). Kill switch:
cycles.auth.enforce-permissions=false.

Error mapping: Spring MVC client errors return their 4xx instead of 500; a
key-store outage during auth returns 500 INTERNAL_ERROR instead of 401.

Expiry: expire.lua validates every budget row before mutating (quarantine
CORRUPT_BUDGET) so a bad row cannot cause a repeated partial release; the
sweeper drains up to cycles.expiry.max-batches-per-sweep batches per tick.

Events: reservation.denied on live 409 reserve denials and deepest scope on
/decide; budget.exhausted when remaining crosses below zero; event balance
events carry the resolved overage policy.

Performance: GET /v1/balances reads the budgets:<tenant> index (SCAN
fallback); reservation ownership is checked inside commit/release/extend Lua
and the GET read; auth uses one pooled connection; release.lua single HMGET.
Three-trial medians of PR head 2399262; all 19 cases passed with zero
errors and zero ledger mismatches. No metric approaches the 25% release
threshold. Comparison with v0.1.25.55 is unpaired.
@amavashev
amavashev merged commit c7b2e46 into main Nov 26, 2026
8 checks passed
@amavashev
amavashev deleted the fix/server-review-spec-compliance branch November 26, 2026 18:39
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.

1 participant