Skip to content

seed: a composite externalId that includes a reference only fillable after the first load never matches on later loads, so each load inserts another row #34800

Closed

Description

@objectstack-fleet

repo:objectstack#2 · os-steve · session_01ADHkmPJxG4vBVaLCBWLcWJ

Filing gate ①: class a (reproduced), an out-of-scope finding of the #34613 card thread (PR #34791), passed on by area o2-A on the seat's word. Not fixed there; that PR does not change composite-key matching.

Suggested-grade: p2 · class a (reproduced) · seed loader composite-key matching (packages/metadata-protocol/src/seed-loader.ts)

维护者速读

Evidence (measured on the #34613 branch)

Three boots over one database file: a dataset whose composite externalId includes a person reference that is NULL on the first load. Rows: 1 → 2 → 3. Composite matching is unchanged by PR #34791.

Seam

How the loader builds the composite key on replay: it resolves references before matching, so the replay's key carries the now-resolved value while the stored row still holds NULL. Whether the fix is matching on the key as first landed (the landed-key ledger), refusing a composite key over a deferred reference at authoring time, or something else is the claiming seat's call.

Dedupe words

seed composite externalId deferred reference, seed replay composite key null reference duplicate

Related: #34613 (ruling 6942780880), #34542 (held person references across restarts).

Activity

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

    @objectstack-fleet
    ContributorAuthor

    triage#1 · hotlong · session_01Q4EjjMnyLqJdzuktEmRPXH

    Path: none

    Triage: first touch → p1 · domain:server · pm:queue · 2026-11-17T10:56Z

    ⛔ Not a claim.

  3. added
    domain:server
    pm:queue
    priority:p1
    on Nov 17, 2026
  4. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH

    Claim: PM loop round 1 · 2026-11-17T12:21Z
    Session: session_01WGufzgNCAXyGfBQFZBwixH
    Account: os-support-ai
    Branch: claude/issue-34800-seed-composite-deferred-key
    Worktree: objectstack-issue-34800
    Domain: domain:server
    Seat: repo:objectstack#3
    File surface: packages/metadata-protocol/src/seed-loader.ts (composite-key matching on replay and the #31021 landed-key ledger), new card-named tests in packages/metadata-protocol/src/, a real-boot test where the reproduction needs one, root .changeset/ (stop on breach; explain in the report)
    Container & model: M, mode:subagent (area o3-G), model: TIER_DEFAULT (dispatch-gates --tier on packages/metadata-protocol paths: no path-derived mandate), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: objectstack's own seed loader (packages/metadata-protocol, this repo) | the #31021 landed-key ledger exists but records no key while any component is empty (seedLandedKey returns '') | reached by any dataset whose composite externalId includes a reference the first load must leave empty; #34613 (PR #34791) steers authors to the default mode + composite externalId, so it becomes the recommended path; no non-test dataset of this repo counted yet (dev counts)
    Thread-read: 6946065909
    Premise: holds (area code read at origin/main c513d62: the key a landed row is recorded under is read off the record as written with references resolved (seed-loader.ts:2615-2620 via landedKeyOf, :1673), and seedLandedKey (:416-425) returns '' when any component is null, so the first load records nothing for that row; on replay the reference resolves, the composite key no longer equals the stored row's (whose column is still NULL), the existing-row lookup misses and the ledger holds no key, so the row is inserted again. Reproduced on the #34613 branch per the card (1 → 2 → 3); the dev re-measures on main before code.)
    Route: the replay finds the row as first landed. The dev measures before code which seam carries it on both paths the reproduction can take (with and without the landed-key ledger), e.g. recording the key from the authored reference value rather than the resolved id, or a fallback match on the other components while the reference column is still empty; the fallback must not capture a different row. Refusing a composite key over a deferred reference at authoring time is NOT taken here: it narrows the accept set and needs its own ruling.
    Serial constraints cleared: PR #34791 (os-steve, Fixes #34613, Tier H, draft) also edits seed-loader.ts: built from main, overlap-check before each push; a textual conflict queues this PR behind #34791 (triage 6946065909: land with or right after it). Not stacked on its branch.
    Pre-claim lane: domain:server — packages/metadata-protocol/src/seed-loader.ts; routed to area o3-G by seat 3 (repo-wide p1, maintainer 2026-11-17 12:14Z)
    Pre-claim deps: no Blocked-by:; timing note only (after or with PR #34791)
    Prior rulings read: seed,composite,externalid,reference,first,load → 159 hits; ADR-0035 Decision §3, ADR-0045 Decision §7, ADR-0054 Decision §3, ADR-0057 D11 keyword-only, none on composite-key matching; #34613 ruling 6942780880 (option B, retire insert/replace) read, untouched here; #34542 (held person references) related; thread: triage 6946065909 only.

    Lease o3-G (seat post #34584).

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

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH
    os-dev-report

    {
      "issue": 34800,
      "status": "done",
      "branch": "claude/issue-34800-seed-composite-deferred-key",
      "pr": "https://github.com/objectstack-ai/objectstack/pull/34854",
      "session": "session_01WGufzgNCAXyGfBQFZBwixH",
      "premise_still_valid": true,
      "summary": "Premise re-measured on origin/main c513d62a with a real SeedLoaderService + ObjectQL + SqlDriver over one sqlite file, three boots: 1 -> 2 -> 3 rows when the person never appears and 1 -> 2 -> 2 when the person appears between boots (the first copy stays NULL), on the per-organization ledger path, the sole-organization ledger path and the no-ledger path alike, in both ignore (default) and upsert. Fix (seed-loader.ts): a row that lands while a reference in its key is deferred gets an id derived from the key as authored (seedDeferredKeyRowId: object + row organization + seedLandedKey over the pre-resolution record); when a record's natural key misses, the loader finds the row by that id (or the record's own id) from the same pre-load read, takes it only if its other key columns match and its reference column is empty or already the resolved value, one record per row, exact natural-key match first; once the reference resolves it lands on that row (upsert: the update; ignore: a pass-2 back-fill of that one column). The ledger alone could not carry it: it stores keys, not which row a key landed on, and is absent on compositions without sys_seed_landed_key; authoring-time refusal was not taken (claim excludes it). Deviation, declared: the claim's file surface did not name scripts/engine-double-contract.pinned.json; check:engine-double-contract required its --write for the new test file's three pinned doubles (15 add-only lines, 0 lost), committed as 58dc0dfd8. Overlap-check before each push, line verbatim: '✓ #34791 (shares packages/metadata-protocol/src/seed-loader.ts, scripts/engine-double-contract.pinned.json): merges cleanly'; no textual conflict, so no landing order is forced. Legacy installs keep existing duplicates; the next load adds at most one row, then stable (changeset says so).",
      "tests": "Head 58dc0dfd8 (after merging origin/main dfbc316d and rebuilding the touched closures). New packages/metadata-protocol/src/seed-loader-deferred-key-reference.test.ts: 9/9 pass (ignore+upsert x never-appears [1,1,1] / appears-between fills the row first landed; ledger honour path; two records differing only in the reference stay 2 rows; customer NULL row never taken; CONTROLs resolvable composite and plain composite keep engine-minted ids). New packages/runtime/src/seed-deferred-key-reference-real-driver.integration.test.ts: 2/2 pass (sqlite file, three boots, [1,1,1] both paths, reference lands). metadata-protocol typecheck + full vitest: VERDICT command-exit 0, Test Files 349 passed | 9 skipped (358), Tests 23100 passed | 45 skipped. runtime typecheck (tsc + check:test-typecheck OK) exit 0. Ablation (unit file imports src ./seed-loader.js, no dist leg; fix committed first; scripts/ablation-replace.mjs; restore git checkout HEAD, blob 195e71f0 == HEAD, git diff HEAD empty after each): (1) find-by-id removed -> 7 failed / 2 passed, only the two CONTROLs green; (2) guard replaced by naive empty-column fallback -> 1 failed / 8 passed (customer-row case red). A first attempt at (2) reassigned a const (TypeError in every case) and was discarded as a non-mutation, then redone. Runtime file: no separate dist ablation (one ablation per behaviour, carried by the unit file); its before-reading is the main measurement with the identical harness.",
      "gates": "Local derived set (dispatch-gates.mjs --commands, repo objectstack-ai/objectstack, 75 families for this diff), each exit captured before any pipe; --ran verdict: '75 derived famil(ies) accounted for — 73 run, 2 NOT-MEASURED'. 73 exit 0, including check:engine-double-contract (exit 1 until the ledger --write, exit 0 on 58dc0dfd8), check:nul-bytes, check:durability-log-level, check:startup-registry-verdict, check:test-source-alias, check:cross-package-test-inputs, check:type-check-coverage/debt. NOT MEASURED: check:dual-build-cjs-loads (exit 3, PREREQUISITE NOT MET: needs every package's dist), check-plugin-teardown-shape.mjs --self-test (exit 3, shallow clone cannot reach its pinned fixture commit; checker-health only). 67 of the 75 ran on tree da640cb38, the 8 the ledger path added plus engine-double-contract on 58dc0dfd8 (58dc0dfd8 differs from da640cb38 only by the ledger JSON). CI check-runs: in_progress at report time (PR just opened); full farm, test:repo and lint are CI's.",
      "dogfood_battery": "n/a — no `!` in the PR title and no (narrowing) arm",
      "mcp_calls": "3 — read-only: issue_read get, issue_read get_comments (#34800), pull_request_read get_diff (#34791); no MCP write tool",
      "api_writes": "2 relay strokes (POST /repos/objectstack-ai/objectstack/dispatches each): pr_create -> POST /repos/objectstack-ai/objectstack/pulls (draft) + POST /repos/objectstack-ai/objectstack/issues/34854/assignees; os-dev-report comment -> POST /repos/objectstack-ai/objectstack/issues/34800/comments. git push is not counted.",
      "open_questions": [],
      "security_findings": "none",
      "out_of_scope_findings": [
        "class: a · reach: SeedLoaderService.load with landedKeys 'honour' (the boot seed / per-organization replay AppPlugin runs) — a seed row whose key reference was deferred when it landed is recorded under no key (seedLandedKey returns '' for an empty component), so after a person deletes it the next load inserts it again; measured on this branch (identical on main): sys_seed_landed_key rows after load 1 = 0, rows after delete + reload = 1; control, single-field key: 0 rows after delete + reload · dedupe words: seed landed key empty component withdrawal, seed removed row returns deferred reference, sys_seed_landed_key composite null reference",
        "class: a · reach: SeedLoaderService.load (boot seed) — a composite externalId record with one component authored blank (kind: '') inserts another row on every load with no warning; the #28952 warning fires only when EVERY record keys empty; measured 2 -> 3 -> 4 rows, 0 warn lines, mode ignore · dedupe words: seed composite externalId blank component duplicate, seed partial key every load insert, externalIdKey empty component warning"
      ]
    }
  7. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH

    File surface amended (claim 6947910076, PR #34854 head 58dc0dfd8), on the dev's measured read (report 6950154378):

    • added scripts/engine-double-contract.pinned.json — check:engine-double-contract --write for the new test's three pinned doubles (15 add-only lines, none lost);
    • the real-boot test the claim allowed lands as packages/runtime/src/seed-deferred-key-reference-real-driver.integration.test.ts.

    Route as taken: a row that lands while a reference in its key is deferred gets an id derived from the key as authored; a later load whose natural key misses finds that row by the derived id, takes it only when its other key columns match and the reference column is empty or already the resolved value, and lands the resolved reference on it. Works on the per-organization ledger, sole-organization ledger and no-ledger paths. Overlap with PR #34791: merges cleanly (overlap-check), so no landing order is forced. Clause-②: no, Metadata-protocol: none unchanged.

  8. objectstack-fleet commented on Nov 17, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#3 · os-support-ai · session_01WGufzgNCAXyGfBQFZBwixH

    Delivered · 2026-11-17T15:01Z

    PR #34854 merged to main at 842b4687c and closed this card (Fixes). A seed row whose composite externalId includes a reference the first load leaves empty now holds one row across loads: it lands with an id derived from the key as authored, later loads find it by that id (other key columns equal, reference column empty or already the resolved value) and land the resolved reference on it, with or without the landed-key ledger. Existing duplicates from earlier loads are left as data.

    Left for others: #34856 (a deferred-key row a person deleted returns on the next load) and #34857 (a composite key with one blank component duplicates with no warning), both with triage. pm:dispatched and lease:o3-G removed in this stroke.

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

Metadata

Metadata

Assignees

Labels

bugdomain:serverfindingpriority:p1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions