Skip to content

feat(observability): count delivery terminal outcomes before alarm calibration - #24426

Merged
Git-on-my-level merged 6 commits into
mainfrom
lane/ic-reads-delivery
Nov 2, 2026
Merged

Git-on-my-level merged 6 commits into
mainfrom
lane/ic-reads-delivery

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Add omi_delivery_outcome_total{kind,outcome} at durable summary terminals, sync callback returns and action-item export boundaries. Labels use only the fixed kinds summary|sync|action_item_export and outcomes delivered|no_op|deferred|failed; unknown values are rejected before creating metric children. Outcomes use the shared closed enum and reason-label adapter without adding debt or allowlist exceptions.

Summary observations emit after the existing transaction commits, once across retries, without changing existing first-summary receipts or business state. An open summary obligation is deferred; deliberately waived short-clip debt stays no-op. Sync holds, absent/redirected/open targets and fences are deferred; discarded results remain no-ops even if old summary text is retained. Deferred/locked processing results cannot become delivered. Export counters observe each public result without changing return values or provider calls; a device enqueue is deferred. The counters measure attempts, including retries, rather than unique deliveries. Helpers keep the existing oversized owner files from growing.

The no-op alarm remains unarmed. Infracost records serving release identities, traffic and visible counters, then collects seven full clean days per kind and service after all serving traffic runs the new code. Only then may a separate monitoring change propose a minimum-volume six-hour no-op ratio threshold from the baseline. First baseline progress decision is due within three days of deploy; it cannot shorten the seven-day hold. No alert rule or production action is part of this PR.

Both GMP keep-lists retain delivery/People counters, all existing metric families, omi_firestore_billed_reads_by_* and omi_fsr_leader_lease_total. The inventory refresh uses ro-prod aggregate metric names, keeps observed names distinct from declarations and preserves admission holds and legacy debt. No production account data is read. Metrics ship on; lead-owned rollback is a later code-revert train. No savings are booked for this instrumentation.

Validation: 1,086 unique unit cases passed across 20 selected files over the implementation. After R1's two classification findings, all 113 focused debt/transaction/sync/parity cases and 29 hermetic E2E cases passed again. Integration with the merged B/C main line then passed 241 combined unit cases, 29 E2E cases and monitoring lint. The label-contract/audio selection passed all 149 cases (36 delivery, 19 enum contract, 94 audio-outbox); the old CI worker's nonzero audio status did not reproduce locally. Targeted types report zero errors. All tests ran through bin/omi-heavy run -- nice -n 19; units use backend/test.sh, explicit file lists and four workers. Tests cover committed-only emission through retries, debt preparation/waivers, discard precedence, deferred/locked results, bounded labels, canonical/legacy parity, export results and both GMP profiles. Malformed observations preserve business results. The oversized owners retain their exact original line counts (4652 and 3965), with no exception.

Main through 1708dc7859b0 (including merged #24413/#24422) is integrated. The three GMP/inventory conflicts were resolved from the full incoming main configuration, preserving every existing family and admission/legacy-debt metadata. The fresh aggregate inventory contains 2,280 observed names and 17 declarations. Final CI and delta review remain required.

Product invariants affected

none

Initiative: unit-economics
ANX: card:ic-reads-1102

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 issues found across 14 files

Confidence score: 3/5

  • outbox.py and consumer.py can count an already-committed summary as failed, skewing the delivery baseline. Preserve and record the committed outcome when record_empty_failure finds the summary.
  • delivery-outcomes.md assigns baseline collection to Infracost, which conflicts with the stated rollout responsibility. Update the runbook to name the responsible team.
  • delivery.py can classify subclasses of deferred or fence exceptions as failed. Match derived exceptions so they retain the deferred outcome.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/utils/enrichment/outbox.py">

<violation number="1" location="backend/utils/enrichment/outbox.py:670">
P2: This records `summary/failed` even when `record_empty_failure` finds that a summary was already committed before the callback lost its acknowledgement. That inflates the failed baseline with an already-delivered terminal state; return the helper's enriched/blocked outcome or otherwise classify the already-enriched case as `no_op` before recording the metric.</violation>
</file>

<file name="backend/docs/runbooks/delivery-outcomes.md">

<violation number="1" location="backend/docs/runbooks/delivery-outcomes.md:28">
P2: This runbook assigns delivery-metric baseline collection to Infracost, which is unrelated to the GMP counter workflow and conflicts with the stated team/rollout-lead responsibility. Replace it with the actual observability or rollout owner so the required seven-day baseline is not left ownerless.</violation>
</file>

<file name="backend/utils/enrichment/consumer.py">

<violation number="1" location="backend/utils/enrichment/consumer.py:173">
P2: This records `failed` even when `record_empty_failure` finds that another writer already committed the summary and retires the row with `summary_seen=True`. Return the committed outcome from `record_empty_failure` (or otherwise distinguish the enriched case) before incrementing this counter, so baseline failure rates are not inflated by already-delivered summaries.</violation>
</file>

<file name="backend/utils/observability/delivery.py">

<violation number="1" location="backend/utils/observability/delivery.py:96">
P3: Subclassed deferred/fence exceptions are miscounted as `failed`. Match the exception MRO (or use `isinstance`) so derived terminal exceptions retain the `deferred` outcome.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

get_firestore_client(), COLLECTION, document_id, owner, task_token
):
raise
record_delivery('summary', 'failed')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This records summary/failed even when record_empty_failure finds that a summary was already committed before the callback lost its acknowledgement. That inflates the failed baseline with an already-delivered terminal state; return the helper's enriched/blocked outcome or otherwise classify the already-enriched case as no_op before recording the metric.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/enrichment/outbox.py, line 670:

<comment>This records `summary/failed` even when `record_empty_failure` finds that a summary was already committed before the callback lost its acknowledgement. That inflates the failed baseline with an already-delivered terminal state; return the helper's enriched/blocked outcome or otherwise classify the already-enriched case as `no_op` before recording the metric.</comment>

<file context>
@@ -666,6 +667,7 @@ def claim(old: Row | None) -> tuple[Row | None, tuple[str, Row | None]]:
                 get_firestore_client(), COLLECTION, document_id, owner, task_token
             ):
                 raise
+            record_delivery('summary', 'failed')
             empty_blocked = True
         finally:
</file context>

Comment on lines +28 to +29
The no-op alarm is **unarmed**; this PR adds no alert rule. Infracost owns the
baseline after the lead deploys. Record the first serving release SHA, traffic

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This runbook assigns delivery-metric baseline collection to Infracost, which is unrelated to the GMP counter workflow and conflicts with the stated team/rollout-lead responsibility. Replace it with the actual observability or rollout owner so the required seven-day baseline is not left ownerless.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/docs/runbooks/delivery-outcomes.md, line 28:

<comment>This runbook assigns delivery-metric baseline collection to Infracost, which is unrelated to the GMP counter workflow and conflicts with the stated team/rollout-lead responsibility. Replace it with the actual observability or rollout owner so the required seven-day baseline is not left ownerless.</comment>

<file context>
@@ -0,0 +1,42 @@
+
+## Alarm admission
+
+The no-op alarm is **unarmed**; this PR adds no alert rule. Infracost owns the
+baseline after the lead deploys. Record the first serving release SHA, traffic
+percentages and first visible counter timestamp. For each kind and service,
</file context>
Suggested change
The no-op alarm is **unarmed**; this PR adds no alert rule. Infracost owns the
baseline after the lead deploys. Record the first serving release SHA, traffic
The no-op alarm is **unarmed**; this PR adds no alert rule. The rollout lead owns
baseline collection after deployment. Record the first serving release SHA, traffic

get_firestore_client(), rows.COLLECTION, claim.row_id, claim.lease_token, claim.wake_token
):
return Result(Outcome.RETRY, RetryReason.CALLBACK_PENDING, available_at=now)
record_delivery('summary', 'failed')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: This records failed even when record_empty_failure finds that another writer already committed the summary and retires the row with summary_seen=True. Return the committed outcome from record_empty_failure (or otherwise distinguish the enriched case) before incrementing this counter, so baseline failure rates are not inflated by already-delivered summaries.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/enrichment/consumer.py, line 173:

<comment>This records `failed` even when `record_empty_failure` finds that another writer already committed the summary and retires the row with `summary_seen=True`. Return the committed outcome from `record_empty_failure` (or otherwise distinguish the enriched case) before incrementing this counter, so baseline failure rates are not inflated by already-delivered summaries.</comment>

<file context>
@@ -169,6 +170,7 @@ def process(self, claim: Claim, heartbeat: Callable[[], bool]) -> Result:
                 get_firestore_client(), rows.COLLECTION, claim.row_id, claim.lease_token, claim.wake_token
             ):
                 return Result(Outcome.RETRY, RetryReason.CALLBACK_PENDING, available_at=now)
+            record_delivery('summary', 'failed')
             empty_blocked = True
         finally:
</file context>

Comment thread backend/utils/observability/delivery.py Resolved
try:
return function(*args, **kwargs)
except Exception as error:
outcome = (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Subclassed deferred/fence exceptions are miscounted as failed. Match the exception MRO (or use isinstance) so derived terminal exceptions retain the deferred outcome.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At backend/utils/observability/delivery.py, line 96:

<comment>Subclassed deferred/fence exceptions are miscounted as `failed`. Match the exception MRO (or use `isinstance`) so derived terminal exceptions retain the `deferred` outcome.</comment>

<file context>
@@ -0,0 +1,142 @@
+        try:
+            return function(*args, **kwargs)
+        except Exception as error:
+            outcome = (
+                'deferred'
+                if type(error).__name__
</file context>

@Git-on-my-level
Git-on-my-level merged commit 2da0a13 into main Nov 2, 2026
63 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/ic-reads-delivery branch November 2, 2026 20:25
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