Skip to content

Writes during a D1 handoff fail once: retry CAS-anchored writes safely by reading the anchor back #324

Done

Description

@Madraka

Found by the cluster failover test (#290, PR #322).

When the instance that owns D1 stops gracefully, the D1 Durable Object moves, and a request that was on its way to it gets D1_ERROR: Network connection lost. #322 makes D1Driver retry read-only statements a few times (about 2 s in all). Writes and batches are deliberately not retried, because a lost write may already have been applied. So a write that lands in that window fails once: a Studio save or an agent's tool call returns an error and has to be repeated. The same happens on Cloudflare after a deploy or an eviction.

Idea. Every graph write is a batch() anchored on a content hash (CAS). After a transient error, the writer could read its anchor back:

  • the new hash is stored → the write was applied, so report success;
  • the old hash is stored → the write was lost, so retry it once;
  • anything else → conflict, as today.

That gives an idempotent retry without transactions (AGENTS.md rule 4).

Done when: graph writes caught in a D1 move either succeed or fail with a conflict, never a transient error; the failover test also checks writes during the SIGTERM handoffs; and the conformance suites cover the read-back on SQLite and D1.

Activity

  1. added 2 commits that reference this issue on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions