Skip to content

fix(browser): report cancellation after cleanup and source-map abort - #2893

Merged
kaoru0822-kitauji merged 12 commits into
mainfrom
cursor/browser-cancellation-after-cleanup-1ffc
Oct 16, 2026
Merged

kaoru0822-kitauji merged 12 commits into
mainfrom
cursor/browser-cancellation-after-cleanup-1ffc

Conversation

@morluto

@morluto morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Summary

An interrupt that arrives while a CDP session is closing could still publish the captured page, session, WebMCP discovery, or screenshot. An interrupt during an approved source-map download was reported as a provider failure instead of cancellation. Both now return AnalysisCancelledError for the operation the caller requested.

This branch also includes the current main typecheck and lint repairs from the companion check-restoration change, so this pull request can pass check:fast on its own.

Problem and expected behavior

inspect-web-page, bundle analysis, session observation, WebMCP discovery, and screenshot capture await closeCdpTargetSession after the result is already built. Cleanup notices an aborted signal and closes the socket, then the caller publishes success.

fetchWebSourceMaps throws the abort reason. That reason is a DOMException named AbortError, so CdpBrowserProvider wrapped it as ProviderAdapterError and the CLI reported execution_failure while still exiting 130 or 143.

After this change, an abort during cleanup or during a source-map download returns AnalysisCancelledError for inspect_web_page, analyze_web_bundle, observe_web_session, discover_webmcp_tools, or capture_web_screenshot.

Change and scope

The browser provider owns this classification. After cleanup, an aborted caller signal replaces a result that was already built. providerError maps an AbortError to AnalysisCancelledError before it can become a provider-adapter failure. Deadline failures stay SourceMapDeadlineError and are not treated as caller cancellation.

Contribution scope fit: ordinary fix inside the existing passive CDP provider. Maintainer scope decision: not applicable. This does not add target execution, injection, or mutation.

Contract and boundary impact

  • Semantic owner and earliest changed stage: CdpBrowserProvider after session cleanup and at provider error classification.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: cancelled operations stay AnalysisCancelledError. No new tool or argument.
  • Provider, bridge, target-format, or platform compatibility: passive CDP only. The fake browser can leave a source-map response open so the regression does not depend on a timer.
  • Evidence, artifact, provenance, or reconstruction contract: a cancelled operation does not publish the page or bundle that cleanup interrupted.
  • Target selection, authority, upstream behavior, and cleanup details: cleanup still runs. The published result is cancellation when the caller signal aborted during that cleanup.
  • Generated metadata: 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.

The network contact is the existing approved source-map fetch. Cancellation stops that fetch.

Evidence and regression coverage

  • Tests added or updated: lifecycle coverage for an interrupt during page cleanup, session cleanup, and a hung source-map download.
  • Base reproduction: on the previous provider, aborting during Network.disable or during the source-map response still produced a successful result or ProviderAdapterError.
  • User-visible CLI/MCP output: callers that already map AnalysisCancelledError to code: "cancelled" now do so for these two windows. The CLI signal wrapper in fix(cli): honor SIGINT/SIGTERM in browser and JS-runtime commands #2879 is unchanged here.
  • Remaining proof gaps: real-browser interruption was not run. The fake CDP socket and HTTP server cover the same provider boundaries.

Validation performed

  • npm run test:focused -- tests/boundary/browser/cdpBrowserProvider.lifecycle_failures.test.ts — 14 passed.
  • npm run check:fast — typecheck and lint passed.

Compatibility, safety, and release

No breaking contract change. Operations that previously returned success after an interrupt during cleanup now return cancellation. That matches the signal the caller already raised.

Open in Web Open in Cursor 

An interrupt during CDP cleanup could still publish the captured page, and a source-map download abort was wrapped as a provider failure. Both now return AnalysisCancelledError for the requested operation.
The empty DSH_HOME fix also changed Devin's declared format to "devin", which is not a configuration format and stops the typecheck. Devin still writes mcp_config.json.
The added interrupt cases made the existing lifecycle suite exceed the function-length lint limit.
The inventory MCP test imported join twice, which fails lint on current main.
noUncheckedIndexedAccess treats the unlabeled pair list as an open array, so the directory passed to join was string or undefined.
@morluto
morluto marked this pull request as ready for review October 13, 2026 16:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-10-16T09:41:53.489666Z c245b32 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.

@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: 82bcf0814d

ℹ️ 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 src/browser/CdpBrowserProvider.ts Outdated
Comment on lines +470 to +471
: isAbortError(cause)
? new AnalysisCancelledError(operation, { cause })

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 Use the signal state to classify source-map cancellation

When a caller cancels source-map fetching with a custom reason, such as controller.abort(new Error("cancelled")), fetchWebSourceMaps rethrows that reason verbatim, so this name-based check fails and wraps the cancellation in ProviderAdapterError. AbortSignal.reason may be any value, not only the default AbortError; therefore SDK/MCP callers using custom reasons still receive execution_failure instead of the intended tagged cancellation. Pass the signal into this classification or check options.signal.aborted in analyzeBundle's catch path.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The current test-only changes appear safe to merge.

Summary

The current PR diff adds tests and fixture support. The production cancellation changes are already in the target branch.

  • Browser tests now cover interrupts during CDP cleanup.
  • Bundle tests now cover interrupts during source-map downloads.
  • MCP tests keep the same checks with updated syntax.

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

Comment thread src/browser/CdpBrowserProvider.ts Resolved
# Conflicts:
#	src/browser/CdpBrowserProvider.ts
#	tests/boundary/cli/clientProfileLifecycle.test.ts

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

ℹ️ 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 src/browser/CdpBrowserProvider.ts Outdated
Comment on lines +343 to +344
if (options.signal?.aborted === true)
throw new AnalysisCancelledError(operation);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the existing cleanup-cancellation regression

When the full boundary suite runs, the unchanged tests/boundary/browser/cdpCleanupCancellation.test.ts case “releases cleanup when cancellation arrives after capture completes” still aborts during Page.disable and asserts result.ok is true. This new post-cleanup throw deterministically turns that same call into an error result, so npm run check:pr will fail even though the newly added focused tests pass. Update that regression to expect cancellation while retaining its detach and socket-cleanup assertions.

AGENTS.md reference: AGENTS.md:L77-L77

Useful? React with 👍 / 👎.

@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: 49ada44d9b

ℹ️ 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 src/browser/CdpBrowserProvider.ts Outdated
Comment on lines +345 to +346
if (options.signal?.aborted === true)
throw new AnalysisCancelledError(operation);

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 Preserve work failures when cleanup is cancelled

When the work callback has already thrown—for example, because the target changed or CDP returned a protocol error—and the caller aborts while a *.disable cleanup command is pending, throwing from this finally block replaces that pending error under JavaScript semantics. The result reports only cancellation and discards the actual operation failure; retain the primary error, at least as the cancellation cause, rather than unconditionally replacing it.

AGENTS.md reference: AGENTS.md:L29-L29

Useful? React with 👍 / 👎.

@morluto morluto added area: runtime Process capture and runtime observation bug Something isn't working labels Oct 14, 2026
@kaoru0822-kitauji kaoru0822-kitauji added the ci-fix-wip Claimed by the CI-fix track label Oct 14, 2026
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

CI-fix track: this conflicts with main's newer design, so it needs your call. I didn't push anything.

  • `analyze_web_bundle` abort: main's `providerError(cause, operation, signal)` (f690571) already maps untyped failures under an aborted signal to `AnalysisCancelledError` and keeps typed `AnalysisError`s unchanged. That covers this part.
  • Cleanup-time cancellation: this PR throws `AnalysisCancelledError` from `withTargetSession`'s `finally`, and its tests (4 in `cdpBrowserProvider.lifecycle_failures`, plus `cdpCleanupCancellation`) expect the provider to report cancellation. Main instead returns the provider result and reports cancellation in `BrowserObservationService` (`result.ok && options.signal?.aborted`). Main's `cdpCleanupCancellation` asserts `result.ok` at the provider. With main's provider, those 5 tests fail. Taking the `finally` throw would also replace a genuine provider failure with cancellation.

If you keep the service-layer design, this PR is superseded except possibly for its fixture additions. If you want provider-level cancellation, main's service checks and `cdpCleanupCancellation` expectation would change instead. The failing Static checks and `productCatalog` jobs on this PR came from main's state at the time.

@kaoru0822-kitauji kaoru0822-kitauji removed the ci-fix-wip Claimed by the CI-fix track label Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Complete owned teardown before deciding whether a successful observation can be published. Classify an exactly propagated source-map abort reason as cancellation while preserving unrelated failures.

Validation: all four cleanup/cancellation boundary tests pass, retaining detach, socket and target-liveness assertions. Based on #2893.
@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main covers this in its own way in ad9e22d. The code is in src/browser/CdpBrowserProvider.ts. The test releases cleanup when cancellation arrives after capture completes shows it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

# Conflicts:
#	src/browser/CdpBrowserProvider.ts
@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Conflict-sweep note: merged latest main. main now preserves cancellation both in the source-map catch (only when the cause is the abort reason) and after withTargetSession cleanup (with the abort cause), so I kept main's version of those lines and removed this PR's duplicate check inside the finally (TypeScript rejected it as an impossible comparison after main's narrowing). Your new lifecycle tests and fixtures are kept; I split the first describe in cdpBrowserProvider.lifecycle_failures.test.ts to satisfy max-lines-per-function (150). Both browser test files pass (22 tests).

@kaoru0822-kitauji
kaoru0822-kitauji merged commit b25d351 into main Oct 16, 2026
33 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the cursor/browser-cancellation-after-cleanup-1ffc branch October 16, 2026 10:10
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.

4 participants