Skip to content

Commit dc67620

Browse files
authored
perf(github): durable ETag read broker - 304s replace repeat quota charges (#1164)
Quota campaign PR 4/5: durable ETag read broker - unchanged GitHub responses stop costing quota. No wrapper sent If-None-Match before this; every repeat read paid a full quota charge (measured repeat floors: item_metadata 21.5%, comments 17.6%, reviews 19.5%). The broker persists ETag + body + digest in the queue DO (publisher-HMAC endpoints per the #1163 pattern; 30-day TTL; 2048-entry/512KiB bounds), keyed by credential pool, sorted route/query, media type, and page - a page-1 304 can never validate page 2. Cached bodies are released only after a live 304 plus digest confirmation; final pre/post-mutation guards always revalidate (a 304 is a live authoritative answer, but no guard ever consumes an unrevalidated cache). Composes with #1161: generations cover within-run reuse, the broker covers cross-run revalidation. Integrated at the highest-repeat sites first: apply issue/pull metadata, paged comment/review collections, dashboard run/job health reads. Telemetry counts 200-with-store, 304-from-cache, miss, and skip as distinct units - this PR reduces QUOTA CHARGES, not wire requests (5 wire calls / 3 charged 200s in the counted fixture). Proof: loopback ETag semantics with byte-identical 304 replay (digest asserted), page isolation, final-guard revalidation; full gate 3446/0 + dashboard-strict; Crabbox local-container receipt at this exact head, machine-verified provenance. Verdict clean (no actionable findings, proof sufficient) on bd2ef95.
1 parent 6a358d2 commit dc67620

25 files changed

Lines changed: 2126 additions & 17 deletions

‎.github/workflows/sweep.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ jobs:
14171417
continue-on-error: true
14181418
env:
14191419
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
1420+
EXACT_REVIEW_QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
14201421
GH_TOKEN: ${{ steps.target-write-token.outputs.token }}
14211422
CLAWSWEEPER_PUBLIC_GH_TOKEN: ${{ steps.target.outputs.target_repo == 'openclaw/openclaw' && github.token || '' }}
14221423
REPO_TOKEN: ${{ github.token }}

‎dashboard/exact-review-queue.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ import {
7373
} from "./exact-review-command-intake.ts";
7474
import { recentDurablePublicationEvents } from "./recent-durable-publication-events.ts";
7575
import { sanitizedServerError } from "./error-safety.ts";
76+
import { GithubEtagResponseStore } from "./github-etag-cache.ts";
77+
import { githubEtagCacheKeyFromValue } from "../src/github-etag-cache-contract.ts";
7678
import {
7779
ExactReviewArtifactReceiptStore,
7880
exactReviewArtifactReceiptTuple,
@@ -665,6 +667,7 @@ export class ExactReviewQueue {
665667
private githubEgressTelemetryStore;
666668
private commandIntakeStore;
667669
private artifactReceiptStore;
670+
private githubEtagResponseStore;
668671
private readonly random: () => number;
669672
private readonly baselines = new WeakMap<ExactReviewQueueState, ExactReviewQueueBaseline>();
670673
private reviewCoverageCache: { at: number; summary: ReviewCoverageSummary } | null = null;
@@ -694,6 +697,7 @@ export class ExactReviewQueue {
694697
this.storage,
695698
env.STATE_SNAPSHOTS,
696699
);
700+
this.githubEtagResponseStore = new GithubEtagResponseStore(this.storage);
697701
// Direct in-process users retain the established eager setup behavior.
698702
// A real Durable Object has blockConcurrencyWhile; defer that setup until a
699703
// non-Bay request so constructing it for the public pure reader cannot
@@ -3014,6 +3018,34 @@ export class ExactReviewQueue {
30143018
return json({ ok: true, hit: Boolean(receipt), receipt });
30153019
}
30163020

3021+
if (request.method === "POST" && url.pathname === "/github-etag-cache/lookup") {
3022+
const body = await request.json().catch(() => null);
3023+
if (!githubEtagCacheKeyFromValue(body)) {
3024+
return json({ error: "invalid_github_etag_cache_key" }, 400);
3025+
}
3026+
const entry = this.githubEtagResponseStore.lookup(body, Date.now());
3027+
return json({ ok: true, hit: Boolean(entry), entry });
3028+
}
3029+
3030+
if (request.method === "POST" && url.pathname === "/github-etag-cache/store") {
3031+
const body = await request.json().catch(() => null);
3032+
try {
3033+
const result = await this.githubEtagResponseStore.store200(body, Date.now());
3034+
if (!result.ok) return json({ error: result.error }, result.status);
3035+
return json(result, result.stored ? 201 : 200);
3036+
} catch (error) {
3037+
console.warn(`GitHub ETag cache store failed: ${sanitizedServerError(error)}`);
3038+
return json({ error: "github_etag_cache_unavailable" }, 503);
3039+
}
3040+
}
3041+
3042+
if (request.method === "POST" && url.pathname === "/github-etag-cache/confirm") {
3043+
const body = await request.json().catch(() => null);
3044+
const result = this.githubEtagResponseStore.confirm304(body, Date.now());
3045+
if (!result.ok) return json({ error: result.error }, result.status);
3046+
return json(result);
3047+
}
3048+
30173049
if (request.method === "POST" && url.pathname === "/artifact-cache/receipt/store") {
30183050
const body = await request.json().catch(() => null);
30193051
const now = Date.now();
@@ -7569,6 +7601,7 @@ export class ExactReviewQueue {
75697601
this.lifecycleTelemetryStore.ensureSchemaSync();
75707602
this.githubEgressTelemetryStore.ensureSchemaSync();
75717603
this.artifactReceiptStore.ensureSchemaSync();
7604+
this.githubEtagResponseStore.ensureSchemaSync();
75727605
let meta = this.readStorageMetaSync();
75737606
let migratedLegacy = false;
75747607
const legacy = this.storage.kv.get(EXACT_REVIEW_QUEUE_STATE_KEY) as

‎dashboard/github-egress-telemetry.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,25 @@ export class GithubEgressTelemetryStore {
323323
start,
324324
),
325325
) as Array<Record<string, unknown>>;
326-
const byUnit = { invocation: 0, wire_attempt: 0, member: 0 };
326+
const byUnit = {
327+
invocation: 0,
328+
wire_attempt: 0,
329+
member: 0,
330+
broker_lookup: 0,
331+
conditional_response: 0,
332+
};
327333
let complete = 0;
328334
let incomplete = 0;
329335
for (const row of totals) {
330336
const count = Number(row.count || 0);
331337
const unit = String(row.unit || "");
332-
if (unit === "invocation" || unit === "wire_attempt" || unit === "member") {
338+
if (
339+
unit === "invocation" ||
340+
unit === "wire_attempt" ||
341+
unit === "member" ||
342+
unit === "broker_lookup" ||
343+
unit === "conditional_response"
344+
) {
333345
byUnit[unit] += count;
334346
}
335347
if (Number(row.telemetry_complete) === 1) complete += count;

0 commit comments

Comments
 (0)