Skip to content

feat: globally pace held-audio recovery - #22970

Merged
Git-on-my-level merged 1 commit into
mainfrom
lane/recovery-pacing
Oct 21, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lane/recovery-pacing

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Recovery can currently create provider intents without a shared audio budget. This adds an always-on, fail-closed Redis Lua token bucket immediately before each new intent, including persisted retries. Pacing denials durably defer the hold without creating a provider attempt or metered charge.

Redis is the existing cross-pod rate-limit pattern (database/redis_db.py), with server-clock Lua also used by import quotas and messaging pacing; a dedicated bounded client uses the same Redis bindings without adopting fail-open behavior. One atomic, global key spends audio seconds and intent tokens together using Redis TIME. Plain env defaults are 60 audio-hours/hour and 12,000 provider intents/hour (pieces/retries count conservatively toward the holds ceiling), with one minute of burst credit. Missing/evicted state starts empty. Invalid config, unavailable Redis, ambiguous replies and oversized pieces defer; uncertain tokens are never refunded.

The existing durable owner cursor stays in place. The sweep now gives each discovered owner one newest-first candidate per round, up to 100 turns/owner within the existing 900-second budget. Holds retain fenced claims/receipts, consent, cutoff, original-lane and allowance checks. Release preserves durable retry deadlines, claim respects them, and sealing/cleanup plus cached-result settlement stay independent of pacing.

Metrics expose intent decisions and requested audio tokens with only outcome=granted|deferred|refused, plus sampled age since first durable pacing deferral. The deferred-age histogram is not a fleet maximum; existing fleet custody gauges remain authoritative.

Validation:

  • 304 hermetic tests passed across 8 focused files, including real production Lua on fakeredis shared by four simulated pods, contention, independent intent ceiling, empty-on-eviction behavior, shared-state failure, strict Firestore defer/release/reclaim, no attempt/usage on denial, retry token use, cached-result settlement and owner rotation/newest-first coverage.
  • Command: BACKEND_PYTEST_WORKERS=4 BACKEND_UNIT_TEST_FILE_LIST=/Volumes/Ephemeral/scratch/recovery-pacing/focused-tests.txt /Users/dazheng/workspace/omi/bin/omi-heavy run -- nice -n 10 bash backend/test.sh (equivalent environment placement used in the actual run).
  • Feature-flag registry check passed. These capacity values are plain config, not new flags; no new registry row or ramp is needed.
  • Targeted type check passed with zero errors using the worktree Python 3.11 interpreter.
  • Final-commit local preflight passed all 33 checks; the normal bounded pre-push gate, full backend type check (zero errors), runtime-image source closure, selected units and release guards passed. GitHub owns the current CI result in this PR’s Checks tab for head 144c0ecbf7d3287f46113db6362b53180f59585e.

Lessons and debt: release previously overwrote retry timestamps, so durable pacing needs both a fenced defer checkpoint and a claim/release contract. Ambiguous writes conservatively waste credits. Round-robin candidates add lease/query overhead and do not guarantee equal audio shares for multi-piece holds. The one-minute burst plus the nominal two-minute sweep cadence can underfill the configured rate when visits finish quickly; the configured rate is a ceiling, not demonstrated drain throughput. Frozen pieces larger than the burst envelope remain held for operator diagnosis/replanning (ordinary VAD defaults to 300 seconds). All recovery hosts must share the Redis endpoint and capacity values; mixed runtime config is unsupported. Live throughput/activation, unsupported-language and explicit-consent/restart acceptance remain prerequisites for STT cap 100%. No production writes, account reads, Cloud Logging, deployment or merge; no GCP tier used. Ready for Grok review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T03:34:44.418885Z 144c0ec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level
Git-on-my-level merged commit 20bc2e3 into main Oct 21, 2026
67 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/recovery-pacing branch October 21, 2026 04:06
Git-on-my-level added a commit that referenced this pull request Oct 21, 2026
Picks up #22995 (P17 capture_live_recovery fix) and main through 31756b9,
which includes #22877 episodes (d6b734b; prod deploy freeze until the
EPISODES_PERCENT=0 overlay lands, staging allowed per lead 88c5cd).

Conflicts:
- utils/sync/cap_hold_recovery.py: main's optional recovery cohort (#22991) and
  pacing metrics (#22970); module gates on recovery_admission_enabled. Kept
  integration's lane-returning _selected_lane, funded-processing reservation
  and batch hand-off.
- main.py / app_roles.py: kept the B8 role-map mount; Mount(episodes) added in
  main's position (between pending_work and commitment_followup).
- .github/ci-budget.yaml: six rationale strings carry both sides' notes.
- config/feature-flags.yaml: both sides' rows; registry re-rendered.
Adaptations: 8 label-debt entries (episodes/memory-source/held-content metrics,
owner lane 14); test_summary_delivery first-import case allowlisted.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant