Repository navigation
perf(media): share attachment playback metadata inspections - #158548
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 2:25 AM ET / 06:25 UTC (Revision 6). ClawSweeper reviewWhat this changesThe branch shares audio and video attachment inspections across Control UI metadata, playback, and outgoing media creation, with bounded queueing and cancellation. Merge readiness✅ Ready for maintainer review Keep open. Pinned main still performs a separate probe for each metadata request, while this PR remains a useful, well-supported candidate. The earlier review findings are addressed in the current source, and this review found no new actionable defect. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway turns local attachment files into metadata and playable responses for Control UI clients, and prepares managed attachments for outgoing replies. Its media inspection path supplies display facts and playback decisions after checking file identity and request access. flowchart LR
A[Local attachment] --> B[Gateway media request]
C[Current viewer access] --> B
B --> D[Shared inspection queue]
D --> E[File identity and access checks]
E --> F[Metadata and playback choice]
F --> G[Control UI or outgoing reply]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +162, Tests +431, Docs +11, Other 0. Total +604 across 18 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one bounded, access-scoped inspection owner that preserves original outgoing attachments when optional playback facts are unavailable. Do we have a high-confidence way to reproduce the issue? Yes. Pinned main invokes a descriptor probe for each audio or video metadata request, and the PR records a real-process ten-request handler comparison; this reviewer did not execute the path. Is this the best way to solve the issue? Yes. Consolidating inspections in the existing playback owner removes the duplicate probe path while preserving bounded admission and current-access checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 837fad120fba. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
Queue distinct playback inspections behind the existing two-probe limit while sharing pending work by file identity. Release caller-owned descriptors before waiting; the inspection owner reopens and validates the captured identity. Replace the capacity-fallback expectation with an HTTP regression that failed on the prior head with missing duration and transcode classification. It now covers queued same-file sharing and descriptor disposal. Independent Codex review is clean through P2.
|
Addressed the capacity finding in 7765014. Distinct inspections now wait behind the two-probe limit, queued same-file requests share their result, and callers release source descriptors before waiting. The inspection owner reopens and verifies the captured file identity. The HTTP regression failed on the previous head with missing duration and transcode classification, then passed with the correction. Final focused validation passed 256 tests across five files; fresh independent Codex review is clean through P2. The PR body contains the commands and measured cost. Exact-head CI is running. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Limit distinct queued inspections to 32 behind two active probes. Track consumer cancellation within the shared identity-keyed owner, skip orphaned queued work, and keep live consumers when another viewer disconnects. Return existing retryable metadata-unavailable and playback-preparing outcomes at saturation. Bind byte inspection cancellation to the byte-stream owner, preserve descriptor identity checks, and move coherent helpers out of oversized Gateway modules. Overflow and abandoned-work HTTP regressions failed on the prior head. The final focused cohort passed 496 tests across seven files; independent Codex review is clean through P2.
|
Addressed bounded admission and cancellation in 704722b. The inspection owner admits two active probes plus 32 distinct pending jobs. A full queue produces retryable metadata unavailability or the existing playback-preparing response. Each consumer can detach; a queued job with no live consumers skips its probe, while another live viewer retains shared work. Byte requests use cancellation from their byte-stream owner. The actual-handler overflow and abandoned-work regressions failed on the previous head. Final validation passed 496 tests across seven files, including a disconnected byte-playback request and later live work. Independent Codex review is clean through P2; formatting, lint, and line-cap ratchets passed. The PR body records the complete proof and measured cost. Exact-head CI is running. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Remove the unnecessary type assertion exposed by moving error classification to its own module. The assertion-safety ratchet and targeted lint pass; independent review is clean through P2.
Reuse the FIFO permit pool to reclaim orphaned pending inspection slots immediately. Revalidate each viewer at queued file-open and probe boundaries while retaining shared work for authorized viewers. Keep outgoing media and original bytes when optional inspection is busy. The negative controls reproduced queue starvation, late reads after revocation, and failed outgoing attachments. Validation passed 510 focused tests plus a 134-test final replay, production and test typechecks, and fresh independent review through P2. Move unchanged policy and fixture helpers to their existing owners to satisfy line caps. Complete the assertion-safety cleanup by shrinking the control-ui.ts allowance from 2 to 1. The prior removal left a stale allowance; the ratchet now passes with this exact shrink.
|
Addressed the remaining findings in 5b215e2:
These cases failed for the intended reasons before the repair and now pass. The expanded suite passed 510 tests across nine files; the final replay passed 134 tests across five files. Production and all test typecheck shards pass, and fresh independent review is clean through P2. The PR body records the exact commands, timings, original real-ffprobe evidence, and CI failure cause. The current head's hosted CI is running. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Use immediate permit admission for managed outgoing media while retaining shared active and cached inspections. Busy capacity preserves the attachment without optional playback facts instead of queueing delivery behind viewer requests. Prove actual managed creation completes with both inspection slots held. The final focused run passed 511 tests in 160.41 seconds, all 25 test type groups and typed lint passed, and fresh independent review found no actionable issues through P2. Restore the extracted fixture alias and simplify the authority test boolean check caught by hosted lint.
|
@clawsweeper re-review Head c496076 fixes the remaining outgoing-delivery delay. Managed creation now requests immediate admission: it reuses cached or active same-file inspection, but never joins queued work or waits for a free slot. The canonical busy outcome preserves the outgoing attachment and original bytes without optional playback metadata. The existing FIFO permit pool remains the sole admission owner. The regression invokes actual managed creation while both inspection slots remain held. It reached the natural 120 s test deadline before the repair, then passed in 26 ms on the first positive run. The final nine-file cohort passed 511 tests in 160.41 s; all 25 selected test typecheck groups and typed lint passed. Fresh independent review of the complete candidate and the final staged correction found no actionable issues through P2. The hosted lint finding was also fixed by directly calling the guaranteed boolean authority method. The body records the full proof, earlier fixture failures, CI failures and their causes. Please review this exact head, including immediate admission, shared consumers, cancellation and current-authority checks. |
|
🦞👀 Re-review progress:
|
Merge origin/main at 837fad1 after CI 36222683624 failed on an unrelated chained cast in server-chat-progress-snapshot.ts. Main repair 66b812f removes the invalid assertion chain. Automatic integration was conflict-free. The exact boundary lint command passes, the focused nine-file cohort passes in 86.95 seconds, and independent review of the candidate against the merged main found no actionable issues through P2.
|
@clawsweeper re-review Head 37aaef2 merges repaired main without conflicts after CI 36222683624 failed on an unrelated main defect: the chained cast in server-chat-progress-snapshot.ts, fixed by main commit 66b812f. This preserves the reviewed playback change; it does not rebase the branch or rerun the failed CI jobs. The exact failed boundary-lint command passes locally. The post-merge nine-file playback/Gateway/permit-pool replay passes 506 tests in 86.95 s, and fresh independent review of the complete candidate against merged main is scoped-clean through P2. Your previous candidate review established no remaining findings. Please refresh the exact-head review for this integration commit. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…#158548) * perf(media): share playback metadata inspections * test(media): isolate playback metadata route coverage * fix(media): retain metadata while inspection slots are busy Queue distinct playback inspections behind the existing two-probe limit while sharing pending work by file identity. Release caller-owned descriptors before waiting; the inspection owner reopens and validates the captured identity. Replace the capacity-fallback expectation with an HTTP regression that failed on the prior head with missing duration and transcode classification. It now covers queued same-file sharing and descriptor disposal. Independent Codex review is clean through P2. * fix(media): bound and cancel pending playback inspections Limit distinct queued inspections to 32 behind two active probes. Track consumer cancellation within the shared identity-keyed owner, skip orphaned queued work, and keep live consumers when another viewer disconnects. Return existing retryable metadata-unavailable and playback-preparing outcomes at saturation. Bind byte inspection cancellation to the byte-stream owner, preserve descriptor identity checks, and move coherent helpers out of oversized Gateway modules. Overflow and abandoned-work HTTP regressions failed on the prior head. The final focused cohort passed 496 tests across seven files; independent Codex review is clean through P2. * fix(media): use narrowed attachment error codes Remove the unnecessary type assertion exposed by moving error classification to its own module. The assertion-safety ratchet and targeted lint pass; independent review is clean through P2. * fix(media): preserve queued read authority and outgoing attachments Reuse the FIFO permit pool to reclaim orphaned pending inspection slots immediately. Revalidate each viewer at queued file-open and probe boundaries while retaining shared work for authorized viewers. Keep outgoing media and original bytes when optional inspection is busy. The negative controls reproduced queue starvation, late reads after revocation, and failed outgoing attachments. Validation passed 510 focused tests plus a 134-test final replay, production and test typechecks, and fresh independent review through P2. Move unchanged policy and fixture helpers to their existing owners to satisfy line caps. Complete the assertion-safety cleanup by shrinking the control-ui.ts allowance from 2 to 1. The prior removal left a stale allowance; the ratchet now passes with this exact shrink. * fix(media): keep optional inspection off the outgoing queue Use immediate permit admission for managed outgoing media while retaining shared active and cached inspections. Busy capacity preserves the attachment without optional playback facts instead of queueing delivery behind viewer requests. Prove actual managed creation completes with both inspection slots held. The final focused run passed 511 tests in 160.41 seconds, all 25 test type groups and typed lint passed, and fresh independent review found no actionable issues through P2. Restore the extracted fixture alias and simplify the authority test boolean check caught by hosted lint.
What Problem This Solves
Opening one audio or video attachment in multiple Control UI clients launches a separate ffprobe process for every metadata request, even when the playback inspection is already cached.
User Impact
Concurrent viewers share one inspection, and warm metadata requests launch no probe. Distinct files wait for bounded inspection capacity, disconnected requests release queued work, and access revocation prevents delayed file reads. A busy inspector preserves outgoing attachments and their original bytes; optional playback metadata may be absent. Outgoing reply creation uses immediate admission, so queued viewer requests cannot delay delivery. There are no protocol, configuration, dependency-version, or storage schema changes.
Why This Change Was Made
The existing playback inspection owner now retains duration and display dimensions alongside codec classification. Control UI metadata and managed attachment creation consume that result, replacing their separate pre-probes. Native byte playback retains its cheap passthrough path, replacements invalidate cached facts, and failed probes remain retryable.
The existing FIFO permit pool owns the two active inspection slots. The media owner bounds distinct pending work at 32 jobs, shares consumers by file identity, and removes an orphaned pending permit immediately. Shared work continues when another authorized viewer remains. The owner checks current authority before reopening a queued file and again before probing it; each consumer also checks its own authority before accepting the result. Byte-stream ownership supplies cancellation for byte requests.
Metadata callers release their descriptors before waiting. Saturation uses existing retryable metadata-unavailable and playback-preparing/HTTP 202 outcomes. Outgoing creation catches only the canonical busy error, preserving genuine authorization, cancellation, and preparation failures. Coherent helper moves keep the oversized Gateway modules within their line-cap ratchets.
Related: #158464 changes static serving in the same Control UI file; #158450 changes managed artifact handling. Their changes are in separate regions and do not implement this consolidation.
Evidence
The original optimization was measured through the actual assistant-media handler with a valid 100 ms WAV, ten concurrent synthetic HTTP requests, and real ffprobe children. Five paired rounds used fresh identities for cold batches on one shared host. No listener, external provider, or live Gateway was involved.
Process counts held in every round. These timings describe the original component comparison, not final-head or end-to-end latency. The original real-process handler check also exercised replacement invalidation and transient probe failure recovery in 52.80 s wall.
The final actual-handler regressions use real file admission and deterministic probe/authority barriers. They cover cold/warm sharing, replacement, transient failures, third-file metadata, bounded backlog with retry, disconnects for metadata and byte playback, immediate reclamation of a full abandoned queue, and allowed-versus-revoked viewers at queued reopen and probe boundaries. A revoked-only viewer does not trigger the delayed read; another authorized viewer retains shared work. Managed creation tests verify retained original audio/video bytes at saturation and preserve the existing non-busy failure control.
Negative controls reproduced the defects before their repairs: missing duration/playback, an extra orphaned probe, rejected later work after 32 queued clients disconnected, a revoked viewer reopening/probing, and busy metadata causing outgoing delivery failure. Two initial retained-file assertions used the wrong fixture media root; they were corrected to use the persisted root and were not treated as product failures.
Before merging the repaired main, focused validation passed 511 tests across nine files:
Pre-integration wall time: 160.41 s, including worker preparation. Gateway: 385 tests in 135.16 s; media: 123 tests in 9.48 s; permit pool: 3 tests in 0.572 s. New scenarios use deferred/event barriers, without sleeps, polling, or per-test Gateway boots.
The last outgoing-delivery regression holds both real inspection slots and invokes actual managed creation. Before immediate admission, it reached the lane's natural 120 s test deadline; afterward it passed in 26 ms on the first positive run. That run also exposed seven fixture ReferenceErrors caused by a removed import alias during helper extraction; restoring the alias fixed them, and the complete final cohort above passed. No timeout or assertion was weakened.
Earlier focused proof passed 510 tests in 367.35 s and a targeted replay passed 134 tests in 141.02 s. Production typechecking, all 25 selected test typecheck groups, typed lint, formatting, and the line/assertion ratchets passed. The all-in-one local changed-check run was not completed; its formatting and initialization-type findings were fixed and checked directly. Hosted exact-head CI remains the full landing gate.
Fresh independent Codex review of the complete staged candidate is scoped-clean through P2, with no accepted/actionable findings. The earlier lane's incomplete Vitest runs were superseded by the passing focused proof. No full local build or live Gateway swarm is claimed.
CI run 36215981273 failed the assertion-safety ratchet after an existing cast moved into the new error-classification module; fail-fast canceled the remaining selected jobs. The unnecessary cast was removed using the existing type narrowing, and its old file's allowance was tightened from 2 to 1. No failing CI job was rerun without a code correction.
CI run 36220093091 failed typed lint because the new authority regression compared a guaranteed boolean method result with
falseunnecessarily. The test now calls that method directly; local typed lint passed. Fail-fast canceled downstream checks. New CI runs followed source corrections; no jobs were rerun merely to obtain green.CI run 36222683624 failed
lint:no-chained-type-assertionsinsrc/gateway/server-chat-progress-snapshot.ts, an unrelated main change. Main repair66b812f26e725cd709e08860d2cb46ba496cd308replaced that assertion chain with typed boxed-number coercion. Merged repaired main at837fad120fbab0c0df0dd7bc7009dd90decfbd38without conflicts; no rebase or CI rerun. The exact failing boundary-lint command now passes locally.The final integration replay passed 506 tests across the same nine files in 86.95 s wall (380 Gateway, 123 media, 3 permit-pool tests). Current main's separate static-serving changes reduced the existing Control UI HTTP test count by five; this PR's playback regressions remain present. Fresh independent review against merged main is scoped-clean through P2. ClawSweeper completed review of merged head
37aaef2ded6d65947e9db3d2b03490e9553c2286at 06:25 UTC with no actionable findings. Exact-head CI run 36223378189 passed, including the finalopenclaw/ci-gateat 06:34:41 UTC. Hosted boundary checks took 172 s and core lint took 271 s, including their job setup. No CI jobs were manually rerun.