Skip to content

fix(frontend): one reader for the cached security score (#18907) - #21132

Merged
mrveiss merged 11 commits into
mainfrom
issue-18907-one-call
Nov 9, 2026
Merged

mrveiss merged 11 commits into
mainfrom
issue-18907-one-call

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Thinking Path

Two composables each fetched the cached security score. The page one (useCodeIntelScores) was already source-scoped; useCodeIntelligence kept its own ApiClient copy. Per #20999 the page reader is canonical, so the fetch moves into one composable that both delegate to, with the full raw payload kept so from_cache and completed_at stay reachable.

What Changed

  • autobot-frontend/src/composables/analytics/useCachedSecurityScore.ts (new): the single useFetchEndpoint call, always source-scoped; exposes raw, the score pick, and an onSuccess hook.
  • useCodeIntelScores.ts: loadCachedSecurityScore now delegates to it (behaviour unchanged).
  • useCodeIntelligence.ts: getSecurityScoreCached delegates to it; same return shape, skip without a scoper, errors still collected.
  • codeIntelTypes.ts: CachedSecurityScoreRaw moved to the shared types.
  • Tests: useCachedSecurityScore.oneHome.test.ts (sweep fails if any other source file names the route; planted control included) and useCodeIntelligence.cachedScore.test.ts (request carries source_id, fields kept, no scoper sends nothing, failure surfaced).
  • repo_tests/frontend_api_contract_ratchet_test.py: inline_generics baseline 534 to 533, as the ratchet prescribes (one ApiClient.get<...> removed).
  • Behaviour note: the error message useCodeIntelligence collects on a failed cached read changed from the thrown err.message to Cached security score returned <status> (the shared reader's message).

Verification

Closes #18907
Closes #20999

Model Used

Claude Sonnet 5.5

@mrveiss mrveiss added frontend phase:M4.9 One definition per concept labels Nov 8, 2026
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 206bfb5 and a8f0244.

Files selected for processing: 7

  • autobot-frontend/src/composables/__tests__/useCodeIntelligence.cachedScore.test.ts
  • autobot-frontend/src/composables/analytics/__tests__/useCachedSecurityScore.oneHome.test.ts
  • autobot-frontend/src/composables/analytics/codeIntelTypes.ts
  • autobot-frontend/src/composables/analytics/useCachedSecurityScore.ts
  • autobot-frontend/src/composables/analytics/useCodeIntelScores.ts
  • autobot-frontend/src/composables/useCodeIntelligence.ts
  • repo_tests/analytics_page_open_reads_only_20491_test.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at b88f4f7

Parity holds for both former callers: the page keeps SecurityScoreResult and the skip-on-failure rule, and getSecurityScoreCached keeps the source_id skip, the raw no_data payload, and from_cache/completed_at. The inline_generics 534 to 533 change is exact: the one removed match is ApiClient.get<SecurityScoreCached> and the diff adds none. The shared state is per call, not global, because useCachedSecurityScore() is created inside each useCodeIntelligence()/useCodeIntelScores() call, so components do not share an instance. Two items should be fixed before merge.

Severity File:line Finding Fix
MEDIUM analytics/codeIntelTypes.ts:44 vs useCodeIntelligence.ts:140 CachedSecurityScoreRaw and SecurityScoreCached are the same payload defined twice (they differ only in status: string vs 'success'|'no_data'). #20999 exists to remove exactly this kind of duplicate. Keep one type in codeIntelTypes.ts with status: 'success' | 'no_data'. Have SecurityScoreCached re-export or alias it.
MEDIUM useCodeIntelligence.ts:303 cachedScore.raw.value as SecurityScoreCached | null is an unchecked cast. It exists only because of the duplicate type above and hides a status mismatch. Remove the cast once the types are unified.
LOW useCodeIntelligence.ts:297-304 load() aborts the prior in-flight request, and an abort ends with no error. If the onMounted prefetch and an explicit call overlap, the aborted call returns the stale or null raw as if it had succeeded. Before the change, each call had independent state. After load(), return null when loading is still true or no answer was recorded. Or serialise the calls. Add a test for the overlapping case.
LOW useCodeIntelligence.ts:297-301 The error message changes from the thrown err.message to Cached security score returned <status>. That is consistent, but it is a visible behaviour change. Note it in the PR body. No code change needed.
LOW __tests__/useCachedSecurityScore.oneHome.test.ts:15,29-31 ROUTE is a single-line literal match, so a reader that builds the path dynamically escapes it: ${base}/security/score/${x}, 'security/' + 'score/cached', or a path split across lines. The tree scan covers only autobot-frontend/src. The planted control proves only the literal case. It has no negative control (a comment-only mention that must not trip the guard) and no dynamic-path control. Also flag any file other than HOME that imports CACHED_SECURITY_SCORE_PATH and calls fetch with it. Match score\/cached|security\/score loosely. Add a dynamic-path control and a comment-only control. State the literal-match limit in the test header.
LOW __tests__/useCodeIntelligence.cachedScore.test.ts Covers source_id, the no-scoper skip, and the error path. It does not cover a no_data payload being returned and stored, or the loading state returning to false. Add both cases.
INFO analytics/useCachedSecurityScore.ts:30 r.security_score ?? 0 is redundant after the undefined guard. Drop ?? 0.
INFO functions, strings, logging New functions are at most 22 lines and none breach 30. There is no console.*. useFetchEndpoint is used correctly: scopeToSource plus the injected withSourceId, and pickData records raw before the pick. The path is a shared constant. None.

Closes check

The Closes keywords are justified once the guard gap is fixed or explicitly scoped. Otherwise use Refs #20999 for AC3.

CHANGES: unify the duplicate type and drop the cast. Harden or scope the sweep. The remaining items can be fixed in the same PR.

@mrveiss

mrveiss commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner Author

Review findings fixed in b6faf3a.

Row Fix
1 MED One type: CachedSecurityScoreRaw now has status: 'success' | 'no_data'; SecurityScoreCached is an alias of it; the cast in getSecurityScoreCached is gone.
2 LOW getSecurityScoreCached returns null while the reader is still loading (a newer call aborted this one) or when no new payload was recorded for the call. New overlap test.
3 LOW Error-message change (err.message to Cached security score returned <status>) noted in the PR body.
4 LOW Guard flags any non-owner file importing CACHED_SECURITY_SCORE_PATH; route match loosened to security/score (the live non-cached route, whose path ends right after score, is the one exempt shape); planted controls for dynamic/concatenated paths and path-constant import; comment-only and live-route negative controls; literal-match limit in the header. Holds on the current tree.
5 LOW no_data test: returned, stored, isLoading false, no errors.
6 INFO Redundant ?? 0 dropped in pickCachedSecurityScore.

Verification: vitest on the 3 touched/related test files, 20 tests (6 + 5 + 9); eslint clean on touched files; vue-tsc reported nothing for them. reka-ui is missing from the local install, so the two component-importing tests ran with it aliased to a stub in a throwaway config.

The guard is hardened, so Closes #18907 and Closes #20999 stay.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at b6faf3a

Delta reviewed: b88f4f7..b6faf3a. All six earlier rows are resolved in code, and no new blocker was found.

Severity File:line Finding Fix
RESOLVED codeIntelTypes.ts:46, useCodeIntelligence.ts:141 One type: status is now 'success' | 'no_data', SecurityScoreCached is an alias of it, and the cast is gone. None.
RESOLVED useCodeIntelligence.ts:286-296 Null-on-overlap logic checked. Overlap case: the aborted call's continuation sees loading still true (the newer refresh() ran synchronously) and returns null, so it never reports a stale result. Completed-call case: load() resolves, loading is false, raw is a fresh parsed object so raw !== before, and the data is returned. If the newer call has already finished by the time the aborted one resumes, the aborted one returns the newer call's payload, which is harmless. No path returns null for a legitimately completed call. The two overlap/no_data tests exercise this. None.
RESOLVED oneHome.test.ts The guard now matches security/score, flags imports of CACHED_SECURITY_SCORE_PATH, and has dynamic, concatenation, constant-import, comment-only and live-route controls. The header states the literal-match limit. None.
RESOLVED useCachedSecurityScore.ts:31 Redundant ?? 0 removed. None.
LOW oneHome.test.ts:26 (LIVE_ROUTE) The exemption is narrow: the line must end right after security/score plus a closing quote and an optional , or ). ...score' + and ...score?x are not exempt, so they are flagged. One gap remains: a multi-line concatenation with a leading operator ('/security/score' on one line, + '/cached' on the next) exempts the first line, and the second line spells nothing. A cached reader could hide this way. This is the same line-based literal limit the header already documents, and the pattern is unlikely in this codebase. Optional: also reject a LIVE_ROUTE line whose next non-blank line starts with + or .concat. Or add a line to the header limit note naming this shape.
LOW useCodeIntelligence.ts:289-290 If a newer overlapping call errors, the aborted call also reads the shared cachedScore.error and appends a duplicate entry to errors. Optional: only the call that was not aborted records the error, or de-duplicate.

Closes check

APPROVE

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Both lows fixed in e89b67e: the guard now flags a live-route line followed by a line starting with + (planted control added), and getSecurityScoreCached records an error or answer only for the call that owns it (call-sequence check; test added so an aborted call does not duplicate the newer call's error). vitest on the 3 touched test files: 22 passed; eslint clean.

@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Delta review b6faf3a → e89b67e: APPROVE. Both lows from the approved review are fixed, with no other change:

  • The one-home guard no longer exempts a live-route line when the next line starts with +, and there is a planted multi-line control for it.
  • getSecurityScoreCached now decides ownership by a per-call sequence id instead of the shared loading flag, so an aborted call never records the newer call's error. A new test asserts exactly one error entry.

0 unresolved threads. Queued for the next merge train.

@mrveiss

mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Ejected from T101 on analytics_page_open_reads_only_20491 (shard 4); fixed at 1351266. The guard now reads the cached security read at useCachedSecurityScore.ts (scopeToSource) and the two callers' withSourceId hand-off; added planted controls for a dropped scoper, a non-GET method/.post, and an added page-open scan or mount call.

@mrveiss

mrveiss commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Delta review at 1351266 (T101 ejection fix): APPROVE. analytics_page_open_reads_only_20491_test follows the cached security read to its new home, useCachedSecurityScore.ts. It asserts scopeToSource: true with the scoper handed on, that both callers pass withSourceId, and that the cached read can't write (no non-GET method and no post/put/patch/delete). Planted controls cover a dropped scoper, a non-GET request and a scan or mount call on page open, so the moved guard can still fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend phase:M4.9 One definition per concept

Projects

None yet

1 participant