Repository navigation
perf(backend): profile and streamline isolated seal repair rows - #24738
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| chunks = list_audio_chunks( | ||
| uid, cid, max_count=4096, require_archive=True, client=storage_client, source_metadata=True | ||
| ) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
3 issues found across 12 files
Confidence score: 3/5
- In
storage.pyandlive.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'): |
There was a problem hiding this comment.
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>
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>
| 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, |
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_msfor 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 withunknown. 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_reloadsexposes 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):
backend/utils/batch_pipeline/record_seal_cluster_repair.py:381throughbackend/utils/batch_pipeline/record_seal_cluster_repair.py:604(parent launch monotonic timestamp through row entry).backend/utils/batch_pipeline/record_seal_cluster_repair.py:605(dependency imports and Firestore/GCS/artifact construction).backend/utils/batch_pipeline/record_seal_cluster_repair.py:93(job/conversation reads, inventory proof and planner reads before retained listing).backend/utils/batch_pipeline/record_seal_repair.py:96(authorization, listing, owner key).backend/utils/batch_pipeline/record_seal_repair.py:105(tail precheck, full retained walk and tail validation).backend/utils/batch_pipeline/record_seal_cluster_repair.py:195(canonical seal transaction); partial/missing-row variants enter apply at their existing mutation call.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.shviaomi-heavy: 627 passed, 2 skipped (isolated Firestore emulator unavailable).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.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.