Skip to content

fix(cleanup): restore shared ownership across browser, capture, and adb boundaries - #4345

Closed
SoufianoDev wants to merge 2 commits into
morluto:mainfrom
SoufianoDev:fix/shared-cleanup-ownership
Closed

SoufianoDev wants to merge 2 commits into
morluto:mainfrom
SoufianoDev:fix/shared-cleanup-ownership

Conversation

@SoufianoDev

Copy link
Copy Markdown

Fixes the 7 CI failures on main (run 38833320851), all regressed in the 93c620c/3b698645a batch, not in the adb hash-cleanup commits.

Observable outcome: the 7 failing tests pass locally (plus the contradicted serverLifecycle neighbor).

Approach:

  • finishAnalysisCommand no longer resolves unrelated cleanup on service close; only the owning release may resolve.
  • Playwright provider and capture service keep step-level cancellation as the terminal representation instead of re-projecting to a top-level Cancelled error.
  • Shared MCP observation providers are caller-owned via a new createServer flag, so discarded SDK probes no longer kill peers; direct createServer use keeps server-close.
  • adb reinstall assertion tracks the staged snapshot path instead of the caller tmpdir.

Evidence (actually ran): targeted suites green (Playwright provider 20/20, capture/signal/adbCli/probeLifecycle, SIGINT+SIGTERM acceptance, serverLifecycleMcp, finishAnalysisCommand, capture service), plus build, typecheck, and lint. Full 7-shard CI not run.

Author readiness left for the human owner.

…db boundaries

Own shared MCP observation providers in the transport instead of closing
them per server, keep step-level cancellation as the terminal scenario
representation, and stop resolving unrelated cleanup on service close.
Relax the adb reinstall assertion to the staged snapshot path.

Verified the 7 previously failing tests plus serverLifecycle, build,
typecheck, and lint locally.
@SoufianoDev
SoufianoDev marked this pull request as ready for review October 16, 2026 02:43
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-16T03:04:01.078322Z 34468b1 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 Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; the shared-provider cleanup gap is fixed.

Summary

This PR restores shared cleanup ownership and preserves step-level cancellation results.

  • Shared MCP providers stay open until transport shutdown.
  • Cancelled browser steps stay in the scenario evidence.
  • CLI shutdown leaves cleanup status with its owning release.
  • The adb install test accepts staged APK paths.

Review used source inspection; tests were not run. Whether another PR supersedes this one could not be checked because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Transport["MCP transport"] --> Shared["Three shared observation providers"]
  Transport --> Probe["Discovery probe server"]
  Transport --> Replacement["Replacement server"]
  Probe --> ProbeClose["Close server-owned resources only"]
  Replacement --> ServerClose["Close server-owned resources only"]
  Shutdown["Process shutdown"] --> SharedClose["Close all shared providers"]
  SharedClose --> Success["Remove successful closes"]
  SharedClose --> Failure["Retain failed closes for retry"]
Loading

Reviews (2) · Last reviewed commit: "fix(mcp): close all shared observation p..." · Reviewed by Greptile

Comment thread src/main/transport.ts Resolved

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

ℹ️ 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 src/main/transport.ts
environment: serverContext.environment,
delivery: serverContext.delivery,
...optionalProviders,
optionalObservationProviderOwner: "caller",

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 Close every caller-owned optional provider at shutdown

In the stdio MCP path, optionalProviders can include shared browserObservation and electronObservation instances, and setting this owner makes every SDK-created server skip their close() calls, while startMcpTransport.closeOptionalProviders closes only browserScenarioCapture. After either CDP provider retains a WebSocket whose operation-level close failed, process shutdown therefore never invokes its CdpTargetSessionOwner.close(), so the transport can remain live and shutdown can report success without retrying it; include both transferred CDP providers in the caller-owned cleanup path.

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

Useful? React with 👍 / 👎.

@@ -35,8 +35,6 @@ export const finishAnalysisCommand = async <
}
try {
await service.close();

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 Resolve CDP cleanup before projecting the original error

For one-shot browser, Electron, or web-runtime CLI commands, if CdpTargetSessionOwner.finish() reports a socket cleanup failure and the subsequent service.close() retry succeeds, this function now projects the original error unchanged. CdpTargetSessionOwner.#closeAll() removes the retained connection but does not resolve, or retain a link to, the returned ProviderCleanupError or wrapper, so callers still receive cleanup_incomplete and recovery instructions for an already released resource; migrate that resolution to the exact owner before removing this fallback.

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

Useful? React with 👍 / 👎.

Caller-owned browserObservation and electronObservation previously
received no final close once servers stopped closing them. The
transport now closes all three shared providers with retry for
failures, keeping successful closes settled.
@SoufianoDev

Copy link
Copy Markdown
Author

@morluto

@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: 34468b12f9

ℹ️ 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 +328 to +330
if (
options.signal?.aborted === true &&
steps.every((step) => step.status === "completed")

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 cleanup-time cancellation after failed steps

When an action has already produced a failed step and the abort arrives while session.close() is pending, steps.every(...) is false, so this new guard skips the cancellation error; captureBrowserScenario's new non-completed-step fast path then returns successful Evidence. That makes final-cleanup cancellation disappear from MCP results (and emits ordinary Evidence from the CLI despite its interrupt exit code), whereas the same abort after completed steps is retained as an AnalysisCancelledError; distinguish request-cancelled steps from pre-existing failures before bypassing the late-cancellation projection.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix! All four parts of this change have already landed on main: src/cli/finishAnalysisCommand.ts now delegates finalization to runOwned (#10645 / #14071), src/browser/PlaywrightBrowserScenarioProvider.ts and src/application/BrowserScenarioCaptureService.ts preserve step-level non-completed status, src/main/transport.ts uses optionalProvidersToClose with optionalObservationProviderOwner: "caller", and the adb staged-path test landed in ffeba6aae0 (#4354). Closing as already landed.

@morluto morluto closed this Nov 24, 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.

2 participants