Guard the capture-scope timeout bound - #181
Merged
Merged
Conversation
The pre-send capture-scope check is the only thing that keeps an excluded repository's transcript on the machine, and it is bounded by an AbortController so a hung endpoint cannot stall a detached capture. Every existing stub in this file resolves on the same tick, so none of them ever raced that timer — which left the bound itself completely unguarded. Setting it to 0 keeps all 953 cli tests green. In production it destroys the feature: a 0 ms abort always beats a real round-trip, so every preflight fails open and a repository the user excluded is captured anyway. Nothing reports it, because failing open is deliberate and silent — from the outside "the server said capture" and "we never waited for the answer" are the same. The new test answers after a real 40 ms and honours the signal, which is what a live preflight does, and asserts the skip verdict still arrives. It is the only test in the suite that dies when the bound goes degenerate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The capture-scope timeout was pinned by nothing
checkCaptureScopeis the pre-send preflight: before the hook reads a transcript it asks the worker whether capture is on for this repository, and a clean200 {decision:'skip'}means nothing is read and nothing is sent. That request is bounded by anAbortControllerso a hung endpoint cannot stall the detached capture.Every existing stub in
captureScope.test.tsresolves on the same tick, so no test ever races that timer. The bound was therefore untested in both directions.What that allows
Setting
CAPTURE_SCOPE_TIMEOUT_MSto0keeps the whole cli suite green. Measured on the pre-PR tree (this file atorigin/main),tscclean: 952 tests, 952 pass, 0 fail — including all 143 tests acrosscapture.test.ts,captureCommand.test.tsandfromHook.test.ts.In production it removes the feature. A 0 ms abort always wins against a real network round-trip, so the preflight always throws into the catch, the catch fails open by design, and a repository the user excluded is captured anyway. Nothing anywhere reports it: failing open is deliberate and silent, and from the outside "the server said capture" and "we never waited for the answer" produce identical behaviour.
The test
One new case. The stubbed fetch answers after a real 40 ms and honours the abort signal — which is what a live preflight does — and the assertion is that the
skipverdict still arrives.40 ms is far quicker than any real call to the endpoint and far under the real bound, so this is not a timing-flaky test: it can only fail when the bound is small enough to abort a live request, which is precisely the defect.
Verified
cli/src/captureScope.test.ts10 pass / 0 fail; fullcli/src/*.test.ts953 pass / 0 fail.0:tsc -p cli/tsconfig.jsonclean, and this test is the only one in the suite that fails — 9 pass / 1 fail here, 143/143 green in the three capture suites.Test-only. No version bump, no change to
dist-bundle/.Reasoning
written by the agent in-session via
backthread/add-reasoning-to-prsDecisions
CAPTURE_SCOPE_TIMEOUT_MSis module-private, and a test that reads the constant back only compares it to itself.Assumptions
setTimeout, this test goes red for a timing reason and not a real defect. Check: if it ever flakes, raise the real bound rather than lowering the delay.Limitations
capture.test.ts, which assert the first request is/capture-scope.