Repository navigation
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
52a462c to
168d12e
Compare
ca8150d to
0e2831b
Compare
0fa72c3 to
e80bdb0
Compare
e80bdb0 to
e4b07b8
Compare
|
TL;DR: The fix works on Linux. An interrupted command now exits 130 or 143 and prints a cancelled result. Without the fix, the same interrupt kills the process and prints nothing. Head 0fa72c3 did not move while I tested. It was then rebased onto newer main twice, most recently as e4b07b8. The 14 files this PR changes are the same, byte for byte, so these results still apply. Results
Before means the head tree with six source files put back to their 93e29d2 (#2768) version. The PR's tests stay. The first file also skips 16 Windows-only cases. By handI ran the compiled CLI against a loopback server that never answers. Then I sent one signal to the CLI's PID.
On head, stdout held the cancelled result and stderr stayed empty. The CLI exited about 30 ms after the signal. Its process group held only the CLI, and nothing was left after exit. NotesThe description says no app or provider code changed. The later commits changed both. PR #2893 also edits Not run
Thanks, DeryFerd, for the fix and for the quick follow-up commits. CommandsNode 24 was first on PATH unless noted. On head, I also sent two signals back to back. The first one set the exit code. SIGINT first gave 130, and SIGTERM first gave 143. On the Before tree, the acceptance failures read Driver script// Usage: node signal-driver.mjs <tree> <command> <signal[,signal2]> [extra CLI args...]
// Starts a loopback HTTP server that accepts and never answers, starts the compiled CLI
// from <tree>/scripts/rea.mjs in its own process group, waits until the CLI has contacted
// the server, sends the signal(s) to the recorded child PID, and prints one JSON report.
import { spawn, execFileSync } from "node:child_process";
import { once } from "node:events";
import { createServer } from "node:http";
const [tree, command, signalArg, ...extra] = process.argv.slice(2);
const signals = signalArg.split(",");
const sockets = new Set();
const server = createServer(() => undefined);
server.on("connection", (socket) => {
sockets.add(socket);
socket.once("close", () => sockets.delete(socket));
});
server.listen(0, "127.0.0.1");
await once(server, "listening");
const port = server.address().port;
const contacted = once(server, "request");
const groupMembers = (pgid) =>
execFileSync("ps", ["-eo", "pid,ppid,pgid,stat,args", "--no-headers"], {
encoding: "utf8",
})
.split("\n")
.map((line) => line.trim())
.filter((line) => line.length > 0)
.map((line) => {
const [pid, ppid, group, stat, ...args] = line.split(/\s+/);
return { pid: Number(pid), ppid: Number(ppid), pgid: Number(group), stat, args: args.join(" ") };
})
.filter((row) => row.pgid === pgid);
const child = spawn(
process.execPath,
[tree + "/scripts/rea.mjs", command, "http://127.0.0.1:" + port, ...extra, "--json"],
{
cwd: "/tmp/pr2879/tmp",
detached: true,
stdio: ["ignore", "pipe", "pipe"],
env: {
...process.env,
HOPPER_LAUNCHER_PATH: "/rea-unconfigured-provider/hopper",
},
},
);
const pid = child.pid;
let stdout = "";
let stderr = "";
child.stdout.setEncoding("utf8");
child.stderr.setEncoding("utf8");
child.stdout.on("data", (chunk) => (stdout += chunk));
child.stderr.on("data", (chunk) => (stderr += chunk));
const closed = once(child, "close");
let hung = false;
const hardStop = setTimeout(() => {
hung = true;
try {
process.kill(pid, "SIGKILL");
} catch {}
}, 20000);
await Promise.race([
contacted,
new Promise((_, reject) =>
setTimeout(() => reject(new Error("CLI did not contact the server")), 8000),
),
]);
const before = groupMembers(pid);
const sent = [];
const t0 = Date.now();
process.kill(pid, signals[0]);
sent.push(signals[0]);
if (signals[1] !== undefined) {
const gapMs = Number(process.env.SIGNAL_GAP_MS ?? 30);
if (gapMs > 0) await new Promise((resolve) => setTimeout(resolve, gapMs));
try {
process.kill(pid, signals[1]);
sent.push(signals[1]);
} catch (error) {
sent.push(signals[1] + " (failed: " + error.code + ")");
}
}
const [exitCode, signalCode] = await closed;
const elapsedMs = Date.now() - t0;
clearTimeout(hardStop);
await new Promise((resolve) => setTimeout(resolve, 300));
const after = groupMembers(pid);
let pidAlive = true;
try {
process.kill(pid, 0);
} catch {
pidAlive = false;
}
const serverSocketsOpen = sockets.size;
for (const socket of sockets) socket.destroy();
await new Promise((resolve) => server.close(() => resolve()));
console.log(
JSON.stringify(
{
tree,
command,
extra,
pid,
sent,
exitCode,
signalCode,
elapsedMs,
hung,
groupBeforeSignal: before.map((row) => ({ pid: row.pid, ppid: row.ppid, args: row.args.slice(0, 120) })),
groupAfterExit: after.map((row) => ({ pid: row.pid, ppid: row.ppid, stat: row.stat, args: row.args.slice(0, 120) })),
pidAliveAfterExit: pidAlive,
serverSocketsStillOpenAtExit: serverSocketsOpen,
stdout,
stderr,
},
null,
2,
),
);Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
… JS-runtime commands
The passive browser and V8 Inspector CLI command groups invoked their
services without an AbortSignal, so Ctrl-C did not cancel an in-flight
observation the way it does everywhere else in the CLI. Every other command
family either wraps its handler in withCommandCancellation or reaches
withProcessCancellation inside runDirectAnalysis; these two groups did
neither. Wrap each network-touching handler in
withCommandCancellation((signal) => logCliCommand(...)) and thread { signal }
into the service call. The service layer already accepts options:
ExecutionOptions and the providers already forward options.signal into CDP
discovery, so this is adapter parity with the MCP side, which already passes
context.mcpReq.signal. The pure compare-web-captures / compare-web-screenshots
commands stay unwrapped because they touch no provider.
Once the signal reaches the provider, three more windows could still misreport
an interrupt. `fetchWebSourceMaps` throws the caller's abort reason, which is
not an `AnalysisError`, so `providerError` wrapped it in `ProviderAdapterError`
and `analyze-web-bundle --fetch-source-maps` printed `execution_failure` even
though the command exited 130/143. `providerError` now receives the caller
signal and classifies a non-analysis cause raised under an aborted signal as
`AnalysisCancelledError`; deadline aborts still map to
`SourceMapDeadlineError` and are not misreported as cancellation. An interrupt
that lands while the provider awaits `closeCdpTargetSession` arrives after the
capture has already succeeded: the provider owns its transport and
legitimately reports the completed capture, but the application boundary was
still publishing it as evidence. `BrowserObservationService` now rechecks the
caller signal before publishing and returns `AnalysisCancelledError` for the
operation, matching the existing `WebRuntimeService.evidence()` pattern. The
same gap existed for `list-javascript-runtime-targets`, whose sibling
`observeJavaScriptRuntime` already rechecked the signal while
`listJavaScriptRuntimeTargets` did not; it now rechecks before creating
evidence, since `V8InspectorProvider.listTargets` awaits file authorization
without consulting the signal.
Adds tests/acceptance/passiveObservationCliCancellation.test.ts, which spawns
the real CLI against a stalled loopback socket and interrupts it. On POSIX it
delivers a real OS signal; on Windows it relays an in-process SIGINT/SIGTERM
through a --import hook, because child.kill(signal) force-terminates on
Windows instead of running the handler. All eight commands x {SIGINT, SIGTERM}
now assert terminationSignal === null, exit 130/143, and a
{ code: "cancelled", details: { cleanup: "complete", operation } } envelope.
Adds a `hangOnSourceMap` fixture seam, provider coverage for an interrupted
source-map download, application-boundary coverage for all five browser
commands whose cleanup can outlast an interrupt, and a service test for a
listing abort that lands during file authorization.
Co-Authored-By: Claude Code <noreply@anthropic.com>
e4b07b8 to
b23dd48
Compare
Own service-worker CDP registrations and retry failed teardown. Admit redaction and network metadata against remaining capture capacity, retain explicit omission reasons, and preserve source URL, redirect ancestry, caller-selected content, and historical capture values. Forward CLI cancellation through provider cleanup. Reviewed fixes: #2263, #2637, #2767, #2845, #2859, #2863, #2872, #2874, #2876, #2879, #2955, #2957, #2961, #3033. Validation: 25 current event/network source tests passed; earlier focused browser lanes passed 201 source tests and 176 boundary tests with two skips, plus 35 Python tests. Real browser/Windows lanes were not rerun. Playwright allocation before admission remains unbounded by these retention limits.
Main (f690571) already reports caller cancellation after a provider returns in BrowserObservationService and JavaScriptRuntimeObservationService, and forwards CLI signals. Keep main's versions of those services and of CdpBrowserProvider: the service layer owns the post-result cancellation check, while a provider-level throw from `finally` would replace genuine provider failures with cancellation. Keep this PR's CLI/service cancellation coverage, including the file-check abort case for runtime targets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CI-fix track: the shard 4 and Portable failure ( |
|
Thanks — the robustness point is worth pinning, and I checked the current state. At this head the provider does not throw after cleanup: merging main reverted the post-cleanup throw that an earlier commit on the branch had added, so CdpBrowserProvider returns the completed result and these five cases do exercise the |
|
Heads up: main covers this in its own way in f690571. The code is in 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
@CassieFox23 Thanks for the roundup, and for confirming main carries it. To your question: there is still a little here that main doesn't have, and it is all test-side. The one piece worth keeping is the stub-based service case in
The rest overlaps main and can go if you want a smaller diff. I left all of it in place because the merge kept it, but I'm happy to trim this down to the two unique pieces, or to close it and hand the stub case to main separately, whichever is easier for you. |
Summary
rea's passive browser commands and V8 Inspector commands do not honorSIGINTorSIGTERM. When you interrupt one of them, the process either dies without running any awaited cleanup or reports an ordinary operation failure instead of a cancellation, so a caller watching the process status cannot tell "I interrupted this" from "this broke". This PR wires the eight affected CLI commands through the same cancellation boundary the rest of the CLI already uses, so an interrupt aborts the in-flight observation, waits for cleanup, and exits with the conventional130(SIGINT) or143(SIGTERM) status while printing the typedcancelledresult.The MCP side already threads
context.mcpReq.signalinto these same services, and the services already accept anExecutionOptionssignal. Only the CLI adapter was missing the boundary, which makes this a one-layer fix rather than a contract change. The sibling web-runtime commands (observe-web-execution,inspect-web-event-listeners) already received this exact treatment for the same defect (issue #1126, commit1d9b96a9c); this PR applies the established pattern to the browser and JavaScript-runtime commands that were left behind.Problem and expected behavior
Smallest trigger: run any of these commands against a loopback endpoint that accepts the discovery connection but never answers, then send
SIGINTorSIGTERMonce the command has parked in discovery.Violated invariant: a one-shot CLI command that receives an interrupt should abort its awaited work, run cleanup, and exit with the signal's conventional status and a typed cancellation result, matching every other cancellable command in the CLI. Before this change these eight commands registered their handlers directly, so the interrupt reached the process without any listener that aborts the observation. The command then either terminated abruptly or, once the stalled discovery finally failed on its own, reported a provider failure and exited
1.Expected behavior after the change: the interrupt aborts the pending CDP/Inspector work, the command resolves a
cancelledresult withcleanup: "complete", and the process exits130forSIGINTand143forSIGTERM. Two of the browser commands,compare-web-capturesandcompare-web-screenshots, are pure comparisons with no provider or socket work, so they are correctly left unwrapped.Change and scope
The change is narrow and follows an existing pattern instead of inventing a new one. Each affected handler is wrapped in
withCommandCancellation((signal) => logCliCommand(...))and passes{ signal }into the service call it already makes.withCommandCancellationinstallsSIGINT/SIGTERMlisteners that abort anAbortController, records130/143, and removes the listeners in afinallyblock that also setsprocess.exitCode. The aborted signal travels through the existingExecutionOptionsplumbing intodiscoverCdpEndpointandreadCdpJson, which already translate an aborted signal intoAnalysisCancelledError, andlogCliCommandalready projects that into the typedcancelledresult. Nothing in the domain, application, or provider layers needed to change, because the only broken stage was the CLI adapter's missing boundary.Files changed:
src/cli/browserCommands.tswrapslist-browser-targets,inspect-web-page,analyze-web-bundle, andobserve-web-session.src/cli/browserAdvancedCommands.tswrapsdiscover-webmcp-toolsandcapture-web-screenshot.src/cliJavaScriptRuntimeCommands.tswrapslist-javascript-runtime-targetsandobserve-javascript-runtime.tests/acceptance/passiveObservationCliCancellation.test.tsandtests/fixtures/passiveObservationCancellation.mjsadd the regression coverage.Intentionally not included: no change to
withCommandCancellationitself, no change to the MCP adapters (they already passcontext.mcpReq.signal), no change to service signatures (they already acceptExecutionOptions), and no change to the pure comparison commands. The change is additive at the adapter boundary and does not expand what any command reads, launches, injects, or mutates.Follow the contribution scope. This is a routine bug fix inside existing boundaries, so no advance maintainer scope decision is required; the linked scope decision is "not applicable".
Contract and boundary impact
130/143and returns the existingcancelledresult instead of exiting1with a provider failure. MCP is untouched and already cancels throughcontext.mcpReq.signal. No generated tool catalog changes.SIGINT/SIGTERM; Windows cannot deliver a catchable signal throughchild.kill(signal), so the test exercises the same handler through an in-process relay. No CDP, Inspector, or bridge protocol change.cancelledresult withcleanup: "complete"; no artifact is published for a cancelled observation, and partial evidence semantics are unchanged.docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs andskills/; edit authored instructions in.agents/skills/reverse-engineer-anything/and never commit build outputs): None. No contract, schema, catalog, package, or installation surface changes.Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible.
The two checked items describe the commands' existing passive behavior: they read page and runtime evidence and connect to a caller-supplied loopback CDP/Inspector endpoint. This PR changes none of those effects; it only adds awaited cleanup when the caller interrupts.
Evidence and regression coverage
tests/acceptance/passiveObservationCliCancellation.test.tsdrives all eight commands through a realreaprocess against a stalled loopback server, and asserts that the process exits130/143, that it was not force-terminated, and that stdout carries thecancelledresult withcleanup: "complete"and the matchingoperation. It runs 16 cases (eight commands acrossSIGINTandSIGTERM).tests/fixtures/passiveObservationCancellation.mjsis the relay hook that re-emits the signal in-process on Windows, where the OS cannot deliver a catchable signal to a child.terminationSignal: "SIGINT"with a null exit code) or the stalled discovery eventually fails and the command exits1with a provider failure instead of thecancelledresult. With the fix in place all 16 cases pass. The regression therefore fails on the affected base revision and passes after the change.{ "code": "cancelled", "category": "cancelled", "details": { "cleanup": "complete", "operation": "list_browser_targets" } }For evidence-bearing changes:
The middle item is left unchecked because a cancelled observation publishes no artifact, so artifact identity and provenance are not exercised by this change. The typed
cancelledresult keeps the interrupted outcome visible rather than collapsing it into a generic failure.Validation performed
npm run test:focused -- tests/acceptance/passiveObservationCliCancellation.test.ts— 16 passed, 16 skipped (the OS-signal lane is skipped on Windows; the relay lane runs). On the reverted base revision the same file reports 16 failed, 16 skipped.npm run check:fast— passed (cached typecheck and lint, plus the pre-push check).git diff --stat upstream/main...HEAD— 5 files changed, 420 insertions, 165 deletions.Compatibility, safety, and release
1to the conventional130/143, which is the fix, not a break. Command names, arguments, options, and JSON fields are unchanged.reabinary against a stalled loopback CDP/Inspector endpoint. A real browser or Electron target was not exercised; see the remaining proof gap above.finally. It does not add target selection, execution, injection, mutation, persistence, or new network behavior, and it does not weaken any existing boundary. No secrets or sensitive values are involved.Before merge
type(scope): outcome.On the issue link: no open issue tracks this exact gap. Issue #1126 covers the sibling web-runtime commands and was fixed by the same pattern, so this PR extends that fix to the browser and JavaScript-runtime commands rather than reopening a closed issue. If maintainers prefer, this can be filed as a follow-up issue first.