# Synchronized concurrency

Status: migrated and deployed on 2026-11-27 with SDK 0.1.23 and MCP 0.1.28. This is bounded work coordination on existing surfaces.
It adds no World resources, provider authority, generic lock service, or shared memory.

## SY1: plan effects and the plan document commit together

Every SQL-backed plan operation, including creation and expiry triggered by a read,
uses one store transaction for its plan document, Garden sessions, Handoff packets,
Evidence, identity binding writes, and SQLite journals. The plan CAS remains a guard;
it is no longer asked to undo effects that already committed elsewhere. A failed CAS,
failed store write, defect, interruption, or connection loss before commit rolls back
that operation. A stopped request cannot leave a usable child absent from the plan.
The save path cannot reinsert a deleted plan under an expected nonzero version.

Neon uses a request-scoped interactive transaction through the existing serverless
driver, with serializable isolation and bounded statement/idle timeouts. Ordinary
reads retain the existing HTTP driver. Each transaction closes its own connection.
SQLite uses `BEGIN IMMEDIATE` on a dedicated connection, never the shared connection
another request uses. Nested service transactions reuse that connection or its
savepoints. A competing writer gets an actionable conflict instead of joining the
first request's transaction. Memory test stores use a serialized journal with rollback;
they remain unavailable as an API fallback.

A serialization failure or busy writer returns a validation refusal and a read next
action. There is no automatic retry against a newer intent. A lost commit response is
uncertain: read the authoritative plan trace before deciding whether to retry. These
writes cannot automatically fail over to SQLite and repeat on a second authority.
Existing ordinary read failover remains separate. Plan start is state-idempotent:
a committed node has its ids in the plan, so a repeated tick does not create it again.
Plan creation without a caller operation key is not an exactly-once command; do not
blindly recreate a plan after an uncertain response.

The transactional planner may call store services, not external execution or vendor
APIs. Database rollback cannot undo an external action. Participants still own their
execution, permissions, credentials, and provider-side idempotency.

Driver references: [Neon transaction connections](https://github.com/neondatabase/serverless#using-pool-and-client),
[Drizzle Neon drivers](https://orm.drizzle.team/docs/connect-neon).

## SY2: explicit strict Handoff fencing

An offer may declare `fenced: true`. That mode is immutable for the packet. Existing
packets and offers that omit it remain legacy; no stronger guarantee is inferred for
old clients. Confirm the returned packet says `fenced: true`. The SDK
checks the advertised Gateway action schema before posting a strict offer, and also
checks the response, so an older server cannot silently turn that request into a
legacy offer. An unconfirmed response retains the recorded offer in the SDK error
cause for inspection rather than inviting another publication.

Each packet publishes:

- `revision`: increases once for every successful lifecycle mutation.
- `generation`: increases on claim, release, recall, rejection/rework, completion,
  and acceptance. Delivery and verification change revision without transferring work.
- `lastMutation`: one bounded operation id, kind, actor, and original counters.

Every mutation of a strict packet requires both `expectedRevision` and
`expectedGeneration` from the same observation, plus `operationId` shaped as
`hmo_` followed by 32 lowercase hexadecimal characters. This is public idempotency
metadata, not a credential. Legacy packets accept the same fields when supplied.
All mutations reserve their next counters with a conditional store update and perform
the lifecycle transition in the same transaction. Failed authorization, validation,
expiry, competing writes, and stale counters do not consume a revision or generation.
A dead request cannot retain an application lock; the store rolls back its transaction.

Release/reclaim by the same actor creates a different generation. Rejection starts a
new work generation even when the same worker stays assigned. An old delivery,
completion, release, or verdict request cannot act on that later cycle. Merely
re-reading and substituting newer counters does not make an old result current.
Identity and permission checks still apply independently: a correct fence grants no
authority. Claims against an expired row are unavailable rather than reviving it.

For SDK runtimes, create a fence from a packet you actually observed:

```ts
import { handoffFence } from "@chitmark/pactmere-agent";
const guard = handoffFence(observedPacket);
await pactmere.handoff.transition("complete", observedPacket.id, guard, {
  evidenceNote: "The agreed bounded work is complete.",
});
```

`pactmere.handoff.claim` accepts the same fields. Gateway/MCP `handoff` accepts them
alongside the existing operation. No new tool or runtime space is introduced.
The SDK never fetches newer counters to make a refused mutation pass.

A lost-response retry must retain the same operation id and original counters.
`lastMutation` recognizes that exact request, so it cannot apply the transition
again. The service returns an explicit already-applied refusal with a packet read
next action. Existing completion, delivery, and acceptance Prove recovery paths can
reuse their recorded Evidence and return success; rejection and verification callers
inspect the current packet after an already-applied result. This is at-most-once
state transition handling, not a promise of identical response JSON or exactly-once
external execution. A later mutation replaces `lastMutation`; older operations then
fail as stale. A fresh id is a new intent, not a workaround for a refused old result.

`claim_next` observes and fences one selected row at the server. It is a queue action,
not a globally idempotent command: repeating it can select another packet. Use a named
claim and retained fence when recovering a lost response. Winning order is database
commit order; no deterministic participant ordering is promised.

Existing mutation audit events include revision, generation, mode, and operation id.
Strict release accountability is generation-bound, so a receipt from an earlier claim
cannot conceal a later abandonment. Packet waits/Wake revisions also include the
counters. Metadata lives only under the existing packet or Evidence lease. Reads,
operation ids, conflicts, and acknowledgments do not renew a work lease.

Historic Pages deployments see a compatibility view that excludes strict packets.
The ordinary LWW sync path refuses strict creates, updates, and deletes, including
attempts that omit or clear the incoming flag. Conditional target writes also protect
an existing strict row. Strict custody is authoritative at one node; this is not a
multi-node lock protocol, and offline copies cannot acquire it by merging state.

## SY3: barrier exploration and decision

The demonstrated workflow is fork, independent bounded work, then synthesis or
review. Existing plan dependency edges already express the join: the successor starts
only after each predecessor has a successful live receipt. Independent branches can
start together; failures and unfinished predecessors do not release the successor.
Wake supplies bounded attention, not a second source of completion or readiness.
Its notification acknowledgment is not arrival at a synchronization barrier.

The existing execution tests cover dependency readiness, predecessor citations,
parallel branches, failure, budget exhaustion, cancellation, and expiry. Wake tests
cover duplicate observations, consumption/acknowledgment, cancellation, and timeout.
Together with atomic plan transitions, these express the current shared-work cases.
No demonstrated production workflow supplied here requires a new rendezvous record.
Therefore this implementation adds no barrier table, endpoint, tool, or payload field.

A hypothetical repeated-phase rendezvous is different: a fixed participant set arrives
at generation N, and the coordinator atomically releases or aborts that phase before
N+1. A completed task receipt does not prove that every participant is still present,
and a Wake timeout never proves readiness. If a real task needs that contract, its RFC
must state the named finite membership, work/revision binding, generation, authenticated
arrival, deduplication, release predicate, timeout, cancellation, participant loss,
expiry, and release/abort events. Tests must interleave arrivals, retries, stale
phases, and crashes. It must have no arbitrary context body or read-renewed lifetime.

A barrier would coordinate a phase, not grant access or guarantee simultaneous actions
in external systems. Provider-side resource ownership stays with the provider. A need
for that provider's transactional API is not evidence that Pactmere needs shared memory.

## Remaining boundary and verification

The separately tracked S.8 Garden ownership-transfer race remains open. Handoff
fences do not make a caller's separate claim read and Garden rewrite one operation.
Do not call a second pre-write read a fix or claim that all cross-domain transfers
are atomic because plan operations now are.

Regression coverage includes failed final plan save, interrupted transaction,
competing cancel, a real child-process exit before commit, post-write failure on the
memory twin, stale same-owner reclaims/rework, competing claims, and strict sync
refusals. `scripts/verify-synchronized-concurrency-neon.ts` exercises the migration,
rollback and retry, compatibility view, ownership fences, and Evidence-safe retry on
an explicitly selected disposable Neon branch. Run the full repository gate before
rollout. No production migration or package publication is implied by local success.

## Federation and deployed API status

The deployed HTTP and Gateway API, including the immutable fenced mode, was
verified by the federation release on 2026-11-28. Installed SDK/MCP support is version-specific; inspect the accepted
fields and retain observed fences rather than assuming every package release
has the current repository surface. The deployment does not close the S.8
cross-domain Garden transfer race described above.

`pactmere.federation.v1` exports only public fenced task advertisements. Their
revision and generation describe an observation, not a reservation. Claims and
all later mutations commit at the task's authoritative node with that node's
credential and the observed fence. Advertising or carrying a task elsewhere
never creates another claim authority. If a response is uncertain, follow this
document's recovery rules on the same authority. See [federation](https://pactmere.chitmark.com/federation.md).
