Skip to content

Derive lossless NOT NULL relaxation from durable table declarations - #2896

Merged
trissim merged 1 commit into
mainfrom
fix/derive-relaxed-fields
Oct 23, 2026
Merged

trissim merged 1 commit into
mainfrom
fix/derive-relaxed-fields

Conversation

@trissim

@trissim trissim commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Toad saves an ACP launch before its provider handshake completes. Its provider session ID therefore widens from str to str | None, but Core's durable schema derivation refuses the earlier NOT NULL declaration even though every retained row satisfies the new declaration.

Extend the existing derivation owner: TypedTable._table_sql renders an earlier declaration's required nullable fields; derive_relaxed_fields reads column names and NOT NULL flags through one typed pragma_table_info query. It rebuilds only when columns match exactly and the stored SQL equals that exact earlier declaration. Generated fields, primary keys and all other structural differences retain the existing refusal. derive_schema invokes it immediately after derive_nullable_fields.

Add one test beside the existing nullable-field derivation test: two retained values survive a durable reconcile and a third row accepts NULL. The test was not run. The only runtime check was DB(path=COPY).prepare() on a private copy of the live toad.db, using this Core head and Toad #1162. The first attempt failed during imports because this fresh worktree lacked its pinned refactor-audit submodule; no schema changed. After initializing that pinned submodule, the copy check exited 0.

Copy: /home/ts/.cache/agent-scratch/toad-nullability.qsTIUt/toad.db (0600), cp --reflink=auto from /home/ts/.local/state/toad/toad.db; no WAL/SHM files existed beside the source at copying. The new code opened only the copy. The private ccea runtime supplied dependencies, with sys.path selecting /home/ts/wt/installer-relaxed-fields/src and /home/ts/wt/installer-toad-incoming/src.

Before (0 rows):

CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "agent" TEXT NOT NULL, "agent_identity" TEXT NOT NULL, "agent_session_id" TEXT NOT NULL, "title" TEXT NOT NULL, "protocol" TEXT NOT NULL, "prompt_count" INTEGER NOT NULL, "created_at" TEXT NOT NULL, "last_used" TEXT NOT NULL, "meta_json" TEXT NOT NULL) STRICT

After (0 rows):

CREATE TABLE "sessions" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "agent" TEXT NOT NULL, "agent_identity" TEXT NOT NULL, "agent_session_id" TEXT, "title" TEXT NOT NULL, "protocol" TEXT NOT NULL, "prompt_count" INTEGER NOT NULL, "created_at" TEXT NOT NULL, "last_used" TEXT NOT NULL, "meta_json" TEXT NOT NULL) STRICT

The source copy contains no session rows; this runtime check demonstrates the schema widening, while the added unrun test exercises preservation of nonempty rows.

Required by OpenHCSDev/toad#1162. No Toad carry tool, install hook, sentinel provider ID or second sessions table. Neither PR enables auto-merge.

Assumed: writer-owned reconciliation remains the schema-change authority; exact earlier SQL excludes every other structural change; only nullable writable non-key fields can widen; the private runtime dependencies are suitable for this schema-open check, which passed; no application restart or live installation was performed.

@trissim
trissim marked this pull request as ready for review October 23, 2026 20:37
Copilot AI balanced review requested due to automatic review settings October 23, 2026 20:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown

debt-src at 086cf07, every finding:

grew BooleanChainTerms:src/agent_comms/typed_table.py +4
grew GodClassExcess:src/agent_comms/typed_table.py::TypedTable +38
grew LongBooleanChain +1

@trissim
trissim merged commit da12825 into main Oct 23, 2026
11 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants