feat(scan): serve socket scan view from cached results with 202 polling (SURF-742)#1425
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
John-David Dalton (jdalton)
force-pushed
the
jdalton/surf-742-add-support-for-the-cached-flag-in-the-sdkcli-for-full-scans
branch
from
July 24, 2026 12:57
b784521 to
c57dc34
Compare
Collaborator
Author
|
Withdrawing — the cached scan-view behavior (SURF-742) will land as part of bumping socket-cli v1.x to the latest @socketsecurity/sdk (4.x) under SURF-1446, rather than a bespoke direct-API poll. Superseding this branch. |
socket scan view from cached results with 202 polling (SURF-742)
Backports the cached scan-view behavior from main (e5fb60b, f6741d2) to the v1.x line. socket scan view (default and --json non-stream) now reads pre-computed results from the immutable scan store: fetchScan hits ...full-scans/{id}?cached=true, polls on 202 ({status:'processing'}) with exponential backoff and a 10 minute deadline, then parses the 200 ndjson. The --stream --json live-stream path is unchanged. Uses the direct API via a new queryApiSafeTextWithStatus helper (which surfaces the HTTP status so the 202 poll loop can see it) — no SDK dependency, so no @socketsecurity/sdk release is required.
John-David Dalton (jdalton)
force-pushed
the
jdalton/surf-742-add-support-for-the-cached-flag-in-the-sdkcli-for-full-scans
branch
from
July 24, 2026 21:49
c57dc34 to
800e362
Compare
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.
What this does
socket scan viewshows the results of a full scan. Today it asks the API to compute those results from scratch every time. This change makes it read a pre-computed (cached) copy instead, which is faster and cheaper.It does that by adding
?cached=trueto the request. The server has two possible answers:{"status":"processing"}. When this happens the CLI waits a moment and asks again, backing off a little each time (1s, then 2s, … up to 10s, giving up after 10 minutes). The user never sees the "processing" state — they just wait a bit longer and get the finished scan.Which modes change: the default view and
--json(the non-streaming modes that already buffer the whole response). The live--stream --jsonpath is intentionally left untouched.Why it's safe to ship on its own
This is self-contained. It uses the CLI's own HTTP helper (
queryApiSafeTextWithStatus) and does not call the Socket SDK for this path, so it stays on the currently-pinned@socketsecurity/sdk(1.4.96) and needs no SDK release. CI is green on its own.The separate effort to move socket-cli
v1.xonto the latest SDK (4.x) is tracked as SURF-1446 — that is not required by, and does not block, this PR.Implementation detail & parity with
mainqueryApiSafeTextWithStatusinutils/api.mtsreturns{ status, text }so the caller can tell a 202 apart from a 200 (the existingqueryApiSafeTextswallowed the status).queryApiSafeTextnow delegates to it, so its behavior is unchanged for every other caller.fetchScanbuilds the?cached=truerequest, runs the 202→200 backoff loop, and parses the 200 ndjson via an exportedparseArtifactsNdjson.main's CLI already does cached scan reads (commitse5fb60b1+f6741d2d), adapted to the older v1.x layout. It deliberately does not use the SDK's cachedgetFullScan, because that method returns scan metadata, not the artifact listscan viewrenders.--stream --jsonstill calls the streaming full-scan method unchanged.Verification
tsgo,eslint,oxlint,biome: clean.vitest src/commands/scan/fetch-scan.test.mts: 5 tests vianockagainst the real HTTP path — 200 cache hit, 202→200 poll, 404 error, plusparseArtifactsNdjsonvalid/invalid line cases. No owned-module mocking.vitest src/utils/api.test.mts: 10 tests, no regression from thequeryApiSafeTextrefactor.Linear: SURF-742. Do not merge yet.