Skip to content

feat(browser-extension): fetch chatgpt-dom-v1 attachment bytes via the page bridge - #3075

Merged
Sinity merged 4 commits into
masterfrom
feature/browser-extension/chatgpt-dom-v1-attachment-bytes
Jul 18, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/browser-extension/chatgpt-dom-v1-attachment-bytes

Conversation

@Sinity

@Sinity Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the last remaining gap in polylogue-83u.3: the chatgpt-dom-v1 DOM-scrape capture fallback now fetches attachment bytes through the same authenticated page-bridge mechanism the native adapter already uses, instead of recording only the chip name with byte_count=0.

Problem

General ChatGPT attachment fetching already ships: chatgpt_bridge.js (fetchAssetBytes) and chatgpt.js (acquireAssets/collectAssetDescriptors) live-fetch sandbox/file-service bytes for the normal chatgpt-native-v1 capture path (landed PR #2669, hardened #2672/#2712/#2926). The only remaining gap is the older chatgpt-dom-v1 fallback — used only when the authenticated backend-api conversation read fails — which had no acquisition path at all: collectAttachments recorded just the chip's name.

Architecture constraint

chatgpt-dom-v1 has no backend-api mapping to resolve a file/sandbox id from (unlike chatgpt-native-v1); the DOM chip's own href/src is the only evidence available, and it is sometimes already a concrete https:// URL the page itself rendered (e.g. an inline <img src>).

Solution

Added a "url" request kind to chatgpt_bridge.js's fetchAssetBytes that skips the metadata round trip entirely and reuses the exact same fetch+budget+hash mechanism already proven for the sandbox/file kinds (refactored the shared tail into fetchBytesFromResolvedUrl), including the existing cross-origin credential-drop rule (never forward page cookies/bearer to a provider-issued or DOM-rendered cross-origin URL). chatgpt.js's collectTurns now awaits a new acquireDomAttachmentBytes step — budget-bounded identically to the native path (same per-file/total-byte/time/consecutive-failure caps) — that requests those bytes and sets inline_base64 on the DOM attachment. That is the exact field polylogue/sources/parsers/browser_capture.py already decodes into ParsedAttachment.inline_bytes for every adapter, so no receiver/parser change was needed — inline_base64 is not a new payload field, just one chatgpt-dom-v1 was never wired to populate.

Chips with no resolvable URL stay honestly byte_count=0.

Consistency with polylogue-ptx

polylogue-ptx (PR #2928, merged) replaced the extension's browser-action/campaign machinery with a provider-neutral BrowserAction conduit. This change only extends the existing content-script/bridge byte-fetch mechanism at its one documented gap; it does not touch, duplicate, or compete with the BrowserAction conduit's submit/receipt machinery.

Verification

  • cd browser-extension && npx vitest run → 329 passed (1 pre-existing unrelated failure in build.test.js's packaged-service-worker backfill fixture — reproduces identically without this change)
  • npx eslint src/ tests/ → clean
  • node scripts/validate-manifest.mjs → ok
  • New coverage: 5 focused fetchAssetBytes "url"-kind tests (direct fetch, cross-origin credential drop, same-origin credential keep, non-https rejection, byte-cap enforcement) plus 2 full-capture DOM-fallback smoke tests (chatgpt_bridge.test.js) executing the real production sources through a simulated authenticated page, proving a chatgpt-dom-v1 capture now yields inline_base64 whose SHA-256 exactly matches the delivered bytes, and that a chip with no fetchable URL stays honestly byte_count=0.

Ref polylogue-83u.3

Co-Authored-By: Claude [email protected]

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 28 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5aba7256-9efa-42ed-9c8e-0a55dd524636

📥 Commits

Reviewing files that changed from the base of the PR and between 1501536 and a4bd0b9.

⛔ Files ignored due to path filters (26)
  • browser-extension/.cache/packaged-smoke-1784345221351/build-manifest.json is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/polylogue-browser-capture-0.9.0-chrome.zip is excluded by !**/.cache/**, !**/*.zip
  • browser-extension/.cache/packaged-smoke-1784345221351/polylogue-browser-capture-0.9.0-firefox.xpi is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/README.md is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/manifest.json is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/package.json is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/actions/chatgpt.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/capture_jobs.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/coordinator.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/models.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/page_transport.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/providers.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/backfill/storage.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/background.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/capture/freshness.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/common.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/ambient_surface.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/chatgpt.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/chatgpt_bridge.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/claude.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/claude_bridge.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/grok.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/content/message_layer.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/operator_status.js is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/popup.html is excluded by !**/.cache/**
  • browser-extension/.cache/packaged-smoke-1784345221351/unpacked/src/popup.js is excluded by !**/.cache/**
📒 Files selected for processing (6)
  • .beads/interactions.jsonl
  • .beads/issues.jsonl
  • browser-extension/src/content/chatgpt.js
  • browser-extension/src/content/chatgpt_bridge.js
  • browser-extension/tests/content/chatgpt_bridge.test.js
  • docs/topology-status.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/browser-extension/chatgpt-dom-v1-attachment-bytes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5d8ea6f31

ℹ️ 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".

@Sinity

Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

Addressed the Codex finding in 669c122:

  • P2 (unbounded buffering before the size check): added readBoundedBody, which reads the response via response.body.getReader() and cancels the stream the moment accumulated bytes exceed the budget, instead of buffering the whole response with arrayBuffer() and checking size only afterward. fetchBytesFromResolvedUrl now uses it for every asset kind (sandbox/file/url). Two new tests prove the actual mid-stream bound with no declared Content-Length: an oversized undeclared-length body is rejected (downloaded_bytes_over_limit) without ever needing the header, and a within-budget undeclared-length body is still acquired correctly.

330 tests pass (npx vitest run, 1 pre-existing unrelated build.test.js failure), npx eslint src/ tests/ clean.

Re: ci/circleci: quick-gate failing — confirmed pre-existing/unrelated: it also fails on 4053787ab (master itself, PR #3064, already merged). Not something this PR introduced.

Sinity and others added 4 commits July 18, 2026 05:23
…e page bridge

Problem: the chatgpt-dom-v1 DOM-scrape fallback (used only when the
authenticated backend-api conversation read fails) recorded just the
attachment chip's name with byte_count=0 -- there was no acquisition
path at all. The normal chatgpt-native-v1 path already fetches
sandbox/file-service bytes live through chatgpt_bridge.js
(fetchAssetBytes: sandbox/file kinds resolve a signed download URL via
a backend-api metadata call, then fetch+hash it).

Solution: chatgpt-dom-v1 has no backend-api mapping to resolve a
file/sandbox id from -- the DOM chip's own href/src is the only
evidence available, and it is sometimes already a concrete https URL
the page itself rendered (e.g. an inline <img src>). Added a "url"
request kind to fetchAssetBytes that skips the metadata round trip
entirely and reuses the exact same fetch+budget+hash tail already
proven for sandbox/file (refactored into fetchBytesFromResolvedUrl),
including the existing cross-origin credential-drop rule. chatgpt.js's
collectTurns now awaits a new acquireDomAttachmentBytes step (bounded
by the same per-file/total-byte/time/failure budgets as the native
path) that requests those bytes and sets inline_base64 on the DOM
attachment -- the exact field browser_capture.py already decodes into
ParsedAttachment.inline_bytes for every adapter, so no receiver/parser
change was needed. Chips with no resolvable URL stay honestly
byte_count=0.

Consistent with polylogue-ptx (PR #2928): this only extends the
existing content-script/bridge mechanism precisely where it was
missing (chatgpt-dom-v1's byte-acquisition gap); it does not touch the
provider-neutral BrowserAction conduit or add a second submit/fetch
mechanism.

Verification: cd browser-extension && npx vitest run ->
329 passed (1 pre-existing unrelated failure in build.test.js's
packaged-service-worker backfill fixture, reproduces identically
without this change). npx eslint src/ tests/ -> clean. New coverage:
5 focused fetchAssetBytes "url"-kind tests (direct fetch, cross-origin
credential drop, same-origin credential keep, non-https rejection,
byte-cap enforcement) plus 2 full-capture DOM-fallback smoke tests
proving a chatgpt-dom-v1 capture now yields inline_base64 whose
SHA-256 matches the delivered bytes exactly (the invariant the archive
blob store re-derives as acquisition_status='acquired'), and that a
chip with no fetchable URL stays honestly byte_count=0.

Ref polylogue-83u.3

Co-Authored-By: Claude <[email protected]>
chatgpt-dom-v1 attachment byte acquisition (this branch, commit above)
closes the only remaining gap this bead scoped -- the general
chatgpt-native-v1 sandbox/file-service asset acquisition already
shipped in earlier PRs (#2669/#2672/#2712/#2926).

Hand-merged the one touched record from a fresh `bd export` rather
than copying the whole file: bd resolves its export target independent
of invocation cwd, so it also carries unrelated concurrent-session bead
activity that doesn't belong on this branch.

Co-Authored-By: Claude <[email protected]>
Problem: Codex review of the "url" asset kind (previous commit) found
that fetchBytesFromResolvedUrl only checked the byte budget against
Content-Length when declared, then buffered the WHOLE response body
via arrayBuffer() before checking its actual size. Chunked/streamed
CDN responses -- common for DOM-rendered attachments, unlike the
sandbox/file endpoints ChatGPT itself controls and which reliably
declare Content-Length -- could omit the header entirely, letting an
oversized body download in full before being rejected. This was
pre-existing behavior for the sandbox/file kinds too, but extending
the same tail to arbitrary DOM-rendered URLs meaningfully raises the
odds of hitting an undeclared-length response.

What changed: added readBoundedBody, which reads the response body via
its ReadableStream (response.body.getReader()) and cancels the stream
the moment accumulated bytes exceed the budget, rather than buffering
first and checking after. Falls back to the previous buffer-then-check
behavior only if the environment's Response has no streaming body.
fetchBytesFromResolvedUrl now uses it in place of a bare arrayBuffer()
call; behavior for a within-budget or declared-oversized body is
unchanged.

Verification: cd browser-extension && npx vitest run -> 330 passed (1
pre-existing unrelated build.test.js failure). npx eslint src/ tests/
-> clean. Two new tests prove the actual mid-stream bound: a body with
no declared Content-Length that exceeds the cap is rejected
(downloaded_bytes_over_limit) without needing the header, and a body
of the same undeclared-length shape under the cap is still acquired
with a correct SHA-256/base64.

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/browser-extension/chatgpt-dom-v1-attachment-bytes branch from 669c122 to a4bd0b9 Compare July 18, 2026 03:29
@Sinity
Sinity merged commit e885e1e into master Jul 18, 2026
1 of 3 checks passed
@Sinity
Sinity deleted the feature/browser-extension/chatgpt-dom-v1-attachment-bytes branch July 18, 2026 03:29
Sinity added a commit that referenced this pull request Jul 18, 2026
…3078)

## Summary

Removes 26 accidentally-committed build artifacts from
`browser-extension/.cache/` (a packaged-smoke test's zip/xpi output and
unpacked source copy) that landed in master via #3075, and adds the
missing `.gitignore` entry.

## Problem

The root `.gitignore` covers `/.cache/` and `webui/.cache/` but never
`browser-extension/.cache/` — a `git add -A` while reconciling #3075's
rebase against a fast-moving master swept these up.

## Solution

`git rm -r --cached browser-extension/.cache`, add
`browser-extension/.cache/` to `.gitignore`.

## Verification

`devtools verify --quick` — 16/16 green.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <[email protected]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 53.F018 / P2: fixed-already at the checked revision: browser-extension/src/content/chatgpt_bridge.js:374 routes resolved URL downloads through readBoundedBody. Its streaming branch at lines 320-323 counts received chunks and cancels immediately upon exceeding maxBytes, rather than calling arrayBuffer on an unbounded chunked browser response.

Only the rows listed above are dispositioned. Held findings remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant