Skip to content

Commit c75fc49

Browse files
committed
fix(calibration): cap raw-context diffs on the D1 CLI path — SQLITE_TOOBIG hit live
wrangler --command cannot bind parameters, so the UPDATE inlines the diff as literal SQL and quote-doubling can double it past D1's per-statement length (failed live at row 37 of the first cloud apply). The literal path now caps at 45KB with a self-describing truncation marker inside the diff text; the pg driver binds parameters and keeps full diffs — production is unaffected. Advances #8170
1 parent 7a8b9b6 commit c75fc49

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

scripts/backfill-calibration-corpus-phase2.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,13 @@ async function runRawContextPass(args: Args, budget: RequestBudget, state: Curso
440440
state.rawContextResumeFrom = row.target_key;
441441
continue;
442442
}
443-
const patched = patchFiredMetadataWithDiff(row.metadata_json, await diffResponse.text());
443+
const diffText = await diffResponse.text();
444+
// The D1 CLI driver inlines the UPDATE as literal SQL (wrangler --command cannot bind parameters), and
445+
// quote-doubling can double the payload: a full 120KB diff exceeds D1's per-statement length
446+
// (SQLITE_TOOBIG, hit live at row 37 of the first cloud apply). Cap the literal path with a
447+
// self-describing marker; the pg driver binds parameters and keeps the full bound diff.
448+
const bounded = pgSession || diffText.length <= 45_000 ? diffText : `${diffText.slice(0, 45_000)}\n[diff truncated: D1 CLI statement-length limit]`;
449+
const patched = patchFiredMetadataWithDiff(row.metadata_json, bounded);
444450
if (patched === null) {
445451
report.alreadyPatched += 1;
446452
} else if (args.apply) {

0 commit comments

Comments
 (0)