Skip to content

fix(depscore): poll for packages not yet scanned (SURF-2362) - #265

Open
Gerardo Sabetta (gerardosabetta) wants to merge 2 commits into
mainfrom
gerardosabetta/surf-2362-socket-mcp-depscore-should-wait-for
Open

Gerardo Sabetta (gerardosabetta) wants to merge 2 commits into
mainfrom
gerardosabetta/surf-2362-socket-mcp-depscore-should-wait-for

Conversation

@gerardosabetta

@gerardosabetta Gerardo Sabetta (gerardosabetta) commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

depscore still does its usual POST /v0/purl lookup without poll, exactly as before. Then, for the packages that came back without a score (notFound/pendingScan), it asks again with poll=true&timeoutSec=20. A poll answer replaces the first answer only when it carries a score, so depscore never returns less than it did before this PR. Packages that already have a score make no extra request and don't wait.

The two answers are matched by the response's inputPurl, which the API returns with and without poll.

Why poll goes second. The first commit sent poll=true on the main lookup. Live testing showed that poll=true answers pendingScan with no score for many already-scored packages while Socket re-analyzes them. In a 40-package batch of popular versions (express, react, lodash, axios, …), all 40 came back pendingScan with poll=true&timeoutSec=5, while the same request without poll returned 40 scores in 1.3s. Single versions did the same (express@4.17.1, express@4.18.2). Polling first, even with a fallback, would add ~20s to ordinary lookups (22.2s for that batch). Polling only the gaps keeps those at their old latency.

Why 20s. The spec allows 1–1200. socket-mcp sets no tool timeout of its own; the bound is the shared httpRequest default of 30s (@socketsecurity/lib http-request). MCP SDK clients default to 60s per request. 20s keeps the poll under the 30s client timeout. A package left unscored now costs up to ~20s more; when the poll still has no score, the first answer is kept.

Not in this PR:

  • purlErrors and summary. Both come back as _type control frames, which depscore drops today, so they would need new parsing. Follow-up.
  • The org-scoped endpoint migration (separate ticket).

Note: the poll URL is derived from the lookup URL, so a SOCKET_API_BASE_URL override polls too.

Verification

Live API on 2026-12-04, using gera's local socket-mcp OAuth session (scope packages:list), never printed. "Through the handler" means handleDepscoreRequest from this branch, with a preload logging each request's path, poll flag, status and time (no headers). "Fresh" means an npm version published under 10 minutes earlier and never requested before.

Before (main, single lookup without poll)

Package Result Latency
@zukhruf/chaos@0.8.353 (fresh) notFound, no score 0.28s
anbaric-plugins@1.88.0 (fresh) notFound, no score 0.62s
express@4.18.2 score 0.25s
40 popular versions, one request 40/40 scored 1.30s

Poll-first (first commit, dropped)

Package Result Latency
@zukhruf/chaos@0.8.353, anbaric-plugins@1.88.0 (scan queued ~1 min earlier) scores (95, 74) 13.4s, 10.2s
@zukhruf/pool@0.8.353, @randock/nameshift-api-client@0.0.589 (fresh) pendingScan 20.2s, 20.3s
lodash@4.17.21, react@18.2.0, express@4.21.2 scores 0.25–0.26s
express@4.18.2 (mid-re-analysis) pendingScan, score lost (twice) 20.9s, 20.2s
40 popular versions, raw, timeoutSec=5 40/40 pendingScan 5.5s
express@4.17.1 alone, raw, timeoutSec=5 pendingScan 5.4s
40 popular versions through the handler, poll then no-poll fallback 40/40 scored 22.2s (poll 20.7s + fallback 1.2s)

After (this PR: lookup, then poll only the unscored), through the handler

Package Requests Result Total
lodash@4.17.21 lookup only score 0.99s
express@4.17.1 (raw poll gave pendingScan minutes earlier) lookup only score 0.64s
express@4.18.2 lookup only score 0.62s
40 popular versions, one call lookup only 40/40 scored 2.21s
@reallexi/rmai-ui-windows-amd64@1.6.659 (fresh) lookup 0.50s + poll 16.95s score 17.73s
@holtjs/stage@0.12.0 (fresh) lookup 0.58s + poll 20.27s no score, first answer kept 21.21s
@lintrs/sdk@0.3.0 (fresh) lookup 0.47s + poll 0.56s no score (unresolvable version), first answer kept 1.30s

Totals include the alert-types metadata call (~0.2–0.4s). Earlier in the session, two other fresh versions scored on poll-only calls in 7.5s and 13.2s.

CI

The first push failed Test (windows-2025) in test/repo/integration/tool-audit-stdio.test.mts:199 ("expected 'Error connecting to Socket API' to contain 'synthetic_response_canary'"). This PR didn't cause it:

  • That fixture sets SOCKET_API_BASE_URL to its own URL, so the first commit's change never reached its request.
  • The same assertion failed on Windows in runs 46710239330 and 46697125550 (Dec 1) and 46962222772 (Dec 2) on other branches. The same test failed on main in run 46726240978 with a different assertion.
  • Re-running the job with no code change passed.

What I ran

  • pnpm run fmt / pnpm run fmt:check
  • pnpm run lint (clean)
  • pnpm run repo:check (tsc + build, clean)
  • pnpm test: 76 files, 742 tests passed

New tests in test/repo/unit/tool-depscore.test.mts:

  • Only the unscored package is polled (poll=true, timeoutSec=20, body with just that PURL), and its score is used.
  • A poll answer without a score leaves the first answer in place.

Linear: https://linear.app/socketdev/issue/SURF-2362/socket-mcp-depscore-should-wait-for-packages-socket-hasnt-scanned-yet

Slides

cover

gap

budget

verify

headsup

🤖 Generated with Claude Code

Gerardo Sabetta (gerardosabetta) added a commit that referenced this pull request Dec 4, 2026
Gerardo Sabetta (gerardosabetta) added a commit that referenced this pull request Dec 4, 2026
@gerardosabetta
Gerardo Sabetta (gerardosabetta) marked this pull request as ready for review December 4, 2026 18:44
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Adds a second upstream call with up to ~20s wait per unscored package and changes when scores appear, but scored lookups stay single-request and failures fall back to the first response.

Overview
The depscore tool keeps the fast initial POST /v0/purl lookup unchanged, then follows up only for packages that returned without an overall score. It derives a poll URL (poll=true, timeoutSec=20) from the same base as the primary request and runs pollUnscored before parsing alerts and scores.

Polling is selective and conservative: unscored rows are identified by missing score.overall and matched on inputPurl; the poll body includes only those PURLs. Poll results replace the first response only when a scored document comes back—otherwise the original answer (e.g. notFound) is kept, avoiding regressions from pendingScan on already-scored packages.

Unit tests cover mixed batches (one scored, one polled into a score) and poll responses that still lack a score.

Reviewed by Cursor Bugbot for commit ed2f5e9. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ed2f5e9. Configure here.

Comment thread lib/tool-depscore.mts
typeof inputPurl === 'string' ? unscored.get(inputPurl) : undefined
if (index !== undefined && hasOverallScore(doc)) {
lines[index] = fallbackLines[i]!.trim()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Poll keeps one artifact per purl

Medium Severity

pollUnscored keeps only the last line index for each inputPurl. Both the lookup and the poll can return several artifacts for one purl. Each scored poll row overwrites that same index, leaving earlier rows unscored. deduplicateArtifacts can then keep an unscored sibling or the wrong build, so platform does not choose among the poll artifacts.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ed2f5e9. Configure here.

This branch has not been deployed

No deployments
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.

1 participant