Skip to content

fix(test): size TestDetectionScansUntruncatedResponse for the race detector - #1207

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/activity-truncation-test-race-timeout
Sep 4, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/activity-truncation-test-race-timeout

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 4, 2026

Copy link
Copy Markdown
Member

Pull Request

Follow-up to #1174. Related #1173

Description

TestDetectionScansUntruncatedResponse, added in #1174, fails in both Unit Tests and End-to-End Tests. The defect is the test's payload sizing, not the behaviour it guards — the production change in #1174 is correct and unmodified here.

To put a secret past the storage cut, the test padded the response to storage.DefaultMaxResponseSize+10_000 (~75KB) so it could rely on the 64KB default cap. security.Detector.Scan costs ~5.5 µs/byte, and the race detector multiplies that by ~24x (measured 114–137 µs/byte across 1K–75K payloads). The scan therefore took ~9.5s against the 5s poll deadline in waitForDetectionMetadata.

Two things made this read as a logic failure rather than a slow one:

  • runAsyncDetection writes metadata only when something is detected, so an over-budget scan and a scan of the wrong (truncated) text produce the identical symptom: timed out waiting for detection metadata.
  • CI runs -race in both workflows; a plain local go test does not. Without -race the same test passes in 0.48s.

What this changes

Test-only, three hunks in one file:

  • svc.SetMaxResponseSize(1024) in both subtests, instead of leaning on the 64KB default
  • padding 4096 bytes instead of DefaultMaxResponseSize+10_000
  • a comment recording why, so nobody restores the large payload

The seam is identical. The AWS key sits at bytes [4113, 4133), i.e. 3089 bytes past the 1024-byte cut, and truncateResponse honours any positive maxSize with no minimum floor. Runtime drops from ~9.5s to ~0.5s per subtest.

TestDefaultResponseCapAppliesWithoutConfig still covers the 64KB default separately, so no coverage is lost.

Testing

  • I have tested these changes locally

  • I have added/updated tests that prove my fix is effective or my feature works

  • All existing tests pass

  • 5/5 runs under -race: 0.45–0.50s per subtest against the 5s deadline

  • Negative control — moving the detectionSource capture back to after truncateForStorage in both handlers still fails the test at the smaller payload (10.07s, both subtests, same timeout message). It is not passing vacuously.

  • Second control — stubbing truncateForStorage to return response, false fails the NotContains assertion, proving the key really is past the cut and the assertion is live.

  • Whole internal/runtime package green under plain -race, under the unit-tests.yml invocation, and under the e2e-tests.yml -short invocation. No data races.

  • Headroom measured, not assumed: under graded CPU oversubscription the test still passes at an 8x slowdown (2.96–3.76s) and breaks only around 10.8x. GOMAXPROCS=1 changes nothing (0.47s vs 0.46s) — the scan is single-goroutine CPU-bound, so only single-core speed matters.

Noted for later, not fixed here

internal/security/mask_test.go:TestMaskTextStaysCheapOnAPayloadFullOfSecrets builds a 64KB payload under a hard 2 * time.Second wall-clock assertion. It is safe today — MaskText costs ~3.8 µs/byte under -race, ~36x cheaper per byte than Scan, leaving ~8x headroom — but it is the same fragile shape, and it converts into this failure immediately if anyone ever routes masking through Scan.

…tector

The test added in #1174 failed in both Unit Tests and End-to-End Tests, and the
defect is its payload sizing rather than anything it guards.

To place a secret past the storage cut it padded the response to
storage.DefaultMaxResponseSize+10_000 (~75KB), relying on the 64KB default cap.
security.Detector.Scan costs ~5.5us/byte, and the race detector multiplies that
by ~24x (measured: 114-137us/byte at 1K-75K). So the scan took ~9.5s against the
5s poll deadline in waitForDetectionMetadata. Because runAsyncDetection only
writes metadata on a hit, an over-budget scan surfaces as "timed out waiting for
detection metadata" rather than a failed assertion, which is why it read as a
logic failure. CI runs -race in both workflows; a plain local run does not.

Set the cap explicitly with SetMaxResponseSize(1024) and pad to 4KB instead. The
seam is identical - the AWS key sits at bytes [4113, 4133), 3089 bytes past the
1024-byte cut - and truncateResponse honours any positive maxSize with no
minimum floor. Runtime drops from ~9.5s to ~0.5s per subtest.

Verified:

- 5/5 runs under -race, 0.45-0.50s per subtest against the 5s deadline
- negative control: moving the detectionSource capture back to after
  truncateForStorage in both handlers still fails the test at the smaller
  payload, so it is not passing vacuously
- second control: stubbing truncateForStorage to a no-op fails the
  NotContains assertion, proving the key is genuinely past the cut
- whole internal/runtime package green under -race, under the unit-tests.yml
  invocation and under the e2e-tests.yml -short invocation
- headroom measured under CPU oversubscription: still passes at 8x slowdown
  (2.96-3.76s), breaks only around 10.8x

TestDefaultResponseCapAppliesWithoutConfig continues to cover the 64KB default
separately, so no coverage is lost.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved (Model B): Paperclip review verdicts = ACCEPT and qa-gate green at this head SHA. Arming auto-merge; GitHub merges when all required checks pass.

@github-actions
github-actions Bot enabled auto-merge (squash) September 4, 2026 11:07
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: ba5434f
Status: ✅  Deploy successful!
Preview URL: https://dde9fb27.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-activity-truncation-test.mcpproxy-docs.pages.dev

View logs

@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

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions
github-actions Bot merged commit 913097a into main Sep 4, 2026
40 of 44 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