Skip to content

improve: release captured audio cache leases directly - #139174

Merged
steipete merged 1 commit into
mainfrom
codex/perf10-audio-cache
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf10-audio-cache

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Releasing each chat audio player traversed the entire waveform Blob cache to check for overflow, even though insertion already enforced both cache limits and release could only lower its retained count.

Why This Change Was Made

The cache now releases the exact captured entry under its existing idempotence guard. Unreachable release-time trimming, a map relookup, and a redundant cache-key argument are removed. Insertion remains the sole owner of the 32-entry/48 MiB limits and only evicts entries with no active leases.

User Impact

Shared audio playback and waveform reuse behave the same with less temporary work when players disconnect or change source. Production is 18 lines smaller; the existing lease test adds 21 net lines.

Evidence

  • 22 audio-cache/player tests passed. Six actual-owner scenarios covered both caps, duplicate insertion, shared leases, duplicate release, final-release eviction, and old released handles after key reinsertion.
  • A deterministic 1,000-release probe reduced cache values-array scans from 1,000 to zero. Across 32,000 sampled releases, owner-attributed allocation was 11,993,224 → 2,568 bytes; this is approximate Node allocation sampling, not browser retained-memory measurement.
  • Real Chromium before/after proof used actual Control UI audio components, native fetch/Web Audio decode, and a synthetic 12-second WAV. Both arms rendered 96 waveform bars, played and sought, coordinated shared players, kept the survivor playing after sibling removal, and remounted another player with one total waveform fetch.
  • Managed P0–P2 review, formatting, and diff checks passed. Browser proof uses isolated source-component mounting, not full application boot or a live Gateway; no browser latency/RSS improvement is claimed. Current-head CI is publisher-owned.

Before/after: actual Control UI audio player, synthetic 12-second WAV, playing after seeking. These images show preserved behavior; the allocation measurement above comes from the separate owner probe.

Before After
Before: playing and seeked After: playing and seeked

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 15:20
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 11:44 AM ET / 15:44 UTC.

ClawSweeper review

What this changes

The PR simplifies chat audio cache cleanup by releasing the captured entry directly and extends coverage for shared leases and eviction.

Merge readiness

✅ Ready for maintainer review

This remains a useful optimization absent from current main and the latest release. No blocking correctness findings were identified.

Priority: P3
Reviewed head: 61695a7a29c076cbba4717200d155e3bc3344c43

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level simplification with useful lease coverage and no identified correctness blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The supplied body reports actual Chromium audio-player lifecycle coverage; linked screenshots could not be independently inspected because GitHub DNS was unavailable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The supplied body reports actual Chromium audio-player lifecycle coverage; linked screenshots could not be independently inspected because GitHub DNS was unavailable.
Evidence reviewed 9 items Verified introduced change: The merge-base-to-head diff contains only the cache simplification and lease-test extension; unrelated endpoint drift is excluded.
Cache ownership invariant: Insertion enforces 32 entries and 48 MiB, evicts only entries with zero leases, and reuses existing entries for duplicate keys. Release is idempotent and only decrements the captured entry, so it cannot cause overflow or premature eviction.
Production consumer and lifecycle: The audio player acquires cached entries during waveform preparation and playback, then releases them on disconnect, replacement, or rejected adoption. Chat attachments and sidebar previews share this component. Its cache key retains source, playback and authentication context; the patch does not change those boundaries.
Findings None None.
Security None None.

How this fits together

Control UI audio players reuse fetched audio and waveform data through a bounded browser-memory cache. Each player holds a lease that prevents eviction until that player releases it.

flowchart TD
  A[Chat or sidebar audio] --> B[Audio player]
  B --> C[Cached audio available?]
  C -->|No| D[Fetch and decode audio]
  D --> E[Enforce cache limits]
  C -->|Yes| F[Retain cached entry]
  E --> F
  F --> B
  B -->|Disconnect or source change| G[Release captured entry]
  G -->|Last lease released| E
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -18, Tests +21. Total +3 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 27 -18
Tests 1 22 1 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 31 28 +3

Review metrics

Metric Value Why it matters
Production versus test footprint Production −18 lines; tests +21 lines The refactor removes redundant ownership work while extending the existing lease contract test, without introducing another abstraction.

Technical review

Best possible solution:

Keep insertion as the sole cache-cap and eviction owner, with constant-work, idempotent releases bound to their original entries.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug reproduction: this is a performance refactor, and current source directly confirms the redundant scan on release.

Is this the best way to solve the issue?

Yes. Removing unreachable trimming at the cache owner is simpler than optimizing that scan or adding cleanup logic to individual players, while preserving admission and lease invariants.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 952105ddd981.

Labels

Label changes:

  • add P3: This is a bounded, behavior-preserving performance cleanup rather than a broken user workflow.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The supplied body reports actual Chromium audio-player lifecycle coverage; linked screenshots could not be independently inspected because GitHub DNS was unavailable.

Label justifications:

  • P3: This is a bounded, behavior-preserving performance cleanup rather than a broken user workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor proof gate does not apply to this maintainer-authored, behavior-neutral refactor. The supplied body reports actual Chromium audio-player lifecycle coverage; linked screenshots could not be independently inspected because GitHub DNS was unavailable.

Evidence

What I checked:

  • Verified introduced change: The merge-base-to-head diff contains only the cache simplification and lease-test extension; unrelated endpoint drift is excluded. (ui/src/pages/chat/components/chat-audio-waveform.ts:104, 61695a7a29c0)
  • Cache ownership invariant: Insertion enforces 32 entries and 48 MiB, evicts only entries with zero leases, and reuses existing entries for duplicate keys. Release is idempotent and only decrements the captured entry, so it cannot cause overflow or premature eviction. (ui/src/pages/chat/components/chat-audio-waveform.ts:83, 61695a7a29c0)
  • Production consumer and lifecycle: The audio player acquires cached entries during waveform preparation and playback, then releases them on disconnect, replacement, or rejected adoption. Chat attachments and sidebar previews share this component. Its cache key retains source, playback and authentication context; the patch does not change those boundaries. (ui/src/pages/chat/components/chat-audio-player.ts:255, 61695a7a29c0)
  • Sibling implementation and dependency boundary: The separate SVG preview owner also uses captured, idempotent releases, but retires URLs explicitly rather than maintaining this audio cache. Repository-wide caller search found the audio player as the cache's only production consumer; no Codex runtime or protocol contract is involved. (ui/src/pages/chat/components/chat-svg-attachment.ts:99, 61695a7a29c0)
  • Focused behavioral coverage: The extended test protects shared retention, duplicate-release idempotence, admission refusal while leases remain, and eviction after final release. Existing byte-cap and player tests cover adjacent behavior. These tests were inspected, not executed during this read-only review. (ui/src/pages/chat/components/chat-audio-waveform.test.ts:71, 61695a7a29c0)
  • Current-main necessity: Fetched main still performs the cache lookup and overflow scan on every first release. A separate comparison confirmed that the cache, its tests and the player have not changed between the pinned merge base and fetched main. (ui/src/pages/chat/components/chat-audio-waveform.ts:130, 952105ddd981)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vyctor H. Brzezowski: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit c8c6557 into main Sep 5, 2026
185 checks passed
@steipete
steipete deleted the codex/perf10-audio-cache branch September 5, 2026 15:49
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to aniruddhaadak80/openclaw that referenced this pull request Sep 5, 2026
* origin/main: (46 commits)
  fix(gateway): keep chat metadata responsive across auth refresh (openclaw#139192)
  fix(doctor): keep Workshop relocation lint read-only (openclaw#139193)
  perf(ui): retain unchanged forwarded avatar publications (openclaw#139181)
  fix(config): guide exec policy migration repairs (openclaw#139143)
  test(i18n): refresh representative Watch key (openclaw#139197)
  fix(agents): preserve recovered scheduled-run outcomes (openclaw#139037)
  refactor(acp): simplify pending operation accounting (openclaw#139189)
  fix(plugin-sdk): harden account scope for pairing requests and challenges (openclaw#139142)
  perf(gateway): avoid redundant PR landing ancestry checks (openclaw#139186)
  perf(ui): release captured audio cache leases directly (openclaw#139174)
  fix(skills): validate names in library forms (openclaw#139184)
  fix(sessions): reduce cold catalog listing delays (openclaw#139146)
  perf(cron): scan preserved action output once (openclaw#139163)
  fix(agents): keep fresh tool results readable under context pressure (openclaw#139165)
  fix(compaction): heartbeat sessions ignore the active transcript byte cap (openclaw#136533)
  perf(agents): reuse snapshotted web search result rows (openclaw#139162)
  fix(onboarding): keep Tauri setup recoverable and verify model results (openclaw#139140)
  fix(memory): rank indexed sessions by source activity (openclaw#139112)
  perf(terminal): avoid rebuilding sanitized link fallbacks (openclaw#139159)
  perf(agents): bound retained tool result projection data (openclaw#139157)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant