Skip to content

Commit 8236d9b

Browse files
feat(service-automation)!: a sync-in pull marks the rows the source deleted (ADR-0153 D3, #32062 slice 6) (#37179)
<!-- 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
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/service-automation': minor
4+
'@objectstack/runtime': minor
5+
'@objectstack/objectql': patch
6+
---
7+
8+
feat(service-automation)!: a sync-in pull marks the rows the source deleted, and an incremental source states how it learns of a delete
9+
10+
Clause-②: no (narrowing)
11+
Metadata-protocol: narrowed
12+
Skills-docs: none (no skills/ page names `deletePolicy`, `deletedField` or `_sync_deleted_at`; the guide that teaches them is `content/docs/automation/jobs.mdx`, updated here)
13+
14+
<!-- adr-0087: registered incremental-source-delete-policy-stated -->
15+
16+
ADR-0153 D3, delete marking (#32062, slice 6).
17+
18+
- **A pull marks a row the source deleted, and never deletes it.** Under `deletePolicy: 'mark'`, the reading when the key is absent, a pull stamps the platform column `_sync_deleted_at` on a row of a `synced` object that the source deleted, and clears it when a later pull reads the row again. `deletePolicy: 'ignore'` leaves every row as it is. Two detections:
19+
- `deletedField`, on any pull that declares it: a read record whose value in that source field is truthy has its copy marked; every other read record's copy is cleared.
20+
- Absence, on a full pull whose read was complete: every row of the mapping (`_sync_source`) the run did not read is marked. A `datasourceSource` with `full: true` is complete when its windows read to their end and no source row in the job's organization has a NULL watermark; it marks only rows whose copied watermark is at or above `watermark.start`. A `connectorSource` without a `watermark` is complete only under `paging: { style: 'none' }` (one response is the whole set); with no `paging`, or a paging style the pull does not follow yet, it marks nothing by absence. A refused or interrupted pull marks nothing by absence; a row the import runner refused was read, so it is not marked. A record whose `upsertKey` value is blank names no row, so one such record makes the run mark nothing by absence (`unjudged, rows refused`). A row pulled before the provenance columns existed carries no `_sync_source`, so it is no mapping's row: if the source has since deleted it, no pull marks it.
21+
- Two mappings on one target: each marks and clears only the rows whose `_sync_source` is its own; a second mapping is not refused.
22+
- **`sys_sync_run` records it.** New columns: `marked_deleted_count`, `deletes` (`judged`, `by deletedField`, `ignored`, or `unjudged, …` with the reason: `null watermark`, `no paging declared`, `pages not followed`, `rows refused`) and `skipped_null_watermark` (a datasource source's rows with a NULL watermark, counted under the organization predicate; through a plugin driver's row cap a count above the cap is recorded as the cap plus one). The end-of-pull log line says what the run marked and cleared. `job_run_id`'s and `trigger`'s descriptions now say when each is empty.
23+
- **BREAKING: an incremental source states how it learns of a delete.** A `connectorSource` with a `watermark`, or a `datasourceSource` without `full: true`, never sees an absent row, so under `deletePolicy` absent or `'mark'` with no `deletedField` it is refused at parse (`MappingSchema`, so `defineStack` and `os validate`) and again when the pull runs (`400 VALIDATION_ERROR`, reason `delete_policy_unhonourable`). Fix: name the source's soft-delete field (`deletedField: 'is_deleted'`), or write `deletePolicy: 'ignore'`, which is what every pull did before this release. New export: `incrementalSourceDeleteRefusal` (`@objectstack/spec/data`), the rule both doors ask.
24+
- **BREAKING: a `synced` target that withholds the provenance columns** (`systemFields: false`) is refused under `deletePolicy` absent or `'mark'` (`400 mapping_target_refused`): no row of it can carry the mark. Fix: let the platform add its columns, or write `deletePolicy: 'ignore'`. This arm is judged only when the pull runs: `os validate` and `defineStack` do not catch it, so a stack that validates green can still fail every scheduled pull. Migration entry `incremental-source-delete-policy-stated` names both arms.
25+
- A datasource source's `deletedField` must name a field of the source object (`400 source_binding_invalid` otherwise). `deletedField` is read by truthiness: the text `'false'` or `'0'` marks the row, and on a connector source a field the records do not carry reads as falsy on every record and marks nothing.
26+
- A stored `deletePolicy` outside `'mark'` / `'ignore'` (which the parse refuses) is refused by the pull too (`delete_policy_unhonourable`) instead of being read as `'mark'`.
27+
- The liveness rows for `deletePolicy` and `deletedField` on both sources are `live`, and `os validate` no longer warns that nothing reads them. `paging` stays `planned`: the connector paging loop is a later change.
28+
- A connector pull whose target definition cannot be read now says whether the object is not registered or the metadata read failed.
29+
- A connector pull keeps the job run id and trigger only when the run record can hold them: a trigger other than `schedule` or `manual`, or a run id longer than 255 characters, is left out instead of failing the run record's open.
30+
- `JobHandlerContext` (`@objectstack/runtime`) declares `trigger` and `runId`: the handler run form spreads the job service's context into the handler's, so every `handler` job already receives `trigger`, and `runId` under the database job adapter. The jobs guide lists both.

‎content/docs/automation/jobs.mdx‎

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,46 @@ export const OrdersPullJob = defineJob({
313313
part-way keeps the position of its last finished window. The first run,
314314
every run of a mapping that declares `full: true`, and a run whose mapping
315315
now reads another source object or field, or writes another target, read
316-
from `watermark.start`; a run never reads below it. The delete keys change
317-
nothing yet, and `os validate` says so.
316+
from `watermark.start`; a run never reads below it.
317+
- **A row the source deleted is marked, never deleted.** Each source block
318+
carries `deletePolicy`: `'mark'` (the reading when the key is absent) or
319+
`'ignore'`, which leaves every row as it is. Under `'mark'` a pull stamps
320+
`_sync_deleted_at` on a row the source deleted and clears it when a later pull
321+
reads the row again; the row stays an ordinary row on every read path, so
322+
filter on `_sync_deleted_at` where a deleted row should not show. A pull learns
323+
of a delete two ways:
324+
- **`deletedField`**, on any run that declares it: a read record whose value
325+
in that source field is truthy (a soft-delete flag or a deleted-at column)
326+
has its copy marked, and every other read record's copy is cleared.
327+
Truthy is JavaScript's: the text `'false'` or `'0'` marks the row, so map a
328+
real boolean or a deleted-at value; on a `connectorSource` a misspelt field
329+
reads as falsy on every record and marks nothing, silently.
330+
- **Absence**, on a full run whose read was complete: every row of the
331+
mapping (its `_sync_source`) the run did not read is marked. A
332+
`datasourceSource` run with `full: true` is complete when its windows read
333+
to their end and no source row in the job's organization has a NULL
334+
watermark (such a row is in no window and would read as absent); it marks
335+
only rows whose copied watermark is at or above `watermark.start`, so
336+
raising the start marks nothing below it. A `connectorSource` run without a
337+
`watermark` is complete only when it declares
338+
`paging: { style: 'none' }`, which says its one response is the whole set;
339+
with no `paging`, or a paging style the pull does not follow yet, it marks
340+
nothing by absence. A run that is refused or stops part-way, one whose
341+
rows the import runner refused beyond a thousand, or one that read any
342+
record whose `upsertKey` value is blank (it names no row) marks nothing by
343+
absence (`deletes: unjudged, rows refused`). A row pulled before the
344+
provenance columns existed has no `_sync_source`, so no pull marks it.
345+
- **Two mappings on one target** each mark and clear only the rows whose
346+
`_sync_source` is their own; a second mapping is not refused.
347+
348+
An incremental source (a `connectorSource` with a `watermark`, a
349+
`datasourceSource` without `full: true`) never sees an absent row, so under
350+
`'mark'` it must name `deletedField`, or declare `deletePolicy: 'ignore'`:
351+
`os validate` refuses it otherwise, and so does the pull of a mapping no build
352+
judged. A `synced` target that declares `systemFields: false` has no column to
353+
mark, so its mapping declares `deletePolicy: 'ignore'`; `os validate` does not
354+
catch this one, only the pull refuses it (`mapping_target_refused`), so a
355+
stack that validates green still fails each run until it is fixed.
318356
- **Every row says where it came from.** A `synced` object carries five
319357
hidden, read-only columns the platform adds to it, beside the tenant and audit
320358
columns, with an index on (`organization_id`, `_sync_source`,
@@ -323,14 +361,14 @@ export const OrdersPullJob = defineJob({
323361
a key of several fields, a JSON array of their values in the order `upsertKey`
324362
lists them, such as `["10","A-1"]`), `_sync_pulled_at` (when it was written)
325363
and `_sync_run_id` (the pull's `sys_sync_run` row; not written when no run
326-
record is kept). `_sync_deleted_at` is there but empty on every row: delete
327-
marking has not landed yet. Nothing else writes these columns: a write that
364+
record is kept). `_sync_deleted_at` is the delete mark (above). Nothing else writes these columns: a write that
328365
names a `_sync_` column is refused with `400
329366
ERR_SYNC_PROVENANCE_WRITE_REFUSED`, a system-context one included, and so is
330367
a write whose `beforeInsert` or `beforeUpdate` hook assigns, changes or
331368
removes one, the pull's own write included. A mapping whose `fieldMapping`
332369
targets one is refused when it runs, and so is a connector pull whose target
333-
object's definition cannot be read. A `synced`
370+
object's definition cannot be read (the refusal says whether the object is not
371+
registered or the metadata read failed). A `synced`
334372
target that declares `systemFields: false` has none of these columns, and its
335373
rows are written without them.
336374
- **How a run is recorded.** A pull the platform refuses — the mapping is gone,
@@ -341,11 +379,14 @@ export const OrdersPullJob = defineJob({
341379
would refuse the same rows. Otherwise the run is `success`, including a pull
342380
that found nothing new. Every pull also leaves one `sys_sync_run` row in the
343381
job's organization: the mapping, the job run that drove it (`job_run_id`, the
344-
attempt's `sys_job_run` id, and `trigger`, `schedule` or `manual`; both empty
345-
under a job service that keeps no run history, where only the trigger may be
346-
kept), where it read from and from which position,
347-
the rows read, created, updated and refused, the position it committed, and
348-
how it ended (`completed`, `degraded` or `failed` with the refusal's reason).
382+
attempt's `sys_job_run` id, empty under a job service that keeps no run
383+
history; and `trigger`, `schedule` or `manual`. Both are empty for a pull no
384+
job started), where it read from and from which position,
385+
the rows read, created, updated, refused and marked deleted, what it did about
386+
deletes (`deletes`: `judged`, `by deletedField`, `ignored`, or `unjudged, …`
387+
with the reason), the source rows with a NULL watermark
388+
(`skipped_null_watermark`, a datasource source only), the position it
389+
committed, and how it ended (`completed`, `degraded` or `failed` with the refusal's reason).
349390
A pull still `running` when the server stopped is closed `failed`
350391
(`interrupted`) at the next start. Rows are kept 30 days, except the one
351392
holding each mapping's read position.
@@ -440,6 +481,8 @@ At run time the handler is invoked with a `JobHandlerContext`
440481
| `ql` | the live ObjectQL engine — the same handle `defineStack({ onEnable })` receives |
441482
| `logger` | the platform logger, so a job's diagnostics are not `console` output |
442483
| `executionContext` | the context the job runs as — `{ isSystem: true, tenantId }` for a job that declares an [`organization`](#the-organization-a-job-runs-as), else `{ isSystem: true }`. `ql` is the raw engine, so pass it as each call's `context` to write as that organization |
484+
| `trigger` | why this run started — `schedule` or `manual`; absent under a job service that sends none |
485+
| `runId` | the job service's run-history id for this attempt (a `sys_job_run` id under the database job adapter); absent under a job service that keeps no run history |
443486

444487
```typescript
445488
import type { JobHandlerContext } from '@objectstack/runtime';

‎packages/objectql/src/sync-provenance-write.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ export function snapshotSyncKeys(row: unknown): ReadonlyMap<string, unknown> {
154154
* caller judged clean the snapshot is empty, so any `_sync_` key is a hook's;
155155
* on the pull's write it holds the pull's stamps, which must reach the driver
156156
* as written.
157+
*
158+
* The comparison is by identity (`Object.is`), so a hook that replaced the
159+
* payload with a deep copy would be refused if a stamp were held as an object
160+
* such as a `Date`; the pull hands every stamp in as a string, and the error
161+
* errs toward refusing, so nothing is stored wrongly.
157162
*/
158163
export function refuseHookSyncProvenanceWrite(
159164
object: string,

‎packages/runtime/src/job-handler-context.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* unchanged byte for byte; no `IJobService` implementation grows a member.
4747
*/
4848

49-
import type { IObjectQLEngine, Logger } from '@objectstack/spec/contracts';
49+
import type { IObjectQLEngine, JobRunTrigger, Logger } from '@objectstack/spec/contracts';
5050

5151
/**
5252
* What `AppPlugin` invokes a declarative job's `functions` entry with.
@@ -111,4 +111,17 @@ export interface JobHandlerContext {
111111
* keeps compiling — the widening stays additive in both directions.
112112
*/
113113
executionContext?: { isSystem: true; tenantId?: string };
114+
/**
115+
* Why this run started: `'schedule'` on the job's schedule, `'manual'`
116+
* when someone ran it now. Handed on from the job service's own context
117+
* (`IJobService`'s handler context), so it is absent under a job service
118+
* that sends none.
119+
*/
120+
trigger?: JobRunTrigger;
121+
/**
122+
* The job service's run-history id for this attempt: on the shipped
123+
* adapters, the `sys_job_run` row `DbJobAdapter` wrote. Absent under a job
124+
* service that keeps no run history.
125+
*/
126+
runId?: string;
114127
}

‎packages/services/service-automation/src/connector-pull-undeclared-input-key.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function incrementalMapping(input: Record<string, unknown>) {
5252
connectorSource: {
5353
connector: 'crm_api', action: 'list_contacts', input,
5454
watermark: { field: 'updated_at', param: 'since' },
55+
deletePolicy: 'ignore',
5556
},
5657
};
5758
}

‎packages/services/service-automation/src/connector-pull.integration.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const MAPPING = {
6262
input: { method: 'GET', path: '/contacts' },
6363
recordsPath: 'body.results',
6464
watermark: { field: 'updated_at', param: 'since' },
65+
deletePolicy: 'ignore',
6566
},
6667
};
6768

0 commit comments

Comments
 (0)