Skip to content

fix(browser): start coverage at domain enablement - #6276

Closed
sachinkr7368 wants to merge 1 commit into
morluto:mainfrom
sachinkr7368:fix/6232-coverage-start
Closed

sachinkr7368 wants to merge 1 commit into
morluto:mainfrom
sachinkr7368:fix/6232-coverage-start

Conversation

@sachinkr7368

@sachinkr7368 sachinkr7368 commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

inspect_web_page now reports network.coverage_started_at and console.coverage_started_at from the moment REA dispatches the corresponding CDP domain-enable command, instead of reusing capture_window.started_at from before attach and setup. Events delivered while a domain is being enabled therefore remain inside that section's reported coverage boundary. Fixes #6232.

Problem and expected behavior

On the base revision, normalizedInspection set both section timestamps to state.startedAt, which is captured before Page.enable, the authorized-main-frame check and enableObservationDomains. A successful MCP request against the repository's loopback CDP fake therefore returned:

  • network.coverage_started_at === capture_window.started_at, and
  • console.coverage_started_at === capture_window.started_at,

even though Runtime.enable and Network.enable had not been dispatched yet. CDP can deliver events after a command is dispatched but before its reply, and the capture already ingests those events; reporting a start later than their delivery would place retained events outside their own coverage window.

Expected: each section's coverage start reflects when observation of that domain becomes available, and an event delivered while a domain is being enabled remains represented within the boundary. capture_window.started_at and prior_activity_available: false are unchanged.

Change and scope

  • src/browser/CdpPageCapture.ts: add networkCoverageStartedAt / consoleCoverageStartedAt to CaptureState; record each immediately before dispatching Network.enable / Runtime.enable; report them in the two section objects.
  • tests/boundary/mcp/coverageStart.test.ts: MCP regression with deterministic 25 ms reply barriers for Page.enable, Runtime.enable and Network.enable, a Network.enable event delivered before its reply, and assertions that both starts are later than capture entry, at/after the Page.enable reply, at/before their enable command reaches the fake, and that the pre-reply request remains present. The per-command barriers make a timestamp recorded after an enable reply fail the test.
  • docs/browser-observation.md: clarify that coverage starts when REA begins enabling the domains and includes events delivered during enablement.

Not included: no change to event filtering or retention, capture_window, prior_activity_available, the scripts/workers/storage sections, or CDP command order. This is an ordinary fix inside the existing inspect_web_page boundary; no new capability or maintainer scope decision is required.

Contract and boundary impact

  • Semantic owner and earliest changed stage: browser observation normalization in src/browser/CdpPageCapture.ts; no new capture stage.
  • Contribution scope fit and linked maintainer decision: existing inspect_web_page behavior; not applicable (no new capability).
  • CLI and MCP/tool-catalog contract: the inspect_web_page output schema is unchanged; the two timestamps now reflect domain enablement. CLI projection carries the same corrected timestamps.
  • Provider, bridge, target-format, or platform compatibility: none; CDP command order and transport are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; raw headers, bodies, cookies, storage values and console objects remain unretained.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): unchanged; authorized-main-frame, origin checks and capture cleanup are untouched.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • 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

  • Tests added or updated: tests/boundary/mcp/coverageStart.test.ts exercises the registered MCP tool and production CDP provider against the loopback fake, with a 25 ms Page.enable reply barrier and a Network.enable event sent before its reply.
  • Base reproduction: with the source fix reverted and the regression kept, npm run test:boundary -- tests/boundary/mcp/coverageStart.test.ts failed at expect(networkStart).toBeGreaterThan(captureStart) with expected 1792652942473 to be greater than 1792652942473; the same test passes with the fix. This shows coverage previously started at capture entry rather than at domain enablement.
  • Forward check: a temporary implementation that recorded both timestamps after the enable replies failed the same test with expected 1792654033686 to be less than or equal to 1792654033654, confirming the barriers distinguish dispatch from reply. The mutation was reverted.
  • User-visible CLI/MCP output (if applicable): inspect_web_page now returns network.coverage_started_at and console.coverage_started_at after capture_window.started_at, at or before the corresponding Network.enable / Runtime.enable dispatch. All other output is unchanged.
  • Remaining proof gaps: no real browser was run; ordering is exercised against the repository's loopback CDP fake, which models command latency and pre-reply events deterministically. The change is platform-neutral and has no OS-specific branches.

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

  • Base reproduction with the source fix reverted — 1 file, 1 failed (networkStart === captureStart).
  • Temporary post-reply timestamp mutation (reverted) — 1 file, 1 failed (networkStart exceeded the Network.enable receipt time).
  • npm run test:boundary -- tests/boundary/mcp/coverageStart.test.ts — 1 file, 1 test passed with the fix.
  • npm run test:boundary -- tests/boundary/mcp/browserMcp.test.ts tests/boundary/browser/ — 60 passed | 1 skipped (61 files), 792 passed | 6 skipped (798 tests).
  • npm run test:local -- <all 56 src/browser/**/*.test.ts files> — 56 files, 744 tests passed.
  • npm run typecheck — exit 0.
  • npm run check — pass (Turbo tasks and architecture guards across 1,785 source files).
  • npm run docs:check — 9 tests passed.
  • npx oxfmt --check src/browser/CdpPageCapture.ts tests/boundary/mcp/coverageStart.test.ts docs/browser-observation.md — pass.
  • git diff --check — clean.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The timestamps are descriptive metadata within the existing schema.
  • Real Hopper/Ghidra, browser, or OS coverage: no real browser was used; the production CDP provider was exercised against the suite's loopback HTTP/WebSocket fake. See the proof gaps above.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none. The change only moves two timestamps later within an already-reported capture window; no new data is retained.

Author readiness

Human owner: @sachinkr7368

  • 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.

AI-assisted: the diff and evidence were prepared by an AI coding agent. The human owner directed that this PR be marked ready for initial review and dictated the readiness declarations above.

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-22T07:20:42.916562Z
We couldn’t complete this review. Comment @codex review to try again.
450e6c4 PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous test gap is fixed and no new blocking issue was found.

Summary

The PR reports network and console coverage from domain-enable dispatch rather than capture entry.

  • Network and console coverage starts when REA sends each enable command.

Reviews (2) · Last reviewed commit: "fix(browser): start coverage at domain e..." · Reviewed by Greptile

inspect_web_page reported network and console coverage as starting at capture entry, before Page.enable completed and before Runtime.enable or Network.enable was dispatched. Record the dispatch time of each observation domain so events delivered while a domain is being enabled remain inside the reported section boundary.

Fixes morluto#6232
@sachinkr7368
sachinkr7368 force-pushed the fix/6232-coverage-start branch from 450e6c4 to 5abcff3 Compare October 22, 2026 07:27
@sachinkr7368

Copy link
Copy Markdown
Author

Addressed the Greptile finding in 5abcff3: the regression now holds the Runtime.enable and Network.enable replies for 25 ms after receipt, so a coverage timestamp recorded after any enable reply fails the <= receipt assertion. Verified by temporarily recording both timestamps after their replies (the test failed with expected 1792654033686 to be less than or equal to 1792654033654) and then restoring the dispatch-time implementation (the test passes).

@gongfpp gongfpp mentioned this pull request Oct 22, 2026
17 of 22 tasks

@baron baron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI-assisted review traced capture entry, authorized-frame reset, separate Runtime/Network dispatch boundaries, pre-reply event ingestion and final normalization. The changed producer owns explicit start facts; consumers no longer guess from capture-entry time. Cancellation, target identity and cleanup remain on existing paths.

The MCP regression uses the production CDP provider and clock barriers for both enable calls, addressing the earlier after-reply mutation gap. This is stronger than asserting nonempty events, but fake-browser tests are not real-browser verification.

I authorized the waiting exact-head CI/title runs (CI 39740635792). Authorization is not a successful result; approval is withheld pending completed required checks and inspection of applicable coverage. No local full focused-suite or real-browser pass is claimed by this review.

@CassieFox23 CassieFox23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TL;DR: Main still reports both coverage start times as the capture start (issue #6232). This PR moves them to just before the Runtime.enable and Network.enable commands, and the test fails if a stamp is taken after a reply. The code reads right. CI is red on one process test this PR does not touch, and the body drops two template parts.

Findings

Should fix

  • CI failed on this head: CI required, Portable tests and Test shard (4/8). Each shows the same single test, rejects a reparented alternate launcher without signaling it in tests/process-global/cleanLinuxHopperRuntime.test.ts (error Command failed: ps -p 17653 -o ppid=,pgid=). This PR does not touch that file. The run is attempt 2 of run 39740635792. It tested a merge of this head into main c9b4cae (#6260, 22 Oct). Since then #6570 (cc8835c, merged 23 Oct) changed that test file and its boundary twin. In the two failed main push runs among the latest 20 (39975172638 and 39972636909), that file passes. I did not confirm that #6570 fixes this exact failure. Please update the branch and rerun. The other seven shards were cancelled in this run, so it does not show whether they pass.
  • The body does not keep the repo template as written. Please restore:
    • The "Follow the contribution scope" paragraph is gone. It sits between "Change and scope" and "Contract and boundary impact" in the template. The "Contribution scope fit" line below it is filled in.
    • The "Generated metadata" label lost its note in parentheses. The template says that CI generates the catalogs and skills/. It says to edit authored instructions in .agents/skills/reverse-engineer-anything/. It also says to never commit build outputs.
    • The label "Base reproduction or other evidence" is now just "Base reproduction".
    • Every other heading, label and checkbox is there. The added "AI-assisted" line under "Author readiness" is fine by me.

Worth a look

  • The stamp is taken before the command is sent, not after the reply (lines 399 to 403). That is the point of the fix: an event delivered before the reply stays inside the window. It also means a section can claim coverage a few milliseconds before the domain is on. The new doc sentence says "begins enabling", so it matches. In issue #6232, the ask was for the time "when observation becomes available". That is a little different. I think dispatch time is a fair choice. A maintainer may want it said in the body.
  • Nothing in src reads coverage_started_at except the producer and the schema (grep at the head sha), so no consumer sees a changed value.
  • CdpPageCapture.ts line 88 still says "Observation starts when REA attaches". It is true for the capture as a whole. With this change the two sections start later than that. Not new, but the limitation text and the section stamps now say different things.
  • The test blocks the whole process for 25 ms three times with Atomics.wait (line 28). The fake's commandResult hook is synchronous (fakeCdpBrowser.ts line 231), so a timer would not work there. No other test on main uses Atomics.wait (grep of tests and src). It reads as deliberate and I did not run it.

Looks good

  • Main (ecd997e) still has the bug: startedAt at line 98 is reused for network and console coverage.
  • Small and focused: 3 files, 115 changed lines (compare API). It changes one producer, and the docs line that describes it.
  • The test gives each of the three enable calls its own 25 ms barrier. That answers the Greptile thread. The thread is about late timestamps passing. The head test waits 25 ms in the fake for Page.enable, Runtime.enable and Network.enable alike. The body also shows a mutation that stamps after the reply and fails the test.
  • The test sends Network.enable events before its reply and checks the request is kept. That is the exact case in the issue.
  • The body is open about the gap: no real browser, only the loopback fake.
  • baron already reviewed this head as a comment and held approval until CI finishes. I have not repeated that.
  • No other open PR targets #6232 (search on the number found only this one), so there is no overlap to compare.

Not run

  • No checkout, no build, no tests, no formatter.
  • I did not run the test or the mutation in the body, and did not start a browser.

Thanks, sachinkr7368, for the fix, the three-barrier test, and the plain "no real browser" note. Thanks, coygeek, for the clear report in #6232.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.11
  • Head / base: 5abcff3 / c8ed328 (merge base); main was ecd997e

🤖 Written with Claude Code (Sonnet 5.5, verified by Opus 5.5), posted with my OK 🦊

@sachinkr7368

Copy link
Copy Markdown
Author

Closing this as already fixed upstream. Issue #6232 was closed on 2026-10-24, and ba781330d (fix(browser): separate domain readiness and worker attribution coverage) now derives coverage_started_at per domain from the first observed domain event or the successful enable acknowledgment, preserving pre-reply events. That supersedes this branch's dispatch-time timestamps. Thanks for the review so far — no further action needed here.

@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Page inspection reports network and console coverage before CDP domains are enabled

4 participants