Files
reverse-engineering-anything/src/sqlite/SqliteDatabaseLimits.ts
T
morluto a5c71e8c88 fix(limits)!: let inspect_sqlite_database take producer_limits.input_bytes and type SQLite, Kuna and web-bundle refusals (#14627)
* fix(limits)!: let inspect_sqlite_database take producer_limits.input_bytes and type SQLite, Kuna and web-bundle refusals

The SQLite snapshot refused a database and WAL above a fixed 256 MiB. The copy
streams to private disk, so inspect_sqlite_database now accepts
producer_limits.input_bytes (default 256 MiB) and reports details.limit for it.

Refusals that carried recovery only in prose are typed: SQLite's result-column
limit and the 16 MiB value/statement/reply allowance as fixed ceilings, occupied
SQLite slots and live Kuna and web-bundle heap headroom as measured exhaustion,
and the Kuna cache capacity as the REA_KUNA_CACHE_MAX_BYTES environment control.
The SQLite worker diagnostic capture is reclassified as protocol.

BREAKING CHANGE: the SQLite snapshot refusal reports details.limit for
producer_limits.input_bytes, and the SQLite column and reply refusals carry a
fixed_ceiling refusal in place of their authored remediation.

* fix(sqlite): keep producer_limits in Evidence parameters and report the effective input bound
2026-11-25 23:09:10 -05:00

75 lines
2.6 KiB
TypeScript

import { SQLITE_DATABASE_OUTPUT_BYTES } from "../domain/sqlite/sqliteDatabase.js";
/** Bound frozen input, retained JSON and worker allocation before parsing untrusted files. */
export const SQLITE_DATABASE_LIMITS = {
concurrentInspections: 2,
outputBytes: SQLITE_DATABASE_OUTPUT_BYTES,
diagnosticBytes: 1024 * 1024,
/** V8 old-space ceiling for the owned worker, passed as --max-old-space-size. */
workerHeapMiB: 256,
} as const;
/** The owned worker's JavaScript heap ceiling in bytes, as reported on memory refusals. */
export const SQLITE_WORKER_HEAP_BYTES =
SQLITE_DATABASE_LIMITS.workerHeapMiB * 1024 * 1024;
/**
* Failure reasons the worker protocol may carry. The reply schema and the
* worker's own failure type read this one list, so a refusal that the worker
* can emit cannot be one the client refuses to parse.
*/
export const SQLITE_INSPECTION_REASONS = [
"malformed",
"selection",
"column-selection",
"row-offset",
"column-evaluation",
"row-evaluation",
"column-limit",
"unsupported",
"unavailable",
"output-limit",
"memory",
] as const;
export type SqliteInspectionReason = (typeof SQLITE_INSPECTION_REASONS)[number];
/** Reasons that carry their own reply fields rather than a bare message. */
export const SQLITE_STRUCTURED_INSPECTION_REASONS = [
"column-evaluation",
"column-limit",
] as const;
/** Internal rejection retains the failed boundary without returning partial success. */
export class SqliteInspectionFailure extends Error {
constructor(
readonly reason: SqliteInspectionReason,
message: string,
) {
super(message);
}
}
/** Selected generated cells the private connection cannot compute; the database stays readable. */
export class SqliteColumnEvaluationFailure extends SqliteInspectionFailure {
constructor(
message: string,
/** Selected or stored columns that remain readable without the failed expressions. */
readonly readableColumns: readonly string[],
) {
super("column-evaluation", message);
}
}
/** A projection above this connection's result-column capacity; the database stays readable. */
export class SqliteColumnLimitFailure extends SqliteInspectionFailure {
constructor(
message: string,
readonly selectedColumns: number,
readonly engineColumnLimit: number,
) {
super("column-limit", message);
}
}
/** SQLite's primary result code for a native node:sqlite failure, if it carries one. */
export const sqlitePrimaryResultCode = (cause: unknown): number | undefined =>
cause instanceof Error &&
"errcode" in cause &&
typeof cause.errcode === "number"
? cause.errcode & 0xff
: undefined;