Skip to content

Commit df65abe

Browse files
committed
fix: re add the token check
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 5df5d59 commit df65abe

7 files changed

Lines changed: 30 additions & 17 deletions

File tree

backend/src/api/public/v1/akrites-external/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function akritesExternalRouter(): Router {
7373
// (same as advisories above — see the scope-naming note in the akrites-external
7474
// OpenAPI). Not issued by Auth0 yet, so reuse READ_PACKAGES for now.
7575
const blastRadiusSubRouter = Router()
76-
// blastRadiusSubRouter.use(requireScopes([SCOPES.READ_PACKAGES]))
76+
blastRadiusSubRouter.use(requireScopes([SCOPES.READ_PACKAGES]))
7777
blastRadiusSubRouter.post('/jobs', blastRadiusRateLimiter, safeWrap(submitBlastRadiusJob))
7878
blastRadiusSubRouter.get('/jobs/:analysisId', rateLimiter, safeWrap(getBlastRadiusJob))
7979
router.use('/blast-radius', blastRadiusSubRouter)

backend/src/api/public/v1/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export function v1Router(): Router {
4343
router.use('/ossprey', oauth2Middleware(AUTH0_CONFIG), osspreyRouter())
4444

4545
router.use('/akrites', oauth2Middleware(AUTH0_CONFIG), akritesRouter())
46-
router.use('/akrites-external', akritesExternalRouter())
47-
// router.use('/akrites-external', oauth2Middleware(AUTH0_CONFIG), akritesExternalRouter())
46+
router.use('/akrites-external', oauth2Middleware(AUTH0_CONFIG), akritesExternalRouter())
4847

4948
router.use(() => {
5049
throw new NotFoundError()

backend/src/api/public/v1/packages/blastRadiusAnalysis.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,25 @@ function toResultItem(row: VerdictResultRow): BlastRadiusResultItem {
9999
// candidates the topN walk never reached (so candidatesConsidered - analyzed
100100
// overstates range exclusions). dependentsAnalyzed = number of verdicts produced,
101101
// dependentsAffected = count with an 'affected' verdict, affectedPercentage rounded
102-
// to 1 decimal (null when nothing was analyzed, to avoid a misleading 0%).
102+
// to 1 decimal — computed over conclusive verdicts only (affected/not_affected), so
103+
// persistent agent/tarball failures ('unclear') don't drag it toward a misleading 0%.
104+
// null when nothing conclusive was analyzed.
103105
function toSummary(
104106
dependentsExcludedUpfront: number,
105107
results: BlastRadiusResultItem[],
106108
): BlastRadiusAnalysisSummary {
107109
const dependentsAnalyzed = results.length
108110
const affected = results.filter((r) => r.affected)
111+
const conclusive = results.filter((r) => r.verdict !== 'unclear')
109112

110113
return {
111114
totalDependentsInRange: dependentsAnalyzed + dependentsExcludedUpfront,
112115
dependentsExcludedUpfront,
113116
dependentsAnalyzed,
114117
dependentsAffected: affected.length,
115118
affectedPercentage:
116-
dependentsAnalyzed > 0
117-
? Math.round((affected.length / dependentsAnalyzed) * 1000) / 10
119+
conclusive.length > 0
120+
? Math.round((affected.length / conclusive.length) * 1000) / 10
118121
: null,
119122
affectedDependents: affected.map((r) => r.dependent),
120123
}

services/apps/packages_worker/src/blast-radius/clients/npmTarball.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ export async function downloadAndExtractTarball(
9191
} finally {
9292
fs.rmSync(tempDir, { recursive: true, force: true })
9393
}
94-
} catch (err) {
94+
} finally {
9595
clearTimeout(timeoutHandle)
96-
throw err
9796
}
9897
}
9998

services/apps/packages_worker/src/blast-radius/stages/intel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export async function runIntelStage(
111111
for (const url of patchUrls.slice(0, 3)) {
112112
try {
113113
const patchText = await fetchPatch(url)
114-
const slug = url.split('/').slice(-2).join('-')
114+
const slug = new URL(url).pathname.split('/').filter(Boolean).join('-')
115115
patches[slug] = patchText
116116
} catch {
117117
// Ignore patch fetch errors

services/apps/packages_worker/src/blast-radius/stages/reachability.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ export async function runReachabilityStage(
7272
const concurrency = 4
7373
const queue = [...dependents]
7474

75-
const upsertErrorVerdict = (dependentId: string, reasoning: string, model: string | null) =>
75+
const upsertErrorVerdict = (
76+
dependentId: string,
77+
reasoning: string,
78+
model: string | null,
79+
costUsd = 0,
80+
) =>
7681
blastRadiusDal.upsertVerdict(qx, {
7782
analysisId,
7883
dependentId,
@@ -85,7 +90,7 @@ export async function runReachabilityStage(
8590
reasoning,
8691
model,
8792
turnsUsed: null,
88-
costUsd: 0,
93+
costUsd,
8994
})
9095

9196
const processOne = async (dep: blastRadiusDal.DependentRow): Promise<void> => {
@@ -114,7 +119,11 @@ export async function runReachabilityStage(
114119
return
115120
}
116121

117-
// Try agent up to MAX_ATTEMPTS times with exponential backoff
122+
// Try agent up to MAX_ATTEMPTS times with exponential backoff. costUsd is
123+
// accumulated across attempts — a persistent failure still spends real money
124+
// on every retry, and that spend must show up in the verdict/stage/analysis
125+
// totals even though only the last attempt's outcome is persisted.
126+
let accumulatedCost = 0
118127
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
119128
try {
120129
const systemPrompt = buildReachabilitySystemPrompt(spec)
@@ -129,6 +138,7 @@ export async function runReachabilityStage(
129138
timeoutMs: 600_000,
130139
onProgress,
131140
})
141+
accumulatedCost += agentResult.costUsd || 0
132142

133143
if (!agentResult.isError && agentResult.structuredOutput) {
134144
const output = agentResult.structuredOutput
@@ -145,7 +155,7 @@ export async function runReachabilityStage(
145155
reasoning: String(output.reasoning || ''),
146156
model: 'claude-sonnet-5',
147157
turnsUsed: agentResult.numTurns,
148-
costUsd: agentResult.costUsd || 0,
158+
costUsd: accumulatedCost,
149159
})
150160

151161
return
@@ -161,6 +171,7 @@ export async function runReachabilityStage(
161171
dep.id,
162172
`Agent failed: ${err instanceof Error ? err.message : String(err)}`,
163173
'claude-sonnet-5',
174+
accumulatedCost,
164175
)
165176
return
166177
}

services/libs/data-access-layer/src/packages/blastRadius.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export async function markAnalysisRunning(qx: QueryExecutor, analysisId: string)
140140
await qx.result(
141141
`
142142
UPDATE blast_radius_analyses
143-
SET status = 'running', started_at = NOW(), updated_at = NOW()
143+
SET status = 'running', updated_at = NOW()
144144
WHERE id = $(analysisId) AND status = 'pending'
145145
`,
146146
{ analysisId },
@@ -203,12 +203,13 @@ export async function resolveAdvisoryAndPackageIds(
203203
`
204204
UPDATE blast_radius_analyses bra
205205
SET
206-
advisory_id = COALESCE(a.id, bra.advisory_id),
206+
advisory_id = COALESCE(
207+
(SELECT id FROM advisories WHERE osv_id = $(advisoryOsvId)),
208+
bra.advisory_id
209+
),
207210
package_id = COALESCE($(packageId), bra.package_id),
208211
updated_at = NOW()
209-
FROM advisories a
210212
WHERE bra.id = $(analysisId)
211-
AND a.osv_id = $(advisoryOsvId)
212213
`,
213214
{ analysisId, advisoryOsvId, packageId },
214215
)

0 commit comments

Comments
 (0)