Skip to content

driver-sql on SQLite: a boolean field retyped from text keeps a TEXT column, so create() stores false as '0.0' and find() and distinct() then read it as true #35341

Closed

Description

@objectstack-fleet

repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

Filing gate: ② out-of-scope finding (class a, named producer) from the os-dev report on #34974 (comment 7000733773, PR #35332), measured live on SQLite in the driver's own tests.
Reader: domain:server (packages/drivers/driver-sql). Suggested-grade: p2 · data wrong × rare (a stored false reads as true on a field whose type was changed from text to boolean).
Dedupe: TEXT affinity boolean, boolean retyped column sqlite, presentStoredBoolean in open issues: only #34974 (the read presenter, which this does not cover) and #35084 (backfill on Turso remote), neither covers this.

维护者速读

  • 现象:在 SQLite 上,把一个字段的类型从「文本」改成「是/否」后,数据库列仍是 TEXT。之后驱动自己写入 false 会存成文本 '0.0'、true 存成 '1.0',读回来时两者都显示为「是」,去重和分组也都算成「是」。按 = false 过滤还会漏掉启动时收敛写入的 '0' 行。
  • 影响:改过字段类型的老应用,在 SQLite(本地/单机)上看到错误的是/否值。
  • 修法要先定:是让共用的读取函数也认 '0.0' / '1.0'(会改变 find() 的结果),还是在写入或启动时把这种列的存储收敛成整数。
  • 需要你做的:无(分诊定级)。

Facts (measured by the #34974 dev on SQLite)

  • A field retyped from text to boolean keeps declared column type TEXT after initObjects (pragma_table_info reads TEXT before and after).
  • SqlDriver.create(p, { flag: false }) / { flag: true } store the text '0.0' / '1.0': better-sqlite3 binds the JS number as REAL and TEXT affinity keeps it as text.
  • find() presents both as true: presentStoredBoolean('0.0') (packages/drivers/driver-sql/src/sql-driver-sqlite-serialisation.ts) falls through to Boolean('0.0'). distinct() answers [true] (after PR fix(driver-sql): distinct and aggregate group keys present a text boolean as find() does #35332, which routes distinct / aggregate through the same function).
  • On the same column, a flag = false filter misses the text '0' rows that the boot convergence (backfillCanonicalBooleans, PR fix(driver-sql): boot converges legacy text booleans on SQLite to 1 / 0 #35076) leaves.
  • Not measured at the HTTP door.

Ask

Measure at the data door first (create through REST on a retyped field, read back). Then pick one route with a pin: (A) the shared presenter and the filter accept '0.0' / '1.0'; or (B) the write binds a boolean as an integer the column keeps as 0 / 1, plus boot convergence of existing '0.0' / '1.0' text. Pins: a retyped TEXT column, create false and true, find() / distinct() / = false filter all agree; CONTROL: an INTEGER boolean column unchanged. Ablate red.

Order: after PR #35332 (same files).

Related: #34974 / PR #35332, #34973 / PR #35076, #34916 / PR #34965, #35084.

⛔ Not a claim.

Activity

  1. added
    priority:p2
    pm:queue
    finding
    domain:server
    on Nov 19, 2026
  2. objectstack-fleet commented on Nov 19, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

    Claim: PM loop round 13 · area data-1 (the maintainer, verbatim, 2026-11-19T04:35Z project chat: 「再开 area:data」; standing 「暂时都只派 p1 p2 的卡」) · 2026-11-19T11:16Z
    Area: data-1
    Session: session_01Utp6Ca1jJvsA1dHsPwMiQb
    Account: os-bill
    Branch: claude/issue-35341-sqlite-retyped-boolean
    Worktree: objectstack-issue-35341 (os-dev worktree in the data-1 container)
    Domain: domain:server
    Seat: repo:objectstack#5
    File surface: packages/drivers/driver-sql/src/** (the SQLite boolean write bind, sql-driver-sqlite-serialisation.ts, and the boot convergence in sql-driver-schema-sync.ts / sql-driver.ts if route B), a new test in packages/drivers/driver-sql/src/ named for this card, root .changeset/. Anything outside driver-sql is reported before widening. Stop on breach and report.
    Container & model: M, mode:subagent, model: default — no path-derived mandate, effort: high
    Clause-②: no (a stored false that reads as true is a wrong answer; measure on the diff)
    Metadata-protocol: none
    Responsibility: platform — on SQLite, a field retyped from text to boolean keeps a TEXT column, so create() stores '0.0' / '1.0' and find() / distinct() read both as true; any app that changed a field's type to boolean on SQLite.
    Thread-read: none
    Premise: measured by the #34974 dev on SQLite (report 7000733773); the dev re-measures at the data door first. PR #35332 (same files) has merged.
    Serial constraints cleared: #34974 / PR #35332 merged; no open PR holds driver-sql's SQLite boolean path.
    Pre-claim lane: domain:server (packages/drivers/driver-sql/**)
    Pre-claim deps: PR #35332 merged; PR #35076 (boot convergence) merged.
    Prior rulings read: #34973 / PR #35076 boot convergence to canonical booleans; #34916 / PR #34965; thread: none

  3. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 19, 2026
  4. objectstack-fleet commented on Nov 19, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb
    os-dev-report

    {
     "issue": 35341,
     "status": "done",
     "branch": "claude/issue-35341-sqlite-retyped-boolean",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/35511",
     "head": "af25ec33ef9b5f4adac57664ab038caf738f398b",
     "session": "session_01Utp6Ca1jJvsA1dHsPwMiQb",
     "premise_still_valid": true,
     "route": "B, no read-side backstop. The write (formatInput) and the boolean comparand (coerceFilterValue) of a declared scalar boolean on SQLite bind the text '1' / '0' (sqliteBooleanBinding): NUMERIC affinity folds it to INTEGER 1 / 0 (unchanged storage for driver-created columns), TEXT affinity keeps '1' / '0', the spelling backfillCanonicalBooleans writes and presentStoredBoolean reads. SQLITE_LEGACY_BOOLEAN_TEXT (backfill count, sample, UPDATE, os migrate plan preview) now also selects '1.0' / '0.0'. Why: find(), distinct() and = false agree on new and converged existing rows without widening the presenter (Prime Directive 12), matching PR #35076's one-canonical-spelling direction. BigInt was rejected: it binds INTEGER but knex's query formatter throws on it (measured: 'str.replace is not a function').",
     "readings": {
      "A0": "Reproduced at the REST data door on origin/main 6f36818f03: todo example on a better-sqlite3 file DB, field booted as text then retyped to boolean; pragma_table_info reads TEXT after the retype boot; POST /api/v1/data/todo_task probe_flag:false answers 201 with probe_flag:true, cell '0.0' (true: '1.0'); list reads both true; probe_flag=false filter returns the false row presented as true. After the fix (driver-sql rebuilt at af25ec33ef, same DB file): boot rewrote the rows to '0' / '1'; POST false answers false and stores '0'; list [door_false,false],[door_true,true],[post_false,false],[post_true,true]; = false returns exactly door_false, post_false.",
      "A1": "Confirmed. knex 3.3.0 client-better-sqlite3 _formatBindings maps a boolean to Number(b); better-sqlite3 13.0.3 binds a JS number as REAL; TEXT affinity stores '0.0' / '1.0'. The driver had no boolean conversion in formatInput. Measured at main on create, update, bulkCreate, updateMany (all '0.0' / '1.0' on TEXT; 0 / 1 integer on an INTEGER-form column); post-fix pin covers six doors (adds upsert, bulkUpdate), all through formatInput.",
      "A2": "backfillCanonicalBooleans writes integer 1 / 0, which a TEXT column stores as the text '1' / '0'. '0.0' / '1.0' were NOT in its population: counted as withheld; a reboot at main logged 'left 7 row(s) of probe_35341.flag unconverted' and changed nothing.",
      "A3": "presentStoredBoolean: 'false'/'0' -> false, 'true'/'1' -> true, else Boolean(value), so '0.0' -> true. The = false comparand (JS false -> REAL 0.0) compared as '0.0' on the TEXT column: matched the '0.0' rows and missed the '0' row the convergence left; on an INTEGER column it matched 0."
     },
     "summary": "On SQLite a text field retyped to boolean keeps a TEXT column and every driver write stored false/true as '0.0'/'1.0', which find()/distinct() read as true. The SQLite write bind and filter comparand of declared scalar booleans now use the text '1'/'0' (INTEGER 1/0 on driver-created columns, unchanged; '1'/'0' on TEXT columns), and the boot convergence also rewrites existing '1.0'/'0.0' rows. Measured before and after at the REST door and pinned at the driver with a CONTROL integer column; each of the three mechanisms ablated red.",
     "files_changed": [
      ".changeset/35341-sqlite-retyped-boolean-text-column.md",
      "packages/drivers/driver-sql/src/sql-driver-35341-retyped-boolean-text-column.test.ts",
      "packages/drivers/driver-sql/src/sql-driver-filter-helpers.ts",
      "packages/drivers/driver-sql/src/sql-driver-schema-sync.ts",
      "packages/drivers/driver-sql/src/sql-driver-sqlite-serialisation.ts"
     ],
     "line_budget": "+271 / -13 over 5 files (changeset 14, test 199, filter-helpers +9/-2, schema-sync +15/-10, serialisation +34/-1); under the 3000-line human-merge threshold; sql-driver.ts untouched",
     "tests": "New pin src/sql-driver-35341-retyped-boolean-text-column.test.ts: 'Test Files 1 passed (1) / Tests 11 passed (11)'. Ablation via scripts/ablation-replace.mjs (test imports src; no dist on the path): arm 1 write bind removed, blob 70f2a4d38a7c -> aadb818335c5, '5 failed | 6 passed', restored blob == HEAD; arm 2 comparand branch removed, 21ac54f81c71 -> 528a57d1a45e, '3 failed | 8 passed', restored; arm 3 convergence predicate reverted to ('true','false'), 66b443f687f8 -> 3886962a9261, '3 failed | 8 passed', restored; CONTROL green in every arm. pnpm --filter @objectstack/driver-sql test (lock VERDICT command-exit 0, tree 5d191faf28; af25ec33ef adds only the changeset): 'Test Files 265 passed | 13 skipped (278) / Tests 4408 passed | 257 skipped (4665)'. pnpm --filter @objectstack/driver-sql typecheck exit 0 (include src/**/*, test compiled). Public surface unchanged (sqliteBooleanBinding is not exported from the package index), so no import-side tests owed.",
     "gates": "Local: dispatch-gates.mjs --commands --repo objectstack-ai/objectstack on head af25ec33ef derived 68 families for 5 paths; 66 exit 0; 2 NOT MEASURED (exit 3 PREREQUISITE NOT MET): pnpm check:dual-build-cjs-loads (needs whole-repo dist) and pnpm check:type-check-debt (its re-measure build got exit 99 on the shared lock). --ran reconciliation: '✓ dispatch-gates --ran: 68 derived famil(ies) accounted for — 66 run, 2 NOT-MEASURED'. check:nul-bytes exit 0 (in the 66). overlap-check.mjs --branch=HEAD: 'VERDICT clean exit 0' before each push. CI check-runs on PR #35511: in_progress at report time (not awaited, per os-dev.md).",
     "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
     "deviations": [
      "driver-sql typecheck ran outside the verify lock after about 27 min of queue-timeouts (3 x exit 99) behind a dogfood holder (pid 4250, pnpm --filter @objectstack/dogfood test); declared narrowing; the build and the full test ran under the lock",
      "A0 required a scratch, uncommitted edit to examples/app-todo/src/objects/task.object.ts (outside the claim's file surface) to boot a text field then retype it; reverted with git checkout HEAD, git status clean before the gate run; not in the diff",
      "2 derived gate families NOT MEASURED locally (above); CI's Lint & Repo Gates runs both",
      "commit trailers model-free per the dispatch order (Co-Authored-By: Claude plus Claude-Session), not the harness reminder's model-bearing form",
      "PR body Acceptance note: the sqlite-wasm / turso effect is reasoned from sql.js's integer bind, not measured"
     ],
     "mcp_calls": "0",
     "api_writes": "2 relay strokes (objectstack-fleet[bot]): pr_create (POST /repos/objectstack-ai/objectstack/pulls draft, POST /repos/objectstack-ai/objectstack/issues/35511/assignees os-bill); os-dev-report comment (POST /repos/objectstack-ai/objectstack/issues/35341/comments). Plus 3 git pushes of the branch (empty probe, fix, changeset), not REST.",
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": []
    }
  5. objectstack-fleet commented on Nov 19, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#5 · os-bill · session_01Utp6Ca1jJvsA1dHsPwMiQb

    Close-out 2026-11-19T14:27Z: PR #35511 merged, and Fixes closed this card.

    On SQLite, a text field retyped to boolean now stores and filters a saved false as false. It took route B, the card's Ask. The driver binds a JS boolean as the text '1' / '0' on write and on a filter comparand, and the boot convergence also rewrites the legacy '1.0' / '0.0' rows. find(), distinct() and = false / = true / $in / $ne agree on new and existing rows. A boolean column the driver created keeps its INTEGER 1 / 0 (CONTROL).

    The fix was measured at the REST data door before and after. It is pinned 11/11, with one ablation arm per mechanism.

    L1-a ACCEPT 7010360361 accepted that sqlite-wasm and turso inherit the bind, since column affinity decides the stored form. pm:dispatched off.

  6. removed
    pm:dispatched
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:datadomain:serverfindingpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions