Skip to content

feat(objectql)!: sync-in provenance columns on synced objects, stamped by the pull and refused elsewhere - #36795

Merged
os-zhuang merged 7 commits into
mainfrom
claude/project-thread-l53erx
Nov 24, 2026
Merged

os-zhuang merged 7 commits into
mainfrom
claude/project-thread-l53erx

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Yibo Wang · project thread

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

Part of #32062

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none (no skills/ page names the _sync_ columns or the synced bucket's injected columns; grep of skills/** for _sync_, managedBy: 'synced' and SYNC_PROVENANCE finds nothing)

维护者速读

Slice 5 of the sync-in P2 engine, route A of the seat's revised order: the D4 column half. Every managedBy: 'synced' object now gets five hidden, read-only _sync_ columns and an index on (organization_id, _sync_source, _sync_external_id). Both pulls stamp four of them on every row they write. Any other write that names a _sync_ column is refused with 400 ERR_SYNC_PROVENANCE_WRITE_REFUSED, system context included. That refusal is the narrowing. _sync_deleted_at is planned but nothing stamps it until slice 6 (D3). No authorable key changes.

What changes

  • Plan (spec). resolveInjectedSystemColumns gains plan.sync, true for managedBy: 'synced' only (and false under systemFields: false, like every other column). It adds SYNC_PROVENANCE_COLUMNS to names. injectedSystemColumnDefs / SYNC_PROVENANCE_FIELD_DEFS hold the five definitions (hidden, readonly, system, not required). New exports: SYNC_PROVENANCE_COLUMNS, SYNC_PROVENANCE_PREFIX, SyncProvenanceColumn, SYNC_PROVENANCE_FIELD_DEFS. ERR_SYNC_PROVENANCE_WRITE_REFUSED joins the error-code ledger under @objectstack/objectql.
  • Registry (objectql). applySystemFields injects the five columns from the plan, and provisionSyncProvenanceIndex appends the index after the tenant index (led by organization_id when the object has it). The write-side inverse (stripProvisionedSyncProvenanceIndexFrom) runs before the tenant inverse in stripMaterializedStampsFrom, so the tenant stamp stays last for its own re-stamp-and-compare. materializeBaseLayer provisions it the same way.
  • Write refusal (objectql). refuseSyncProvenanceWrite runs in insert and update right after assertWriteAllowed, before middleware, defaults and hooks. It refuses any payload key starting _sync_ unless the context carries SYNC_PULL_WRITE (a Symbol.for key, same shape as SUMMARY_RECOMPUTE_WRITE). The engine consumes the mark, so a hook's ctx.api write inside the pull's write is refused like any other system write. After the before* hooks are sealed, refuseHookSyncProvenanceWrite compares each row's _sync_ keys with the snapshot taken before the hooks. A key a hook assigned, changed or removed is refused (by: 'hook') before the driver, on any write, the pull's own included.
  • Pulls (service-automation). Both pulls stamp _sync_source (the mapping name), _sync_external_id, _sync_pulled_at and _sync_run_id through stampSyncProvenance, after the mapping projects the rows and before runImport. They write with markSyncPullWrite(context ?? { isSystem: true }). A mapping whose fieldMapping targets a _sync_ column is refused 400 mapping_target_refused before any read or write. Before this PR it was already refused as an unknown target. A connector pull whose target definition cannot be read is refused the same way before the call, as the datasource pull already did.
  • Diagnostics (metadata-protocol). computeMetadataDiagnostics drops the injected _sync_ columns from a served object before the parse. They have to be exactly the platform definitions; an author _sync_ field is still refused for the reserved prefix.
  • Docs. The jobs.mdx bullet "Every row says where it came from", one sentence on the synced row of objects.mdx, notes on the liveness rows mapping.deletePolicy and object.managedBy, and regenerated references.

Decision for review: composite upsertKey encoding (ADR-0153 open question L853)

encodeSyncExternalId (packages/services/service-automation/src/sync-provenance-stamp.ts, which cites the open point):

  • One key field: its value as plain text. A string is trimmed, as the runner matches it. A number, bigint or boolean goes through String(), a date through ISO 8601, anything else through JSON.
  • Several fields: JSON.stringify of the array of those spellings, in the order upsertKey declares them, never sorted. So upsertKey: ['amount','external_no'] gives ["10","A-1"]. The order is the author's declaration, so it stays stable for as long as the mapping does. JSON escaping keeps a value that contains "," unambiguous.
  • Any blank key value: no id is stamped. The runner skips that row anyway (a blank match key).
  • Within one mapping the number of key fields is fixed, so the plain spelling and the array spelling never meet among rows of one _sync_source.

This changes nothing an author may declare; the stamp only reads upsertKey. Pinned in sync-provenance-stamp.test.ts and in datasource-pull.test.ts (the composite case).

_sync_deleted_at: planned, unstamped

The column is in the plan and injected, and no gate trips on it. Its description says nothing writes it until delete marking lands, and the mapping.deletePolicy liveness row (still planned) says the same. Slice 6 (D3 + N1–N5) stamps and clears it.

Acceptance notes

  • Two mappings on one target (L854): not refused. Each row carries its _sync_source, so slice 6 can scope its mark by it.
  • _sync_run_id without a run ledger: not written. The import runner reads a blank cell as "leave the field as it is", so null could not clear it either. On a row such a pull created, the column is empty. On a row it updated, it keeps the earlier id. The column description says this. That composition already logs a warning once at boot.
  • systemFields: false on a synced target: no columns, so its rows are written unstamped, as before. Refusing it would narrow what an author may declare, which this slice does not take; D3, which needs the columns, can judge it.
  • What the refusal judges: the caller's payload before anything runs, and the hooks' writes to the _sync_ keys before the driver.
  • _sync_external_id for a transformed key: taken from the mapped value the row is matched on, before a lookup resolves. The column description now says so.

Narrowing

The engine refuses a _sync_ key in any insert or update but the pull's, isSystem included (ADR-0153 D4: "A _sync_ column in any write except the pull's is refused by name, whatever the caller's context"). Before this PR no object carried such a column (ObjectSchema reserves the prefix), so such a write was naming a column that did not exist. A before* hook that writes a _sync_ key is refused the same way, and on the pull's write too.

Deviations from the claimed surface

  • packages/metadata-protocol/src/metadata-diagnostics.ts (+ its test): without it, every served synced object reads valid: false for the reserved _sync_ prefix once the columns are injected.
  • packages/objectql/src/engine-insert.ts, engine-update.ts, index.ts, registry-object-registration.ts, sync-provenance-*.ts: these are the claimed "objectql system-field consumer" and "the door that refuses _sync_ writes", named file by file.
  • packages/spec/src/api/error-code-ledger.zod.ts (the new wire code's ledger row, ADR-0112) and packages/spec/src/data/injected-system-column-provenance.ts (the definitions the plan rows inject).
  • content/docs/data-modeling/objects.mdx, automation/hooks.mdx, automation/flows.mdx: one sentence each; packages/objectql/src/federated-injected-column-readers.test.ts: the reader-ledger row for the new index.
  • packages/core is untouched.

Verification

  • Full package suites on the merged tree: objectql 636/636 files, service-automation 294/294 files; spec (880 files) and metadata-protocol (366 passed, 9 skipped) green before the main merge. Targeted and typecheck green for all four packages.
  • Ablations, each on disk, then restored: with the caller-payload refusal disabled, 3 cases in sync-provenance.test.ts go red; with the hook-write refusal disabled, 4 go red.
  • dispatch-gates --ran: 128 derived families accounted for. 125 ran green. 3 are NOT-MEASURED because a local prerequisite is missing (exit 3): check-plugin-teardown-shape --self-test needs a deeper clone, and check:skill-examples and check:dual-build-cjs-loads need a full build.
  • Dogfood battery on 805d6199: os-verify-lock VERDICT command-exit 0; Test Files 487 passed, 3 skipped (490); Tests 4125 passed, 68 skipped. It is re-run on the rework head, and the result is in the report.
  • Fix round for L1 7119029164 / contract review 7119012685:
    • S1: the hooks' _sync_ writes are judged, with tests for a hook on a system write and on the pull's write (insert and update).
    • S2: a connector pull with an unreadable target is refused, with a test.
    • N2: the description is aligned.
    • N7: this section and the open-point line are corrected.

…ite refusal

Tests for both pulls' stamping, the L852 external-id spelling, the
plan/registry parity cases, and the served-document diagnostics; docs,
liveness notes, changeset and regenerated spec artifacts. A synced target
with systemFields: false is written unstamped rather than refused.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzeX8NmUPt5KSzQar4X
… gates

Move the sync column additions beside their index helper so registry.ts
does not grow, add the provenance index's reader row, bound the test
double's find, and pay the lint load at collection in the diagnostics test.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzeX8NmUPt5KSzQar4X
@github-actions github-actions Bot added size/xl documentation Improvements or additions to documentation protocol:data tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 4 package(s): @objectstack/metadata-protocol, @objectstack/objectql, @objectstack/service-automation, @objectstack/spec, touching 51 documentable anchor(s). ⚠️ 5 changed file(s) yielded no anchor (packages/objectql/src/index.ts, packages/spec/api-surface/data.json, packages/spec/export-origins/data.json, …), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

36 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152.

⛔ 10 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 5 changed file(s) yielded no anchor (packages/objectql/src/index.ts, packages/spec/api-surface/data.json, packages/spec/export-origins/data.json, …) — pages documenting those are invisible to this run
  • 1 anchor(s) matched too much of the corpus to be a work list: organization_id (literal, 41 pages)
  • 6 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 68 of 251 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 — 178 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 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from b18259ee85a2da8ed868c57a9a8ff8a64aee37d4 — the merge of head b501462548d911695306ab278fbe7cca1d3b6e3e into base 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152, 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 b18259ee85a2da8ed868c57a9a8ff8a64aee37d4 && git checkout b18259ee85a2da8ed868c57a9a8ff8a64aee37d4
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152 b501462548d911695306ab278fbe7cca1d3b6e3e && git checkout -B drift-repro 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152 && git merge --no-ff b501462548d911695306ab278fbe7cca1d3b6e3e

node scripts/docs-audit/affected-docs.mjs --json 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152

⚠️ 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 65ee4b7ad49361bc3cfaf3a32c9ed02752d4a152 → 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#3 · os-support-ai · session_01WGufziwMkZG34d69p8BHb4

Contract-review-claim: session_01WGufziwMkZG34d69p8BHb4 · head 805d619 · 2026-11-24T01:14Z

Face: published schema (packages/spec/src/** non-test) plus the Clause-②: no (narrowing) declaration ⇒ CONTRACT_REVIEW_TIER. L1-b runs it in an isolated reviewer beside its L1 read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 805d6199124e63712dfc8e107cae8c50ed94206f
Local-runs: none
Scope: packages/spec/src/api/error-code-ledger.zod.ts, packages/spec/src/data/injected-system-column-provenance.ts, packages/spec/src/data/injected-system-columns.ts + packages/objectql/src/sync-provenance-index.ts, packages/objectql/src/sync-provenance-write.ts, packages/objectql/src/registry.ts, packages/objectql/src/registry-object-registration.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/objectql/src/index.ts, packages/services/service-automation/src/sync-provenance-stamp.ts, packages/services/service-automation/src/connector-pull.ts, packages/services/service-automation/src/datasource-pull.ts, packages/metadata-protocol/src/metadata-diagnostics.ts; agreement only: packages/spec/api-surface/data.json, packages/spec/export-origins/data.json, packages/spec/liveness/mapping.json, packages/spec/liveness/object.json

Inputs read: card #32062 body and all 28 comments (through the slice-5 dev report 7118824246), PR #36795 body and both comments, the net diff origin/main...805d6199, the 70 check-runs on the head (60 success, 10 skipped, none failed), and on origin/main: AGENTS.md Post-Task Checklist item 3, ADR-0153 D4 and its open points (the two this slice touches now sit at L853 and L854 of the file; the PR and the card cite them as L852 and L854).

① Derived judgments

  • Injected-columns plan (resolveInjectedSystemColumns). plan.sync is true for managedBy: 'synced' alone and false on both hard opt-outs (systemFields: false, better-auth); names gains the five columns under the same condition. Right: this is ADR-0153 D4's "on a synced object only". InjectedSystemColumnPlan gains a required sync member: a widening of a published return type; every in-repo constructor of the plan is this function. Right.
  • New public exports. SYNC_PROVENANCE_COLUMNS, SYNC_PROVENANCE_PREFIX, SyncProvenanceColumn, SYNC_PROVENANCE_FIELD_DEFS from @objectstack/spec/data; SYNC_PULL_WRITE, markSyncPullWrite, SyncProvenanceWriteRefusedError, SYNC_PROVENANCE_WRITE_REFUSED_CODE from @objectstack/objectql. All additions. api-surface/data.json and export-origins/data.json each carry exactly the four spec names, with the right origins. Right.
  • Error-code ledger. ERR_SYNC_PROVENANCE_WRITE_REFUSED is added under @objectstack/objectql, the package that throws it; the class carries code, status: 400 and httpStatus: 400 (ADR-0112). An addition to the accept-set of codes a client may receive. Right.
  • Registered shape of a synced object. Five hidden, read-only, system columns and one index. The index is document-gated on _sync_source and _sync_external_id being present, which only the plan can cause on a parsed object (the prefix is reserved), and applySystemFields reaches the stamp only past the !plan.sync early return or with the columns already present. So it lands on synced objects only, led by organization_id when the object has the tenant column. Stamp order (after the tenant index) and strip order (before the tenant inverse) are consistent at both producers and in stripMaterializedStampsFrom. Right.
  • Write accept-set. An insert or update whose payload names any key starting _sync_ is refused on every object unless the context carries the pull's mark. All engine write doors funnel through the two guarded facets: insert (single and array), insertMany (calls insert), the repository insert / create / update / updateById, and update on both the by-id and the predicate exit. The refusal sits after assertWriteAllowed and before middleware, defaults and hooks. Right for the caller's payload; see S1 for what it does not judge.
  • Diagnostics. computeMetadataDiagnostics leaves out a _sync_ field only when it is identical to the platform definition (isInjectedColumnDefinition), so an authored _sync_ field is still refused for the reserved prefix. Right, and it honours carrier note 6762989212 item 5.
  • Mapping refusal. A fieldMapping target under _sync_ is refused 400 mapping_target_refused by both pulls before any read. It was refused before as an unknown target, so the author's accept-set does not move. Right.

② Semver level

  • Clause-②: no (narrowing) is right. The engine now refuses a system-context write it used to judge like any other key, and the PR title carries !. The line is on the PR body and in the changeset body.
  • Metadata-protocol: none is right. No key, accepted value or metadata type is added, removed or re-shaped: the _sync_ field prefix was reserved by feat(spec)!: one-way sync-in, the spec half — datasource source, paging and delete policy keys, the pull refusals, and the synced bucket (ADR-0153) #32118, a _sync_ mapping target was already refused at run time, and the planned columns, the index and the error code are platform surface, not something an author writes. The new exports and the new code are a non-protocol widening.
  • Level: none takes patch, and a non-protocol breaking change ships patch with its BREAKING banner (AGENTS.md, Post-Task Checklist 3). The changeset moves the four packages the diff changes, each at patch. Right. The Check Changeset check-run is green on the head.
  • Narrowing companions, all present: the BREAKING bullet states what is refused, with which code and status, and the one-line fix ("leave the _sync_ columns out of the write; the next pull of the mapping stamps them"); exactly one ADR-0087 marker (not-required (no-migration-prescription)), which fits, since no authored value has to be rewritten; Skills-docs: none with its reason on both carriers, confirmed (no file under skills/ or ui/skills/ names _sync_ or SYNC_PROVENANCE on the head); the dogfood battery on this head is in the dev report on the card (7118824246: 805d6199, command-exit 0, 487 files passed, 3 skipped). The PR body's Verification section still reads "owed"; the reading exists, on the card.

③ Boundary flags

  • Composite upsertKey encoding (ADR-0153 open point "a composite upsertKey written as _sync_external_id text"). Answered in encodeSyncExternalId, cited at the spot in its doc comment, and pinned in sync-provenance-stamp.test.ts (single, composite, a value holding ",", blanks) and through a real engine in datasource-pull.test.ts ('["10","A-1"]'). Judged in ④: it holds, with nits N1 to N3.
  • Two mappings on one target (ADR-0153 open point at L854). Still open, as the claim's seat route requires: the diff adds no refusal of a second mapping on a target, in the spec files or in either pull. Each row carries _sync_source. See N4 for what slice 6 must weigh before it scopes a mark by that column.
  • _sync_deleted_at planned and unstamped (ADR-0078). Allowed here: its field description says "Not written yet: the delete marking that stamps it has not landed, so it is empty on every row", the plan's doc comment says the same, and the mapping.deletePolicy liveness row (still planned) and the object.managedBy note both say it. The other four columns each have a writer in both pulls. _sync_run_id is left unwritten when no run ledger is composed, and its description says so.
  • systemFields: false on a synced target. Not refused; the rows are written unstamped and unmarked, pinned in both pull tests and stated in jobs.mdx. Refusing it would narrow what an author may declare, which this slice does not claim. Left to D3, as the PR says. Accepted.
  • Dev report open_questions: empty. Nothing to escalate to the maintainer.
  • SQL push-down: no new id materialisation and no in-app join. The stamp is computed per row from values already in hand, and the index exists so that slice 6's diff can be a predicate.
  • Claim surface: metadata-diagnostics.ts and the three one-sentence doc edits are outside the claimed file list and are declared as deviations with their reason. Without the diagnostics change every served synced object would read valid: false. Accepted.

④ Design judgment

packages/spec/src/data/injected-system-columns.ts — against ADR-0153 D4 and its first consumer (applySystemFields, syncProvenanceColumnAdditions). The five names, the bucket condition and the opt-outs match the ADR table and the registry's injection. One sentence does not hold against the engine; see S1.

packages/spec/src/data/injected-system-column-provenance.ts — the five definitions are hidden, readonly, system, not required, text for the run id (never a lookup, as D7 requires), and satisfies ties them to the column list. injectedSystemColumnDefs follows plan.sync. The _sync_deleted_at description is truthful. "Written by the pull only." on the other four is the S1 sentence again. The _sync_external_id description is N2.

packages/spec/src/api/error-code-ledger.zod.ts — the row agrees with SyncProvenanceWriteRefusedError: 400, judged on the caller's payload before middleware, defaults and hooks, system context included. The comment says "of a synced object"; the engine refuses the prefix on every object, which the reserved prefix makes equivalent in practice.

Implementing files, against those contracts.

  • sync-provenance-write.ts, engine-insert.ts, engine-update.ts: the mark is a Symbol.for key that JSON cannot carry, it is consumed at the door (object rest keeps every other key, symbol keys included), and a hook's ctx.api write inside the pull's write is refused. Tests assert code and status for a system insert and a system update, the control write, the admitted pull write, the consumed mark and the nested hook write. The pull itself still writes: both pulls write under markSyncPullWrite(context ?? { isSystem: true }), pinned through a real engine.
  • sync-provenance-index.ts, registry.ts, registry-object-registration.ts: hold, as in ①. The inverse is plan-gated and takes only an exact platform entry in last position; an author entry with a name stays.
  • sync-provenance-stamp.ts: the encoding is injective over tuples of text (a JSON array of strings), order is the declared upsertKey order (both pulls pass matchFields in declaration order, unsorted), a blank part yields no id and the runner skips that row (BLANK_MATCH_KEY, any blank field in the key set), and arity is fixed within a mapping. A number and a string of the same digits spell alike; inside one key column of one type that cannot collide.
  • metadata-diagnostics.ts: holds, as in ①.

Findings.

S1 (should-fix) — The published sentences say more than the engine enforces. injected-system-columns.ts says "The pull is the only writer of all five", SYNC_PROVENANCE_FIELD_DEFS says "Written by the pull only." on four columns, the changeset title says "nothing else may write those columns", and jobs.mdx says "Nothing else writes these columns". ADR-0153 D4 says "A _sync_ column in any write except the pull's is refused by name, whatever the caller's context" and "the pull is their only writer". refuseSyncProvenanceWrite judges the caller's payload only, before the hooks run. A beforeInsert or beforeUpdate hook on a synced object that assigns a _sync_ key to the write's data is not judged: on a system write the static readonly strip is skipped, and a hook-assigned key is exempt from it in any case (hookWrittenKeys), so the value reaches the driver. That covers a declared action's system write and the pull's own write, where a hook can replace _sync_source or set _sync_deleted_at, the two columns slice 6's mark reads. The PR body discloses this under "What the refusal judges"; no published sentence does. Either judge the post-hook write image too (the engine already tracks hook-written keys per row on insert, and the update door has the same seam), with a test for a hook that assigns a _sync_ key on a system write and on the pull's write; or, if the seat keeps the payload-only rule, say so in the four sentences above and record the deviation from D4's letter on the card for slice 6.

S2 (should-fix) — The connector pull decides whether to stamp from a schema read that fails open. In connector-pull.ts the target's definition is read inside try { … } catch { }; when that read throws or answers nothing, carriesSyncProvenanceColumns(undefined) is false, so the rows of a synced target are written with no _sync_ column and no mark, and nothing is logged or refused. The changeset and jobs.mdx both say every row a pull writes gets the four stamps. The datasource pull has no such path: it refuses before the first read unless the target is known and synced. An unstamped row carries no _sync_source, so slice 6 can never mark it, and an incremental pull never reads it again to repair it. Make the connector pull refuse the run (or otherwise not write) when a sourced mapping's target definition cannot be read, with a test; or state the exception where the two sentences are published.

N1 — encodeSyncExternalId's comment gives "two fields' values are not interchangeable" as the reason not to sort. Sorting by field name would not interchange values; the real property is that the order is the author's declaration. A reordered upsertKey therefore re-keys every row the next run writes, and rows that run does not read keep the old spelling until a complete read. D3's completeness rule bounds the harm, since a mark needs a complete read, which restamps every live row. Carry to slice 6: its diff must not compare ids across a changed upsertKey before a complete read.

N2 — ADR-0153's table defines _sync_external_id as "the source values upsertKey's target fields are copied from, as text". The stamp reads the mapped row (row[f] after applyMappingToRows), so for any transform other than a plain copy or a lookup it is the transformed value, not the source value. The column description ("the source value of the mapping's upsertKey") follows the ADR's wording, not the code. The PR body discloses it. Slice 6 computes its diff from the same mapped rows, so the two sides agree; align the description, or record the deviation, when the file is next touched.

N3 — Spelling edges the tests do not pin, none reachable inside one well-typed key column: an object key part is spelled with JSON.stringify, whose member order is not canonical; a Date part is cut to milliseconds; a decimal that one driver returns as the number 1.1 and another as the string "1.10" spells two ways.

N4 — _sync_source holds the mapping's bare name, as the ADR table says. Slice 3's finding (record 6786503520, S1) established that a mapping's identity is its holder package plus its name: two packages may each hold a mapping of one name. If both write one target, their rows carry one _sync_source. That is the L854 case with no way to tell the writers apart. Carry to slice 6 before a mark is scoped by this column.

N5 — markSyncPullWrite and SYNC_PULL_WRITE are public exports of @objectstack/objectql, and the mark is a Symbol.for key, so any in-process code can mint it. "Only the pull calls it" is a convention, not an enforced rule. In-process code is trusted today; the export's comment could say so.

N6 — The refusal tests pin a single-row system insert and a by-id system update. An array insert, insertMany and a predicate update are covered by construction (one funnel each) but have no pin of their own.

N7 — The PR body's Verification section still says the dogfood battery is owed, and the PR and the card cite the composite-key open point as L852; it is at L853 of the ADR on main.

Implemented-by: claude/project-thread-l53erx
Reviewed-by: session_01WGufziwMkZG34d69p8BHb4

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

席位核对 — REWORK · repo:objectstack#3 · head 805d619 · 2026-11-24T01:21Z

L1: REWORK
Head-sha: 805d6199124e63712dfc8e107cae8c50ed94206f
Card: #32062, slice 5 (route A, the D4 column half) · claim 7101769273 · os-dev-report 7118824246.
Contract review on this head: 7119012685 (CONTRACT_REVIEW_TIER, PASS with two open should-fix findings; claim 7118910439).

Checklist

  • Shape: l1-face at this head. Draft, base main, first line Part of #32062. Slice 6 (D3 + N1–N5) is still owed on the card, so Part of is right and no closing keyword binds any card. pm:dispatched stays on the card until slice 6 lands.

  • Checks at this head: 70 check-runs. 60 success, 10 expected skip, 0 failed. Lint & Repo Gates and TypeScript Type Check: success. mergeable_state clean.

  • Governance: check-governed-merges: NOT governed, 0 of 34 paths, 1313 lines. Tier H comes from the narrowing leg, as the seat said.

  • Narrowing companions:

    • The ! in the title and Clause-②: no (narrowing) appear in the body and the changeset.
    • The changeset carries a BREAKING bullet with its fix ("leave the _sync_ columns out of the write; the next pull stamps them") and one ADR-0087 not-required (no-migration-prescription) marker.
    • Skills-docs: none: confirmed, nothing under skills/** names _sync_, managedBy: 'synced' or SYNC_PROVENANCE.
    • Dogfood battery on 805d6199: os-verify-lock VERDICT exit 0, 487 files passed and 3 skipped, 4125 tests passed and 68 skipped (report 7118824246). Full, pinned to this head.
  • Declarations: Metadata-protocol: none and patch on all four packages. The contract review's ② agrees: the planned columns, the index, the exports and the new error code change nothing an author writes. The changeset names every published package whose src/** moved: spec, objectql, metadata-protocol and service-automation.

  • Scope vs claim: these files sit outside the claim's surface:

    • packages/spec/src/api/error-code-ledger.zod.ts: the new code's ledger row, which ADR-0112 requires for a new wire code;
    • packages/spec/src/data/injected-system-column-provenance.ts: the field definitions the plan rows inject;
    • metadata-protocol diagnostics and their test, the one non-sync-in docs sentence each in objects.mdx, hooks.mdx and flows.mdx, and the reader-ledger row in federated-injected-column-readers.test.ts. The report declares all of these.
    • generated references and baselines.

    Each is a direct consequence of the claimed change. The two spec files are not in the report's deviations list, so the seat should amend the claim's File surface: line with them (paper).

  • Tests: real commands with output. The ablation disabled the throw, three refusal cases went red and the restore went green. The refusal cases assert code (SYNC_PROVENANCE_WRITE_REFUSED_CODE) and status 400 for a system insert, a system update and a hook's ctx.api write (ADR-0112). There is a CONTROL for a plain system write, and the marked pull write is admitted with its mark consumed. Overlap with feat(formula): working-day functions addWorkingDays, workingDaysBetween and addWorkingHours over the organization calendar #36796 is clean on engine-insert.ts and engine-update.ts.

  • Docs, read sentence by sentence:

    • jobs.mdx "Every row says where it came from": five columns, the index, four stamps, the composite encoding with its example, _sync_deleted_at empty, the refusal with its code, the fieldMapping refusal and systemFields: false. Each matches the code, except "Nothing else writes these columns" and "every row a pull writes gets", which are S1 and S2.
    • objects.mdx table cell, and the hooks.mdx / flows.mdx null-guard sentences (_sync_deleted_at always null for now): true.
    • references/api/* and error-code-ledger.mdx: generated, +1 code each.
    • Changeset bullets 1–4 read against the diff; they carry the same two gaps.

Findings

Should-fix (both are the contract review's; I re-read each in the code):

  • S1 (should-fix) = contract review S1.
    • refuseSyncProvenanceWrite judges the caller's payload before the hooks run.
    • A beforeInsert / beforeUpdate hook that assigns a _sync_ key on a system write is not judged. That includes the pull's own write, where a hook could replace _sync_source or set _sync_deleted_at, the two columns slice 6 reads. Hook-written keys are exempt from the readonly strip, so the value reaches the driver.
    • ADR-0153 D4 and four published sentences say the pull is the only writer: injected-system-columns.ts, SYNC_PROVENANCE_FIELD_DEFS ("Written by the pull only."), the changeset title, and jobs.mdx.
    • Fix: judge the post-hook write image too, with tests for a hook on a system write and on the pull's write. Alternatively, if payload-only is kept, soften the four sentences and record the deviation on the card for slice 6.
  • S2 (should-fix) = contract review S2.
    • connector-pull.ts:771-778 reads the target definition inside try { … } catch { }.
    • If that read throws or answers nothing, carriesSyncProvenanceColumns(undefined) is false, and a synced target's rows are written unstamped, unmarked and unlogged.
    • Such rows have no _sync_source, so slice 6 can never mark them. The changeset and jobs.mdx say every row a pull writes gets the four stamps. The datasource pull refuses instead.
    • Fix: refuse the run (no write) when a sourced mapping's target definition cannot be read, with a test, or state the exception where those sentences are published. Refusing is the reading the docs imply.

Nits (the contract review's N1–N7, with no effect on correctness or the contract this slice):

  • N1: a reordered upsertKey re-keys rows. Carry to slice 6.
  • N2: the external id comes from the mapped value, not the source value the ADR table names.
  • N3: spelling edges for object key order, Date cut to milliseconds, and decimal as number vs string are unpinned.
  • N4: the bare mapping name in _sync_source. Carry to slice 6 with L854.
  • N5: markSyncPullWrite is public and Symbol.for-minted.
  • N6: no own pin for array insert, insertMany or predicate update; the single funnel covers them.
  • N7: the PR body still says the dogfood battery is owed, and the ADR line is L853 on main, cited as L852. N7 is prose: fix it with the rework.

Decision for review (L852, composite upsertKey encoding)

It holds, per the contract review's ③/④:

  • A JSON array of the text spellings in declared upsertKey order is order-stable and injective.
  • It is cited at the spot and pinned in a unit test and through a real engine.
  • No refusal of two mappings per target was added, so L854 stays open as ordered.

Next

The fix round goes to the card thread. The delta read covers S1 and S2 (and N7) on the new head; the contract review gets its own delta from the same reviewer. The new head needs a fresh dogfood battery (the narrowing leg). Then Tier H to the approver.

…use a connector pull with an unreadable target

A _sync_ key a beforeInsert or beforeUpdate hook assigns, changes or
removes is refused before the driver, on any write, the pull's own
included. A connector pull whose target definition cannot be read is
refused before the call instead of writing unstamped rows. The
_sync_external_id description names the mapped value.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WGufzeX8NmUPt5KSzQar4X
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract-review-claim: session_01WGufziwMkZG34d69p8BHb4 · head b501462 · 2026-11-24T02:26Z

Delta of record 7119012685 (S1, S2), by the same isolated reviewer.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: b501462548d911695306ab278fbe7cca1d3b6e3e
Local-runs: none
Scope: packages/spec/src/api/error-code-ledger.zod.ts, packages/spec/src/data/injected-system-column-provenance.ts, packages/spec/src/data/injected-system-columns.ts + packages/objectql/src/sync-provenance-write.ts, packages/objectql/src/engine-insert.ts, packages/objectql/src/engine-update.ts, packages/services/service-automation/src/connector-pull.ts (the delta's implementing files); unchanged since record 7119012685 and not re-judged: packages/objectql/src/sync-provenance-index.ts, registry.ts, registry-object-registration.ts, index.ts, packages/services/service-automation/src/sync-provenance-stamp.ts, datasource-pull.ts, packages/metadata-protocol/src/metadata-diagnostics.ts, the generated baselines

Delta review of record 7119012685 (head 805d6199). Inputs: the delta 805d6199..b5014625 (one commit, 10 files, +180 / −24), the net diff against main for context, the PR body as it now stands, the round's dev report (card comment 7120133737) and the claim amendment (7119042246), and the 74 check-runs on this head: 61 success, 12 skipped, 1 cancelled (a superseded PR-body guards run; its rerun on the same head is green).

① Derived judgments

  • Write accept-set, narrowed once more. A _sync_ key that a beforeInsert or beforeUpdate hook assigns, changes or removes is now refused with the same 400 ERR_SYNC_PROVENANCE_WRITE_REFUSED, before the driver, on every write, the pull's own included. Right: this is ADR-0153 D4's "refused by name, whatever the caller's context" and "the pull is their only writer", made true for the hook path.
  • SyncProvenanceWriteRefusedError gains an optional fourth constructor argument and a by: 'caller' | 'hook' member, defaulting to 'caller'. Additive; code, status and httpStatus are unchanged. Right.
  • Connector pull. A target whose definition cannot be read is refused 400 VALIDATION_ERROR, reason mapping_target_refused, before the connector action is called. It was written as pass-through before. A run-time refusal, not a change to what an author may declare. Right.
  • No export, ledger code or generated baseline moves in the delta. The ledger hunk is its comment only. Right.

② Semver level

Unchanged and still right: Clause-②: no (narrowing), Metadata-protocol: none, patch on the four packages. Both new refusals are stated in the changeset body; the hook refusal sits inside the BREAKING bullet, and the fix line now reads "leave the _sync_ columns out of the write and out of your hooks". Check Changeset is green on this head. The dogfood battery was re-run on this head (dev report 7120133737: b5014625, command-exit 0, 487 files passed, 3 skipped).

③ Boundary flags

  • The round's open_questions is empty.
  • The composite-key decision and the open point on two mappings per target are untouched by the delta: no encoding change, no refusal of a second mapping.
  • No new id materialisation and no in-app join. The hook judgment is a per-row key comparison in memory.

④ Design judgment

  • S1: closed. snapshotSyncKeys reads each row's _sync_ keys before the hook recording is armed, and refuseHookSyncProvenanceWrite compares after the seal and before the hand-back, the strips and the driver.
    • Insert: one snapshot per row over defaultedData, compared per row after the per-row seal, so a batch and insertMany are covered; rows already dead at the declared-field door are skipped.
    • Update: the snapshot is taken from opCtx.data after the read-only hide pass; all three beforeUpdate dispatches (by-id, unscoped multi, per-row) run before the one seal and the comparison, so the predicate path is covered too.
    • The pull's own write still reaches the driver with its stamps. The hide-and-hand-back passes run for a non-system context only, and on both doors they run before the snapshot, so a withheld key is absent on both sides of the comparison and cannot read as "removed". The stamps are compared by Object.is on the same references the pull handed in; nothing between the snapshot and the comparison copies values. A control test pins it (a hook writes a mapped field on the pull's write; both stamps are stored).
    • Tests: a hook on a system insert (code, status 400, by: 'hook', driver not called), a hook on the pull's insert by in-place write and by payload replacement, a hook on a system update, a hook on the pull's update. The dev report's ablation turns four of them red.
  • S2: closed. connector-pull.ts refuses when the target definition is not a plain object, before carriesSyncProvenanceColumns and before the action call. The new test serves no definition and asserts VALIDATION_ERROR, 400, mapping_target_refused, the handler not called and no write.
  • N2: closed. The _sync_external_id description now says "the value the mapping writes to its upsertKey field (the source value for a plain copy)", which is what stampSyncProvenance reads.
  • N7: closed. The PR body carries the battery reading and cites the open point at L853.
  • Published sentences against the code. The changeset, jobs.mdx, the ledger comment and the error class comment each state both judgments (the caller's payload before anything runs, the hooks' writes before the driver) and the connector refusal. They agree with the code. "The pull is the only writer" in injected-system-columns.ts and "Written by the pull only." in the definitions now hold for callers and hooks.
  • N1, N3, N4, N5, N6 of record 7119012685 stand as written there: carried to slice 6 or left as accepted deviations. The delta does not touch them.

New in this round:

N8 — The comparison is by Object.is. A hook that replaces the payload with a deep copy on the pull's write would be refused if a stamp were held as an object such as a Date. The pull hands its stamps in as strings today, and the error errs toward refusing, so nothing is stored wrongly. Worth one sentence in refuseHookSyncProvenanceWrite's comment when the file is next touched.

N9 — An unreadable target definition answers 400 VALIDATION_ERROR with reason mapping_target_refused and "Register the object, then run the pull again". When the cause is a transient metadata read failure, that reads as a defect in the mapping. The run record keeps the reason, so an operator can tell; a reason of its own is slice 6's call if the case shows up.

No must-fix, no should-fix.

Implemented-by: claude/project-thread-l53erx
Reviewed-by: session_01WGufziwMkZG34d69p8BHb4

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

席位核对 — ACCEPT · repo:objectstack#3 · head b501462 · 2026-11-24T02:30Z

L1: ACCEPT (delta of 7119029164)
Head-sha: b501462548d911695306ab278fbe7cca1d3b6e3e
Card: #32062, slice 5 · claim 7101769273 (File surface amended by the seat with the two spec files) · os-dev-report 7120133737.
Contract review on this head: 7120208665 (CONTRACT_REVIEW_TIER, PASS, No must-fix, no should-fix., same reviewer as 7119012685; claim 7120155658).

Delta read (805d619 → b501462, one commit, 10 files, +180/−24)

  • S1: closed.

    • snapshotSyncKeys takes each row's _sync_ keys before the hooks: per row on insert, so batch rows are covered, and once on update.
    • refuseHookSyncProvenanceWrite compares after the seal and before the hand-back and the driver, and throws the same 400 ERR_SYNC_PROVENANCE_WRITE_REFUSED with by: 'hook'.
    • New cases cover a hook on a system insert, on the pull's insert (in place and by replacing the payload), on a system update and on the pull's update. A CONTROL lets a hook's write to a mapped field pass with the stamps untouched.
    • Ablation: the hook-write refusal disabled turns 4 red.
  • S2: closed. connector-pull.ts refuses 400 mapping_target_refused before the connector action when the target definition is not a plain object. The new test asserts the handler is not called and nothing is written.

  • N7: closed. The body records the battery on this head and cites L853.

  • Published sentences re-read:

    • changeset bullets 2 and 3 (the hook clause and the unreadable-target refusal);
    • the jobs.mdx paragraph;
    • the error-code-ledger.zod.ts comment;
    • the _sync_external_id description (the contract review's N2: "the value the mapping writes to its upsertKey field").

    Each now matches the code.

  • Nothing else moved: no export, no ledger code, no generated baseline. The error class gains one optional constructor member (by), which the changeset states.

Gates at this head

  • 74 check-runs: 61 success, 12 expected skip, and 1 cancelled, which is a superseded PR-body guards run (01:44:29Z). The same check re-ran green at 01:44:45Z on this head, so it is not a red.
  • Lint & Repo Gates and TypeScript Type Check: success. mergeable_state clean.
  • Dogfood battery on b5014625 (the narrowing leg): os-verify-lock VERDICT exit 0, 487 files passed and 3 skipped, 4125 tests passed and 68 skipped. Full, pinned to this head.
  • Declarations unchanged: Clause-②: no (narrowing), Metadata-protocol: none, patch ×4.

Findings

Must-fix: none. Should-fix: none.

Nits:

  • The contract review's earlier N1, N3, N4, N5 and N6 stand; N1 and N4 carry to slice 6.
  • New in the delta record: N8 (Object.is would refuse a deep-copied Date stamp; the pull writes strings today) and N9 (a transient metadata read failure reads as "Register the object").

None affects correctness or the contract.

Landing

Tier H by the narrowing leg (! + Clause-②: no (narrowing)). ⛔ Not readied by this record: the seat hands it to the approver on this head with 7120208665 as the review of record. Part of #32062: the card keeps its claim for slice 6.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

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

维护者速读

  • 外部数据同步进来的对象(managedBy: 'synced')现在每行都记下来源:哪个映射、对方系统里的编号、拉取时间、哪一次运行;这几列对用户隐藏且只读。
  • 属于「数据同步 P2」专题第 5 片(sync-in P2 engine (epic #31763, ADR-0153): windowed and paged reads, committed position, delete marking, provenance, drift, sys_sync_run, organization scope #32062,按本席修订后的路线 A);第 6 片再处理删除标记。
  • 申报为收窄(Clause-②: no (narrowing)):除同步拉取本身以外,任何写入(包括系统上下文和钩子)碰到 _sync_ 列都会被拒绝(400);读不到目标对象定义的连接器拉取也会在调用前被拒绝。
  • 请审批人批准;批准后由维护者入队(本席尚无「审批人批准后的 Tier H PR 你可以自主落地」授权)。PR 正文「Decision for review」里写了复合键的编码方式(按 upsertKey 声明顺序的 JSON 数组),请一并过目。

Request: approval · Tier H by declared narrowing (2026-11-19 ruling) · 2026-11-24T02:34Z

席位意见: land. The provenance columns are what ADR-0153 D4 asks for, the refusal makes the four published "only the pull writes" sentences true (hooks included after the fix round), and slice 6 builds on this.

  • L1: ACCEPT 7120223324 (L1-b) at head b5014625; first-round REWORK 7119029164 closed.
  • Contract review (CONTRACT_REVIEW_TIER): record 7119012685 on 805d6199, delta record 7120208665 on b5014625 reads PASS with no open finding (S1 hook writes, S2 fail-closed pull: closed). Remaining nits carry to slice 6.
  • Dogfood battery on the final head b5014625: VERDICT exit 0 (487 files passed / 3 skipped; 4125 tests passed / 68 skipped).
  • Checks at b5014625: 61 success, 12 skipped, 0 failed; mergeable clean. NOT governed by path, 1469 lines; Tier H only by the narrowing leg. Part of #32062 (slice 5 of the card).

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 24, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review November 24, 2026 04:13
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 1d28405 Nov 24, 2026
79 of 80 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-l53erx branch November 24, 2026 04:43
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 24, 2026
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 protocol:data size/xl tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants