Skip to content

fix(driver-turso): remote ADD COLUMN on a populated table adds a storage.notNull column nullable and reports tighten_not_null - #37343

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37281-turso-remote-add-notnull-nullable
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-37281-turso-remote-add-notnull-nullable

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Alice · project thread
Fixes #37281

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:托管云数据库上,作者给已有数据的对象新增一个带列约束的必填字段后升级,该对象照常同步、照常可写;这一列先按可空加上,迁移报告里提示需先回填再收紧,与本地数据库的行为一致。
  • 为什么做:今天这样升级会让托管环境里整个对象同步失败、不可写,而字段说明承诺的是「先回填、经迁移流程收紧」;本地那一半上一轮已修好,这是剩下的云端一半。
  • 出错会怎样:只影响给已有数据的表加列这一步;万一判断错,最坏是列多一个收紧提示,数据不会坏,可直接撤回。
  • 要你做什么:无。

What changes

  • RemoteTransport.columnDeclarationSQL (remote-transport.ts) stays the one renderer and takes one more flag, addedToPopulatedTable. When it is set and the field declares storage.notNull with no literal or NOW() default, the column is rendered without NOT NULL. This is the same decision the local face's createColumn makes (PR fix(driver-sql): a storage.notNull field added to a populated table is added nullable and reported as tighten_not_null #37279).
  • Both ADD COLUMN doors ask whether the table holds a row with SELECT 1 FROM "t" LIMIT 1, and only when a column about to be added declares storage.notNull (addsNotNullColumn). syncSchema sends one statement. syncSchemasBatch sends ONE extra read batch covering every such table, between the column introspection and the DDL batch. A sync that adds no such column sends nothing extra, so the steady-state round-trip count is unchanged.
  • declaresEmittedColumnDefault is the remote twin of driver-sql's emitsDeclaredColumnDefault, composed from the same two spec predicates (isNowDefaultToken, isRuntimeDefaultToken) in the same order. It is a twin because driver-sql does not export that predicate and the claimed file surface is driver-turso only. See Acceptance notes.
  • The drift report needed no new code. The shared differ already compares the column against storage.notNull, so the nullable column shows up as tighten_not_null on the remote face's own detectManagedDrift. Measured: the PM's Zone 2 assumption holds.
  • Docblocks: the columnDeclarationSQL section "ADD COLUMN on a table that already holds rows" is rewritten to the storage.notNull contract. The stance "Never drop the NOT NULL" from driver-turso remote face: create table and add column never emit NOT NULL, so storage.notNull is unenforced and every such field reads as destructive drift #23847 now applies only to the literal/NOW() default case, where the local face keeps the constraint. The syncSchemasBatch round-trip docblock now counts five possible calls.
  • turso-driver.ts: REMOTE_DRIFT_REPORT_CAVEAT and its docblock now also name the populated-table add as a source of tighten_not_null this face's own sync produces. Its "the sync creates it now" clause stopped being the whole story after this change. The only pin on it is stringContaining('NOT NULL').

Tests

turso-remote-not-null.test.ts, case 4 (the KNOWN ASYMMETRY note is removed). There is a describe.each over two defaults that fill no row (none, and the current_user token) and an it.each over local / syncSchemasBatch / syncSchema. Every cell asserts the same answer: plain, added and multi-value added_tags all have notnull 0, and tighten_not_null covers exactly added and added_tags. A create providing the columns then succeeds and reads back. A new batch cell syncs a populated table and an empty table in one syncSchemasBatch and checks each answer: the populated table gets nullable plus tighten_not_null, and the empty table gets NOT NULL with no drift.

Case 5 (RECORDED ASYMMETRY, a literal defaultValue) is unchanged and still passes: the local face accepts it as NOT NULL, and this face still refuses.

Fix at head 056bae7
pnpm --filter @objectstack/driver-turso exec vitest run --maxWorkers=2 src/turso-remote-not-null.test.ts
 Test Files  1 passed (1)
      Tests  15 passed (15)
os-verify-lock: VERDICT command-exit 0

pnpm --filter @objectstack/driver-turso typecheck && pnpm --filter @objectstack/driver-turso exec vitest run --maxWorkers=2
 Test Files  104 passed | 1 skipped (105)
      Tests  2657 passed | 36 skipped (2693)
os-verify-lock: VERDICT command-exit 0

The typecheck program includes the test file (tsc --noEmit --listFiles: 1 hit).

Ablation (scripts/ablation-replace.mjs): the populated-table guard removed, red, then restored to the HEAD blob
anchor "      && !(addedToPopulatedTable && !declaresEmittedColumnDefault(field));"  x1 -> x0
replace "      && true;"  x0 -> x1
ok mutation landed: anchor 1 -> 0, blob b6abce46b1c9 -> 7262586662a3
Tests  5 failed | 10 passed (15)   (the 4 remote cells of case 4 + the batch cell; every local cell stays green)
command exited 1
ok restored: blob == HEAD (b6abce46b1c9) and `git diff HEAD` is empty

This suite imports TursoDriver from src/, and remote-transport.ts is reached by a relative import with no package exports hop, so the mutation needed no rebuild.

Acceptance notes

  • The remote face can report the tightening but cannot apply it. REMOTE_DRIFT_OP_ANSWERS.tighten_not_null is needs-table-rebuild (migrate plan on a Turso remote primary: a tighten_not_null (and every column entry the remote face cannot apply) is printed with the remedy os migrate apply --allow-destructive, which then names it as not applied and exits 1 #23925), so os migrate apply --allow-destructive on a remote database names the entry as not applied, and driftReportCaveat already says the report is for reading. This is an existing declared limit of the face, and this PR does not widen it. Before this change, the object's sync failed outright.
  • Literal/NOW() default on a populated table (case 5). This still refuses on the remote face, because the face emits no declared column DEFAULT. This PR keeps it as case 5 records it, as the card's acceptance asks ("default-carrying fields keep NOT NULL"). Closing it means deciding whether, and from which shared source, the remote face emits declared defaults. If that is owed, it is a separate card for the seat to file.
  • Twin predicate. declaresEmittedColumnDefault restates driver-sql's emitsDeclaredColumnDefault (4 lines, same spec predicates, same order). The shared form would be to export it from @objectstack/driver-sql and import it here. That is outside the claimed surface and would move driver-sql's published exports, so it is not done here. The current_user cell of case 4 and case 5 hold the two faces to one answer for the token and literal kinds.
  • A rows-then-ALTER race (a row inserted between the probe and the ALTER) fails the way main fails today, as on the local face. It is not widened.

Verification

Read first: remote-transport.ts columnDeclarationSQL (the notNull line and its rewritten docblock), then the two call sites in syncSchema and syncSchemasBatch (phase 2c), then case 4 of turso-remote-not-null.test.ts.

Two-minute check: pnpm --filter @objectstack/driver-turso exec vitest run src/turso-remote-not-null.test.ts. Expect 15 passed, with [schema-drift] rows_t.added: metadata declares storage.notNull but the column is nullable lines printed by the remote cells.

Gates (head 056bae7)

试行偏离 (maintainer-authorized trial, 2026-11-25): only a local subset ran. It is the driver-turso tests and typecheck above, plus these families. Every other derived family is cited from this PR's CI check-runs. There was no in-session wait on CI.

Local gate readings at 056bae7
  • pnpm check:type-check-coverage exit 0; pnpm check:type-check-debt exit 0 (surplus: none).
  • pnpm check:doc-authoring, check:issue-citations, check:nul-bytes, check:closed-ceremony-text, check:durability-log-level, check:published-files: all exit 0.
  • check-empty-changeset, check-changeset-no-major, check-adr-0087-registration (--base origin/main): all exit 0.
  • check-platform-checklist --changed-from origin/main: 0 anchored files in the change set, nothing judged.
  • dispatch-gates --ran: 72 derived, 11 run, 0 NOT-MEASURED, 61 UNRUN. The 61 are left to CI under the trial.

Generated by Claude Code

@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/driver-turso, touching 8 documentable anchor(s).

4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/data-modeling/drivers.mdx (via syncSchema (symbol, a method of class RemoteTransport), syncSchemasBatch (symbol, a method of class RemoteTransport))
  • content/docs/data-modeling/virtual-objects.mdx (via syncSchema (symbol, a method of class RemoteTransport))
  • content/docs/protocol/kernel/lifecycle.mdx (via syncSchema (symbol, a method of class RemoteTransport))
  • content/docs/protocol/objectql/types.mdx (via syncSchema (symbol, a method of class RemoteTransport))

⛔ 1 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/implementation-status.mdx (via syncSchema (symbol, a method of class RemoteTransport))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 8 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json a182fbe37765ab486f3aa5e372ffa9d6af1f6758 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from a128500eae27f1ee67dfcbe0a6795c41cc19d4ab — the merge of head 056bae7f5ffdb12c18d6b6943811ebc9d445cb5a into base a182fbe37765ab486f3aa5e372ffa9d6af1f6758, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a128500eae27f1ee67dfcbe0a6795c41cc19d4ab && git checkout a128500eae27f1ee67dfcbe0a6795c41cc19d4ab
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin a182fbe37765ab486f3aa5e372ffa9d6af1f6758 056bae7f5ffdb12c18d6b6943811ebc9d445cb5a && git checkout -B drift-repro a182fbe37765ab486f3aa5e372ffa9d6af1f6758 && git merge --no-ff 056bae7f5ffdb12c18d6b6943811ebc9d445cb5a

node scripts/docs-audit/affected-docs.mjs --json a182fbe37765ab486f3aa5e372ffa9d6af1f6758

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs a182fbe37765ab486f3aa5e372ffa9d6af1f6758 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · os-alice · session_011y7As8wf3DSPRevwNnYLcM

席位意见:ACCEPT,排队落地。

席位核对 — ACCEPT · head 056bae7 (2026-11-25T20:11Z)

  1. Shape: 4 files, all inside the claimed surface (packages/drivers/driver-turso/src/** + one patch changeset): remote-transport.ts, turso-driver.ts (drift caveat text only), turso-remote-not-null.test.ts, .changeset/37281-…md. +187/-62. Fixes #37281 delivers all three acceptance bullets (both doors add nullable on a populated table with tighten_not_null reported; case 4 one outcome for local and both remote doors, asymmetry note removed; docblock rewritten to the storage.notNull contract). Not governed (check-governed-merges --pr 37343), no narrowing arm, no !. Clause-②: no holds: no export or accept-set widening beyond the contract text quoted in the claim.
  2. Premise measured: read in the diff: columnDeclarationSQL stays the one renderer and drops NOT NULL only when addedToPopulatedTable && !declaresEmittedColumnDefault(field); the probe (SELECT 1 … LIMIT 1) is sent only when an added column declares storage.notNull (one statement in syncSchema, one extra read batch in syncSchemasBatch). CREATE TABLE, empty-table ADD COLUMN and tenant columns unchanged. The new batch case pins a populated and an empty table in one batch getting different answers. Dev's ablation of the anchor turns the 4 remote case-4 cells + the batch cell red (report 7172805674).
  3. Gates: at this head 37 success, 16 expected skip, 0 failed, 0 pending (l1-face all-checks). l1-face CLEAN, 13 items. landing-k: K = 0 < 15.
  4. Accepted deviations: 试行偏离 (fresh agent, no in-agent CI wait, local runs limited to driver-turso tests/typecheck + 11 derived families, rest read from CI at this head; dev ran l1-face). turso-driver.ts edit is inside the surface though not named in the claim: the REMOTE_DRIFT_REPORT_CAVEAT clause would have become incomplete. declaresEmittedColumnDefault is a 4-line twin of driver-sql's unexported predicate, built from the same two spec predicates and held to parity by case 4 (current_user) and case 5; sharing it would cross the claimed surface — accepted, noted, not filed.
  5. Out of scope: case 5 (storage.notNull + literal/NOW() default on a populated table: local accepts, remote refuses, the remote face emits no declared DEFAULT) filed driver-turso remote: a storage.notNull field with a literal defaultValue, added to a populated table, is refused remotely and accepted locally (the remote face emits no declared column DEFAULT) #37345 (finding, area:data). Skills-docs: not owed. Changeset read sentence by sentence: matches the diff (populated-table add nullable + drift, os migrate apply cannot impose it remotely, empty/create/default-carrying keep NOT NULL, required unaffected, one extra read only when needed).
  6. Landing: ordinary queue landing by the seat via label-write --land; the card closes on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants