A service accepts a write. The response times out. You look up the operation, get nothing back, and retry.

That last step is safe only if the API contract makes it safe. A lookup against a lagging replica can return nothing after the write has committed. A correlation ID helps find the operation later; it does not stop a second write.

I maintain Hexagon, an open-source agent control plane. While working through recovery examples, I wanted a small test that kept this distinction visible. The program below runs locally with Python 3 and no dependencies. It models the decision after a lost response, not a real provider or a Hexagon deployment.

Put the failure after the commit

Save this as replica_lag.py, then run python3 replica_lag.py.

The write method appends a record before raising TimeoutError. The lookup method hides that record for a configurable number of reads. There are no threads or sleeps: hidden_reads is a deterministic way to control visibility, not a simulation of elapsed time.

"""Deterministic remote-write model; no HTTP, model, or Hexagon calls."""
import json
from dataclasses import dataclass, field


@dataclass
class Remote:
    hidden_reads: int
    writes: list = field(default_factory=list)
    reads: int = 0

    def write(self, operation_id, payload):
        # This endpoint deliberately has no downstream idempotency guarantee.
        self.writes.append({'operation_id': operation_id, 'payload': payload})
        raise TimeoutError('The response was lost after the remote commit')

    def lookup(self, operation_id):
        self.reads += 1
        if self.reads <= self.hidden_reads:
            return None
        return next((row for row in self.writes if row['operation_id'] == operation_id), None)


def reconcile(remote, operation_id, budget):
    observations = []
    for attempt in range(budget):
        found = remote.lookup(operation_id)
        observations.append({'attempt': attempt + 1, 'visible': found is not None})
        if found:
            return {'state': 'confirmed', 'observations': observations}
    return {'state': 'unknown', 'observations': observations}


def run(hidden_reads, budget):
    remote = Remote(hidden_reads)
    intent = {'operation_id': 'patch-request-001', 'payload': 'create pull request'}
    try:
        remote.write(**intent)
    except TimeoutError:
        pass
    result = reconcile(remote, intent['operation_id'], budget)
    assert len(remote.writes) == 1, 'Reconciliation must never issue another write'
    assert result['state'] == ('confirmed' if hidden_reads < budget else 'unknown')
    return {'hidden_reads': hidden_reads, 'read_budget': budget,
            'actual_remote_writes': len(remote.writes), **result}


def negative_control():
    remote = Remote(1)
    for attempt in range(2):
        try:
            remote.write('patch-request-001', 'create pull request')
        except TimeoutError:
            if remote.lookup('patch-request-001'):
                break
    assert len(remote.writes) == 2, 'Negative control must expose duplicate effects'
    return {'policy': 'resend_after_negative_lookup', 'actual_remote_writes': len(remote.writes)}


if __name__ == '__main__':
    print(json.dumps({'scope': 'deterministic simulation; not a provider or product test',
                      'scenarios': [run(0, 3), run(2, 3), run(5, 3)],
                      'negative_control': negative_control()}, indent=2))

The three scenarios use the same read budget:

Reads hiding the write Reads attempted Result Writes
0 1 confirmed 1
2 3 confirmed 1
5 3 unknown 1

The last row is an expected result. The client has spent its read budget without learning whether the operation is visible. It stops looking, but it does not submit another write or label the first one failed.

The negative control does resend after the first empty lookup. It finishes with two records. Keeping that branch in the exercise makes the consequence concrete: a later change to retry policy should have to account for those duplicate effects.

What this leaves out

The model has one writer and one intended operation. Its lookup returns the first matching record; a real reconciliation path also needs to handle multiple matches, stale payloads, tenant boundaries, and missing permissions. A lookup that returns a record is useful only if that record proves the effect you are trying to confirm.

It also has no provider-enforced idempotency. If your receiving endpoint atomically binds a key to an operation, repeating the same key and request may be the documented recovery path. Check the key's scope, retention period, conflict behavior, and what happens while the first request is still running. Giving two non-idempotent writes the same label does not create that contract.

For a service without such a guarantee, an authoritative lookup, a receipt, or a webhook may settle the original outcome. If none is available, someone may need to investigate before retrying. A deadline can stop the investigation; it cannot turn missing evidence into proof of failure.

Keep reconnection separate

A dropped event stream presents a different problem. The viewer lost observations; it has not established that the task stopped. Recovering those observations should not create a new task.

Hexagon's browser replay example makes that distinction visible with an in-memory model. Disconnect the viewer, produce more events, then reconnect: the original Run remains and the missing events appear. It does not test network durability or cloud recovery.

The practical question is which boundary you are recovering. Replaying stored events, repeating an idempotent submission, and retrying an external side effect need different evidence.

If you have dealt with a write that was temporarily invisible to lookup, what finally settled it? A redacted sequence of requests and observations would be useful. The important detail is what the receiving API actually guaranteed.

[ END OF TRANSMISSION ]View source ↗