Skip to content

Commit 5db8f4d

Browse files
mstrathmanclaude
andcommitted
feat: fit()/predict()/backtest() SQL surface + hardened training core
Reshape the tabular and evaluation surface into the scikit-learn shape agents guess, and extract and harden the native-student training core that backs it. Surface: - fit(f1, ..., fN, label [, options]) is an aggregate over the caller's rows and returns a registered model id or a serialized blob; predict(model, f1, ..., fN [, options]) is a scalar serving one prediction per row (deserialized once, cached on the model argument). The label is the last positional argument; the optional trailing '{...}' is always the options object. - backtest(ts, value, horizon [, options]) is an aggregate (matching forecast / detect_anomalies) that runs rolling-origin evaluation and returns one JSON document; backtest_rows() expands it into typed rows. The old TVF is renamed predict_batch. - The tabular training core (tree / gradient-boosted / MLP fitters) moves to predict-train.{c,h}, shared by fit() and the distill recipes. Correctness and safety hardening (a thorough review pass, fixed at the root and swept across every sibling, not only where first flagged): - Memory safety: a compile-time assert that predict()'s feature buffer holds any student the loader admits; re-fetch after sqlite3_set_auxdata to avoid a use-after-free; propagate OOM through the row-cursor mprintf paths instead of silent NULL columns; 64-bit sizing for model-scaled allocations; bounded, overflow-safe onnx io_spec arrays (a 32-bit-wasm overflow); a fit() training-set cap. - Determinism: total-order split comparators so the tree, and its content_hash, are identical across platforms/libc (no reads of uninitialized task-union fields). - Fail loud, never silently: reject non-finite features/labels/teacher cells and NULL labels; surface malformed-JSON parse errors, prepare failures, and mid-read step errors; preserve distinct error codes; cap the classifier vocabulary at PREDICT0_MAX_CLASS during interning and parsing; require a positive json-array cap rather than a silent-unbounded footgun. - The receipt tool's operation taxonomy is restructured (aggregate vs row-shaped, with the *_rows TVFs first-class and wrapper-aware inference). Tests: adversarial coverage for the new surface and every hardening path (malformed/oversized/boundary/non-finite inputs asserting concrete PREDICT_ERR_* codes); the corrupt-blob tests now supply a matching content hash so they reach the bounds-checked deserializer; the C soak drivers assert row counts and the specific error code per branch, and propagate statement failures to the exit code. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cb86af3 commit 5db8f4d

25 files changed

Lines changed: 3290 additions & 1787 deletions

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ prefix?=dist
3737

3838
TARGET_LOADABLE=$(prefix)/predict0.$(LOADABLE_EXTENSION)
3939

40-
OBJS=sqlite-predict.c predict-forecast.c predict-registry.c predict-tabular.c predict-student.c predict-distill.c vendor/sha256.c
40+
OBJS=sqlite-predict.c predict-forecast.c predict-registry.c predict-tabular.c predict-student.c predict-train.c predict-distill.c vendor/sha256.c
4141
ONNX_OBJS=$(OBJS) predict-onnx.c
4242

4343
# onnxruntime is a build+runtime dependency of the loadable-onnx variant

0 commit comments

Comments
 (0)