Skip to content

fix(javascript): keep unselected sources out of cancellation failures - #1975

Closed
kaoru0822-kitauji wants to merge 1 commit into
mainfrom
fix/issue-1968
Closed

kaoru0822-kitauji wants to merge 1 commit into
mainfrom
fix/issue-1968

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Fixes #1968

Behavior

With source_paths, analyzeAndAdoptJavaScriptArtifactFiles checked cancellation before it recognized an outside-analysis-scope file. If cancellation arrived after the last selected source finished, the next unselected file was recorded as a cancelled analysis_failure. The completion loop then skipped that file as already analyzed. Every unselected file now stays classified as outside the caller-selected source_paths, and the cancellation is still returned as the interruption. Found by Codex on #1944.

Related cleanup

The worker loop, its interruption handler, and the completion loop now share one recordOutsideSelection owner. Before, the loop and the completion loop each had their own copy of the classification, and the handler had none.

Still separate: analyzeArtifactFileSteps, the in-process step path, has its own out-of-scope check. It has no semantic projection to record into, so it only appends the file.

Validation

  • New boundary test tests/boundary/filesystem/javascript-applications/javascriptSelectedSourceCancellation.test.ts uses the real selection fixture and the real worker, and aborts right after the selected source returns. It fails on main (one unselected file carries a cancelled analysis_failure) and passes here.
  • The 229 tests in the selection, application service, source-selection CLI, and src/application/javascript suites pass.
  • npm run lint, npm run typecheck, npm run format:check: pass.
  • npm test: 8,408 passed, 16 failed. Twelve are this Mac's usual environmental failures (ibtool, hdiutil, JS runtime paths under /private/var). The other four fail identically on clean main 1d4c4eb03 and are unrelated to this change:
    • src/browser/CdpCaptureEvents.redirectBodyShape.test.ts: already captured response shape
    • tests/boundary/filesystem/qwenClientConfiguration.test.ts (×2): { ok: true, value: "installed" } vs "installed"
    • tests/boundary/providers/native/nativeProvider.test.ts: otool output is missing the Mach header

🤖 Generated with Claude Code

With source_paths, the analysis loop checked cancellation before it
recognized an outside-analysis-scope file. Cancellation arriving after the
last selected source therefore recorded the next unselected file as a
cancelled analysis failure, and the completion loop skipped it as already
analyzed.

Give out-of-selection classification one owner, used by the loop, the
interruption handler and the completion loop. The cancellation is still
reported as the interruption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T21:51:27.300282Z 8a8efb8 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.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Linux. On 1d4c4eb (#1962), a cancel after the last chosen source marks one unchosen file as cancelled. On 8a8efb8, no unchosen file is marked, and the cancel is still reported.

Results

Each row says which commit it ran on. "Base" is 1d4c4eb (#1962), the commit this PR branched from.

Check Node 22 Node 24 Node 26
New test file on base 1d4c4eb fails fails fails
New test file on head 8a8efb8 passes passes passes
Four related suites on head, 231 tests passes passes passes
Four related suites on base, 230 tests (no new test) not run passes not run
Built-code repro, late cancel, base not run 1 of 5 unchosen files marked cancelled not run
Built-code repro, late cancel, head not run 0 of 5 marked not run
Service path, late cancel, base not run cancel text in the result for broken.json not run
Service path, late cancel, head not run result identical to a run with no cancel not run
CLI, no cancel, base vs head not run byte-identical output not run
Cancel before the first source, base and head not run same on both: main.mjs cancelled, 0 unchosen marked not run
typecheck, format check, oxlint on head not run pass not run

The key result: on base, the file wrongly marked is broken.json. It carries an analysis failure with the code "cancelled", and the other four unchosen files are fine. On head, all five stay outside the selection and the run still reports the cancel. The partial result on head is byte-identical to a run with no cancel (same sha256).

How I cancelled: the real command line has no way to hit this. The gap is one event-loop tick wide, and no progress event falls inside it. So I injected the cancel two ways. In the built-code repro, the cancel fires right after the worker returns the chosen file. In the service-path run, the abort flag turns true when the analysis loop reads it for the second file. Both use the real worker, the real inventory scan and the fixture from the PR.

The PR body says 229 tests in the four suites. I count 231 on head: 230 existing plus the 1 new test. I don't know why the counts differ.

Not run

  • Cancelling the real CLI or MCP server with a signal. The gap is too short to hit on purpose.
  • verify:module-boundaries, the second half of npm run lint. It needs a git checkout, and I tested a plain source copy. oxlint itself passed. It gave 790 warnings on both base and head.
  • The full npm test suite, and macOS.
  • Main has moved on to 55b6148 since this PR branched. I tested the PR as it stands, not merged into the newer main.

Thanks, Kaoru0822, for the fix.

Commands
# sources, from a read-only mirror
git -C ~/code/rea-mirror/rea.git archive 8a8efb822677327070ef36fa187f00eafc9d0ef6 | tar -x -C /tmp/p1975/head
git -C ~/code/rea-mirror/rea.git archive 1d4c4eb0308b4cb5761a91533edeb33fcfb442f2 | tar -x -C /tmp/p1975/base

# in each tree (Node 24 first on PATH)
npm ci && npm run build && npm run test:prepare

# the PR's new test, on base and head, Node 22 / 24 / 26
npx vitest run tests/boundary/filesystem/javascript-applications/javascriptSelectedSourceCancellation.test.ts

# four related suites plus the new test, on head
npx vitest run tests/boundary/mcp/javascriptSourceSelection.test.ts \
  tests/boundary/filesystem/javascript-applications/javascriptApplicationService.test.ts \
  tests/acceptance/applications/javascriptSourceSelectionCli.test.ts \
  src/application/javascript \
  tests/boundary/filesystem/javascript-applications/javascriptSelectedSourceCancellation.test.ts

# CLI control, no cancel
node scripts/rea.mjs analyze /tmp/p1975/fixture --source-path main.mjs --format json

# built-code repro (modes: late, none, early) and service path (modes: late, none)
node dist-repro.mjs <tree> late /tmp/p1975/fixture
node service-dump.mjs <tree> late /tmp/p1975/fixture <out.json>

# checks on head
npm run typecheck ; npm run format:check ; node_modules/.bin/oxlint
Test setup

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

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator Author

Superseded by 7285e15 on main, which consolidates source-scope classification so cancellation can't mark unselected files as failed, and adds coverage in javascriptApplicationService.test.ts. This PR's boundary repro (javascriptSelectedSourceCancellation.test.ts, real worker, abort right after the selected source returns) passes unchanged on main 7285e1583, so nothing here is still needed. Closing.

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks, @kaoru0822-kitauji, for the late-cancellation repro showing an unselected source could be mislabeled as failed. Main now keeps cancellation outcomes within the selected source set (main).

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.

Cancellation after the last selected JavaScript source misreports the next unselected file as cancelled

3 participants