Skip to content

fix(scanner): Pass 2 dropped by Pass 1 slot race; clock-independent staging deadline test - #1648

Merged
Dumbris merged 2 commits into
mainfrom
fix/scanner-e2e-flakes
Oct 17, 2026
Merged

Dumbris merged 2 commits into
mainfrom
fix/scanner-e2e-flakes

Conversation

@Dumbris

@Dumbris Dumbris commented Oct 17, 2026

Copy link
Copy Markdown
Member

Fixes the two E2E failures on main after #1628 (#1602) that block v0.71.0.

Root causes

  1. macOS: TestServiceStartScanDeepOnRunsSourceResolutionAndPass2 (run 39002404847). Not caused by fix(scanner): bound source staging enumeration and run it under the scan timeout #1628 (Pass 2 staging/in-process path unchanged; fix(scanner): bound source staging enumeration and run it under the scan timeout #1628's own main run was green). Real production race: OnScanCompleted spawns startPass2 inside executeScan, before the deferred clearActiveJob frees the server's engine slot. When Pass 2 reaches StartScan first it is rejected with "scan already in progress", logged at Warn and dropped: no Pass 2 job is ever saved (test times out after 10s) and the resolved source dir leaked. Slow runners widen the window.
  2. Windows: TestStagedSource_ScanDeadlineCoversStaging. A 1ns context.WithTimeout is not observably expired on the coarse Windows clock, so staging of a tiny dir finished before the ctx check.

Fix

  • ErrScanInProgress sentinel; startPass2 retries (bounded 10s) while the blocking job is a Pass-1 job, releases the resolved source and saves a failed Pass 2 job if it still cannot start.
  • Staging test now uses a 20ms timeout, plus a non-skipped source file and a stall in the stagingAfterReadBatch seam past the deadline, so the following ctx check deterministically fails. Still proves staging runs under the scan deadline.
  • New regression test TestStartPass2WaitsForPass1SlotRelease (fails before: Pass 2 saved as failed with "scan already in progress").

Verification

go test -race ./internal/security/... green, -count=30 on the touched tests, GOOS=windows go vet, both golangci-lint runs (bare and --build-tags server) 0 issues. The macOS flake did not reproduce locally under CPU load; diagnosis is from code plus the deterministic regression test.

…ging-deadline test clock-independent

Pass 1's OnScanCompleted spawns Pass 2 inside executeScan, before the deferred
clearActiveJob frees the server's slot. A fast Pass 2 got "scan already in
progress" from StartScan and was silently dropped (no job saved, source
cleanup leaked). startPass2 now waits (bounded, 10s) while the blocker is a
Pass-1 job, releases the resolved source on rejection and records a failed
Pass 2 job. Fixes the macOS flake in
TestServiceStartScanDeepOnRunsSourceResolutionAndPass2.

TestStagedSource_ScanDeadlineCoversStaging relied on a 1ns timeout being
expired when staging checked ctx; the Windows coarse clock makes that false.
It now uses a 20ms timeout and stalls inside staging past the deadline.

Follow-up to #1628 (#1602).
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: c27da55
Status: ✅  Deploy successful!
Preview URL: https://c1f7fe25.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-scanner-e2e-flakes.mcpproxy-docs.pages.dev

View logs

… Pass 2

A user-triggered rescan that registers after the originating Pass 1 is
cleared must not hold Pass 2 for the full slot wait.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/scanner-e2e-flakes

Available Artifacts

  • archive-darwin-amd64 (31 MB)
  • archive-darwin-arm64 (28 MB)
  • archive-linux-amd64 (19 MB)
  • archive-linux-arm64 (17 MB)
  • archive-windows-amd64 (31 MB)
  • archive-windows-arm64 (28 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (27 MB)
  • installer-dmg-darwin-arm64 (25 MB)
  • smart-mcp-proxymcpproxy-go7B0MNE.dockerbuild (0 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 39004485680 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/security/scanner/service.go 88.23% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit bb7ddcc into main Oct 17, 2026
55 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants