Skip to content

fix(browser): record the redirect answered to a request step - #8467

Closed
PranitSakhuja wants to merge 9 commits into
morluto:mainfrom
PranitSakhuja:fix/7410-redirect-request-evidence
Closed

PranitSakhuja wants to merge 9 commits into
morluto:mainfrom
PranitSakhuja:fix/7410-redirect-request-evidence

Conversation

@PranitSakhuja

@PranitSakhuja PranitSakhuja commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

A capture-browser-scenario request step that is answered with a redirect failed as intended, but its network evidence had no response event, status or Location, even with network events and header values selected. The step error and docs/browser-scenario-contract.md both promise that evidence. This records the redirect's status and Location as the request's response.

Fixes #7410

Problem and expected behavior

Smallest trigger: a GET request step to a loopback endpoint returning 302 Location: /destination, with capture.events: ["network"] and network.header_values: true.

  • Before: the transaction contains only request, network-content, request-failed (net::ERR_ABORTED). No status, no Location. A goto control to the same URL records both.
  • Expected: the redirect stays unfollowed and the step fails, but the redirect response and Location remain in the capture.

Cause (observed in a standalone probe, Chrome + Playwright 1.64.1): the request step installs a page.route guard. With interception active, Playwright emits no response event for the manually handled redirect and reports the request as failed. Without the route it emits response 302 normally. Chrome's Network.responseReceivedExtraInfo still reports status 302 and Location in both cases.

Change and scope

  • New PlaywrightScenarioRedirect.ts observes the Network domain for one request step's own dispatch (matched by URL and method) and, on a Fetch redirect status (301, 302, 303, 307, 308) with a Location header, presents it to the network collector as the withheld response. It does this when the browser reports it, so the response precedes request-failed, and the failed-request path then attaches header content as for any response. Body reads are never attempted (it rejects, and the failed path marks the body unavailable).
  • Only attached when network events are selected. If the CDP transport cannot be attached, or two identical dispatches make attribution ambiguous (including after an early answer), the step does not claim recovery and the existing opaque-redirect coverage disclosure from fix(browser): disclose opaque redirect coverage gaps #7943 still applies.
  • PlaywrightScenarioNetwork.response() now records at most one response per request, so a recovered answer and a browser-reported one cannot both be emitted.
  • The step error and contract doc now describe the recovered behavior and keep the fallback.
  • Not included: write methods and non-302 statuses are not separately tested; no change to redirect following (still never followed); no change to goto captures.

Contract and boundary impact

  • Semantic owner and earliest changed stage: request-step dispatch (PlaywrightScenarioRequest) is the producer; the network collector and event capture consume. No superseded path removed; the fix(browser): disclose opaque redirect coverage gaps #7943 disclosure is retained as the fallback.
  • Contribution scope fit and linked maintainer decision: not applicable (ordinary fix within existing browser-scenario boundaries).
  • CLI and MCP/tool-catalog contract: no schema or catalog change. Captures that previously lacked the redirect response now include it.
  • Provider, bridge, target-format, or platform compatibility: Chromium only (CDP). Tested on macOS arm64, Chrome via REA_BROWSER_EXECUTABLE.
  • Evidence, artifact, provenance, or reconstruction contract: recovered status and headers are what the browser's network service reported; they flow through the same redaction and budget admission as other responses.
  • Target selection, authority, upstream behavior, and cleanup details: the added CDP session is attach/detach bounded (2s) and detached in the step's finally; a late attach is released when it settles.
  • Generated metadata / package / installation impact: none.

Expected effects:

  • 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

All executed, not source-derived.

  • Tests added or updated: PlaywrightScenarioRedirect.test.ts (8: delivery and header shaping, either arrival order, non-redirects/foreign requests ignored, ambiguous dispatch, stop/detach, no transport, a slow attach released after the bounded wait, a claim withdrawn by a later identical dispatch, and a 300 answer left alone), a step-level test in PlaywrightScenarioRequest.test.ts (recovered redirect is delivered, no gap disclosed, session detached), a collector test for one response per request, and a mock update in PlaywrightScenarioSession.test.ts.

  • Base reproduction or other evidence (real Chrome, loopback fixture, same scenario as the issue):

    before  request: kinds [request, network-content, request-failed]            statuses []     location []
    after   request: kinds [request, network-content, response, request-failed, network-content]
                     statuses [302]   location [{name: Location, value: /destination}]   destination hits 0
    control (200 request step, after): step completed, kinds include response, statuses [200]
    

    After-run repeated 3 times with identical results.

  • User-visible CLI/MCP output: the capture-browser-scenario JSON above.

  • Remaining proof gaps: only GET + 302 in Chrome on macOS; write methods, other 3xx statuses, connect mode and other Chromium builds were not run. The new unit tests use fakes for CDP; the real-browser result comes from the manual run above, not an automated test.

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 test:local -- <all src/browser/PlaywrightScenario*.test.ts and src/browser/network/*.test.ts> — 11 files, 316 tests passed
  • npm run check:fast (typecheck, lint) — passed
  • npm run verify:test-discovery — all 2943 test files discovered once
  • Real Chrome run of the issue's scenario via the source CLI — see Evidence above
  • Not run: npm run check:pr, docs:check, any non-Chrome or non-macOS browser

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Chrome on macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the recovered headers (including Set-Cookie) pass through the existing header redaction and selection (header_values); nothing is captured when network events are not selected.

Author readiness

Human owner: @PranitSakhuja

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

A request step sends its fetch with manual redirect handling while a route
guard is installed. Chromium then reports the request to Playwright as failed
(net::ERR_ABORTED) with no response event, so the capture lost the redirect's
status and Location even though network events and header values were
selected, and the step error promised both.

The browser still reports the answer on the Network domain
(responseReceivedExtraInfo). Observe that for the step's own dispatch and
present it to the network capture as the response Playwright withheld, ahead
of the request-failed event. When the browser offers no such report, the
existing opaque-redirect coverage disclosure still applies. The collector
now records at most one response per request.

Fixes morluto#7410

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@chatgpt-codex-connector

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

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 ✅ Completed 2026-11-01T10:57:52.490785Z 3e4d0f5 Manual request
ℹ️ 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 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: 7ce5ff2abf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain from this review.

Summary

This PR records redirect responses that Playwright withholds from request-step captures. Redirects remain unfollowed, and recovered responses use the existing capture limits and redaction.

  • Request steps capture redirect responses without following them.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Attach redirect observer] --> B{Step still active?}
  B -->|No| C[Stop observer and fail step]
  B -->|Yes| D[Install route guard and send request]
  D --> E[Offer recovered redirect to network capture]
  E --> F[Fail step without following redirect]
  F --> G[Stop observer and remove route guard]
Loading

Reviews (9) · Last reviewed commit: "fix(browser): recheck the step boundary ..." · Reviewed by Greptile

Address review of morluto#8467:
- Recover only 301/302/303/307/308. Fetch returns other 3xx answers, such as
  300, as ordinary responses; a synthetic one would displace the real response
  and lose its body.
- Withdraw the delivered claim when a second identical dispatch makes
  attribution ambiguous, so the step keeps disclosing the coverage gap.
- Expand header arrays only when the capture asks for them.
- Cover the late-attach release with a controlled slow attachment.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

Measure the raw redirect header report before building the normalized map or
the repeated-value array, and decline recovery above Chromium's 256 KiB
response-header ceiling so the step discloses the gap instead. Build the
normalized map once, since the collector reads it for metadata and names.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe

@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: 4e2afcd9f2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

… honestly

Address second review of morluto#8467:
- Remove the route guard before awaiting the bounded CDP detach, so a slow
  detach cannot keep aborting matching requests or consume the step deadline.
- Stop retaining transport identities once attribution is ambiguous.
- Say the browser reported the redirect to network capture rather than that
  the capture holds it: event budgets can still omit the event or its headers.
  Document the same in the contract.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@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: 302cdb0525

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +191 to +194
await withPlaywrightExecutionBoundary(
() => session.detach(),
REDIRECT_TRANSPORT_TIMEOUT_MS,
).catch(() => undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain ownership when CDP detach is unconfirmed

When CDPSession.detach() rejects or is still pending after the two-second boundary while the target remains live, this catch makes stop() succeed and drops the only redirect-session cleanup owner. Each later request step can then add another Network-enabled session, leaving unresolved event streams until the parent browser connection closes; retain or retry the unconfirmed detach through scenario cleanup rather than swallowing it.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not changing this one, for the following reasons. Failure mode: detach() rejects or exceeds its 2s bound while the target stays live. Consequence: that one session stays Network-enabled and idle until the scenario ends; I checked that both launch and connect modes close the Playwright browser connection at scenario end (PlaywrightScenarioBrowser closeBrowser → browser.close()), which drops every CDP session, so it cannot outlive the scenario or touch the user's browser state beyond the connection. It does not hold the route, a lock, or any target state, and evidence is unaffected. Likelihood: low; detach of a live session is a single protocol call. Cost of the change: threading an AnalysisCleanupLease/retain owner through the request step, session and browser cleanup for a best-effort evidence aid. The storage CDP session uses a lease because it restores target state; this one holds none. Happy to add retention if a maintainer wants it, but I did not want to add that complexity speculatively (AGENTS.md asks for buy-in first).

A slow CDP attachment previously ran with the route guard already installed,
so matching application traffic could be aborted after the step deadline
while this step had not yet dispatched. Attach first, then install the
route, and stop the observer if the route cannot be installed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@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: e3c5974d0c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Count the entries a redirect header report would expand to while measuring its
raw size, and decline recovery above 4096 entries. A 256 KiB raw bound alone
still allowed tens of thousands of tiny repeated fields to expand into several
MB of entry objects before the capture's header budget applied.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@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: 297a648114

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…esponses once

Address review of morluto#8467:
- Read requestWillBeSent with the existing CDP facts parser and add the
  matching responseReceivedExtraInfo parser beside it, so a malformed or
  version-skewed payload declines recovery instead of throwing out of the
  event dispatcher.
- Track that a response was reported for a request independently of whether it
  was retained, so a refused first report is not omitted a second time when the
  browser's own report of the same answer follows.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@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: b0eda74c9d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread docs/browser-scenario-contract.md Resolved
The request-step redirect fallback also applies above 4,096 expanded header
entries, not only above 256 KiB.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@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: 094139f8c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

…uard

Attaching the redirect observer first adds an await before page.route. If the
step's deadline or cancellation fires during it, install no guard and stop the
observer, using the same pre-dispatch check as before the attachment.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Ecyy52XPaYusX4ko4WTbVe
@PranitSakhuja

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 3e4d0f5574

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@PranitSakhuja

Copy link
Copy Markdown
Author

Friendly ping for a maintainer look when there's time. All checks pass, the Codex and Greptile findings are addressed, and the branch is mergeable. The redirect response and Location now show up in the request step's network evidence (verified against real Chrome, 0 hits on the destination). One thread is open on purpose: I did not add retention for an unconfirmed CDP detach, because the browser connection is closed at scenario end. I'll add it if you want it. Happy to change anything else you'd like.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @PranitSakhuja, thanks for putting this together, the fix looks useful. What's left: there are 13 unresolved review threads from Codex and Greptile (7 still on current code), e.g. "Restrict synthetic responses to Fetch redirect statuses" and "Avoid calling delivered redirects retained evidence"; the 6 on outdated lines may just need resolving if they're already handled. Happy to get this in once that's sorted out.

@PranitSakhuja

Copy link
Copy Markdown
Author

Thanks for taking a look. I went through the threads: the ones that were fixed in follow-up commits (the 300 status, late ambiguity, header bounds, attach/route ordering, expiry recheck, CDP parsing, the duplicate omission, and the docs disclosure) have replies pointing at the fix, and I've now resolved them. All checks pass on the current head. One thread is left open on purpose: Codex asked to retain ownership of the CDP session when detach is unconfirmed. I did not add that, since both launch and connect modes close the browser connection at scenario end and the leftover session is idle. I'm happy to add retention if you'd prefer it, or you can resolve that thread if you agree.

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

Thanks. This now conflicts with main in src/browser/PlaywrightScenarioEvents.ts and src/browser/PlaywrightScenarioRequest.ts, which were reworked after this branch. Since then main also reports an opaque request-step redirect as a network coverage gap ("A request step received an opaque redirect; its response status and Location may be unavailable in network events."), so the remaining value here is recording the actual redirect. Could you rebase onto current main and keep that limitation for the cases this change still cannot observe?

@morluto morluto added the bug Something isn't working label Nov 23, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution! Closing this PR as the target issue (#7410) was closed as fixed by #7943 (0179d94420) in src/browser/PlaywrightScenarioRequest.ts and src/browser/PlaywrightScenarioEvents.ts.

@morluto morluto closed this Nov 24, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 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.

[Bug] Redirected request steps omit the promised Location from network evidence

3 participants