Skip to content

perf(backend): profile and streamline isolated seal repair rows - #24738

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/pipeline-sealrow
Nov 5, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/pipeline-sealrow

Conversation

@Git-on-my-level

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

Copy link
Copy Markdown
Member

Problem

Seal repair row children are silent and row INFO events can be sampled away, obscuring time spent before useful I/O. Each row also creates redundant GCS clients and reloads metadata already present in its listing, then fetches the tail twice.

Fix

Return compact counts-only stage_ms for startup, clients, proof, list, walk and apply, plus chunks, bytes and metadata reload count. Stream bounded stage checkpoints over the existing private pipe so capped rows retain their last known stage; older children remain supported with unknown. Parent row events and pass summaries use WARNING; summaries aggregate elapsed milliseconds by disposition.

Reuse the row's single GCS client for artifacts and primary/derived/raw listing. Preserve listing metadata for the generation-pinned reader and cache only the decoded last chunk across precheck and full proof. Missing listing size, custom metadata or metageneration still performs one generation-pinned metadata reload (raw archive entries currently omit custom metadata); metadata_reloads exposes that case. Reload-free downloads pin both the listed data generation and metageneration. A failure of either precondition refuses the row through the existing read-error path before decoding or sealing. Size budgets, SHA256, authenticated decrypt, privacy checks, proof checks and seal transactions remain unchanged. No concurrency, control values or flags change.

Stage boundaries (repository paths):

  • startup: backend/utils/batch_pipeline/record_seal_cluster_repair.py:381 through backend/utils/batch_pipeline/record_seal_cluster_repair.py:604 (parent launch monotonic timestamp through row entry).
  • clients: backend/utils/batch_pipeline/record_seal_cluster_repair.py:605 (dependency imports and Firestore/GCS/artifact construction).
  • proof: backend/utils/batch_pipeline/record_seal_cluster_repair.py:93 (job/conversation reads, inventory proof and planner reads before retained listing).
  • list: backend/utils/batch_pipeline/record_seal_repair.py:96 (authorization, listing, owner key).
  • walk: backend/utils/batch_pipeline/record_seal_repair.py:105 (tail precheck, full retained walk and tail validation).
  • apply: backend/utils/batch_pipeline/record_seal_cluster_repair.py:195 (canonical seal transaction); partial/missing-row variants enter apply at their existing mutation call.
  • chunks/bytes: backend/utils/batch_pipeline/source_audio.py:144 (completed source downloads, including the precheck once).

Validation

  • BACKEND_UNIT_TEST_FILE_LIST=<21-file seal/source_audio/related selection> DYLD_LIBRARY_PATH=/opt/homebrew/lib BACKEND_PYTEST_WORKERS=4 bash test.sh via omi-heavy: 627 passed, 2 skipped (isolated Firestore emulator unavailable).
  • Integrity regression cases emulate metadata-only and data-generation races: either failed download precondition produces read_error, never decodes stale metadata and never seals or writes. Missing listed metageneration reloads fresh metadata; happy-path reads pin both versions and retain zero reloads.
  • Single review round completed; the B1 metageneration integrity blocker is addressed inline. No additional review round.

Risk and rollback

No production access, PR merge or deploy performed. Runtime throughput and credential-storm effects remain unmeasured. The new last-chunk cache keeps one decoded object alive for the proof walk. Revert this commit to restore the previous read and logging paths.

Failure-Class: none

This combines observability and redundant-call reduction with the listed-metadata integrity correction; no existing failure-class prevention primitive is changed.

Line-Count-Exception: backend/utils/other/storage.py | 2774 -> 2780 | Keep row-owned client injection and listed metadata at the existing listing API; new timing and IPC logic lives in the dedicated repair modules.

View guided diff Turn on auto-fix

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 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-11-05T23:43:35.779948Z aeb63ef New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b44b7160ba

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +100 to +102
chunks = list_audio_chunks(
uid, cid, max_count=4096, require_archive=True, client=storage_client, source_metadata=True
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required audio-pipeline change note

This changes retained-audio reads and conversation seal repair, but the commit adds no note under backend/docs/listen_pusher_pipeline/changes/. backend/AGENTS.md explicitly requires a same-PR note for audio or conversation-lifecycle changes. Add a dated note describing the client/metadata reuse, decoded-tail cache, telemetry changes, rollout/flag state, and validation evidence so these pipeline changes remain discoverable in the required operational history.

AGENTS.md reference: backend/AGENTS.md:L164-L164

Useful? React with 👍 / 👎.

@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.

3 issues found across 12 files

Confidence score: 3/5

  • In storage.py and live.py, missing custom metadata in a GCS listing can be treated as authoritative, skipping the reload; encrypted or raw-live reads may then fail checksum validation or use default decoding. Only pass listing metadata through when custom metadata is present.
  • In test_record_seal_repair.py, the assertion can pass even if archive enumeration is disabled. Assert the complete set of listing options.
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/tests/unit/test_record_seal_repair.py">

<violation number="1" location="backend/tests/unit/test_record_seal_repair.py:114">
P2: This assertion no longer rejects unexpected listing options, so a regression such as `include_archive=False` could disable archive enumeration while the test still passes. Assert the complete keyword set, including the newly required `client` and `source_metadata` arguments.</violation>
</file>

<file name="backend/utils/other/storage.py">

<violation number="1" location="backend/utils/other/storage.py:1226">
P1: `hasattr` is true for GCS blobs even when a listing does not contain custom metadata. The downstream reader then skips its reload, causing encrypted/raw-live reads to fail checksum or use default decoding; copy metadata only when it is not `None`.</violation>
</file>

<file name="backend/utils/batch_pipeline/live.py">

<violation number="1" location="backend/utils/batch_pipeline/live.py:211">
P2: This fast path treats an empty listing metadata mapping as authoritative, so legacy objects whose listing omits custom metadata skip the required generation-pinned reload. Pass the listing only when it contains metadata; otherwise let `read_reference` reload the pinned object.</violation>
</file>

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

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

raise TimeoutError('speaker audio listing budget exhausted')
entry = audio_chunk_entry(blob, source_identity=source_identity, primary_bucket=private_cloud_sync_bucket)
if entry is not None:
if source_metadata and hasattr(blob, 'metadata'):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: hasattr is true for GCS blobs even when a listing does not contain custom metadata. The downstream reader then skips its reload, causing encrypted/raw-live reads to fail checksum or use default decoding; copy metadata only when it is not None.

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/other/storage.py, line 1226:

<comment>`hasattr` is true for GCS blobs even when a listing does not contain custom metadata. The downstream reader then skips its reload, causing encrypted/raw-live reads to fail checksum or use default decoding; copy metadata only when it is not `None`.</comment>

<file context>
@@ -1220,6 +1223,8 @@ def list_audio_chunks(
             raise TimeoutError('speaker audio listing budget exhausted')
         entry = audio_chunk_entry(blob, source_identity=source_identity, primary_bucket=private_cloud_sync_bucket)
         if entry is not None:
+            if source_metadata and hasattr(blob, 'metadata'):
+                entry['metadata'] = blob.metadata or {}
             append_projection_entries(chunks, bucket, blob, uid, entry, deadline, max_count, include_raw)
</file context>
Suggested change
if source_metadata and hasattr(blob, 'metadata'):
metadata = getattr(blob, 'metadata', None)
if source_metadata and metadata is not None:
entry['metadata'] = metadata

def test_archive_listing_must_require_archive_and_fail_closed(source, monkeypatch):
def unavailable(*args, **kwargs):
assert kwargs == {'max_count': 4096, 'require_archive': True}
assert kwargs['max_count'] == 4096 and kwargs['require_archive'] is True

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 assertion no longer rejects unexpected listing options, so a regression such as include_archive=False could disable archive enumeration while the test still passes. Assert the complete keyword set, including the newly required client and source_metadata arguments.

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/tests/unit/test_record_seal_repair.py, line 114:

<comment>This assertion no longer rejects unexpected listing options, so a regression such as `include_archive=False` could disable archive enumeration while the test still passes. Assert the complete keyword set, including the newly required `client` and `source_metadata` arguments.</comment>

<file context>
@@ -111,7 +111,8 @@ def test_missing_short_or_nonfinite_tail_refused(source, monkeypatch, units):
 def test_archive_listing_must_require_archive_and_fail_closed(source, monkeypatch):
     def unavailable(*args, **kwargs):
-        assert kwargs == {'max_count': 4096, 'require_archive': True}
+        assert kwargs['max_count'] == 4096 and kwargs['require_archive'] is True
+        assert kwargs['source_metadata'] is True and kwargs['client'] is not None
         raise OSError('synthetic private path')
</file context>

ref, pcm = dict(decoded_tail['ref']), decoded_tail['pcm']
else:
pcm = read_reference(
client, ref, uid, conversation_id, allowed, key, source_metadata=True, listed_source=chunk

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 fast path treats an empty listing metadata mapping as authoritative, so legacy objects whose listing omits custom metadata skip the required generation-pinned reload. Pass the listing only when it contains metadata; otherwise let read_reference reload the pinned object.

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/batch_pipeline/live.py, line 211:

<comment>This fast path treats an empty listing metadata mapping as authoritative, so legacy objects whose listing omits custom metadata skip the required generation-pinned reload. Pass the listing only when it contains metadata; otherwise let `read_reference` reload the pinned object.</comment>

<file context>
@@ -204,7 +204,14 @@ def retained_record_units(
+            ref, pcm = dict(decoded_tail['ref']), decoded_tail['pcm']
+        else:
+            pcm = read_reference(
+                client, ref, uid, conversation_id, allowed, key, source_metadata=True, listed_source=chunk
+            )
+            if decoded_tail is not None and chunk is chunks[-1]:
</file context>
Suggested change
client, ref, uid, conversation_id, allowed, key, source_metadata=True, listed_source=chunk
client, ref, uid, conversation_id, allowed, key, source_metadata=True,
listed_source=chunk if chunk.get('metadata') else None,

@Git-on-my-level
Git-on-my-level merged commit a7a5c5f into main Nov 5, 2026
58 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/pipeline-sealrow branch November 5, 2026 23:54
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