Skip to content

fix(dags): emit entity.write_back on the executor path, which never did (#770) - #775

Merged
athvin merged 1 commit into
mainfrom
fix/770-write-back-task
Nov 7, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/770-write-back-task

Conversation

@athvin

@athvin athvin commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Closes #770 · unblocks the last of #645's test ports

The gap

write_back_resolutions lived only in dispatcher.rs, called from one place — drain_and_correct, the legacy in-process arm. Nothing under dags/ referenced it. So on the executor path, which is the only path a job takes on a cluster, a review resolution that changed a master queued no entity.write_back and a subscriber integrated against O4 received nothing.

Third gap in the same family, after the run report (#756) and the staged-action hand-off (#760): Phase 3 moved the pipeline into tasks and left control-plane side-effects behind in the arm the tests were still exercising.

Why it needed a decomposition rather than a move

The old function needs both halves, and §6.4 keeps them apart:

  • the lake — a fresh session at the latest snapshot (the corrected corpus is only readable after the pass commits), entity_of_record_key per label, then entity_detail per entity;
  • Postgres — webhooks_for_delivery to find subscribers and webhook::emit to queue each event.

A pod can do the first and not the second; a control task can do the second and not the first, which control_tasks_no_engine.rs enforces by source scan.

So: write_back_scan (pod) reads the corpus and publishes WriteBackScanned; emit_write_back (control) queues the events from it.

The branch is parallel to settle_actions, deliberately

assemble ──┬─> settle_actions (control)      marks the actions applied
           └─> write_back_scan (pod) ─> emit_write_back (control)
                 └─ both -> finish (AllTerminal)

Putting the scan between assemble and settle_actions would make marking the actions applied depend on a webhook scan — so a reporting problem would leave the actions pending and re-apply the corrections on the next pass. That is the opposite of the best-effort bargain O4 has always had.

Best-effort is expressed in the task bodies, not the graph. er_dag::settle derives the job's outcome from its non-teardown leaves, so a task that failed here would fail a pass whose corrections are already applied and marked — destroying work in order to report on it. Both new tasks therefore swallow their own failures and return Done, logging every skip with its reason. That is exactly what the legacy arm did; only the mechanism is new.

One deliberate difference: the legacy half checked for subscribers before opening a lake session, to avoid paying for one nobody wanted. The scan's session is already open — being a pod task is what buys the lake read — and the subscriber list is Postgres, which a pod cannot reach. So emit_write_back skips instead, and a tenant with no subscriber pays for the scan rather than a session.

Evidence

pg_drain_dispatcher.rs is ported off the legacy arm, which is what this unblocks. It subscribes to entity.write_back before the pass precisely so that "nothing to deliver" cannot be mistaken for "nothing delivered", then asserts one master changed, the cause, the run id, and that the master is the assembled golden record rather than an id.

Observed failing with the branch removed — the pre-#770 graph — and the reproduction is the gap itself:

assertion `left == right` failed: the match collapsed the pair into ONE entity,
so one master changed: []
  left: 0
 right: 1

Two things the port had to change beyond the call, both the same as the other seven:

  • the fixture gains the artefacts a correction pass resolves through RunContext (ER_MODEL_PATH, ER_TF_PATH, ER_LEXICON_PATH and the version ids). It carried only the lake and the config, because the legacy run_correct needed only those.
  • the run id is no longer the test's to choose — on this path it IS the job id, so the payload assertion uses the enqueued id where it used to hard-code 01DISPCORRECT….

make check green; full er-server tier green against a real Postgres and DuckLake.

Note

dag_task_coverage.rs — which checks that every DAG node has a dispatch arm — is on the #645 branch and not yet on main, so it could not vet the two new nodes here. Verified by hand instead: write_back_scan resolves to the pod table and emit_write_back to the control table, and dag_assembly.rs confirms the graph still assembles.

`write_back_resolutions` lived only in `dispatcher.rs` with one caller —
`drain_and_correct`, the legacy in-process arm. Nothing under `dags/`
referenced it. So on the executor path, which is the only path a job takes on a
cluster, a review resolution that changed a master queued no
`entity.write_back`, and a subscriber integrated against O4 received nothing.

Third gap in one family, after the run report and the staged-action hand-off
(#760): Phase 3 moved the pipeline into tasks and left the control-plane
side-effects behind in the arm the tests were still exercising.

It needed a decomposition rather than a move, because the old function wants
both halves and §6.4 keeps them apart: a fresh lake session at the latest
snapshot to resolve record keys and read entity detail, and Postgres to find
subscribers and queue events. A pod can do the first and not the second; a
control task can do the second and not the first, which
`control_tasks_no_engine.rs` enforces by source scan. So `write_back_scan`
(pod) publishes `WriteBackScanned` and `emit_write_back` (control) queues from
it.

**The branch is parallel to `settle_actions`, not upstream of it.** Putting the
scan in between would make marking the actions applied depend on a webhook
scan, so a reporting problem would leave them pending and RE-APPLY the
corrections next pass — the opposite of the best-effort bargain O4 has always
had.

**Best-effort lives in the task bodies, not the graph.** `er_dag::settle`
derives a job's outcome from its non-teardown leaves, so a task that failed
here would fail a pass whose corrections are already applied and marked:
destroying work in order to report on it. Both tasks swallow their own failures
and return `Done`, logging every skip with its reason, because a write-back
that silently does not happen is indistinguishable from a tenant whose endpoint
is fine. Same bargain as the legacy arm; only the mechanism is new.

One deliberate difference: the legacy half checked for subscribers BEFORE
opening a session, to avoid paying for one nobody wanted. The scan's session is
already open — being a pod task is what buys the lake read — and the subscriber
list is Postgres, which a pod cannot reach. `emit_write_back` skips instead, so
a tenant with no subscriber pays for the scan rather than a session.

`pg_drain_dispatcher.rs` is ported off the legacy arm, which is what this
unblocks and what proves it. The file subscribes to `entity.write_back` before
the pass precisely so "nothing to deliver" cannot be mistaken for "nothing
delivered". Observed failing with the branch removed, and the reproduction is
the gap itself: zero write-backs and an empty delivery list.

The port also gains the artefacts a correction pass resolves through
`RunContext`, and its run-id assertion becomes the enqueued job id — on this
path the run id IS the job id, so a test cannot choose it.

`make check` green; the full 104-test er-server tier green against a real
Postgres and DuckLake.

Closes #770
Refs #645
@athvin
athvin merged commit 164d4b1 into main Nov 7, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

entity.write_back is never emitted on the executor path

2 participants