fix: Ralph loops ignore approved reviews and always run all iterations#109
Conversation
…Outputs
bun:sqlite does not reliably honor drizzle's { mode: "boolean" } mapping,
returning raw INTEGER 0/1 instead of JS true/false. This causes strict
equality checks like `ctx.latest(schema, nodeId)?.approved === true` to
fail (since 1 === true is false in JS), which prevents Ralph loop `until`
conditions from ever being satisfied.
After loading output rows via drizzle, detect boolean-mode columns and
coerce their values to proper JS booleans.
|
Worth noting: |
|
The CI |
Bug Reproduction ResultsI wrote a dedicated test file ( Finding: drizzle 0.45.1 already coerces boolean-mode columnsOn our current stack ( However, raw So the bug described in this PR is real for any code path that bypasses drizzle's mapper (e.g. raw Test Coverage Added (10 tests, all passing)Minimal unit tests (raw bun:sqlite gap):
Type fidelity for non-boolean columns (ensures the fix doesn't over-coerce):
Ralph loop integration test:
Full test suite: 773 pass, 0 failThe existing test suite continues to pass with the new tests included. AssessmentThe explicit coercion in this PR's
The fix is safe (the added tests confirm non-boolean types like integers, strings, and nulls are not affected), so this is a reasonable hardening even though drizzle 0.45.1 currently handles it. |
Problem
When using Ralph loops with a review step, the loop keeps running all
maxIterationseven after the review approves. For example, if you have:The review task approves on iteration 0, but iterations 1 and 2 still run — wasting time and compute on redundant fix+review cycles that just confirm "everything is already fixed."
Root cause
bun:sqlitereturns raw INTEGER0/1for columns that drizzle declares with{ mode: "boolean" }. In JavaScript,1 === trueisfalse. Soctx.latest(reviewResult, "review1")?.approved === truealways evaluates tofalse, and theuntilcondition is never satisfied.Fix
In
loadOutputs(src/db/snapshot.ts), after reading rows from the database, detect boolean-mode columns and coerce0/1to proper JSfalse/true.Test plan
bun run test