Repository navigation
Commit 8236d9b
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBEaJzgBWzjWCNjBjkVoeRto)_
Part of #32062
Clause-②: no (narrowing)
Metadata-protocol: narrowed
Skills-docs: none (no skills/ page names `deletePolicy`, `deletedField`
or `_sync_deleted_at`: `git grep -c -E
"deletePolicy|deletedField|_sync_deleted_at" -- skills/` exits 1 with
zero hits at 0f46c64, control `git grep -c "name:" -- skills/` hits;
the guide that teaches them is `content/docs/automation/jobs.mdx`,
updated here)
## 维护者速读
-
同步数据的管理员会看到:源系统删掉的记录,在平台里被打上"源已删除"标记(不会真删),源里恢复后标记自动清除;增量同步若没说明如何识别删除,保存时会被拒。
- 属于"单向同步进平台(sync-in)"这件事的第六步:让同步能如实反映源系统的删除。
- 出错时最坏是某些行被误标或漏标为"已删除",数据本身不丢、不删;下一次完整同步会纠正,改动可整体撤回。
- 无
## What changes
ADR-0153 D3 (delete marking) on both sync-in read paths, plus the
carried review nits. Not in this PR (later slices of the card): D4
purge, D6 drift, D8 refusals beyond what landed, the connector paging
loop.
- **Delete marking**
(`packages/services/service-automation/src/sync-delete-mark.ts`, new
sibling module). Under `deletePolicy` absent (reads as `'mark'`) or
`'mark'`, a pull stamps `_sync_deleted_at` on a row the source deleted
and clears it when a later pull reads the row again; `'ignore'` leaves
every row. Two detections:
- `deletedField`, on any pull that declares it: truthy marks the row's
copy, anything else clears it.
- Absence, on a full pull whose read was complete: every row of this
mapping (`_sync_source`) not stamped by this run (`_sync_pulled_at`
before the run start) and not refused by it is marked.
- **Completeness, per ADR-0153 D3.** Datasource source: `full: true`,
the windows read to their end on either read path, and the
NULL-watermark count (D2 invariant 11, under the D8 organization
predicate; through the floor on a floored driver, recorded as cap plus
one above the cap) is zero, else `unjudged, null watermark`. The mark's
range is limited to rows whose copied watermark is non-NULL and at or
above `watermark.start`. Connector source: no `watermark` and `paging: {
style: 'none' }`; no `paging` records `unjudged, no paging declared`, a
paging style whose loop is not built records `unjudged, pages not
followed`. A refused or interrupted pull marks nothing by absence; more
than 1000 runner-refused rows, or any read row with a blank match key
(it names no target row), records `unjudged, rows refused` (review M1).
A batch's keys go into each find 500 at a time (`KEYS_PER_FILTER`), far
below any dialect's bound-parameter limit, however long a connector
response is (review S1).
- **Incremental-`mark` refusal (the narrowing).**
`incrementalSourceDeleteRefusal` (`@objectstack/spec/data`, new export)
refuses at parse (`MappingSchema`, path `[source, 'deletePolicy']`) an
incremental source (connector with `watermark`, datasource without
`full: true`) under `'mark'` with no `deletedField`; both pulls ask the
same rule at run time (`400 VALIDATION_ERROR`, reason
`delete_policy_unhonourable`). Migration entry
`incremental-source-delete-policy-stated` (ADR-0087 semantic); changeset
carries the marker and the FROM/TO fix.
- **A `synced` target that withholds the provenance columns**
(`systemFields: false`) is refused under `'mark'`
(`mapping_target_refused`). This is the second BREAKING arm: it is
judged only when the pull runs, and `os validate` does not catch it.
Migration entry 18 names it, its replacement, and the failed
`sys_sync_run` as the signal for a mapping stored at run time; the
changeset and `jobs.mdx` say the same (review S3, N8). No parse-time
refusal is added for it. A datasource `deletedField` that is not a
source field is refused `source_binding_invalid`.
- **`sys_sync_run`**: new `marked_deleted_count`, `deletes`,
`skipped_null_watermark`; end-of-pull log line says what was marked and
cleared.
- **Liveness**: `deletePolicy` / `deletedField` under both sources flip
`planned` to `live` with evidence, `authorWarn` dropped. `paging` stays
`planned`.
- **Nits.** Record 6791935060: N1 `JobHandlerContext` declares `trigger`
/ `runId`, the jobs guide lists them; N2 `originOf` keeps a trigger or
job run id only when the run record can hold it; N3 the
self-contradicting `jobs.mdx` sentence reworded; N5 `job_run_id` /
`trigger` descriptions say when each is empty; N4 is NOT fixed here (see
Acceptance notes). Record 7119012685 / 7120208665: N1 the
reordered-`upsertKey` consequence stated at `encodeSyncExternalId` and
in the marker; N4 the bare-name `_sync_source` scope stated in the
marker (see Decision below); N8 the `Object.is` sentence in
`refuseHookSyncProvenanceWrite`; N9 the unreadable-target refusal says
whether the object is not registered or the metadata read failed (same
reason `mapping_target_refused`, no new reason).
- **Review round 2 (L2 7151034259, L1 7151052312).** M1 and S1 above; S2
`packages/spec/docs/SYNC_ARCHITECTURE.md`'s `ordersPull` example states
`deletedField: 'is_deleted'`, so it parses; S3 above; S4 below; L1 M1
the changeset names `'@objectstack/objectql': patch`. Nits: N1 marks and
clears are counted per row, so a run that fails part-way closes with the
rows it changed; N2 `deletedField` truthiness (text `'false'` / `'0'`
marks, a misspelt connector field marks nothing) stated in `jobs.mdx`,
the changeset and the marker; N3 the NULL-watermark count reads only
`id` (floored and paged fallback); N4 a stored `deletePolicy` outside
`'mark'` / `'ignore'` is refused `delete_policy_unhonourable` by both
pulls instead of read as `'mark'`; N5 the connectorSource D3 liveness
evidence names `pullOnce` (the executor pin's `pullConnectorSource` kept
beside it); N6 `sys_sync_run.deletes` says it is also empty for a
connector target with no provenance columns; N7 rows pulled before the
provenance columns existed are no mapping's and are never marked
(changeset, `jobs.mdx`); N8 entry 18's acceptance criteria name the
run-time signal; N9 is the report's.
## Decision
Two mappings on one target: decided here. Each mapping marks and clears
only rows whose `_sync_source` is its own; a second mapping is not
refused. Cross-package same-name residual carried as item 7151120322 on
#32062.
This is the behaviour of this tree: `SyncDeleteMarker` scopes every find
by `_sync_source` equal to the mapping's name, and no pull refuses a
second mapping on a target.
### Read first (by risk)
1. `packages/services/service-automation/src/sync-delete-mark.ts` —
`afterBatch` (the keyless-row count and the 500-key chunks) and
`canMarkAbsent` decide whether absence is judged; `markAbsent` (the
where clause: `_sync_source`, `_sync_pulled_at` before `runStartedAt`,
the refused-key `$nin`, the range) decides which rows are marked.
2. `packages/services/service-automation/src/datasource-pull.ts` — the
delete judgment after `readSourceInWindows` and `countNullWatermarks`.
3. `packages/spec/src/data/mapping.zod.ts` —
`incrementalSourceDeleteRefusal` and its use in the sourced-mapping
refinement (the narrowing).
### Two-minute check
`pnpm --filter @objectstack/service-automation exec vitest run
--maxWorkers=2 src/sync-delete-mark.test.ts src/datasource-pull.test.ts
src/connector-pull.test.ts` — expect 135 passing, among them the four
`[review M1]` cases.
## Tests
- `connector-pull.test.ts`: D3 block on a real engine (complete full
pull marks then clears; no `paging` and an unfollowed style mark nothing
by absence; `deletedField` marks and clears; incremental under mark
refused before the action; ignore); `systemFields: false` under ignore
vs mark; N2 origin bounds; N9 read-failure refusal.
- `datasource-pull.test.ts`: D3 block (complete full pull marks then
clears; floored path, with a NULL count over the cap recorded as cap
plus one; range below a raised start untouched; NULL watermark blocks
the mark and is counted; the count carries the organization predicate;
refused row not marked; another mapping's rows untouched; refused
part-way marks nothing; ignore; `deletedField`; the three refusals).
- Round 2: `[review M1]` on both pulls (datasource: one blank-key row
plus a deleted row leaves `unjudged, rows refused`, nothing marked, run
record says so; connector: a response whose records all lost the key,
and one keyless record beside a dropped one); `[review N4]` on both
pulls; new `sync-delete-mark.test.ts` (the 1000-key limit at 1000 and
1001, one keyless row makes the run unjudgeable, `$in` chunks of
500/500/1 on clear and 500/1 on mark, a mark failing at row 3 keeps
`marked` at 2).
- `mapping-sync-in.test.ts`, `mapping-connector-source.test.ts`: the
parse refusal and its legal twins; the liveness pin now expects only
`paging` planned.
<details><summary>Local runs (round 2, head 0f46c64)</summary>
Each through `scripts/pm/os-verify-lock.sh`, verdict line quoted. Head
0f46c64 = 357423a plus one liveness-evidence text edit (N5).
- `pnpm --filter @objectstack/service-automation test && ... typecheck`
at 357423a: `Test Files 295 passed (295)`, `Tests 4316 passed
(4316)`, `VERDICT command-exit 0`. The three touched suites again at
0f46c64's code: `Tests 135 passed (135)`, `VERDICT command-exit 0`.
- `pnpm --filter @objectstack/spec test && ... typecheck` at 0f46c64:
`Test Files 890 passed (890)`, `Tests 28308 passed | 1 todo (28309)`,
`VERDICT command-exit 0`. (At 357423a the connectorSource liveness
pin was red on the first N5 spelling, which dropped
`pullConnectorSource`; fixed in 0f46c64.)
- Ablation (one, the M1 fix): `node scripts/ablation-replace.mjs
--anchor 'return this.unnamed === 0 && this.unwritten.size'
--replacement 'return this.unwritten.size'` (anchor 1 -> 0, blob
5707ffa -> a7b315ca2f01); `vitest run src/sync-delete-mark.test.ts
src/datasource-pull.test.ts src/connector-pull.test.ts`: `Tests 4 failed
| 131 passed (135)`, the four failures being exactly the three `[review
M1]` pull pins and the unit pin "one read row with no key makes the run
unjudgeable", `VERDICT command-exit 1`; restored, blob == HEAD
5707ffa, `git diff HEAD` empty. The suites import the module from
`src/` by relative path, so no dist leg applies.
- Dogfood battery (title carries `!`) at 0f46c64, after `pnpm
--filter '@objectstack/dogfood^...' ... build` (`VERDICT command-exit
0`): `pnpm --filter @objectstack/dogfood test`: `Test Files 487 passed |
3 skipped (490)`, `Tests 4128 passed | 68 skipped (4196)`, `VERDICT
command-exit 0`.
</details>
## Acceptance notes
- **N4 of record 6791935060 (cli CHANGELOG "see its own entry") is not
fixed here.** The sentence is in released entries
(`packages/cli/CHANGELOG.md:1203`, `packages/spec/CHANGELOG.md:3173`;
the same phrase in four more packages' released entries). CHANGELOGs are
release-owned: a released-entry correction is a dedicated docs-only PR,
never a rider on a code PR. Carrier: the seat.
- **Edge stated, not fixed:** on the first run after `upsertKey` is
reordered, a runner-refused row keeps its old `_sync_external_id`
spelling, so the refused-key exclusion (new spelling) does not cover it
and the absence mark stamps it; the next run that writes it clears it.
Stated in `sync-delete-mark.ts`.
- `incrementalSourceDeleteRefusal` and `syncDeletePolicyRefusal` judge a
stored block at run time, a mapping no parse saw, with the parse's rule;
a second door for the same rule, not a lenient alias (a `deletePolicy`
outside the enum is now refused, review N4).
- The refused-key `$nin` of `markAbsent` holds at most 1000 keys,
unchanged this round (the L2 accepted the bound).
- Files outside the order's surface:
`packages/objectql/src/sync-provenance-write.ts` (comment only, N8),
`packages/runtime/src/job-handler-context.ts` (N1),
`packages/spec/src/data/injected-system-column*.ts` (describe text of
`_sync_deleted_at`), the spec migration entry and generated
`api-surface` / `export-origins` / liveness counts; round 2 adds
`packages/spec/docs/SYNC_ARCHITECTURE.md` (review S2). The zone amended
the claim for them.
## Verification
Local subset = `node scripts/pm/dispatch-gates.mjs --commands` (124
commands), each run with its exit captured before any pipe; reconciled
with `--ran` on a record carrying every exit code: "124 derived, 124
run, 0 NOT-MEASURED, 0 UNRUN" ("a DERIVED zero — all 124 recorded an
exit code and none of them is 3").
- First pass at 357423a: 121 exit 0; `cli vitest run
test/migrate-meta-engine-guidance.test.ts` exit 1 (`MODULE_NOT_FOUND`
for `@objectstack/mcp/dist`, the cli closure not built yet), `spec
check:skill-examples` and `check:dual-build-cjs-loads` exit 3 (client
dist not built). After the closure build, all three re-run at
0f46c64: exit 0. `spec check:liveness`, `check:upgrade-guide`,
`check:generated` and `check-nul-bytes` re-run at 0f46c64: exit 0.
- CI on 0f46c64: 60 success, 10 skipped, 0 failure (Lint & Repo
Gates, TypeScript Type Check, Test Core, Build Core, Test UI, Dogfood
Regression Gate, Check Changeset and the PR-body guards among them). The
reds on 677bad4 were the aggregators over lanes cancelled by the next
push.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzg3KqwSpt61Y8ovKK7)_
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzg3KqwSpt61Y8ovKK7 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent d15e439 commit 8236d9b
29 files changed
Lines changed: 1427 additions & 96 deletions
File tree
- .changeset
- content/docs/automation
- packages
- objectql/src
- runtime/src
- services/service-automation/src
- spec
- api-surface
- docs
- export-origins
- liveness
- state-counts
- src
- data
- migrations/entries/semantic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
318 | 356 | | |
319 | 357 | | |
320 | 358 | | |
| |||
323 | 361 | | |
324 | 362 | | |
325 | 363 | | |
326 | | - | |
327 | | - | |
| 364 | + | |
328 | 365 | | |
329 | 366 | | |
330 | 367 | | |
331 | 368 | | |
332 | 369 | | |
333 | | - | |
| 370 | + | |
| 371 | + | |
334 | 372 | | |
335 | 373 | | |
336 | 374 | | |
| |||
341 | 379 | | |
342 | 380 | | |
343 | 381 | | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
349 | 390 | | |
350 | 391 | | |
351 | 392 | | |
| |||
440 | 481 | | |
441 | 482 | | |
442 | 483 | | |
| 484 | + | |
| 485 | + | |
443 | 486 | | |
444 | 487 | | |
445 | 488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
157 | 162 | | |
158 | 163 | | |
159 | 164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
114 | 127 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
0 commit comments