Repository navigation
fix(backend): keep daily summaries from dropping tail users - #12588
aryanorastar wants to merge 7 commits into
Conversation
Failure-Class: FC-scheduled-batch-outlives-execution-contract
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Verification proofThis is the final evidence against current
Commands and resultsThe production observations remain the read-only evidence already attached to #12530: per-minute cadence, overlapping execution IDs, an OOM termination, and the un-awaited webhook warning immediately before container exit. I did not mutate live infrastructure from a development machine. The protected post-merge deployment is the acceptance step and fails closed unless the final Scheduler describe matches the retained contract exactly. No iOS, Android, pendant, or physical-device testing is applicable to this backend/Cloud Run fix. |
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Failure-Class: FC-scheduled-batch-outlives-execution-contract
|
CI follow-up proof The first full backend unit run exposed one import-isolation test double that had not been updated for the new token-count dependency:
Reproduced through the same runner CI requested: The push then passed the complete bounded pre-push gate again, including 34 PR-preflight checks, pyright (0 errors), runtime-image closure for 13 images, workflow/deployment contracts, and all 8 selected backend test files. A fresh authoritative GitHub Actions run is now in progress. |
|
Reviewed against #12530's production evidence — this is a well-executed fix for the tail-user drop, and the deployment contract now matches the worker's actual one-hourly-batch lifecycle. Notes by area: Worker lifecycle — backend/utils/other/notifications.py
Context overflow — backend/utils/llm/external_integrations.py
Deployment contract — .github/workflows/gcp_notifications_job.yml, backend/scripts/provision_notifications_scheduler.py, runtime_env yamls
Records and docs — the new Two decision points for maintainer sign-off before merge, beyond the normal human read:
Checks are green on this head, including the hermetic backend gates. No split needed — this is one cohesive lifecycle fix. Labels applied: backend, positive-signal, workflow-review, needs-maintainer-review. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Failure-Class: FC-scheduled-batch-outlives-execution-contract
Reviewer follow-up: all five findings addressedThe five findings from the Cubic review on
Fresh verification against current mainThe full push gate completed successfully before the new head was published. Fresh GitHub Actions runs are now executing. This remains a backend/Cloud Run lifecycle fix; no iOS, Android, pendant, or physical-device validation is applicable. |
Failure-Class: FC-scheduled-batch-outlives-execution-contract
CI follow-up: import-isolation fixture correctedThe only failing job on
Exact CI-runner reproduction: Combined changed and related suite: The full pre-push gate then passed again: 34/34 PR checks, Python 3.11 pyright with 0 errors, 13/13 runtime-image contracts, all 9 selected backend test files, module-isolation, workflow/deployment contracts, and formatting. A fresh GitHub Actions run is now authoritative for head |
Current-main verification completeThe branch is synchronized with current Fresh local proof after the clean main merge
Authoritative GitHub proof on this exact head
Cubic reports all five review findings addressed. The PR is open and non-draft; its only remaining gate is maintainer review/approval. No merge or production deployment was performed, and no physical-device validation applies to this backend/Cloud Run lifecycle fix. |
|
Follow-up verification on Hardening commit
Fixture-only follow-ups — Deploy contract cross-check — Minor, non-blocking: The two maintainer decision points from the earlier review still stand before merge: shared by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Status change worth flagging before anyone re-reviews this: #12530 was closed on 2026-09-03, fixed on
Edited in place to correct one claim. My first version of this comment said
It is also the better of the two on selection policy. The one axis where this PR's version differs usefully is the measurement unit — tokens via Revised picture
What I would rather doWith item 1 withdrawn, rescoping this branch is the wrong shape. Item 2 is a self-contained change to one function plus its test; item 3 is a workflow change. Neither needs the 1,132-line batching diff, and the conflicted file is one I would rather close this PR and open one small PR for the webhook drain, carrying #12530's evidence as its justification, than resolve a conflict against a merged fix. Item 3 can follow separately if the free-form |
|
Closing in favour of #12742, which carries the one part of this branch that
What genuinely remained was the webhook lifecycle, and researching it for the replacement PR turned up a sharper root cause than this branch had. Not carried over: the batching and accounting half, which |
|
Hey @aryanorastar 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
… evidence Two documentation-accuracy notes from review. The TestNotificationWebhookWiring docstring still said the webhook is "wired through storage_executor" -- stale across two rewirings. It was storage_executor, then postprocess_executor (BasedHardware#7387), and is now an inline awaited call bounded by its own budget. The class name predates all of that, so the docstring now records the sequence and why the current shape is what it is. evidence_prs cited BasedHardware#12588, which was closed unmerged. Replaced with BasedHardware#12742 rather than the suggested BasedHardware#12635: BasedHardware#12635 landed c82237e, the batching/cursor fix that belongs to FC-batch-fault-domain-head-of-line-poison, and it did not touch the pool-lifecycle defect this class describes. Citing it would attribute this class to a change that never addressed it. This PR is where the class is both defined and fixed, which matches FC-task-candidate-unowned-commitment citing its own defining PR. scripts/failure-class validate: OK (fix commits=True; declaration=new). Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]>
* fix(backend): give the daily-summary webhook a lifecycle owner
The daily-summary developer webhook was submitted fire-and-forget:
postprocess_executor.submit(asyncio.run, day_summary_webhook(...))
Two defects in one line. _deliver_current_day_summary already runs *on*
postprocess_executor -- send_daily_summary_notification dispatches every
user through run_blocking(postprocess_executor, _send_summary_notification,
...) -- so the submit made the coordinator its own child on the pool it was
running on, the arrangement backend/AGENTS.md forbids. And nothing owned the
result: the per-user asyncio.wait_for budget covers the call, not what the
call spawns, and the Cloud Run Job exits without joining the pool. A webhook
still queued at exit was never scheduled, which is the
coroutine 'day_summary_webhook' was never awaited
logged immediately before container exit in #12530's evidence.
c82237e fixed the batching half of #12530 with a deadline and a resumable
cursor. That bounds the batch; it does not give this coroutine an owner.
Run it inline, inside the per-user budget that governs the rest of that
user's work. The push moves ahead of it and becomes a branch rather than an
early return, so a tokenless user still reaches their webhook as before. The
call is wrapped because inline changes who pays for a fault: day_summary_webhook
handles its own HTTP failures but not the work around them, and an escaping
error would mark a user whose push already went out as failed. The discarded
Future used to supply that containment by accident; make it a decision, and
log it, where the old path reported nothing.
Also returns 8 slots per batch to postprocess_executor -- the pool
DAILY_SUMMARY_MAX_ABANDONED_USERS exists to protect.
Failure-Class: new
Co-Authored-By: Claude Opus 5 <[email protected]>
* fix(backend): bound the daily-summary webhook inside its own budget
Running the webhook inline gave it an owner, but it also moved its cost onto the
user. day_summary_webhook posts through the shared client (30s read timeout,
retries at 1/5/30s) and now sits inside the per-user asyncio.wait_for budget, so
a slow receiver could burn most of DAILY_SUMMARY_USER_BUDGET_SECONDS and get a
user whose push had already been delivered marked reason=user_budget_exceeded --
which counts toward DAILY_SUMMARY_MAX_ABANDONED_USERS and can abort the rest of
the hour group. A developer webhook must not be able to cost anyone their recap.
Bound it at DAILY_SUMMARY_WEBHOOK_BUDGET_SECONDS (20s, env-overridable), well
inside the 90s budget it shares. The existing except already contains and logs
the resulting timeout.
Verified by mutation: with the bound removed the new test reports
"the webhook must be abandoned at its own budget, took 30.0s"; with it, the
webhook is abandoned at its own budget and the record and push both survive.
Also assert the daily_summary_webhook_failed log line in the containment test.
Containment without the log is the old swallowed Future by another name -- the
fault disappears and #12530's evidence never reappears -- so the test now pins
the record rather than only that nothing raised.
The source pin follows the new wiring: it still forbids the submit, and now
requires the timeout constant rather than a bare asyncio.run call.
Failure-Class: none
Co-Authored-By: Claude Opus 5 <[email protected]>
* docs(backend): correct the webhook wiring docstring and failure-class evidence
Two documentation-accuracy notes from review.
The TestNotificationWebhookWiring docstring still said the webhook is "wired
through storage_executor" -- stale across two rewirings. It was storage_executor,
then postprocess_executor (#7387), and is now an inline awaited call bounded by
its own budget. The class name predates all of that, so the docstring now records
the sequence and why the current shape is what it is.
evidence_prs cited #12588, which was closed unmerged. Replaced with #12742 rather
than the suggested #12635: #12635 landed c82237e, the batching/cursor fix that
belongs to FC-batch-fault-domain-head-of-line-poison, and it did not touch the
pool-lifecycle defect this class describes. Citing it would attribute this class
to a change that never addressed it. This PR is where the class is both defined
and fixed, which matches FC-task-candidate-unowned-commitment citing its own
defining PR.
scripts/failure-class validate: OK (fix commits=True; declaration=new).
Failure-Class: none
Co-Authored-By: Claude Opus 5 <[email protected]>
* fix(backend): run the daily-summary webhook after the owner's backfill
Review point, and it is right. Running the webhook inline gave it an owner but
put its cost inside DAILY_SUMMARY_USER_BUDGET_SECONDS, which the owner's own
backfill walk also spends. Sitting ahead of the backfill, a slow receiver could
take up to DAILY_SUMMARY_WEBHOOK_BUDGET_SECONDS that the owner's missing days
needed, and tip a marginal user into user_budget_exceeded -- counting toward
DAILY_SUMMARY_MAX_ABANDONED_USERS and abandoning the rest of the hour group.
That contradicted the rule this change exists to uphold, which the code comments
already stated: a developer webhook must never cost the owner their recap.
Backfill is owner work. Last in the per-user budget means the webhook can only
ever spend what nobody else still wants.
Lifted out of _deliver_current_day_summary into _deliver_day_summary_webhook and
driven from _send_summary_notification's finally. finally rather than a trailing
call, because the dormant-owner branch returns before the backfill and the
backfill itself can raise: either would drop the webhook for a user whose summary
was already generated, stored and pushed -- the same unowned-work loss this PR
exists to stop, just moved to a different exit.
The bound, the containment and the daily_summary_webhook_failed log are
unchanged, as is the payload call, so TestSendSummaryNotificationWiresSummaryJson
still pins day_summary_webhook(uid, str(summary_data), summary_data) exactly.
Three tests. Ordering is mutation-checked: with the webhook restored to its old
position the assertion reports "the webhook must run after every backfill
generation, not before them", assert 1 == 4. The other two cover the finally --
a raising backfill still sends the webhook, and a dormant owner is unaffected.
Suites: generation 30, async_http_infrastructure 50, async_webhooks 29,
job_resilience 21, lock_bypass_fixes 62, other_notifications_async_boundaries 6,
race_condition 16, empty_overview 2.
Failure-Class: none
Co-Authored-By: Claude Opus 5 <[email protected]>
* test: name the dormant-day webhook test for what it asserts
The test asserts no webhook is sent when a dormant owner declines the day,
but was named as though it proved one survives. Review on #12742 caught it:
a dormant decline means created=False, so pending_webhook is already None
and the finally has nothing to deliver.
Renamed to test_a_dormant_day_sends_no_webhook and rewrote the docstring to
state the real guarantee -- the finally must not push an empty recap on the
early-return path -- and to point at the raising-backfill test, which is what
actually exercises delivery through finally.
---------
Co-authored-by: Claude Opus 5 <[email protected]>
What changed and why
Fixes #12530.
Daily summaries were being scheduled every minute even though the worker is designed to own one hourly batch. That created overlapping Cloud Run executions, OOM/timeout pressure, and tail users who never reached completion. The same path also launched developer webhooks as unowned executor work and rendered an unlimited day of conversation history into one model request.
This PR makes the deployment and worker lifecycle agree:
0 * * * *UTC Scheduler target, itsrun.invokerbinding, and one 3600-second/no-retry/one-task execution;Product invariants affected
INV-DATA-1— preserves the existing production data-plane authority; this is not a migration exception and does not change customer identity, Firebase, Firestore, or serving-plane selection.INV-MEM-4— preserves canonical memory authority. The generated runtime manifest changes only notifications-job execution flags; it does not add a memory intake, promotion, projection, or mutation path.How it was verified
*/1 * * * *, concurrent execution IDs, an OOM kill, andcoroutine 'day_summary_webhook' was never awaitedimmediately before process exit._send_bulk_summary_notificationcannot finish until that webhook is released.backend/.venv/bin/pytest -q ...over the related daily-summary, webhook, scheduler, runtime-env, and workflow suites: 208 passed.PATH="$PWD/backend/.venv/bin:$PATH" backend/scripts/pre-deploy-check.sh: 226 passed, with dev/prod runtime validation and workflow contracts green.python3 backend/scripts/check_workflow_contracts.py: passed.python3 .github/scripts/check_failure_class_guard_ratchet.py: passed.make preflight: passed against the final committed diff and this PR body.No production mutation was performed from a development machine. After merge, the protected notifications deployment must be dispatched with the admitted merged-main SHA; that run applies and then describes the Scheduler, failing if cadence, state, method, URI, or service account differs. This is backend/infrastructure-only and requires no iOS, Android, pendant, or physical-device verification.
Tests
backend/tests/unit/test_other_notifications_async_boundaries.py— event-loop responsiveness, awaited webhook lifecycle, and mixed user accounting.backend/tests/unit/test_provision_notifications_scheduler.py— exact Scheduler create/update/validation and deployment manifest ownership.backend/tests/unit/test_daily_summary_zero_coordinate_locations.py— prompt history remains unchanged below the cap and deterministic above it.asyncio.runsubmit pattern.Failure class (fixes)
Failure-Class: new
Failure-class transition narrative (only when needed)
New class:
FC-scheduled-batch-outlives-execution-contract.The violated contract is that a scheduled batch worker's deployed cadence, deadline, concurrency, and owned async work must match the lifecycle assumed by its code. The canonical prevention is an exact deployment-owned and post-apply-verified Scheduler target, manifest-owned execution bounds, bounded provider input, awaited webhook completion, and explicit run accounting. The supporting guards are the scheduler contract, blocked-webhook lifecycle test, mixed-batch accounting test, and prompt-budget tests listed above.
New guards (only when adding a check or ratchet)
These guards would have caught #12530 before deployment. The exact Scheduler name/target/cadence is intentionally job-specific; the implementation still uses the repository's shared runtime-manifest renderer and async executor primitives rather than creating a second general deployment or concurrency framework.
Rollout and rollback
gcp_notifications_job.ymlfor the protected environment with that exact SHA.0 * * * *,Etc/UTC,ENABLED,POST, the exact v2notifications-job:runURI, and the configured service account.