Skip to content

fix(backend): count the daily TTS allowance in the user's day - #15171

Merged
kodjima33 merged 5 commits into
BasedHardware:mainfrom
singhharsh1708:fix/backend-tts-daily-quota-local-day
Oct 5, 2026
Merged

kodjima33 merged 5 commits into
BasedHardware:mainfrom
singhharsh1708:fix/backend-tts-daily-quota-local-day

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15169.

The TTS daily allowance was counted in tts:chars:{uid}:{UTC date} with a TTL running to UTC midnight, so it reset at 5pm for a Los Angeles user: the full _TTS_DAILY_CHAR_LIMIT before the rollover and the whole allowance again after it, inside one of their days. East of UTC the same rollover cuts their day short instead.

check_tts_rate_limit now takes the zone to count in, builds the bucket there, and expires it at that zone's next midnight through _seconds_until_next_midnight. _seconds_until_midnight_utc stays as the no-zone case so nothing else changes. Both entry points, POST /v1/tts and the desktop synthesis path, now hand check_tts_rate_limit_for_user to the executor instead. resolve_user_timezone reads Firestore, so resolving the zone in the route would have put a sync database read on the event loop, which is what backend-async-blockers flags as mixed_await_sync_db; the helper resolves it inside the executor and falls back to UTC when the user has no stored zone. The burst window is untouched: it is a rolling 60 seconds and has no day boundary.

backend/tests/unit/test_tts_daily_quota_local_day.py freezes the clock and reads the key and TTL handed to the Lua script: 9am and 7pm on the same Los Angeles day share one bucket, the bucket turns over at local midnight, the TTL at 11pm local is about an hour rather than the seven UTC would give, and no zone still produces the UTC day. Three of the four fail on main.

$ cd backend && BACKEND_UNIT_TEST_FILE_LIST=... bash test.sh
4 passed in 0.13s

Line-Count-Exception: backend/database/redis_db.py | 1748 -> 1783 | the zone-aware midnight helper sits with the limiter that uses it

Failure-Class: none

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5/5 confidence — real per-timezone TTS quota bug (main still uses UTC-only midnight rollover), scoped fix + freeze-clock regression test. Not merging: Backend unit shards / Hygiene / PR Metadata Preflight are all failing on this branch.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on d68c68c55d61.

backend/database/redis_db.py still defines unused _seconds_until_midnight_utc after the quota TTL moved to _seconds_until_next_midnight(tz). That trips reportUnusedFunction and is showing up as Backend unit shard failures on this head.

Remove the dead helper (or call it) so pyright/unit is green. I am not merging.

@singhharsh1708

Copy link
Copy Markdown
Contributor Author

Also corrected the 429 detail, which still told the user the quota resets at midnight UTC. That stopped being true with this change.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on 23938c66.

The earlier request still stands: backend/database/redis_db.py still defines unused _seconds_until_midnight_utc (return _seconds_until_next_midnight(None)). Nothing calls it — quota TTL uses _seconds_until_next_midnight(tz) directly. That is the same reportUnusedFunction error failing all four Backend unit shards on this head.

The executor zone helper and 429 copy are fine and do not clear this. Remove the dead wrapper (or call it) so pyright/unit is green. I am not merging.

@singhharsh1708

Copy link
Copy Markdown
Contributor Author

Sorry, that slipped. Removed _seconds_until_midnight_utc in e7b2c4a, nothing referenced it. grep -rn _seconds_until_midnight_utc backend/ is now empty and the 4 tests in test_tts_daily_quota_local_day.py pass.

@singhharsh1708

Copy link
Copy Markdown
Contributor Author

One more from this change, caught on the last run: test_tts_ratelimit_async.py pins the symbol the handler offloads, and this PR moved the entry point to check_tts_rate_limit_for_user so the AST check no longer found the old name.

Updated the guard to the new entry point and widened the direct-call check to cover both check_tts_rate_limit and check_tts_rate_limit_for_user, since both are synchronous and neither may run on the loop. That is stricter than what was there before, not looser.

Checked it still bites: with the await run_blocking(...) in routers/tts.py replaced by a direct call, 2 of the 3 tests fail. Restored, and the file is back to the offloaded form. Both TTS files pass, 3 and 4 tests, exit 0.

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on 2b7da85855.

The unused _seconds_until_midnight_utc wrapper is gone. That was the change request. Hygiene is green, and both TTS routes still offload check_tts_rate_limit_for_user.

I am not approving this SHA. Backend unit shards 1/2/4 are still red, and none of the failures are this PR: test_app_client_schema_inventory.py, test_setup_completed_url_uid_query.py (enable_app_endpoint() missing request), and test_app_enable_install_count.py. Current main Backend Unit is green. Rebase onto current main so those shards can go green; I will re-review that head.

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @singhharsh1708 — this is a clean fix for #15169, and the boundary semantics are handled correctly. File by file:

  • backend/database/redis_db.py — _seconds_until_next_midnight(tz) drives both the bucket key (tts:chars:{uid}:{local date}) and the TTL handed to _TTS_RATE_LIMIT_LUA, so key turnover and expiry agree instead of drifting. check_tts_rate_limit_for_user resolves the user's zone inside the executor context with a UTC fallback, and resolve_user_timezone already returns a validated IANA zone or "UTC", so the extra ZoneInfo() wrap is redundant but harmless. Two small nits: the comment block above _TTS_RATE_LIMIT_LUA (~lines 1365–1366) still says the daily counter "auto-expires at midnight UTC (caller passes seconds_until_midnight_utc as the TTL)" — stale after this rename — and tz: Optional[Any] could be Optional[tzinfo].
  • backend/routers/tts.py — swapping the offloaded callable to check_tts_rate_limit_for_user keeps the sync Redis + Firestore work on critical_executor, and the updated 429 detail ("Resets at midnight in your time zone") now matches the Retry-After header, since the Lua script returns daily_ttl = seconds to the user's local midnight.
  • backend/routers/desktop_tts_updates.py — same swap on the desktop synthesis path; the surrounding trial-paywall/BYOK gating is untouched.
  • backend/tests/unit/test_tts_daily_quota_local_day.py — good coverage: 9am and 7pm on one Los Angeles day share a bucket, the bucket turns over at local midnight, the TTL at 11pm local is ~1h rather than the ~7h UTC would give, and the no-zone path still uses the UTC day. All four passed in CI on this head.
  • backend/tests/unit/test_tts_ratelimit_async.py — _NEVER_ON_THE_LOOP now guards both symbols, so a future regression that calls the raw check_tts_rate_limit directly on the loop would still be caught.

On the failing checks: the four red backend unit jobs are pre-existing main failures, not from this change — the same three files (test_setup_completed_url_uid_query.py, test_app_enable_install_count.py, test_app_client_schema_inventory.py) failed identically on a main run that predates your last push, and main went green again later the same day. A rebase onto current main should clear them; no TTS-related test failed.

The one thing that needs maintainer sign-off: this moves the daily TTS quota boundary from the UTC day to the user's local day. That tightens enforcement west of UTC (no more double allowance) and matches user expectation, but it is a rate-limit enforcement-semantics change on an abuse-control surface, so leaving that call to a human maintainer rather than approving.

🤖 Automated review on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution needs-maintainer-review Needs a human maintainer to sign off before merge backend Backend Task (python) labels Sep 21, 2026
@aryanorastar

Copy link
Copy Markdown
Collaborator

The daily TTS counter on main is not keyed to the user-local day. This head changes that and the tests pin it. The backend unit suite is red on 2b7da85855ce, so this stays open and unapproved.

— Astar, on behalf of @aryanorastar

The daily character bucket was keyed by the UTC date with a TTL to UTC midnight, so the allowance reset mid-afternoon west of UTC and could be spent twice inside one of the user's days. Both TTS entry points now pass the zone resolved for the user.
resolve_user_timezone reads Firestore, so calling it in the async route put a sync database read on the event loop, which backend-async-blockers flags as mixed_await_sync_db. check_tts_rate_limit_for_user does it inside the executor the limiter already runs in.
The 429 detail named UTC, which stopped being true once the bucket followed the user's own day.
@singhharsh1708
singhharsh1708 force-pushed the fix/backend-tts-daily-quota-local-day branch from 2b7da85 to 2b7af9c Compare September 22, 2026 14:58

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2b7af9c.

TTS quota still uses the UTC day on main. The older change request was on d68c68c. This head fixes the boundary.

@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed the full diff at 2b7af9c — this is a well-executed fix for #15169, and the timezone-aware quota logic checks out. Per-file notes:

  • backend/database/redis_db.py — check_tts_rate_limit now derives both the daily key and its TTL from the same tz (_seconds_until_next_midnight), so key turnover and Redis expiry agree on the same midnight; tz=None keeps UTC, so all other callers are unchanged. The new check_tts_rate_limit_for_user resolves the zone via resolve_user_timezone inside the executor (Firestore read stays off the event loop) and falls back to UTC on any error — verified resolve_user_timezone validates the IANA zone and returns "UTC" for missing/invalid, so the limit is never silently disabled.
  • backend/routers/tts.py — entry point swapped to the new wrapper inside the existing await run_blocking(critical_executor, ...); the 429 detail now correctly says the reset is at the user's midnight instead of the old (now false) UTC claim, and Retry-After uses the local-midnight TTL.
  • backend/routers/desktop_tts_updates.py — same offload swap; its 429 details mention no reset time, so no message change was needed (confirmed).
  • backend/tests/unit/test_tts_daily_quota_local_day.py — good test design: freezing redis_db.datetime and asserting on the key/TTL actually handed to the Lua script covers same-local-day bucket sharing, midnight turnover, the ~1h TTL at 11pm LA, and the UTC fallback.
  • backend/tests/unit/test_tts_ratelimit_async.py — the AST guard now targets the new entry point and additionally prevents the raw check_tts_rate_limit from reappearing on the loop via _NEVER_ON_THE_LOOP; the docstring accurately explains the two sync layers.

Two non-blocking observations for maintainers:

  1. The stored timezone is client-synced, so a user deliberately flipping their zone mid-day gets a fresh local-day bucket. That's a strictly smaller hole than the involuntary UTC double-reset this PR fixes and fits the best-effort posture of the limit, but worth knowing it exists.
  2. One-time transition on deploy: users who exhausted today's UTC-keyed bucket get a fresh local-day bucket once; old keys self-expire via TTL.

All checks pass and the earlier review feedback has been addressed. Thanks for the careful write-up and the regression tests.

This is AI-generated feedback posted on behalf of the maintainers.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level removed the needs-maintainer-review Needs a human maintainer to sign off before merge label Sep 30, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix(backend): TTS daily allowance bucket now built from user's local midnight instead of UTC — root cause clear, linked issue #15169, 4 new regression tests (3/4 fail on main), CI green, already approved by kodjima33 and (after follow-up) aryanorastar. Confidence 5/5, merging.

@kodjima33
kodjima33 merged commit 6e92b35 into BasedHardware:main Oct 5, 2026
45 checks passed
aryanorastar added a commit to aryanorastar/omi that referenced this pull request Oct 6, 2026
Both fail on main itself and red every branch's Backend unit shards:
- BasedHardware#15171 moved the TTS routes to redis_db.check_tts_rate_limit_for_user, but
  test_desktop_tts_updates.py still matched check_tts_rate_limit.
- BasedHardware#20665 removed routers.action_items._wake_task_changes, which
  test_accept_shared_tasks_unavailable_claim_returns_503 still patched.

Byte-identical to BasedHardware#20748, so whichever merges first leaves the other a no-op.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Git-on-my-level added a commit that referenced this pull request Nov 4, 2026
* test(backend): catch main up to the TTS rate-limit rename and retired task wake

#15171 renamed the offloaded rate-limit call to
redis_db.check_tts_rate_limit_for_user but left the desktop TTS unit
stub and its identity assertion on the old function name, and #20665
retired routers.action_items._wake_task_changes while the shared-task
503 regression still patched it. Both files failed on origin/main and
blocked every backend unit shard. Align the stub and assertion with the
renamed call and drop the stale wake patch.

* test(listen): guard lag-probe wiring and /metrics exposition

Prod listen pods showed no omi_listen_event_loop_lag_seconds series. The
code path is correct: every listen deployment runs an image older than
#22397 (backend:8d7778a is its parent), while Cloud Run backend runs
4f43b2d, which contains it. Pin the two links the D0b gate depends on:
run_listen_session starts the probe before building the runtime, and the
listen /metrics handler renders the histogram from import. Document the
image-tag check for a missing series.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(listen): tie exposition test to the route wiring; fix frame-histogram doc

Grok review on #22608: the exposition test did not use the listen route
import, and the doc said every loop histogram renders from import, which
is false for the codec-labelled frame histogram. Assert the route ->
runtime -> probe module chain and the import-time registry collector, and
document that the frame series appears only after the first timed frame.

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(listen): frame histogram child appears at receive-loop entry, not first frame

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(listen): exercise the deployed app's /metrics exposition in a fresh process

Codex review: the exposition test imported routers.listen.runtime itself
and called the metrics handler directly, so it kept passing if main.py
stopped registering metrics.router, and its zero-count check only asserted
the series name after earlier tests in the same file had already
incremented the process-global histogram.

Run the assertion path in a fresh interpreter instead: install the
hermetic network blocker, import main (the deployed listen entrypoint per
backend/Dockerfile CMD), make an unauthenticated request (401) and an
authenticated one (200) through the real app routing, and assert the exact
import-time 'omi_listen_event_loop_lag_seconds_count 0.0' with no probe
started before or after serving. Subprocess CPU is not charged to the
fast-unit duration guard, and the network blocker proves the path stays
hermetic for the no-Redis CI lane.

Failure-Class: none

* test(sync): legacy import ratchet and enrichment outbox contracts

Plan C (legacy sync consolidation) PR C1. Tests only; no runtime change.

- tests/unit/test_sync_legacy_import_ratchet.py + fixtures/sync_legacy_import_baseline.json:
  freezes the 10 current importers (outside utils/sync and routers/sync.py) of the
  19 legacy sync modules scheduled for retirement; new edges fail, stale edges must
  be removed, every edge carries a reviewed "why".
- tests/integration/test_enrichment_outbox_contract_emulator.py: Firestore-emulator
  contracts for the sync enrichment outbox that the utils/enrichment move must keep:
  first-summary wake within 120s, coalescing, stale-token refusal, lease expiry
  repaired by the sweep, redirect custody transfer and the privacy fence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sync): address review — selector coverage, keyword imports, fixture teardown

- Ratchet now runs for every in-scope importer on changed-file CI, not only
  the post-merge --all run: new shared scope predicate
  (tests/support/sync_legacy_ratchet_scope.py) wires the selector the same
  way the background-task ratchet is wired, so an importer under e.g.
  backend/utils/apps selects test_sync_legacy_import_ratchet.py. Contract
  tests pin the predicate against the ratchet's own scope.
- import_module detection also accepts the keyword form
  (name='utils.sync.pipeline'); non-literal names still detect nothing.
- Enrichment outbox emulator fixture deletes dormant receipts and synthetic
  conversation documents by key on teardown (uid is cleared on dormant rows,
  so the uid-query teardown misses them; parent deletes keep subcollections).
- All function-local imports in the integration test hoisted to module
  scope (backend AGENTS.md import rules).
- Baseline gains the reviewed upstream edge
  scripts/cap_hold_durability_emulator_test.py -> utils.sync.pipeline
  (rebased onto main that introduced cap-hold durability).

* test(sync): address review — aliased import_module, survivor scope, selector tuple

- import_module detection now resolves aliases bound by
  'from importlib import import_module as load'; calls through the alias
  with a literal module name are dynamic-import edges. Non-importlib
  aliases with the same call shape still detect nothing (parametrized).
- The ratchet no longer excludes the whole utils/sync/ package: only the
  retiring modules themselves and routers/sync.py are out of scope, so
  surviving in-tree callers (cap-hold core, recording_session_target)
  are scanned and their legacy edges are frozen in the baseline with
  reviewed whys. These are exactly the edges C11 (#22635, keep the
  cap-hold core) must cut; the shared selector predicate keeps its
  cheap superset and still defers narrow area selection to AREA_TESTS.
- SYNC_LEGACY_RATCHET_TESTS now selects only the ratchet itself.
  test_workflow_contracts.py has no legacy-ratchet assertions; it keeps
  its own selection via workflow contract sources and backend/testing/
  full-run prefixes, instead of riding every backend-Python selection.

* test(listen): keep the child's network guard referenced for its whole body

Codex review: 'block_outbound_network().__enter__()' drops the only
reference to the _GeneratorContextManager, so CPython finalizes it (and
its finally block restores the socket functions) before 'import main'
runs — the hermetic claim was inert, and an environment supplying Stripe
credentials could turn the import into real network calls. Enter the
guard through an ExitStack held for the entire child body.

Failure-Class: none

* test(sync): address review — proven import_module bindings, relative targets, fence/IO contracts

- Dynamic-import detection now requires proven importlib bindings: attribute
  receivers bound by 'import importlib [as imp]' and bare names bound by
  'from importlib import import_module [as load]'. An unrelated
  obj.import_module(...) or a local function named import_module no longer
  fabricates a legacy edge and fails changed-file CI (V8).
- Relative import_module targets ('.pipeline', package='utils.sync') resolve
  against the literal package argument — positional or keyword — with each
  leading dot beyond the first trimming the package, mirroring the
  interpreter. A relative name without a literal package detects nothing (-s).
- Privacy-fence contract now exercises the race it names: phase 1 keeps the
  pre-blocked discard (entry fence), phase 2 lands the block between the
  entry fence and the claimed callback and proves the adapter's inner
  discard_blocked discards without ever invoking work; blocks are cleared
  between phases so each parametrized block path is really driven (-z).
- Malformed-binding rejection now proves 'before any IO': the Firestore
  client accessor is replaced with a fail-fast mock for both the adapter and
  the outbox, so any pre-validation read/write fails the test (WB).

* test(jobstore): port recovery discovery and progress parity invariants

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): carry recovery custody invariants across job stores

Failure-Class: FC-empty-asr-without-context-recovery

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): pin recap fixture to a reproducible admission time

The unmodified main test fails five assertions before noon because its fixture and recap selection use different dates. Pass one explicit afternoon instant through the existing production input seam; keep every assertion and production behavior unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): port recovery and admission parity invariants

Carry PL-057, PL-072 and PL-086 through the shared Store matrix. Keep the new-store cancellation gap strict and linked to issue #23761.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(mobile-perf): upload-success window, sparse scoring, semantics knob; tag lag stalls with work in flight

- --upload accept --upload-wals N appends wal_sync_upload_success: synthetic
  uploads and jobs drive real sync phases, persistence and reconcile.
- cold_start, home_idle_sync_refresh and the upload window are sparse: cold
  readiness keeps the 15% spread gate and each run has a stall budget (<=2
  stalls over 100 ms, <=500 ms). Dense windows keep 15% p90; no run dropped.
- Semantics is off for heavy perf by default; --semantics on is a separate
  dataset and compare refuses mixed settings.
- LagWorkRegistry: bounded, allocation-free begin/end; mobile_lag_stall
  records overlapping sync/upload/reconcile/WAL-load work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(mobile-perf): dry-run tests pass an explicit artifact root

Without one, device_run.main() exits 2 on hosts with no scratch mount, so
the manifest check failed on ordinary Linux checkouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(jobstore): qualify fenced shard pulls across stores

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(jobstore): require available backends in the selected proof lane

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(outbox): preserve durable enqueue across wake failures (PL-042)

Failure-Class: none

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(outbox): verify committed enqueue result identity

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): qualify partial-pull leases across store backends

Port PL-194 into the shared scheduler/Store matrix and existing emulator proof lane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): qualify pending deletion across old and new stores

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): PL-049 positive-speech custody follows the one Soniox second chance

Main a866d27 (10-30) gives Modulate-empty held units with positive speech one independent Soniox
second chance. The PL-049 case written 10-26 asserted no second provider at all, so it failed on every
store after the merge. It now pins the new contract: the second chance is spent at most once across
repeated sweeps, and an uncertain call keeps audio, intent and custody held. Measured silence still
settles without any paid call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: qualify pull-batch parity across Firestore and Postgres

Preserve PL-321/322/323 at frame boundaries, buffered query overlays and bounded walk stops. Register the shared matrix in the existing emulator-proof runner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test: clean coordination fixtures within their owned namespace

Include merge holds beside pull claims and prove cleanup preserves foreign namespaces and synthetic customer rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): enforce held-custody and no-spend recovery parity

Qualify PL-061, PL-105 and PL-363 on old Firestore, new Postgres
and the simulator through the existing Store harness.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): keep partial-custody identity distinct from producer outcomes

Use PL-396 for phone custody and leave PL-061 producer client_status
as a separate missing invariant in the parity ledger.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(backend): declare isolated stage and fence paid refusal markers

Make the conformance fixture independent of CI stage defaults and
reject paid-attempt metadata on a local no-spend refusal. Clarify
minimum CI stores versus all-store cutover qualification.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style(firmware): match CI clang-format on the safe-mode snapshot initializer

CI's clang-format 18 attaches the compound-literal brace and drops the
space before it; break nothing else and keep the initializer alignment
one column left.

* test(backend): keep the enrichment proof clock a real clock

The consumer's heartbeat hold cap reads time.monotonic, so the injected
consumer clock must carry the full time module with only the wall-clock
pinned, or every PL-397 delivery dies on AttributeError before the
callback runs.

* style(firmware): drop the compound-literal brace space CI's clang-format rejects

CI formats firmware with clang-format 18, which attaches the brace after
the compound-literal cast; the local 23 kept a space and realigned one
column right, so the Formatting job failed on the merge preview. Commit
with clang-format 18 first on PATH so the pre-commit hook agrees.

* test(backend): inventory lifecycle writers and latch invariant gaps

* test(backend): re-baseline the legacy-sync import ratchet to the folded tree

The ratchet fixture arrived from #22390 with a baseline ~4.5k commits stale:
main gained nine importers of the retiring legacy sync modules (staging
syncsplit proof, backfill worker control/job, empty-success guard, watch
recovery e2e, capture coverage lanes) and lost two baseline edges
(enrichment callback, cap_recovery_audio coverage replay). Regenerated with
the ratchet's own --write pass, then reviewed each edge's why against the
retire milestones (C10/C11).

* test(backend): align partial-pull conformance with the current lease API

The PL-194 file predates two scheduler changes main landed since its base:

- The pull transaction now returns (receipts-or-None, eligible, observations)
  where each receipt is (lease, enqueued_at, relet); Scheduler.pull is what
  unwraps receipts into LeasedWork. The conformance helper treated
  result[0][0] as a lease, so its committed list held receipt tuples against
  pull's LeasedWork list, and aborted['lease'].item raised AttributeError.
  Unwrap receipts to the lease on both sides so the whole test speaks the
  one shape main's lease API returns.

- A multi-lease abort rolls back every receipt in its transaction, so the
  exact 'failing_lease - 1 committed' count only holds one lease per
  transaction; pin the documented BATCH_PULL_MULTI_LEASE_ENABLED kill
  switch (as the file already pins shard spread and cap dispatch).

- Shard-spread selection reads control_candidates (plural fanout), not the
  singular control_candidate the overlap test paused; hook both, each
  wrapping its own original, since the singular delegates to the plural.

All 24 partial-pull parametrizations plus both overlap cases pass on sim
and Postgres locally; emulator legs stay with CI's proofs job.

---------

Co-authored-by: David Zhang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] fix(backend): the daily TTS allowance resets at UTC midnight, so it can be spent twice a day ($50 proposed)

4 participants