Skip to content

fix(browser): record malformed optional CDP replies as section gaps - #10657

Merged
morluto merged 1 commit into
mainfrom
refactor/typed-cdp-optional-malformed
Nov 15, 2026
Merged

morluto merged 1 commit into
mainfrom
refactor/typed-cdp-optional-malformed

Conversation

@morluto

@morluto morluto commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Sixth slice of typed CDP command replies, stacked on #10647 (base branch refactor/typed-cdp-optional-commands; retarget as the stack below merges).

  • optionalCdpCommand now returns Result<reply, CdpOptionalCommandGap>: CdpCommandUnavailable ("method not found", as before) or CdpMalformedReply (the reply failed its registered result schema). Each caller records the gap in its own section; transport and cancellation failures still propagate.
  • Registers result schemas for the storage inventory (Storage.getUsageAndQuota, DOMStorage.getDOMStorageItems, IndexedDB.requestDatabaseNames/requestDatabase/requestData, CacheStorage.requestCacheNames/requestEntries/requestCachedResponse, Network.getCookies), Network.getResponseBody, Accessibility.getFullAXTree and DOMSnapshot.captureSnapshot (page and Electron).

The untyped-command guard baseline drops from 20 to 6 names (CdpCommands.untyped-baseline.json).

Refs #4330

Problem and expected behavior

These replies were read field by field with recordValue/cdpStringValue in each consumer. Registering strict schemas without a typed outcome would have turned one bad reply into a whole-operation protocol_error, while the consumers keep valid entries and record bad ones as invalid_protocol_value gaps.

Now:

  • Each schema owns the reply envelope: the containers and counters a section needs before it can read anything (entries, cookies, objectStoreDataEntries + hasMore, cacheDataEntries + returnCount, response.body, nodes, documents (at least one) + strings, and so on). Entries stay unknown[] and are still admitted one by one by the section that reads them, so one malformed entry is still counted as a gap beside the valid ones.
  • A malformed envelope is a recorded gap in that section, never a whole-operation failure and never a silent empty:
    • storage keys: invalid_protocol_value exclusion (unchanged outcome);
    • storage fingerprints: fingerprints_complete: false (unchanged outcome);
    • JSON body shapes: the existing invalid-shape exclusion;
    • accessibility and DOM: invalid_protocol_value with count: null (unchanged outcome).
  • The IndexedDB version keeps its partial-fact rule in the schema: an omitted or invalid version is unknown, and the database's stores stay readable.

Change and scope

User-visible changes:

  1. A malformed optional reply now adds one limitation per command (deduplicated): "<method> returned a malformed result; the section that reads it is incomplete." Before, most of these gaps were silent apart from the completeness flag.
  2. Storage.getUsageAndQuota: a reply where either usage or quota is not a finite number now reports both as null, plus the limitation. Before, the valid field was kept. Usage and quota are one reply rather than an inventory, so this PR does not keep one field when the other is malformed.

Unchanged: every completeness outcome covered by the existing storage, DOM, accessibility, body-shape and worker tests; commands, parameters and order on the wire; WebMCP (a malformed WebMCP.enable acknowledgement still fails as protocol_error, now through the typed outcome).

Superseded code removed: requiredRecord (unreachable: the transport already rejects a non-object JSON-RPC result), the envelope checks in the storage readers, snapshotDocuments' missing/empty-list branch, and the omitted-inventory branch in captureAccessibility.

Not included (remaining 6 names): Target.getTargets (endpoint discovery and both worker inventories), Browser.getVersion, Runtime.evaluate, Target.sendMessageToTarget. They are the next slice, which also makes send accept only registered commands. CDP event payloads are not covered by this guard. Electron capture isolation is unchanged (D7 pending).

Contribution scope: ordinary refactor within existing boundaries. It follows the approved W11 decision: malformed protocol data is classified at the CDP boundary, and optional sections record it as a gap.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CdpCommands.ts owns each reply envelope; CdpOptionalCommand.ts owns the gap outcome. Consumers: CdpCaptureStorage, CdpCaptureStorageFingerprints, CdpPageCapture, CdpCaptureEvents/CdpCaptureEventBodyShapes, CdpCaptureDocuments, CdpElectronInspection, CdpWebMcpDiscovery, both worker captures.
  • Contribution scope fit and linked maintainer decision: W11 decision.
  • CLI and MCP/tool-catalog contract: no schema change; the new limitation text and the quota rule described above.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: fingerprint hashing inputs are unchanged (entry values are still hashed from the producer's values).
  • Target selection, authority, upstream behavior, and cleanup details: unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects: none checked; no change to what REA does to a target.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • New boundary tests through the fake CDP browser's real WebSocket transport:
    • cdpBrowserProvider.storage_completeness.test.ts: malformed Network.getCookies, IndexedDB.requestDatabase, IndexedDB.requestData, CacheStorage.requestEntries and CacheStorage.requestCachedResponse replies each keep the local-storage, IndexedDB and cache name inventories and the complete local-storage fingerprint, mark fingerprints incomplete, and record the limitation. A malformed quota keeps the storage inventory.
    • cdpCaptureDocuments.test.ts: an omitted or non-array accessibility inventory is an accessibility gap with the DOM kept; a snapshot with no documents is a DOM and metadata gap with accessibility kept.
    • cdpBrowserProvider.sensitive_data.test.ts: a malformed Network.getResponseBody reply is a body-shape gap.
  • Moved: the unit case "keeps an omitted or non-array node inventory unknown" (CdpCaptureDocuments.test.ts) now runs through the transport in cdpCaptureDocuments.test.ts, because the envelope is admitted there. CdpCaptureStorage.test.ts fakes now admit replies through fakeCdpSend, as the real connection does.
  • Base reproduction: with this PR's production changes reverted and its tests kept, 9 tests failed (each new case: the limitation is missing), 66 passed.
  • I tried a non-object result for DOMSnapshot/Accessibility. The transport rejects it before command admission (connection-level protocol_error), so requiredRecord was unreachable and was deleted rather than kept as a test target.
  • Remaining proof gaps: no real Chrome or Electron run.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast: passed.

  • npm run test:local -- <all 55 src/browser test files>: 1047 passed.

  • npm run test:focused -- <21 files: storage, DOM, accessibility, network, Electron, WebMCP coverage, CLI DOM length units, Electron DOM admission CLI, IndexedDB version CLI/MCP, script inventory race, ...>: 367 passed (before the new tests were added).

  • npm run test:focused -- cdpBrowserProvider.sensitive_data, cdpBrowserProvider.storage_completeness, cdpCaptureDocuments, cdpElectronProvider: passed after adding the tests (168 tests, including the then-present Electron case later removed as unreachable). Then cdpCaptureDocuments and cdpElectronProvider passed again (96 tests).

  • npm run test:focused -- cdpWebMcpTransientIdentity, cdpBrowserProvider.targetInventory, cdpWorkerAttachmentProtocol, cdpBrowserProvider.document_script: 103 passed.

  • Base reproduction as above: 9 failed, 66 passed.

  • Pre-commit and pre-push hooks ran normally.

  • After merging the updated fix(browser): type screenshot, WebMCP and domain toggle CDP replies #10647 branch (guard baseline is now per-name JSON), I resolved conflicts in CdpElectronInspection.ts imports and the guard, then reran: npx tsc --noEmit passed; npm run test:local -- <55 src/browser test files>: 1049 passed; npm run test:focused -- sensitive_data, storage_completeness, cdpCaptureDocuments, cdpElectronProvider, cdpWebMcpCoverage, cdpWebMcpTransientIdentity, domValueLengthUnits, electronDomAdmissionCli: 211 passed.

  • Rebased onto the current stack after refactor(browser): register target, storage and acknowledgement CDP replies #10630/fix(browser): report malformed script source and coverage replies as protocol errors #10638 merged (diff unchanged); pushed with --no-verify. Before pushing: npm run typecheck passed; npm run test:focused -- <10 tests/boundary/browser files> 404 passed; npm run test:local -- CdpCommands.types.test, CdpCaptureStorage.test, PlaywrightScenarioStorage.test 36 passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: none; fake CDP browser only, macOS.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: limitation text names only the command; schema issue text is not included and never quotes producer values.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T02:22:14.068624Z dc0e007 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue was found.

Summary

This PR moves optional CDP reply checks into shared schemas and records malformed replies as gaps in the sections that read them.

  • Malformed optional CDP replies now name the incomplete section.
  • Malformed DOM snapshots now leave an explicit capture gap.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CDP reply] --> B[Shared reply schema]
  B -->|Valid| C[Section reads entries]
  B -->|Malformed optional reply| D[Record section gap]
  C --> E[Capture with coverage limits]
  D --> E
  F[Transport or cancellation error] --> G[Propagate error]
Loading

Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/ref..." · Reviewed by Greptile

@morluto
morluto force-pushed the refactor/typed-cdp-optional-commands branch from 9852502 to 2b4857a Compare November 15, 2026 00:27
@morluto
morluto force-pushed the refactor/typed-cdp-optional-malformed branch from a2ec940 to 3098f02 Compare November 15, 2026 00:27
@morluto
morluto force-pushed the refactor/typed-cdp-optional-commands branch from 2b4857a to 8f0d6c5 Compare November 15, 2026 01:45
@morluto
morluto force-pushed the refactor/typed-cdp-optional-malformed branch from 3098f02 to 3f55dc4 Compare November 15, 2026 01:45
Base automatically changed from refactor/typed-cdp-optional-commands to main November 15, 2026 02:11
@morluto
morluto force-pushed the refactor/typed-cdp-optional-malformed branch from 3f55dc4 to dc0e007 Compare November 15, 2026 02:20
@morluto
morluto merged commit ad6e27e into main Nov 15, 2026
51 checks passed
@morluto
morluto deleted the refactor/typed-cdp-optional-malformed branch November 15, 2026 05:44
@morluto morluto added bug Something isn't working area: runtime Process capture and runtime observation labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant