Skip to content

feat(runtime): mutations: the host-owned SERIALIZABLE transaction, mutation keys and retry(), write_conflict #400

Closed

Description

@allisonmahmood

Part of #384. Implements spec §6; decisions one transaction per mutation, the init prototype (the transaction as built, astra's fences), the execution service (the cross-host key race, the Neon connection lifecycle), lifecycle points 4–5, limits (Per call, write_conflict).

What to build

  • The host-owned transaction in Runtime, from Transaction.ts on PR prototype(tier2): patchy init --tier 2, server/, dev on the engine and a two-artifact publish #380: one fiber per invocation, callbacks as jobs on it, savepoints under the table handlers, the invocation's connection reused by its callbacks. It opens on the first callback at SERIALIZABLE and commits only after the validated result. Completion closes admission and refuses pending callback jobs before finalising; readiness is resolved on acquisition failure.
  • Retries: on 40001 the whole handler is re-invoked, up to three attempts, abort-only after any 40001; exhaustion is write_conflict. An absolute 5 s deadline covers queue wait, acquisition, every attempt and settlement; each attempt's transaction timeout is the remaining budget. Killed at 6 s.
  • Commit outcome: a driver-acknowledged commit phase. A known non-40001 rejection is a rollback. handler_timeout only on confirmed non-commit; unknown_outcome only while the commit outcome is unresolved. A resolved COMMIT on an aborted transaction is a rollback.
  • Mutation keys (spec §4): the shell's core client mints <ms>-<128 random bits, base64url> with the time on the server's clock as learned from the stream. A company-database table (idempotent upgrade) holds the key with patch, handler, version, initiating viewer, argument fingerprint and the result (≤ 64 KiB), written inside the transaction. A mutation with no callbacks still opens a transaction to write it. A key older than 24 h is refused as expired whether or not a row survives; a key more than 5 min in the future is refused; inside the window, a key with no committed outcome visible is run, and an overlapping attempt resolves by the race rule below. A repeat returns the stored result. A mismatched binding or fingerprint, another principal or an expired key is refused, never run fresh. Rows are swept after 24 h. Cross-host races: a duplicate may fail at INSERT with 23505 or at commit; the loser rolls back and resolves the winner's stored outcome; an unrelated uniqueness violation is never deduplication.
  • The client: every mutation call carries a fresh key; unknown_outcome on a mutation carries retry(), re-sending the same key and arguments.
  • Nested mutations: ctx.run in an action now reaches sibling mutations, each its own transaction with a key the host mints, used to resolve an uncertain commit, never to replay the parent action.
  • A mutation's reply carries the revisions it wrote and resolves on commit; the transaction owner announces touched resources after commit (the one wake rule).
  • ADR-0009's pool is unchanged in size: the transaction holds its one connection until commit.

Admitted at merge

Tier 2 mutations run in tests and the dev instance. The server still refuses tier 2 publish until the publish ticket.

Done when

On real Postgres: eight concurrent increments total eight; write-then-throw leaves zero rows; 50 increments on one row end in commits plus write_conflict, none busy; a reply lost after commit is unknown_outcome and retry() returns the stored result. Acceptance owned here: the dropped-client leak (a client that disconnects mid-call, in each of the three kinds, leaves no pending row and no idle in transaction connection past the bounded cleanup, and four such drops do not fill the pool); and the cross-host mutation-key races. Two hosts replaying one key leave one commit, with 23505 at insert and at commit both resolved to the winner.

Surfaces

ADR-0012 (the transaction contracts), ADR-0009 if the held connection changes its accounting, the Runtime glossary (Mutation key), the patchy-server skill (the retry contract, write_conflict means redesign and busy means wait), the patchy-tables skill (say which tier its transactions line applies to), docs/API.md.

Activity

  1. added
    ready-for-agent
    area:server
    area:primitives
    on Sep 28, 2026
  2. allisonmahmood commented on Sep 29, 2026

    @allisonmahmood
    OwnerAuthor

    Acceptance carried forward from #399, per Foreman direction on Opus finding 4 in PR #431:

    • an action's db_ms covers its nested mutation's connection time

    Verify this with an action invoking a real nested mutation once #400 admits that path. PR #431 verifies nested query accounting; it does not claim to satisfy the nested-mutation check.

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

    area:primitivesarea:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions