Skip to content

objectql: a cleared optional unique lookup or select still stores '' and the second cleared record is refused 409 UNIQUE_VIOLATION #29277

Closed

Description

@objectstack-fleet

domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

Filing gate: ① out-of-scope finding of the #29176 dev (os-dev-report 6575284496, out_of_scope_findings class a), measured at PR #29271's head 28fb6173; kept out of that PR because the $empty ruled table reads '' as a value on single select / lookup, so it needs its own ruling. Filed by domain:server seat 3. ⛔ Not a claim. Suggested-grade: p2 · the sibling of #29176 on the non-text types.

Reach: any object with an optional lookup or select field declared unique (or in a unique indexes[] entry), when two records are saved with that field cleared; the console sends '' for a cleared lookup / select.
Reader who acts: a domain:server seat (packages/objectql/src/validation/record-validator.ts, the write door #29176 extended), after a ruling on the $empty reading.

What happens (dev's scratch probe on SQLite at 28fb6173)

Wanted

A ruling first: does a cleared single select / lookup mean "no value" (store null, and the $empty table's reading of '' for those types moves with it), or is '' a legitimate stored value there? Then either extend the #29176 write-door arm to those types on unique-covered optional columns, or make the console send null when cleared. Report which readers depend on '' before choosing.

Dedupe: searched unique lookup cleared UNIQUE_VIOLATION, unique select empty string 409; only #29176. New.

Links back: #29176, PR #29271.

Activity

  1. added
    finding
    on Nov 2, 2026
  2. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    triage#1 · os-zhuang · session_01AavokzJ5DndAwitDXvKy4U

    Path: none

    Triage: p2 · domain:server · area:records · pm:queue · 2026-11-02T10:56Z

    ⛔ Not a claim.


    Generated by Claude Code

  3. added
    area:records
    domain:server
    pm:queue
    priority:p2
    and removed
    finding
    on Nov 2, 2026
  4. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Claim: PM loop round 1 · card thread · 2026-11-02T12:16Z
    Session: session_01ADHkmQJdgarUjPLNgFBY67 (the seat); the card thread is session_01ADHkmRPC4f86r9bWGuYWJu
    Account: os-steve (the seat's linked user; the card's assignee)
    Branch: claude/project-thread-uzstmh
    Worktree: the card thread's own container checkout
    Domain: domain:server
    Seat: domain:server#3
    Ruling-ref: the maintainer, verbatim, in the project thread: 「开 server 2、3、5 号席位, 前任已经下班,接手所有开发,包括跟进之前未完成的开发落地。」
    File surface: packages/objectql/src/validation/record-validator.ts (the normalizeBlankTypedValues blank-value arm only, for lookup / select on unique-covered optional columns) + tests; ⛔ not the BOUNDED_STRING_FIELD_TYPES string arm (seat 1, #29241) nor the select value-shape check (seat 1, #29244)
    Container & model: card thread cmsg_01FdL1XeUyvVNxLreh3F4Qi9CGzC168tQ8WTbgReWZVSo4, mode:thread, model: opus (--tier names no path mandate: PM's call, default), effort: high
    Clause-②: no if no reader answer moves; if the $empty reading would move, no code: a needs-user-decision card instead
    Metadata-protocol: none
    Responsibility: the card thread measures, codes, tests and opens the PR; the seat reviews and lands
    Thread-read: 6575406743
    Premise: holds (site re-read on origin/main 5780fa49 by the seat before dispatch)
    Serial constraints cleared: PR #29271 (#29176) merged as 9e6df40; seat 1 #29241 in flight in the same file, fenced by region — merge main before opening and again if it lands first
    Resume-from: none — fresh from origin/main

    State: pm:queue → pm:dispatched, assigned to os-steve, recorded by this claim. Order: project file server-seat3/standard-order.md + server-seat3/29277-delta.md.

  5. added
    pm:dispatched
    and removed
    pm:queue
    on Nov 2, 2026
  6. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmRPC4f86r9bWGuYWJu
    os-dev-report

    {
      "issue": 29277,
      "status": "needs_decision",
      "branch": "claude/project-thread-uzstmh",
      "pr": null,
      "session": "session_01ADHkmRPC4f86r9bWGuYWJu",
      "premise_still_valid": true,
      "summary": "Measured first, per the ruling, on a real SqlDriver (better-sqlite3) through ObjectQL at origin/main 5780fa49. The 409 reproduces for both types: a second optional unique select and a second optional unique lookup written '' are refused DUPLICATE_RECORD. Storing null for that clear MOVES the ruled $empty answer: select and lookup are the null_only row of the table (expandEmptyOperator; SQL emits IS NULL / IS NOT NULL), so today a cleared '' row matches $empty:false and not $empty:true, and the same clear stored as null would match $empty:true. The ruling says stop on that, so no code, no PR, no commit: this report carries the reader list and the options for the user-decision card the seat files.",
      "readers": {
        "measured_on": "SQLite SqlDriver via ObjectQL, origin/main 5780fa49; rows: blank (stored ''), nul (stored NULL), val",
        "moves": [
          "$empty:true on select and on lookup: today [nul]; the blank row would join it",
          "$empty:false: today [blank,val]; would be [val]",
          "count with $empty:true: 1 today, would count the cleared row",
          "equality to null / $null:true / $exists:false: today [nul]; the cleared row would join",
          "equality to '' and $in ['']: today [blank]; would stop matching",
          "groupBy on the field: '' and null are two buckets today; would merge",
          "orderBy asc: null sorts before '' today; position of a cleared row moves",
          "REST and engine read shape: '' today, null after (lookup expand leaves '' as '' today, null after)",
          "formula matcher equality to null: false on '' today, true on null",
          "CEL coalesce(field, x): '' today, x after"
        ],
        "do_not_move": [
          "$ne value and $nin [value] on SQL: both rows match today",
          "formula matcher $empty (no declaration, isEmptyFilterValue): '' and null both empty already",
          "objectql having $empty: same undeclared reading",
          "CEL isBlank(): '' and null both blank",
          "required: '' is already read as missing (validateOne isMissing), and required columns are outside the gate anyway"
        ],
        "console_cleared_value_send": "PM assumption NOT confirmed from source: LookupField handleRemove sends null for a single lookup; SelectField's cascade prune sends null (objectui#10291 pin SelectField.clearedNull-10291) and the widget has no clear item. Not run end to end in a browser. So the '' producer is an API, import or flow caller, not these widgets as read; a ui-lane 'send null' fix has nothing to change in them.",
        "not_measured": [
          "PostgreSQL / MySQL: no server in the container; the SQL emitter is the same knex code path (whereNull for null_only)",
          "driver-mongodb: mongod download is 403 in the container",
          "exports, summary/roll-up readers: no reader found that branches on '' for these types; not run",
          "service-analytics empty-operator-sql: reads the same expandEmptyOperator row, so it would move like the SQL driver; not run"
        ]
      },
      "tests": "Scratch probe only (never committed, removed from the tree): packages/rest zz-probe-29277.test.ts under os-verify-lock, VERDICT command-exit 0, one test, its JSON readings are the readers block above. Build of the rest closure: turbo build --filter='@objectstack/rest^...' VERDICT command-exit 0. No red/green, no ablation: no behaviour changed.",
      "gates": "n/a: no diff (git status clean at 5780fa49); dispatch-gates not run because there is no change set",
      "dogfood_battery": "n/a: no PR",
      "files_changed": [],
      "line_budget": "n/a: no diff",
      "deviations": [
        "The delta says the card thread files the needs-user-decision card; the seat's go-message says the seat files it from this report. I followed the seat and filed nothing.",
        "Probe imported @objectstack/formula by relative dist path (rest has no formula dependency); scratch only."
      ],
      "mcp_calls": "0",
      "api_writes": "1: this os-dev-report comment on #29277 via post-stamped.mjs (relay)",
      "open_questions": [
        {
          "question": "Does a cleared single select / lookup mean no value (null), given that storing null moves the $empty answer for the cleared rows?",
          "options": [
            "A: Narrow, as the card planned. Door stores null for '' only on optional unique-covered select/lookup (reuse #29176's predicate). $empty table unchanged. The 409 goes; on those columns a new clear reads empty while legacy '' rows still read as a value, and non-unique columns keep storing ''. Small (one arm plus tests). Clause-2 would be yes, since answers move.",
            "B: Root. '' is never a legal stored state for a single select (not an option code) or lookup (not a record id); the spec's own isEmptyFilterValue docblock already calls a non-text column holding '' a write-door defect. Door stores null for a blank single select/lookup (and radio/user siblings) on every optional column, $empty table unchanged, plus an os migrate stored-row step turning legacy '' into null so old and new rows answer alike. Moves answers toward what formula/CEL/having already say. Medium; needs a ruling, and the migration half may be spec/migrate-lane work.",
            "C: Amend the $empty table so single select/lookup read '' as empty too (spec lane), then A or B moves no $empty answer. Equality-to-null, groupBy and read shape still move. Spec-lane card plus ruling.",
            "D: Refuse '' on single select/lookup at the write door with a prescription to send null. Narrowing (breaking for API callers that send ''), needs dogfood; no stored-state move."
          ],
          "recommendation": "B, because it fixes the cause (an illegal stored state) instead of one symptom (the 409 on unique columns), keeps the ruled $empty table as written, and makes the SQL face agree with the formula, CEL and having faces that already read '' as empty; A leaves two readings of a cleared field side by side."
        }
      ],
      "security_findings": "withheld",
      "out_of_scope_findings": [
        "class: a · reach: engine insert on SQLite, a multi-value unique column (multiselect unique; lookup multiple:true unique) written [] twice: first lands, second DUPLICATE_RECORD (same with '') · evidence: scratch probe at 5780fa49 · dedupe words: unique multiselect empty list 409, multi lookup [] UNIQUE_VIOLATION",
        "carrier: seat 3 · the select value-shape check (#29244, seat 1) may refuse '' on an option-bearing select, which would change option D's and B's footprint; worth reading before the ruling"
      ]
    }

    Stamped 2026-11-02T12:22Z.


    Generated by Claude Code

  7. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Blocked · #29277 · 2026-11-02T12:34Z

    Blocked-by: #29346
    Unlock-action: re-check #29346 when label needs-user-decision absent

  8. added
    pm:blocked
    and removed
    pm:dispatched
    on Nov 2, 2026
  9. 1 remaining item

  10. removed
    pm:blocked
    on Nov 2, 2026
  11. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmRPC4f86r9bWGuYWJu
    os-dev-report

    {
      "issue": 29277,
      "status": "done",
      "branch": "claude/project-thread-uzstmh",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/29464",
      "head": "e607df78",
      "session": "session_01ADHkmRPC4f86r9bWGuYWJu",
      "premise_still_valid": true,
      "summary": "Ruling B on #29346 (record 6579813296) implemented in the write door: normalizeBlankTypedValues stores exactly '' as null on every optional column that is a SINGLE_OPTION_TYPES or REFERENCE_VALUE_TYPES member on the $empty table's null_only row (select, radio, lookup, master_detail, user, tree today; multiple: true excluded by the table's own expansion), unique or not. #29176's column-set builder is extended (renamed blankAsNullColumns), not copied; engine.ts untouched; the #29241 string arm and #29244 value-shape check untouched. $empty table unchanged, required still refuses '', a blank on insert takes a declared defaultValue, stored '' not migrated (migrate-lane card).",
      "clause_2": "no: measured, no door refuses anything it accepted ('' on every ruled type 201/200 on base and head; required refusals identical); the second unique clear moves 409 to 201, the direction #29176 declared no",
      "tests": "New: objectql record-validator.single-value-blank.test.ts (7) and rest rest-data-single-value-blank.test.ts (10, SQLite SqlDriver + RestServer, physical column). Red on origin/main 96fb7b5d: rest 9 failed | 2 passed (11, two were my fixture faults, fixed), unit 2 failed | 5 passed (7). Head: 10/10 and 7/7. Ablation L1 (arm off): marker present in 4 objectql dist files, rest 8 failed | 2 passed, unit 2 failed. L2 (table-row check off): unit multiple:true case red. Restore: blob hash equals HEAD, marker absent from all 8 dist files, rest 10/10. Full suites at e607df78: objectql 534/534 files, 10319/10319 tests; rest 376/376 files, 7328 passed 352 skipped.",
      "gates": "At e607df78: objectql typecheck exit 0; rest typecheck exit 0; pnpm lint exit 0; dispatch-gates --commands 61 derived, --ran 61 run 0 NOT-MEASURED 0 UNRUN; 60 exit 0, check-empty-changeset --base origin/main exit 1 by design (DELIBERATE CORRECTION of .changeset/29176-optional-unique-blank-null.md, whose sentence 'select / lookup columns keep storing ''' this PR makes false); check-changeset-no-major on the PR body offline exit 0 (patch). CI check-runs: in_progress at report time.",
      "dogfood_battery": "n/a: no ! in the title and no (narrowing) arm",
      "files_changed": [
        "packages/objectql/src/validation/record-validator.ts",
        "packages/objectql/src/validation/record-validator.single-value-blank.test.ts (new)",
        "packages/rest/src/rest-data-single-value-blank.test.ts (new)",
        "packages/objectql/src/validation/record-validator.blank-typed-value.test.ts (forced)",
        "packages/objectql/src/validation/record-validator.optional-unique-blank.test.ts (forced)",
        "packages/objectql/src/engine-optional-unique-blank-door.test.ts (forced)",
        "packages/objectql/src/engine-blank-typed-value-door.test.ts (forced)",
        "packages/rest/src/rest-data-blank-typed-value.test.ts (forced)",
        ".changeset/29277-single-value-blank-null.md (new, patch)",
        ".changeset/29176-optional-unique-blank-null.md (one sentence corrected)"
      ],
      "line_budget": "+449 / -52 across 10 files (record-validator.ts +61 -37 net of docs)",
      "deviations": [
        "Corrected another PR's pending changeset sentence (29176), so check-empty-changeset is red by design; needs the seat's confirmation.",
        "File surface widened past the claim's 'unique-covered lookup/select' wording to every optional select/radio/lookup/master_detail/user/tree column, as ruling B binds; five existing test files edited because they pinned select/lookup '' staying ''.",
        "lifecycle columns created_by/updated_by stay excluded (the #29176 SKIP_FIELDS exclusion); owner_id is in the set, and plugin-security already reads its '' and null alike.",
        "No assignee/reviewer on the PR (relay pr_create carries none by ruling)."
      ],
      "mcp_calls": "1: mcp__github__pull_request_read get (read-only)",
      "api_writes": "3 relay writes this round: pr_create #29464, this os-dev-report comment; plus the round-1 report 6577038603 (4 git pushes not counted)",
      "open_questions": [
        {
          "question": "File reference types (image, file, avatar, video, audio) are also string-stored single-value ids on the null_only row, but ruling B names only the option and reference classes. Extend the arm to them?",
          "options": ["A: leave them out, as the ruling's named set says", "B: ask the director whether 'stated by the table' covers them, then a follow-up card"],
          "recommendation": "A for this PR (it follows the named set); B as a question for the seat, since a cleared single image field on a unique column would hit the same 409"
        }
      ],
      "security_findings": "none",
      "out_of_scope_findings": []
    }

    Stamped 2026-11-02T15:51Z.


    Generated by Claude Code

  12. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Seat ruling · #29277 open question · 2026-11-02T15:53Z

    Read: os-dev-report 6581571774, and PR #29464 at e607df78 (the record-validator.ts diff).

    1. File-reference types: in, if they are stored as a single string. Ruling B (6579813296) says the rule "is stated by the table, not by a list of type names, so a later type on that row joins it without a new ruling". The set is every optional column whose type sits on the $empty table's null_only row and stores one string value. The head instead gates on SINGLE_OPTION_TYPES ∪ REFERENCE_VALUE_TYPES first, so a file-reference type on that row, or a later type, would stay out. Measure each null_only type the table lists that the head leaves out (file, image and the rest). For each one, record what the write door stores for a non-blank value: a single string id, an object, or an array.
      • Every type that stores a single string joins the arm.
      • A type that stores an object or an array stays out, and the docblock names why.
      • Derive the set from the table's arm plus that storage shape. ⛔ Not a hand list of names. If the storage shape cannot be read from an existing predicate, say so in the report and keep one stated storage-shape set with a pin that ties it to the table.
      • Add a test per joined type.
    2. The red Check Changeset (check-empty-changeset) is confirmed as the DELIBERATE CORRECTION class. The PR corrects data: clearing an optional unique text field stores an empty string, so the second record whose field is cleared is refused 409 UNIQUE_VIOLATION #29176's pending changeset sentence that said select and lookup keep ''. It is not a required check. ⛔ Do not restore that sentence and do not add skip-changeset.
    3. Declaration stands. Clause-②: no, as measured (no door refuses anything it accepted), and Metadata-protocol: none, with the read-shape move stated in the changeset. The five forced test edits are accepted as named in the body.

    Report the new head when done.

  13. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Seat ruling · #29277 · Test Core (3/8) red on 375469fa · 2026-11-02T16:19Z

    Read: the Test Core (3/8) log on PR #29464 head 375469faebb235f3485ad4b09f3385330310433b; packages/runtime/src/seed-blank-reference-real-driver.integration.test.ts lines 130-163; SeedLoaderService.isNoOpReplay / seedValueEquals in packages/metadata-protocol/src/seed-loader.ts on main.

    This failure is this PR's. a blank seed reference is no reference, on a REAL SqlDriver > loads an optional lookup written blank with no error, and a replay skips clean fails at line 161: totalUpdated is 1, expected 0. The seed writes the optional lookup book: ''. The door now stores it as null. On replay, seedValueEquals('', null) returns false, so the row is rewritten on every boot. That is the churn isNoOpReplay exists to prevent (updated_at bump, re-validation, a phantom history edit).

    1. Root fix, in this PR: the replay compares a blank in its STORED form, the same principle as Seed replay rewrites unchanged rows on every boot: seedValueEquals compares time and ISO-datetime strings literally, so 09:15 vs 09:15:00 and …Z vs ….000Z bump updated_at (5 showcase rows per restart) #24562 for temporal fields. A seed '' on a column whose '' the write door stores as null must compare equal to a stored null. On every other column, '' against null stays a change ("any doubt reads as changed").
      • ⛔ No blanket '' == null in seedValueEquals. On a plain text column the door keeps '', so a stored null against a seed '' is a real change.
      • ⛔ Do not edit the test to expect totalUpdated: 1, and do not delete or skip it.
      • ⛔ No second spelling of the blank-as-null rule. @objectstack/metadata-protocol does not depend on @objectstack/objectql. Measure where one predicate can live that both record-validator.ts and the seed loader read, in a package metadata-protocol already depends on (@objectstack/spec or @objectstack/core), and have the validator consume it too. Build it as a ReplayComparands entry (the per-object set of blank-as-null columns), like temporal and masked. If the unique-text arm (data: clearing an optional unique text field stores an empty string, so the second record whose field is cleared is refused 409 UNIQUE_VIOLATION #29176, isUniqueDeclared) cannot move without pulling a driver predicate along, say so in the report, with what you measured.
    2. Measure whether main already churns for the two older arms: a seed '' on an optional number or date column (record write door: '' skips every type check, so a number, boolean, date, datetime or time column stores an empty string — normalise it to null at the door (seam from objectui#10813) #20308 typed arm), and on an optional unique text column (data: clearing an optional unique text field stores an empty string, so the second record whose field is cleared is refused 409 UNIQUE_VIOLATION #29176). If it does, the fix covers all three arms with a pin for each, and the report says the churn was pre-existing on those arms.
    3. The stale comment at lines 147-150 of that test ("it does not null one") is now wrong. Correct it as a forced edit and name it in the body.
    4. Declaration. A new package export widens the public surface. If the fix adds one, amend both carriers to yes (widening) on one line-initial line, and add a patch for that package to the changeset. Otherwise Clause-②: no stands. The Check Changeset red stays the DELIBERATE CORRECTION class confirmed in 6581612131.

    Run the @objectstack/runtime and @objectstack/metadata-protocol suites in full before pushing, plus an ablation of the new comparand (it must turn this test red). Report the new head when done.

  14. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Claim amendment · #29277 · 2026-11-02T17:43Z

    Branch: claude/project-thread-uzstmh (unchanged)
    File surface: adds packages/core/src/utils/blank-storage-form.ts (with its test and the packages/core/src/index.ts export), packages/metadata-protocol/src/seed-loader.ts (the replay comparand ReplayComparands.blankAsNull), and the runtime seed replay tests. These follow from seat ruling 6582252856: one blank-as-null predicate, read by both the write door and the seed replay.
    Clause-②: yes (widening)

    Why: the fix adds three @objectstack/core exports (blankAsNullColumns, blankStorageForm, ENGINE_LIFECYCLE_COLUMNS), and a new export widens the public surface. The door behaviour itself stays as ruled in 6581612131 (no door refuses anything it accepted). The changeset adds patch entries for core and metadata-protocol. The PR body was updated to match on head 22a779351bf40b62e478721343b78d8360b53b7d. A declaration-face contract review at TIER_DEFAULT is owed on that head.

  15. objectstack-fleet commented on Nov 2, 2026

    @objectstack-fleet
    ContributorAuthor

    domain:server#3 · os-steve · session_01ADHkmQJdgarUjPLNgFBY67

    Landing record · #29277 · PR #29464

    domain:server seat 3 · session_01ADHkmQJdgarUjPLNgFBY67 · 2026-11-02T18:45Z

    Reading Probe Result
    Queue membership git ls-remote origin 'refs/heads/gh-readonly-queue/main/pr-29464-*' 0 refs (released)
    Ancestry git merge-base --is-ancestor bd682481 origin/main yes
    Content git grep -n "export function blankAsNullColumns" origin/main -- packages/core/src/utils/blank-storage-form.ts line 125
  16. removed
    pm:dispatched
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:recordsdomain:serverpriority:p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions