Skip to content

Commit 620e6a9

Browse files
committed
fix(telemetry_policy): suppress baseline fallback on canon_url override
When canon_url is provided, getFile() previously still appended the klappy.dev baseline as a search source. A missing governance file in the override canon would be silently satisfied by the baseline, causing governance_source to report 'canon' instead of 'minimal'. Add an optional skipBaselineFallback flag to ZipBaselineFetcher.getFile and pass it from the telemetry_policy handler when canon_url is set, so a missing file in the override canon correctly falls back to the minimal tier.
1 parent 360b4b5 commit 620e6a9

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

workers/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,14 @@ Time filter example: WHERE timestamp > NOW() - INTERVAL '30' DAY`,
521521
let governanceSource: "canon" | "baseline" | "minimal" = "minimal";
522522

523523
try {
524-
const content = await fetcher.getFile("canon/constraints/telemetry-governance.md", canon_url);
524+
// When a canon_url override is provided, suppress the baseline fallback
525+
// so a missing file in the override canon surfaces as "minimal" rather
526+
// than silently serving the klappy.dev baseline.
527+
const content = await fetcher.getFile(
528+
"canon/constraints/telemetry-governance.md",
529+
canon_url,
530+
canon_url ? { skipBaselineFallback: true } : undefined,
531+
);
525532
if (content) {
526533
policyContent = content;
527534
const parsed = parseSelfReportHeadersTable(content);

workers/src/zip-baseline-fetcher.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,25 @@ export class ZipBaselineFetcher {
978978
* Get a specific file from the baseline or canon.
979979
* Content-addressed: file cache is keyed to each repo's own commit SHA.
980980
* Three-tier: module memory → R2 → ZIP extraction.
981+
*
982+
* When `options.skipBaselineFallback` is true, the baseline repo is not
983+
* appended to the search sources. Callers that need to distinguish between
984+
* "file found in the canon_url override" and "file found in the baseline
985+
* fallback" can pass this flag so a null return unambiguously means the
986+
* override canon lacks the file.
981987
*/
982-
async getFile(path: string, canonUrl?: string): Promise<string | null> {
988+
async getFile(
989+
path: string,
990+
canonUrl?: string,
991+
options?: { skipBaselineFallback?: boolean },
992+
): Promise<string | null> {
983993
const baselineRepoUrl = "https://github.com/klappy/klappy.dev";
994+
const skipBaselineFallback = options?.skipBaselineFallback === true;
984995

985-
// Resolve SHA for each repo independently
986-
const baselineSha = await this.getLatestCommitSha(baselineRepoUrl);
996+
// Resolve SHA for the baseline only when it will actually be searched.
997+
const baselineSha = skipBaselineFallback && canonUrl
998+
? null
999+
: await this.getLatestCommitSha(baselineRepoUrl);
9871000

9881001
// Build the list of repos to search, each with its own SHA
9891002
const sources: Array<{ url: string; repoKey: string; sha: string }> = [];
@@ -998,13 +1011,15 @@ export class ZipBaselineFetcher {
9981011
});
9991012
}
10001013

1001-
sources.push({
1002-
url: this.env.BASELINE_URL.includes("raw.githubusercontent.com")
1003-
? this.env.BASELINE_URL.replace("/main", "").replace("raw.githubusercontent.com", "github.com")
1004-
: baselineRepoUrl,
1005-
repoKey: getCacheKey("baseline"),
1006-
sha: baselineSha || "unknown",
1007-
});
1014+
if (!(skipBaselineFallback && canonUrl)) {
1015+
sources.push({
1016+
url: this.env.BASELINE_URL.includes("raw.githubusercontent.com")
1017+
? this.env.BASELINE_URL.replace("/main", "").replace("raw.githubusercontent.com", "github.com")
1018+
: baselineRepoUrl,
1019+
repoKey: getCacheKey("baseline"),
1020+
sha: baselineSha || "unknown",
1021+
});
1022+
}
10081023

10091024
for (const source of sources) {
10101025
// Content-addressed cache key: repo identity + repo SHA + file path

0 commit comments

Comments
 (0)