Repository navigation
fix(runtime): close general library OCR findings (AP-ISS-0201) #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fa48900
dd09bf3
7fc5f7b
3d4cd35
9ac5446
c469ca3
adcbdcc
945a5fe
5d6fe9b
7e04336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,11 +68,27 @@ const FORWARDING_HEADERS = new Set([ | |||||||||
| "x-client-ip", | ||||||||||
| ]); | ||||||||||
|
|
||||||||||
| function isExplicitTrustedPrivateProxy(peer: string): boolean { | ||||||||||
| const configured = process.env.AGENTPROXY_TRUSTED_PROXY_PEERS; | ||||||||||
| if (!configured) return false; | ||||||||||
| return configured.split(",").some((entry) => { | ||||||||||
| const candidate = entry.trim(); | ||||||||||
| return ( | ||||||||||
| net.isIP(candidate) !== 0 && | ||||||||||
|
khanhkit marked this conversation as resolved.
|
||||||||||
| candidate.replace(/^::ffff:/, "").toLowerCase() === peer.toLowerCase() | ||||||||||
|
Comment on lines
+77
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||
| ); | ||||||||||
| }); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function resolveClientPolicy(remoteAddress: string | undefined): ClientPolicy { | ||||||||||
| const scope = classifyIpScope(remoteAddress); | ||||||||||
| if (scope === "loopback") return { kind: "local" }; | ||||||||||
| const peer = remoteAddress ? remoteAddress.replace(/^::ffff:/, "") : "unknown"; | ||||||||||
| if (scope === "private" && getTrustProxyMode() === "private") { | ||||||||||
| if ( | ||||||||||
| scope === "private" && | ||||||||||
| getTrustProxyMode() === "private" && | ||||||||||
| isExplicitTrustedPrivateProxy(peer) | ||||||||||
| ) { | ||||||||||
| return { kind: "trusted-proxy", peer }; | ||||||||||
| } | ||||||||||
| return { kind: "remote", peer }; | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,6 @@ import { backupDbFile } from "./db/backup"; | |||||||||||||||||||||
| import { | ||||||||||||||||||||||
| applyArenaEloRefresh, | ||||||||||||||||||||||
| deleteModelIntelligenceBySource, | ||||||||||||||||||||||
| getLatestSyncedAt, | ||||||||||||||||||||||
| type ModelIntelligenceEntry, | ||||||||||||||||||||||
| } from "./db/modelIntelligence"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -200,6 +199,24 @@ function writeLastFailedAt(ts: number): void { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function readLastCompleteRefreshAt(): number | null { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| const db = getDbInstance(); | ||||||||||||||||||||||
| const row = db.prepare(KV_READ_SQL).get("arena_elo", "lastCompleteRefreshAt") as | ||||||||||||||||||||||
| { value: string } | undefined; | ||||||||||||||||||||||
| if (!row?.value) return null; | ||||||||||||||||||||||
| const ts = Date.parse(row.value); | ||||||||||||||||||||||
| return Number.isFinite(ts) ? ts : null; | ||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function writeLastCompleteRefreshAt(ts: number): void { | ||||||||||||||||||||||
| const db = getDbInstance(); | ||||||||||||||||||||||
| db.prepare(KV_WRITE_SQL).run("arena_elo", "lastCompleteRefreshAt", new Date(ts).toISOString()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
khanhkit marked this conversation as resolved.
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function clearLastFailedAt(): void { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| const db = getDbInstance(); | ||||||||||||||||||||||
|
|
@@ -495,12 +512,12 @@ export async function syncArenaElo(dryRun = false): Promise<SyncResult> { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!dryRun) { | ||||||||||||||||||||||
| // Freshness guard: a non-empty dataset synced within the interval is | ||||||||||||||||||||||
| // still good — skip the fetch entirely (cheap fast path on boot). | ||||||||||||||||||||||
| const latest = getLatestSyncedAt("arena_elo"); | ||||||||||||||||||||||
| if (latest) { | ||||||||||||||||||||||
| const age = Date.now() - Date.parse(latest); | ||||||||||||||||||||||
| if (Number.isFinite(age) && age >= 0 && age < SYNC_INTERVAL_MS) { | ||||||||||||||||||||||
| // Freshness is advanced only after a complete all-category refresh. | ||||||||||||||||||||||
| // Row timestamps alone can describe a partial historical dataset. | ||||||||||||||||||||||
| const latestCompleteRefresh = readLastCompleteRefreshAt(); | ||||||||||||||||||||||
| if (latestCompleteRefresh !== null) { | ||||||||||||||||||||||
| const age = Date.now() - latestCompleteRefresh; | ||||||||||||||||||||||
| if (age >= 0 && age < SYNC_INTERVAL_MS) { | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
|
Comment on lines
+517
to
521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||
| success: true, | ||||||||||||||||||||||
| modelCount: lastSyncModelCount, | ||||||||||||||||||||||
|
|
@@ -527,11 +544,25 @@ export async function syncArenaElo(dryRun = false): Promise<SyncResult> { | |||||||||||||||||||||
| // sync while the upstream was rate-limiting; remediation 2026-09-12). | ||||||||||||||||||||||
| const leaderboards = await fetchArenaLeaderboards(); | ||||||||||||||||||||||
| const entries = transformToModelIntelligence(leaderboards); | ||||||||||||||||||||||
| const completeRefresh = FETCH_CATEGORIES.every((category) => { | ||||||||||||||||||||||
| const models = leaderboards[category]?.models; | ||||||||||||||||||||||
| return Array.isArray(models) && models.length > 0; | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| if (!completeRefresh) { | ||||||||||||||||||||||
| if (!dryRun) writeLastFailedAt(Date.now()); | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| success: false, | ||||||||||||||||||||||
| modelCount: 0, | ||||||||||||||||||||||
| source: "arena_elo", | ||||||||||||||||||||||
| error: "Incomplete Arena refresh; preserving previous dataset", | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
khanhkit marked this conversation as resolved.
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (!dryRun && entries.length > 0) { | ||||||||||||||||||||||
| if (!dryRun) { | ||||||||||||||||||||||
| try { | ||||||||||||||||||||||
| // Atomic replace: upsert all + prune not-in-refreshed-set in one tx. | ||||||||||||||||||||||
| applyArenaEloRefresh(entries); | ||||||||||||||||||||||
| writeLastCompleteRefreshAt(Date.now()); | ||||||||||||||||||||||
| clearLastFailedAt(); | ||||||||||||||||||||||
|
Comment on lines
564
to
566
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Suggested change
|
||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||
| const message = getErrorMessage(err); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.