Skip to content

fix: validate large media data URLs without stack overflow - #146972

Merged
steipete merged 1 commit into
mainfrom
codex/managed-media-order-fix
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/managed-media-order-fix

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes large inline media payloads failing with a generic preparation error when base64 validation exhausts the regexp stack before checking the size limit.

User Impact

The Gateway validates large media data URLs and reports the intended size or input error. Accepted characters, whitespace, padding, size limits, decoding, and error sanitization are unchanged.

Why This Change Was Made

The quantified whole-string alphabet match can throw RangeError: Maximum call stack size exceeded after the shared Gateway test sequence warms it. Search for an invalid character instead, with an explicit empty-payload check. This preserves the existing grammar without the failing quantified match.

Related: main-branch QA follow-up to #146897 and #146931.

Evidence

  • Original full AWS run exposed both audio/video 16 MiB cap failures. Bounded tracing identified RegExp.test as the original exception; sanitization was behaving correctly.
  • Current-main baseline, exact original seven-file shared-worker order: 1,516 passed, 2 failed. Same order after the fix: 1,518 passed, no instrumentation and no assertion changes.
  • Complete media file: 129 passed before and after (39.18s and 36.08s on Node 24.21.0).
  • Formatting and git diff --check passed. Independent Codex review through P2 found no actionable issues.
  • Complete changed-file checks passed, including core/core-test typechecks, lint, formatting, and repository guards. Exact-head CI is required before landing.

@clawsweeper

clawsweeper Bot commented Sep 13, 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 gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 7:39 AM ET / 11:39 UTC (Revision 2).

ClawSweeper review

What this changes

The Gateway validates inline media by searching for invalid base64 characters, avoiding regular-expression stack exhaustion while preserving existing input rules.

Merge readiness

✅ Ready for maintainer review

This remains a useful, narrowly scoped fix: fetched main and the latest release retain the affected validator. No actionable correctness or security findings remain, and the previous review recorded no unresolved findings.

Priority: P2
Reviewed head: b227299f0a26901bfdef048e5b3d64144d5186af

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving repair with relevant reported regression validation and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported before/after shared-worker tests exercise the changed parser; no live setup execution is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported before/after shared-worker tests exercise the changed parser; no live setup execution is claimed.
Evidence reviewed 7 items Verified introduced change: The pinned merge-base-to-head diff changes only the payload alphabet check. The explicit empty check preserves the old nonempty requirement; the negated character class preserves the accepted alphabet, including whitespace and padding.
Still needed on fetched main: Fetched main retains the quantified whole-payload expression before decoded-size estimation and decoding.
Latest release retains the old validator: The GitHub contents API confirms the old expression in v2026.9.4. This read recovered the release-source check after the local historical blob was unavailable.
Findings None None.
Security None None.

How this fits together

The Gateway turns media in assistant replies into managed attachments for chat display and download. Inline media passes through character validation, size checks, and decoding before storage.

flowchart TD
  A[Assistant reply media] --> B[Parse inline data URL]
  B --> C[Check characters and empty payload]
  C --> D[Check media size]
  D --> E[Decode and store attachment]
  E --> F[Chat display and download]
  C --> G[Sanitized preparation error]
  D --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1. Total +1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 2 1 +1

Review metrics

None.

Technical review

Best possible solution:

Keep validation in the existing managed-media parser, preserving its grammar, byte limits, decoding, and sanitized errors.

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

Yes: the existing oversized audio/video cases exercise the affected production parser, and the PR reports a failing baseline in the original shared-worker order. This read-only review verified the path but did not execute that reproduction.

Is this the best way to solve the issue?

Yes: the replacement accepts the same nonempty character language while removing the quantified whole-payload match, without adding a competing parser or changing downstream policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4883e4699ee3.

Labels

Label justifications:

  • P2: This repairs large inline-media preparation failures with a bounded parser change and no broader runtime outage demonstrated.
  • 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 supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. Reported before/after shared-worker tests exercise the changed parser; no live setup execution is claimed.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff changes only the payload alphabet check. The explicit empty check preserves the old nonempty requirement; the negated character class preserves the accepted alphabet, including whitespace and padding. (src/gateway/managed-image-attachments.ts:638, b227299f0a26)
  • Still needed on fetched main: Fetched main retains the quantified whole-payload expression before decoded-size estimation and decoding. (src/gateway/managed-image-attachments.ts:637, 4883e4699ee3)
  • Latest release retains the old validator: The GitHub contents API confirms the old expression in v2026.9.4. This read recovered the release-source check after the local historical blob was unavailable. (src/gateway/managed-image-attachments.ts, 3a9d69db306c)
  • Existing regression contract and reported validation: Existing audio/video cases submit payloads one byte above their caps through the production attachment owner and require the 16 MiB error. The captured PR body reports 1,516 passes and two failures before the change versus 1,518 passes afterward in the original shared-worker order; the isolated media file passed 129 cases both times. These are contributor-reported test results, not reviewer-executed live proof. (src/gateway/managed-image-attachments.test.ts:1732, b227299f0a26)
  • Production caller and preserved error handling: Assistant reply construction calls the managed-media owner with continueOnPrepareError and receives sanitized preparation errors. The patch leaves storage, authorization, transcript ownership, and error sanitization unchanged. (src/gateway/server-methods/chat-assistant-content.ts:209, b227299f0a26)
  • Parser history and routing: Current-main history includes earlier parser and managed-media work by Peter Steinberger. The GitHub commit patch identifies steipete and shows the earlier header parser change; raw commit inspection records its parent. This supplies a concrete routing pointer rather than attributing responsibility for the failure. (src/gateway/managed-image-attachments.ts:622, 79d3daa09b57)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T11:32:38.515Z sha b227299 :: needs maintainer review before merge. :: none

@steipete
steipete marked this pull request as ready for review September 13, 2026 11:35
@steipete
steipete merged commit 0b47610 into main Sep 13, 2026
261 checks passed
@steipete
steipete deleted the codex/managed-media-order-fix branch September 13, 2026 11:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '4aff70f27016f9acf62d0acc19c8bd3592993e4c': (1537 commits)
  test: align plugin fixtures with current runtime contracts (#147000)
  refactor(browser): separate session tab tracking from cleanup (#146973)
  fix(tests): make systemd clock fixtures private (#146990)
  fix(linux): retire sleep guards when logind disconnects (#146046)
  refactor(matrix): share draft fallback delivery (#144840)
  fix(sessions): preserve cross-agent replies after reload (#146799)
  test(models): cover quota recovery during catalog discovery (#146708)
  fix(macos): recover browser sign-in when no browser opens (#146787)
  fix(process): prevent one-shot agents exiting while polling (#144268)
  fix(status): label the session inventory as stored (#146979)
  fix: avoid repeated background reads while loading chat (#146953)
  refactor(ui): narrow Skill Workshop proposal context (#146977)
  perf(sessions): keep cleanup responsive and reuse workers (#140897)
  fix(sessions): prevent stranded writers after abort and restart (#146792)
  refactor: reuse deferred owners in Gateway and infra fixtures (#146809)
  fix: prevent queued conversation replies from switching storage (#146984)
  test(ui): preserve nested failure summaries in CI logs (#146864)
  fix(test): respect process memory limits in local scheduling (#146298)
  fix: validate large media data URLs without regexp stack exhaustion (#146972)
  fix(ui): label model usage contributions as messages (#146735)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '4aff70f27016f9acf62d0acc19c8bd3592993e4c': (30 commits)
  test: align plugin fixtures with current runtime contracts (#147000)
  refactor(browser): separate session tab tracking from cleanup (#146973)
  fix(tests): make systemd clock fixtures private (#146990)
  fix(linux): retire sleep guards when logind disconnects (#146046)
  refactor(matrix): share draft fallback delivery (#144840)
  fix(sessions): preserve cross-agent replies after reload (#146799)
  test(models): cover quota recovery during catalog discovery (#146708)
  fix(macos): recover browser sign-in when no browser opens (#146787)
  fix(process): prevent one-shot agents exiting while polling (#144268)
  fix(status): label the session inventory as stored (#146979)
  fix: avoid repeated background reads while loading chat (#146953)
  refactor(ui): narrow Skill Workshop proposal context (#146977)
  perf(sessions): keep cleanup responsive and reuse workers (#140897)
  fix(sessions): prevent stranded writers after abort and restart (#146792)
  refactor: reuse deferred owners in Gateway and infra fixtures (#146809)
  fix: prevent queued conversation replies from switching storage (#146984)
  test(ui): preserve nested failure summaries in CI logs (#146864)
  fix(test): respect process memory limits in local scheduling (#146298)
  fix: validate large media data URLs without regexp stack exhaustion (#146972)
  fix(ui): label model usage contributions as messages (#146735)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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