Skip to content

feat(duckfleet): recover remote attempts from evidence, never replay - #1157

Merged
athvin merged 9 commits into
mainfrom
issue/1133-duckfleet-recovery
Nov 21, 2026
Merged

athvin merged 9 commits into
mainfrom
issue/1133-duckfleet-recovery

Conversation

@athvin

@athvin athvin commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #1133

Claimed by Codex session 01a1fb62-5950-78d2-982c-5ecb2cd40d30 on brians-MacBook-Pro.local at 2026-11-21T07:46:12.484822+00:00.
This open draft PR is the claim; closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

A remote golden attempt now holds a dataset fence (remote_attempts) from before its session opens until its publication outcome is established. It journals every request id over the attempt channel before sending it, and tags the publishing commit with a lake receipt. Anything the pod cannot settle is reconciled by a dispatcher sweep from DuckFleet's durable request records and the receipt. Nothing is replayed. job/update/claim.sql admits no writer of any backend for a held dataset.

Why

#1133: after a transport loss, cancellation or worker loss around COMMIT, the job must report a truthful outcome. No retry, re-run or embedded run may race a commit that might still land, and nothing may re-execute SQL to find out what happened.

Proof

  • make check: see the Context block for the run on the final head.
  • pg_remote_attempt_fence (real Postgres): scope comes from the token, stale pods and relaunches are refused, COMMIT is journaled once, every writer is held, and the sweep releases only on conclusive evidence.
  • make check-duckfleet-task (real DuckFleet at the pinned revision). Owner release is committed with exactly one receipt. Then two COMMIT faults through an in-test relay. When the reply is lost after COMMIT landed, the job fails and the dataset is held; the sweep finds the receipt and settles committed, with exactly one publication. When the COMMIT never reaches the gateway, the job fails and the dataset is held; the sweep settles rolled_back, with the lake unchanged.
  • er-duckfleet unit tests: journal ordering and refusal, loss during temp work, during writes and around COMMIT, cancellation with acknowledged close, and one test per decide row.

Risk & rollback

Default-off. Only a task pod with ER_DUCKFLEET_TASK_POLICY journals, and nothing is enrolled. claim.sql gains one NOT EXISTS against an empty table. git revert <merge-sha> is an acceptable rollback. An attempt row left unresolved by a revert would hold its dataset; release it after checking the receipt.

Post-merge ledger

Closed by: agent · session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on brians-MacBook-Pro · 2026-11-21T17:07:16Z

  • main is green with this change on it — the merge SHA, and the run
    that proves it. A later head SHA with this commit as an ancestor counts;
    a cancelled run with zero jobs does not: f5aa9a86. rust 44927305240, frontend 44927305149, infra 44927305141, devcontainer 44927305212, marketing preview 44927305255 all success; baseline b784c21a was all green
  • images built, or correctly never ran because nothing that goes into
    an image changed: images 44927305177 success on f5aa9a86
  • deploy converged — proved by a line the running process emitted, not
    by the image digest and not by the workflow conclusion: blocked (prod only) — dev proven: new pod ci/web-api-blue-f645f9bb9-txvdl emitted er-server listening at 2026-11-21T17:00:51Z, after the deploy began at 16:59; boot reconciles the schema before listening. Prod not read: the athvin-prod kubectl context hung on auth and this session has no CloudWatch path. Observed so far: deploy 44927547497 success with DEPLOY_SHA=f5aa9a86 for prod and dev; cutover logged "traffic is verified on green" (prod) and "on blue" (dev); https://dupezero.com/api/healthz returned {"ready":true,"upstream":"ok"}. Unblock: read er-server's startup or schema-reconcile log line for the new pods in CloudWatch
  • the push-only surface no pull request can pre-test (deploy, drift,
    kind's nightly leg) is green, or knowingly red for a reason that is not
    this change: deploy green (above). drift and nightly kind did not run on this SHA; kind has been red since 2026-11-10 for an undiagnosed cause tracked in kind probe red since 2026-11-10: KeyError 'token_hash' after the credential-omission fix #1106, which predates this change
  • the board card reached Done through the automation rather than by
    hand, and the issue closed: DuckFleet: recover remote jobs safely after cancellation or worker loss #1133 CLOSED, closer = PullRequest feat(duckfleet): recover remote attempts from evidence, never replay #1157; card Status Done
  • follow-ups are open for everything deferred here — numbers: production qualification, rollout and the AWS identity gates belong to DuckFleet: qualify the full API workflow and decide production rollout #1134 (open); upstream teardown is Qualify bounded namespace teardown with long-statement shutdown grace duck-fleet#129 (open)
  • what was learned is written down where the next session will find it
    (a skill, a reference, memory) — or nothing new was learned: ducklake-lakehouse/references/duckfleet-recovery.md (fence, journal, receipt, matrix, bounds); the DATASET_SCOPED trap is already in memory

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Taken over from Codex session 01a1fb62 (idle since 07:56Z); its cleanup-ack commit and remote_attempt entity are kept.

  1. Fence (control plane). remote_attempts row acquired from the live task before any remote session opens. The partial unique index keeps one unresolved attempt per dataset. job/update/claim.sql refuses to dispatch any job for a dataset (or an org-level job for its org) while one is unresolved, so a retry, a new run and an embedded run (backend switch) are all held at the database.
  2. Write-ahead journal. New attempt-token route POST /v1/internal/attempts/{a}/remote (acquire / session / request / release). Scope comes from the authenticated task, never the body. RemoteSession journals each request id (and flags COMMIT) before sending it; if the journal is refused, the SQL is not sent. Only identifiers and bounded phases are stored.
  3. Publication receipt. The golden transaction calls lake.set_commit_message(..., extra_info => {"remote_attempt": id}) before COMMIT, so the receipt is atomic with publication. Probed on DuckDB 1.5.4 (DuckFleet) and 2.0.0 (ER): committed → present, rolled back → absent.
  4. Decision matrix as a pure, exhaustively tested function in er-duckfleet. Inputs: receipt, last and commit request state from durable GET /v1/requests/{id}, grace elapsed, pod still live. Outputs: committed / rolled_back / not_executed / unresolved. Nothing is replayed, ever.
  5. Pod-side settlement + server-side sweep. The pod releases when the evidence is conclusive (COMMIT returned, or COMMIT never sent). Otherwise the row stays unknown, and the dispatcher sweep reconciles it once the task is no longer live, using the pinned binding generation (draining allowed, revoked or replaced refuses). An undecidable outcome stays fenced.
  6. Errors and diagnostics. Public job error names the held dataset and attempt id, with no SQL, binds or credentials. Spans and logs correlate job, task, attempt and remote ids.
  7. Proof. Fault-injection unit tests (scripted HTTP faults: open, temp work, writes, around COMMIT, cancel), a pg test of the fence + claim exclusion + sweep, and a real-service run via the pinned harness. Failure matrix and bounds documented in ducklake-lakehouse/references/duckfleet-recovery.md.

Discoveries

  • The inherited natural key (dataset_id, task_instance_id, launch) permits one remote attempt per launch, so a relaunched pod can never inherit an earlier session. Kept on purpose.
  • Upstream DELETE route state is in memory, so after a gateway restart a close cannot be acknowledged. Recovery therefore relies on durable requests records plus the lake receipt, not on close.
  • Draining bindings did not load credentials, which would have stopped recovery exactly when draining. They now load optionally, for recovery reads only; admission still requires Active.
  • New dataset-scoped tables must join DATASET_SCOPED in fixups.rs, or the aged-store replay refuses them as breaking.

Measurements

Gates on ec86a4e9: make check exit 0, make check-e2e exit 0 (local Postgres). make check-duckfleet-task at upstream ac894b5: fault_outcomes committed/1 receipt and rolled_back/0, recorded in duckfleet-task-evidence.json.

Measurements

Files

@athvin

athvin commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Recovery investigation update:

  • Local checkpoint 515b1a70 requires an explicit boolean closed: true response before the client considers session cleanup complete. Unknown-session responses, missing acknowledgements, and false/string acknowledgements remain unresolved. All 14 execution tests passed, including the new negative cleanup cases. Full gates remain pending; this is not ready to merge.
  • Upstream gateway route loss does not prove worker death. More subtly, queue::recover_worker writes queue_sessions.closed_at after acquiring a stable worker advisory lock. The old process can lose that PostgreSQL connection while DuckDB is still unwinding an interrupted statement. The loss callback interrupts but does not synchronously prove process death. Therefore recovery must not treat that marker alone as proof that a prior COMMIT cannot finish.
  • Dataset release must use a confirmed direct session-close acknowledgement, or stronger physical worker/pod termination evidence followed by an atomic publication receipt read. Unknown or unavailable evidence must keep the dataset fenced. No transaction replay or replacement session is authorized by a missing route, elapsed deadline, heartbeat loss, or recovered request history.

@athvin

athvin commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Claim handed over to Claude Code session d1e3b2dc-3174-4091-9c30-c08fc4820306 on brians-MacBook-Pro at 2026-11-21T15:48Z, at the owner's direction. The previous Codex session 01a1fb62-5950-78d2-982c-5ecb2cd40d30 was idle since 07:56Z. Its local commit 515b1a70 and uncommitted remote_attempt entity work in .claude/worktrees/duckfleet-recovery are kept and continued, not discarded. Do not resume that Codex thread on this branch.

bmoore813 and others added 3 commits November 21, 2026 10:48
…dence

Remote task sessions journal their session and every request id before it
is sent; a refused journal sends nothing further. The recovery module reads
durable upstream request records and the lake publication receipt, and
decide() is the failure matrix. Job claim refuses any writer for a dataset
with an unresolved remote attempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The golden task acquires a dataset fence over the attempt channel before
opening a session, journals every request id before sending it, tags the
publishing commit with a lake receipt, and settles the fence from what it
observed. Attempts it cannot settle are reconciled by a dispatcher sweep
from the pinned binding's durable request records and the receipt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

bmoore813 and others added 4 commits November 21, 2026 11:26
An in-test relay loses a COMMIT reply after it landed, and drops a COMMIT
before it reaches the gateway. Both jobs fail truthfully with the dataset
held; the sweep settles them committed (one receipt) and rolled back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@athvin athvin changed the title feat: reconcile remote attempts before retrying resolution feat(duckfleet): recover remote attempts from evidence, never replay Nov 21, 2026
@athvin
athvin marked this pull request as ready for review November 21, 2026 16:49
@athvin
athvin merged commit f5aa9a8 into main Nov 21, 2026
47 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 21, 2026 16:56 — with GitHub Actions Inactive
@athvin
athvin deleted the issue/1133-duckfleet-recovery branch November 21, 2026 17:27

This branch was previously deployed

1 inactive deployment
marketing-preview — ec86a4e9 Deployed Nov 21, 2026 by athvin via remove closed PR previews #6
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.

DuckFleet: recover remote jobs safely after cancellation or worker loss

2 participants