Skip to content

fix(browser-capture): preserve temporary chats and attachments - #2376

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/claude-native-on-demand
Jun 24, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/claude-native-on-demand

Conversation

@Sinity

@Sinity Sinity commented Jun 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

This updates browser capture so ChatGPT temporary chats without /c/<id> routes get deterministic local ids, browser-observed turn attachments survive through the shared envelope, and non-native preservation payloads no longer get misparsed as empty native ChatGPT sessions. It also adds the Claude.ai main-world native capture bridge that was live-proven locally.

Problem

A live ChatGPT temporary tab at https://chatgpt.com/?temporary-chat=true was important enough to preserve immediately, but temporary chats do not expose the normal provider-native conversation id. The first emergency envelope also showed a parser bug: a non-native raw_provider_payload wrapper was sent through the ChatGPT native parser and materialized a zero-message session. Separately, browser DOM fallback had an attachment model downstream but the extension dropped turn.attachments before storage could see them.

Ref #2308.

Solution

  • Assign deterministic temporary:<hash> ids for ChatGPT temporary-chat URLs.
  • Preserve turn.attachments through browser-extension/src/common.js.
  • Extract ChatGPT DOM file-tile-style attachments from labelled groups/downloads/images while rejecting domain/email/version-text false positives.
  • Use native raw parsers only when raw payloads have the expected provider shape: ChatGPT mapping, Claude.ai chat_messages.
  • Add the Claude.ai main-world bridge and on-demand content-script request path.
  • Add focused browser-extension and parser regression coverage.

Live preservation proof for the urgent tab:

  • Preserved session id: chatgpt-export:temporary:867d1acac2bf4997857fa0a7.
  • Emergency preservation dir: /realm/inbox/chatgpt-temporary-preserve-20260624-165817.
  • Archive-state: state=archived, raw_row_exists=true, indexed_session_exists=true, indexed_message_count=25.
  • Attachment refs: 11 observed upload names; four have matched local byte counts.

Verification

  • npm run validate && npm run lint && npm run build && npm test -- tests/common.test.js tests/content/chatgpt.test.js tests/content/claude.test.js tests/build.test.js — passed, 72 tests.
  • devtools test tests/unit/sources/test_browser_capture.py -k 'non_native_raw_payload_keeps_envelope_turns or parses_session_metadata_and_deduplicates_turns' — passed, 2 selected.
  • devtools verify --quick — passed, run id 20260624T151252Z-quick-2819319-6a00faa2.
  • git push pre-push quick gate — passed, run id 20260624T151412Z-quick-2821092-f9098ead.

Residuals

Seven observed temporary-chat attachment names were preserved without local bytes because matching local files were not found under the checked download/snapshot roots. The archive stores their names and message refs; the preservation directory records the unmatched set for later recovery if the original upload files are found.

Summary by CodeRabbit

  • New Features

    • Added support for capturing attachments in browser conversations.
    • Improved handling of temporary ChatGPT chats with stable, repeatable identifiers.
    • Expanded Claude capture support to retrieve conversation data through a page bridge.
  • Bug Fixes

    • Improved native payload detection so only valid provider-specific data is parsed.
    • Preserved existing conversation turns when captured native data doesn’t match the expected format.

Problem: ChatGPT temporary chats do not expose a normal /c/<id> route, and the browser-capture fallback was dropping turn attachments. A non-native raw preservation payload could also route through the ChatGPT native parser and produce a zero-message indexed session. Claude.ai native capture still needed an on-demand bridge for reliable live proof. Ref #2308.

What changed: add deterministic temporary ChatGPT session ids, preserve turn attachments through shared envelopes, extract ChatGPT DOM file-tile metadata with false-positive guards, add a Claude.ai main-world native bridge, and require native raw payload shape before using provider-native parsers.

Verification: npm run validate && npm run lint && npm run build && npm test -- tests/common.test.js tests/content/chatgpt.test.js tests/content/claude.test.js tests/build.test.js; devtools test tests/unit/sources/test_browser_capture.py -k 'non_native_raw_payload_keeps_envelope_turns or parses_session_metadata_and_deduplicates_turns'; devtools verify --quick.
@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds a new MAIN-world claude_bridge.js content script that intercepts Claude.ai network traffic and implements a postMessage-based request/response protocol. Refactors claude.js to use this on-demand bridge. Extracts ChatGPT DOM attachments and handles temporary-chat sentinel session IDs in shared utilities. Adds structural payload shape guards to the Python browser-capture parser.

Changes

Claude Bridge, ChatGPT Attachments & Temp-Chat Session IDs

Layer / File(s) Summary
Temp-chat sentinel & attachment normalization
browser-extension/src/common.js, browser-extension/tests/common.test.js
sessionIdFromUrl returns __polylogue_temporary_chat__ for ChatGPT temporary-chat URLs; buildEnvelope rewrites that sentinel to a deterministic temporary:<hash> from sourceUrl and turns; turn mapping normalizes missing text to null and attachments to []. Tests cover sentinel detection, deterministic identity, and attachment passthrough.
ChatGPT DOM attachment extraction
browser-extension/src/content/chatgpt.js, browser-extension/tests/content/chatgpt.test.js
Two helpers derive filenames from DOM attributes and scan/deduplicate downloadable links and images into attachment objects with fnv1a-hashed provider IDs. collectTurns() now returns a turn when attachments exist even without visible text. Tests verify .tar.gz tile capture, deduplication, and rejection of domain/email/version strings.
Claude MAIN-world bridge + content-script refactor
browser-extension/manifest.json, browser-extension/src/content/claude_bridge.js, browser-extension/src/content/claude.js, browser-extension/tests/content/claude.test.js
claude_bridge.js (registered at document_start in MAIN world) maintains a bounded capture queue, overrides window.fetch to record chat_conversations JSON, infers API URLs from performance entries and localStorage keys, and implements polylogue.claude.nativeFetchRequest/Response messaging. claude.js drops the injected hook in favor of requestNativeCaptureFromPage (10s timeout) and fetchNativePayloadOnDemand, with rememberNativeAttempt diagnostics in the fallback envelope. Tests cover URL inference, bootstrap derivation, and organizationIdFromStorageKeys.
Python parser payload shape guards
polylogue/sources/parsers/browser_capture.py, tests/unit/sources/test_browser_capture.py
Adds _has_chatgpt_native_payload and _has_claude_ai_native_payload TypeGuard helpers; parse now gates provider-specific delegation on structural shape checks instead of a generic truthiness test. New test verifies non-native raw_provider_payload falls back to envelope-derived turns.

Sequence Diagram(s)

sequenceDiagram
  participant Page as Claude Page (MAIN world)
  participant Bridge as claude_bridge.js
  participant ContentScript as claude.js (content-script)
  participant ClaudeAPI as Claude API

  rect rgba(100, 149, 237, 0.5)
    note over Bridge: Passive fetch interception
    Page->>Bridge: window.fetch(chat_conversations URL)
    Bridge->>ClaudeAPI: original fetch (pass-through)
    ClaudeAPI-->>Bridge: JSON with chat_messages
    Bridge->>Bridge: remember capture in __polylogueClaudeCapturedFetches
    Bridge-->>Page: response (unmodified)
  end

  rect rgba(144, 238, 144, 0.5)
    note over ContentScript,Bridge: On-demand native capture
    ContentScript->>Bridge: postMessage(nativeFetchRequest, {requestId, conversationId})
    Bridge->>Bridge: inferConversationApiUrl(conversationId)
    Bridge->>ClaudeAPI: fetch(inferredUrl, credentials: include)
    ClaudeAPI-->>Bridge: conversation JSON
    Bridge-->>ContentScript: postMessage(nativeFetchResponse, {requestId, capture})
    ContentScript->>ContentScript: parseNativeCapture + rememberNativeAttempt
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Sinity/polylogue#2345: Overlaps directly with browser_capture.py's parse() flow — that PR normalizes provider_session_id routing while this PR adds native-payload shape guards to the same delegation path.

Suggested labels

type:test, area:parser, tool:claude

🐇 A bridge in the MAIN world, fetch hooks so sleek,
Attachments from ChatGPT, .tar.gz mystique!
Temporary chats get a hash all their own,
Shape guards in Python keep bad payloads unknown.
Hop hop, little captures, now safely stored —
The rabbit approves this extensible hoard! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: preserving temporary chats and attachments in browser capture.
Description check ✅ Passed The description covers the Summary, Problem, Solution, Verification, and follow-up details with sufficient specificity.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/claude-native-on-demand

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: 1b2a5100cc

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

Comment thread browser-extension/src/common.js Resolved
@Sinity
Sinity merged commit 80b3af4 into master Jun 24, 2026
16 of 17 checks passed
@Sinity
Sinity deleted the feature/fix/claude-native-on-demand branch June 24, 2026 15:18
@github-actions github-actions Bot mentioned this pull request Jul 5, 2026
@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.F010 / P2: fixed-already at the checked revision: browser-extension/src/content/chatgpt.js:975 supplies the native conversation_id or id to buildEnvelope. Temporary native captures therefore keep the provider identity across added turns rather than hashing the changing transcript into a new session identity.

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