Skip to content

fix(openai): prevent realtime transcription memory growth - #118204

Merged
vincentkoc merged 14 commits into
mainfrom
fix-openai-realtime-transcript-bounds-20260802
Aug 2, 2026
Merged

vincentkoc merged 14 commits into
mainfrom
fix-openai-realtime-transcript-bounds-20260802

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

Related: #116201

What Problem This Solves

Long-lived OpenAI realtime transcription sessions could retain item-correlation history and transcript text without a session-level bound when terminal or predecessor events were delayed or missing.

Why This Change Was Made

OpenAI-specific ordering remains provider-owned and keyed by item_id. The provider now bounds:

  • unresolved items: 64;
  • each item identity: 1,024 UTF-8 bytes;
  • retained partial/final transcript text: 256 KiB;
  • settled terminal identities: 4,096 items and 256 KiB.

Overflow has one explicit owner: clear retained provider state, close the transport, and report one terminal error. Terminal identities are not silently evicted, so the first per-item terminal outcome remains authoritative for the connection generation. Duplicate or late deltas, completions, failures, and commits cannot recreate released state. Explicit reconnect starts a fresh ledger.

Owner decision: accept visible reconnect-at-bound for exceptionally long sessions. This is preferable to unbounded retention or silently weakening terminal precedence. The limit is provider-local and intentionally has no config or environment-variable surface.

Root cause: the ordering ledger introduced for asynchronous completion retained settled items for the socket lifetime and had no aggregate partial/final text budget. Architectural owner: extensions/openai/realtime-transcription-provider.ts.

Production delta: +198/-31 lines. Tests: +740/-2 lines across two focused files. The production growth is the bounded provider-local state owner, UTF-8 accounting, terminal close path, and late-event precedence. No shared provider abstraction was added.

User Impact

Healthy voice sessions preserve current transcript ordering without accumulating unbounded provider state. Malformed, stalled, or exceptionally long event streams fail visibly and can establish a fresh provider connection instead of growing memory indefinitely or delivering a duplicate terminal transcript.

No provider, config, environment-variable, protocol, public SDK, or docs surface changes.

Evidence

Exact reviewed head: 15195713985f5b069f53bbb769a9dc621ed4c7e9.

  • Live authorized OpenAI audio roundtrip on the exact head: 1 passed, 7 intentionally skipped; realtime STT assertion completed in 6.42s.
  • Focused provider tests: 26/26 passed across the primary and bounds suites.
  • Shared realtime websocket lifecycle tests: 26/26 passed.
  • Blacksmith Testbox changed gate: passed on lease tbx_01kz277881hwbjw5f9z8ztwz00.
  • Hosted PR CI: 46 successful, 40 skipped, 0 failed, 0 pending.
  • Independent exact-head review: no remaining concrete merge blocker.
  • ClawSweeper exact-head review: 4/6, no actionable findings; owner accepted the explicit reconnect-at-bound availability contract.
  • git diff --check: passed. All branch commits are signed.

Review Fixes

The branch addresses every prior ClawSweeper finding:

  • terminal completion/failure before commit is tombstoned before callbacks;
  • rejected terminal failures preserve the provider-owned bound error as the only terminal outcome;
  • active predecessor satisfaction survives terminal-history growth;
  • settled identities are never silently evicted;
  • terminal-history saturation closes visibly rather than re-admitting old events;
  • bounds coverage is isolated so changed-file lint remains under the repository line limit.

@vincentkoc vincentkoc self-assigned this Aug 2, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 2, 2026 21:00
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 6:03 PM ET / 22:03 UTC.

ClawSweeper review

What this changes

The PR bounds unresolved OpenAI realtime-transcription items, retained transcript text, and terminal item identity history, then clears state and closes the transport when a limit is exceeded.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This remains necessary: current main has no corresponding bounds in the OpenAI realtime-transcription provider, while the proposed patch places the limits at the provider-owned ordering ledger and preserves first-terminal-event precedence. No concrete patch defect was found, but the intentional outcome at the settled-history limit is to end the active transcription session without automatic reconnect, so the maintainer-labeled, member-authored PR needs an explicit merge-risk decision rather than automated closure.

Priority: P1
Reviewed head: 15195713985f5b069f53bbb769a9dc621ed4c7e9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, well-covered repair with no concrete correctness finding; its remaining blocker is maintainer acceptance of the deliberate session-termination contract.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a member-authored PR, so the external-contributor proof gate does not apply; the PR body nevertheless records an exact-head authorized OpenAI audio roundtrip and redaction-safe focused validation claims.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a member-authored PR, so the external-contributor proof gate does not apply; the PR body nevertheless records an exact-head authorized OpenAI audio roundtrip and redaction-safe focused validation claims.
Evidence reviewed 7 items Current main lacks the requested bounds: The current-main provider retains commit ordering, pending transcripts, and completed transcript state without aggregate item or text bounds; the PR introduces the bounded owner state in the same provider module. git diff from the PR base to current main produced no changes for this provider path, so the central repair is not already present on main.
Provider-local bounded repair: The patch owns unresolved IDs, retained text bytes, settled IDs, reset behavior, and terminal overflow handling inside the OpenAI plugin rather than adding a shared policy or public configuration surface.
Terminal precedence and late-event handling: The patch rejects events for settled or already-completed item IDs, records terminal IDs for the connection generation, and makes overflow a single terminal path instead of silently evicting old identities.
Findings None None.
Security None None.

How this fits together

The OpenAI realtime-transcription plugin converts provider WebSocket events into ordered partial and final transcript callbacks for voice sessions. Its provider-local ledger associates commits, predecessors, partial text, and terminal outcomes before events reach the shared WebSocket session and the voice consumer.

flowchart LR
  A[OpenAI realtime WebSocket events] --> B[OpenAI transcription provider]
  B --> C[Provider-owned item ledger]
  C --> D{Within item and text limits?}
  D -- Yes --> E[Ordered transcript callbacks]
  D -- No --> F[Clear ledger and close transport]
  E --> G[Shared voice session]
  F --> G
Loading

Decision needed

Question Recommendation
Should an OpenAI realtime-transcription session intentionally end and require an explicit new connection when its terminal-item history reaches 4,096 IDs or 256 KiB? Accept visible reconnect at the bound: Merge the provider-local limits and preserve terminal-event precedence, accepting that an affected session ends until its owner explicitly reconnects.

Why: The implementation is coherent and avoids unbounded retention, but it deliberately changes an exceptionally long or malformed session from automatic recovery to a visible terminal failure; that availability contract requires maintainer product and operational acceptance.

Before merge

  • Resolve merge risk (P1) - At 4,096 settled item IDs or 256 KiB of settled identity bytes, the patch intentionally clears provider state, closes the active transcription transport, suppresses automatic reconnect, and requires an explicit new connection; maintainers must accept that availability tradeoff before merge.
  • Complete next step (P2) - No mechanical repair is indicated; a maintainer must explicitly accept or reject the provider overflow contract before this member-authored, maintainer-labeled PR can merge.
Agent review details

Security

None.

PR surface

Source +167, Tests +738. Total +905 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 198 31 +167
Tests 2 740 2 +738
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 938 33 +905

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: extensions/openai/realtime-transcription-provider.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

  • The PR is behind main; the changed provider path has no current-main drift since its base, but merge gating should still recheck the exact head and current required checks.

Maintainer options:

  1. Merge with the explicit session-limit contract (recommended)
    Accept a visible terminal error and explicit reconnect after settled-history saturation to prevent unbounded state while retaining first-terminal-event precedence.
  2. Pause for an alternate recovery design
    Do not merge if transparent continued transcription is a product requirement, because the existing shared session intentionally does not auto-reconnect after this provider terminal close.

Technical review

Best possible solution:

Keep the bounds and first-terminal precedence in the OpenAI provider, and merge only if maintainers accept visible session termination plus an explicit reconnect as the correct recovery for exceptional terminal-history saturation.

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

Yes, source-reproducible with high confidence: current main retains provider ordering and transcript maps without aggregate bounds, and the exact-head tests encode over-limit and late-event sequences. This read-only review did not execute the test or live OpenAI path; the PR body reports an exact-head authorized roundtrip and focused passing suites.

Is this the best way to solve the issue?

Yes, subject to the explicit availability decision: provider-local ownership is the narrowest maintainable repair because the OpenAI plugin alone owns item_id ordering and terminal precedence, while the shared WebSocket wrapper already provides a terminal close and explicit reconnect boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7866ecae4b85.

Labels

Label justifications:

  • P1: Unbounded provider state affects long-lived realtime voice transcription sessions and can degrade or exhaust an active operator workflow.
  • merge-risk: 🚨 availability: Overflow intentionally closes the active transport and disables automatic reconnect until an explicit new connection is requested.
  • merge-risk: 🚨 message-delivery: The provider ledger controls ordered transcript delivery and suppresses late or duplicate terminal events.
  • 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: This is a member-authored PR, so the external-contributor proof gate does not apply; the PR body nevertheless records an exact-head authorized OpenAI audio roundtrip and redaction-safe focused validation claims.

Evidence

What I checked:

  • Current main lacks the requested bounds: The current-main provider retains commit ordering, pending transcripts, and completed transcript state without aggregate item or text bounds; the PR introduces the bounded owner state in the same provider module. git diff from the PR base to current main produced no changes for this provider path, so the central repair is not already present on main. (extensions/openai/realtime-transcription-provider.ts:200, 7866ecae4b85)
  • Provider-local bounded repair: The patch owns unresolved IDs, retained text bytes, settled IDs, reset behavior, and terminal overflow handling inside the OpenAI plugin rather than adding a shared policy or public configuration surface. (extensions/openai/realtime-transcription-provider.ts:203, 15195713985f)
  • Terminal precedence and late-event handling: The patch rejects events for settled or already-completed item IDs, records terminal IDs for the connection generation, and makes overflow a single terminal path instead of silently evicting old identities. (extensions/openai/realtime-transcription-provider.ts:239, 15195713985f)
  • Explicit reconnect contract: closeNow() marks the shared session closed, cancels the reconnect supervisor, and closes the socket; a subsequent explicit connect() starts a new connection generation. The proposed overflow path therefore ends the current session rather than transparently reconnecting it. (src/realtime-transcription/websocket-session.ts:105, dd8e07c11f89)
  • Focused regression coverage: The exact PR head adds tests for releasing settled turns from the unresolved budget, duplicate/late terminal events, pre-commit terminal outcomes, terminal-history saturation, and explicit reconnection after a provider-owned overflow. (extensions/openai/realtime-transcription-provider.test.ts:591, 15195713985f)
  • Feature-history routing: History shows Vincent Koc has repeatedly maintained this provider and its shared realtime session behavior, including prior fixes for session errors, malformed frames, connection setup, and queued-audio handling. (extensions/openai/realtime-transcription-provider.ts:200, 4ccb4fd33173)

Likely related people:

  • vincentkoc: Relevant history shows repeated prior merged work on OpenAI realtime transcription and the shared WebSocket session, and this PR continues that ownership boundary. (role: feature owner and recent area contributor; confidence: high; commits: 4ccb4fd33173, f2a83a7a7125, 0d604f160d06; files: extensions/openai/realtime-transcription-provider.ts, extensions/openai/realtime-transcription-provider.test.ts, src/realtime-transcription/websocket-session.ts)
  • fuller-stack-dev: Current-main blame attributes the surrounding provider ordering and shared connection-generation lifecycle to this contributor's current-main commit. (role: recent current-main contributor; confidence: medium; commits: dd8e07c11f89; files: extensions/openai/realtime-transcription-provider.ts, src/realtime-transcription/websocket-session.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain explicit maintainer acceptance of the reconnect-at-bound behavior, then recheck the exact head's mergeability and required checks.

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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-08-02T21:06:12.356Z sha 53055bb :: needs changes before merge. :: [P2] Tombstone completions received before their commit
  • reviewed 2026-08-02T21:11:59.542Z sha 53055bb :: needs changes before merge. :: [P2] Tombstone pre-commit terminal outcomes
  • reviewed 2026-08-02T21:30:31.744Z sha 01530b8 :: found issues before merge. :: [P2] Prevent evicted terminal IDs from being emitted again
  • reviewed 2026-08-02T21:42:43.237Z sha 6ea9489 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T21:54:37.003Z sha 1519571 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Aug 2, 2026
* origin/main:
  feat(gateway): track event-loop degradation persistence and add concurrency benchmark (#118193)
  fix(config): preserve secret ownership when configuration rows move (#118149)
  fix(cron): deliver failure alerts after persistence (#118200)
  chore(lint): clear 172 lint:all baseline violations in five batches (#118098)
  perf(gateway): remove streaming hot-path rescans (#118192)
  test(gateway): use in-memory task registry (#118191)
  test(macos): fix three races in the bounded process suites (#118196)
  refactor(migrate-hermes): consolidate test fixtures (#118182)
  test(android): share Wear transport fixtures (#118177)
  test(ui): deduplicate control UI e2e setup (#118180)
  fix(plugins): unblock prerelease validation (#118103)
  test(cli): reduce redundant process launches (#118141)
  test(gateway): compact terminal observer fixtures (#118179)
  fix(agents): make requested threads sidebar-visible (#118073)
  test(plugins): canonicalize native resolver fixtures (#118174)
  test: deduplicate agent runner fixtures (#118176)
  refactor(policy): consolidate doctor test fixtures (#118173)
  fix(plugins): remove disabled channel plugin configuration on uninstall (#118127)
  refactor(matrix): consolidate monitor test fixtures (#118175)
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 2, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 2, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 2, 2026
@vincentkoc

Copy link
Copy Markdown
Member Author

Owner decision for the final ClawSweeper rank-up move:

I accept the explicit reconnect-at-bound contract for settled OpenAI transcription identities. The provider keeps terminal identities for the full connection generation and closes visibly at 4,096 items or 256 KiB rather than silently evicting identities, weakening first-terminal precedence, or retaining state without a bound.

This is intentionally provider-local with no config or environment-variable surface. Exact head 15195713985f5b069f53bbb769a9dc621ed4c7e9 has 26/26 provider tests, 26/26 shared websocket tests, an authorized live OpenAI realtime STT roundtrip, a passing Blacksmith changed gate, green hosted CI, and no actionable ClawSweeper findings.

@vincentkoc
vincentkoc merged commit 0a349a8 into main Aug 2, 2026
92 checks passed
@vincentkoc
vincentkoc deleted the fix-openai-realtime-transcript-bounds-20260802 branch August 2, 2026 22:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…transcript-bounds-20260802

* commit '565d0b4a24d741954393c4c2a79867a2680707b8':
  test(openai): isolate terminal history bounds
  test(openai): cover terminal history saturation
  fix(openai): preserve terminal history precedence
  test(openai): cover tombstone eviction ordering
  fix(openai): retain active predecessor satisfaction
  test(openai): cover rejected terminal failures
  fix(openai): preserve terminal error precedence
  test(openai): cover pre-commit terminal events
  fix(openai): tombstone pre-commit terminal events
  test(openai): pin first transcript terminal outcome
  fix(openai): ignore post-terminal transcript events
  test(openai): cover realtime transcription bounds
  fix(openai): bound realtime transcription state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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