Skip to content

fix(server): restore the entity.* aggregate the DAG path dropped - #629

Merged
athvin merged 1 commit into
mainfrom
bm/entity-aggregate-regression
Nov 6, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/entity-aggregate-regression

Conversation

@athvin

@athvin athvin commented Nov 6, 2026

Copy link
Copy Markdown
Owner

A regression I introduced in #498 and did not notice. I found it while implementing the "where does run_job's tail land" decision I had deferred — which is itself the argument for not having deferred it.

What broke

Putting run_all_full on the executor allowlist moved pipeline runs off the legacy arm. That arm's tail did two things once a run settled:

dispatcher.rs:865   emit_entity_aggregates(client, &completed, &entity_counts)
dispatcher.rs:871   run_report_messages(..., &entity_counts)

The DAG path's settle did one:

executor.rs:397     webhook::emit_job_event(&self.client, &settled)

emit_job_event sends the job.* event for the outcome. It does not send the entity.* aggregates — and emit_entity_aggregates had exactly one caller, the arm the pipeline kinds had just stopped using.

So since #498 deployed, every pipeline run on the ci namespace has emitted no entity.created, entity.merged or entity.member_added aggregate, and the emailed run report has carried no entity counts. A subscriber keyed on entity.* simply stopped hearing, with nothing reporting that. Dev-only, since prod isn't deployed.

Why the counts have to ride in the task output

Counting is a lake query; emitting is a Postgres write. No single process does both any more — and the legacy code's own comment says exactly why:

Read HERE because this is the half that holds the lake session; the half that can emit holds the Postgres client.

In run_job those were two halves of one function. Split across a pod boundary they're a pod and the control plane, and the control plane cannot open a lake — which lib.rs's clear-closure probe already states outright: "THIS process cannot open a lake (§3.5 draws that line at the lake, and the control plane is on the wrong side of it)".

So finish counts — it's the last task of the run and the last place a lake session exists — and publishes into FinishReport. Settle emits, reading the counts off the row map the readiness pass already loaded, so no extra query. Best-effort at both ends exactly as the legacy arm was: a count that can't be read must not fail a teardown whose run is already written.

Absent for every kind with no finish task, which is correct rather than a gap — lake_maintain, train and profile reconcile no entities, so there's nothing to announce. §10 says as much: "Entity aggregates fire at settle."

Tests

The boundary is JSON, and nothing type-checks output["doc"]["entity_counts"] — it's Value::get on strings, so a rename on either side would compile and then silently emit nothing, which is this exact bug a second time. Three tests pin it:

  1. the round trip through Plan(FinishReport) using the settle path's literal key chain;
  2. an empty count set reading as "nothing to announce" rather than as a missing reading (finish is a teardown on AllTerminal, so it also runs after a failed init);
  3. an output written before the field existed still deserializing — #[serde(default)] is what keeps a {"settled": "closed"} row already in the ledger readable, and pg_task_instances.rs writes exactly that shape.

make check green.

🤖 Generated with Claude Code

A regression I introduced in #498 and did not notice.

Putting `run_all_full` on the executor allowlist moved pipeline runs off the
legacy arm. The legacy arm's tail did two things once a run settled:

    dispatcher.rs  emit_entity_aggregates(client, &completed, &entity_counts)
    dispatcher.rs  run_report_messages(..., &entity_counts)

The DAG path's settle did one:

    executor.rs    webhook::emit_job_event(&self.client, &settled)

`emit_job_event` sends the `job.*` event for the outcome. It does NOT send the
`entity.*` aggregates, and `emit_entity_aggregates` had exactly one caller —
the arm the pipeline kinds had just stopped using. So since #498 deployed,
every pipeline run on the ci namespace has emitted no `entity.created`,
`entity.merged` or `entity.member_added` aggregate, and the emailed run report
has carried no entity counts. A subscriber keyed on `entity.*` simply stopped
hearing, with nothing reporting that.

## Why the counts have to ride in the task output

Counting is a lake query; emitting is a Postgres write. No single process does
both any more, and the legacy code's own comment says why:

    Read HERE because this is the half that holds the lake session; the half
    that can emit holds the Postgres client.

In `run_job` those were two halves of one function. Split across a pod
boundary they are a pod and the control plane — and the control plane cannot
open a lake, which `lib.rs`'s clear-closure probe already states outright
("THIS process cannot open a lake (§3.5 draws that line at the lake, and the
control plane is on the wrong side of it)").

So `finish` counts — it is the last task of the run and the last place a lake
session exists — and publishes into `FinishReport`. Settle reads the counts off
the row map the readiness pass already loaded, and emits. Best-effort at both
ends, as the legacy arm was: a count that cannot be read must not fail a
teardown whose run is already written.

Absent for every kind with no `finish` task, which is correct rather than a
gap: `lake_maintain`, `train` and `profile` reconcile no entities, so there is
nothing to announce. §10 says as much — "Entity aggregates fire at settle".

## Tests

The boundary is JSON and nothing type-checks `output["doc"]["entity_counts"]`
— it is `Value::get` on strings, so a rename on either side would compile and
then silently emit nothing, which is this exact bug a second time. Three tests
pin it: the round trip through `Plan(FinishReport)` using the settle path's
literal key chain, an empty count set reading as "nothing to announce" rather
than as a missing reading, and an output written BEFORE the field existed still
deserializing — `#[serde(default)]` is what keeps a `{"settled": "closed"}` row
already in the ledger readable, and `pg_task_instances.rs` writes exactly that
shape.

`make check` green.

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin merged commit a172b58 into main Nov 6, 2026
39 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.

2 participants