Timeout after an external request: when the outcome is unknown

The service may finish an operation before the client times out. Two ledgers explain outcome_unknown, reconciliation by a stable key, payload conflicts, and retry limits.

Delivery and an acknowledgement received are separate events.
Delivery and an acknowledgement received are separate events.

A client sends a command, waits for a timeout, and displays an error. On the other side, the service may already have saved the result. Creating a new command with a new key now risks carrying out one intent twice. Marking the operation complete may report a result that does not exist.

Between “completed” and “not performed,” we need a separate state: outcome unknown. It describes the client’s knowledge. The external effect may already exist, still be pending, or be absent. The next step follows from that distinction: reconcile the original intent against the service’s ledger while preserving its identity.

What a timeout does not tell us

A timeout means that the client did not receive the required response within its waiting policy. It is not a receipt for the rollback of someone else’s transaction. In Symfony, timeout limits inactivity, while max_duration limits the entire exchange; the HttpClient documentation distinguishes them.

The word POST alone is also insufficient to decide on a retry. RFC 9110, § 9.2.2 ties automatic retries of a non-idempotent method to knowledge that the particular operation is idempotent or that the previous request was not applied. A timeout adds neither fact.

One retry owner helps prevent competing retries. Even a correctly assigned owner must first establish what it is repeating: delivery of the command or a read of its result. Here we choose bounded reconciliation through GET, with no new POST after uncertainty.

Two ledgers for one card

The teaching example consists of a Symfony client and a synthetic card service. The intent is simple: register an Oak card under reference card-oak. The client stores the reference, exact payload bytes, state, and inspection count in MySQL 8.4/InnoDB tables. The service has a separate logical operation ledger and a cards table. The lab uses separate native PDO connections and separate disposable client and service MySQL schemas, not two database files. UnknownOutcomeDemoCommand creates the unknown_client and unknown_service fixtures independently and initializes each ledger in its own schema. The client and service complete their transactions independently; the PDO transaction boundary belongs to its connection.

The model uses a fixed payload representation:

{"v":1,"label":"Oak card"}

The reference is chosen before the first request and stored with the payload. Changing label under the same reference is a conflict. This is a deliberately small exact-byte contract with version v; it does not define universal canonicalization for arbitrary JSON.

The service retains the key-to-payload association without automatic cleanup within this example. Repeating the same pair returns the existing state; a different payload receives a conflict. The card and its card/card-oak receipt are written together in the service’s transaction. The pending mode stores only the intent; completing the card is a separate call. Another POST with the same key does not accelerate that completion.

Persist uncertainty first

The client starts in ready. Before its first service call, it stores outcome_unknown and consumes its sole permission to POST. The write finishes through autocommit before the mock HTTP call. This boundary requires a connection without an active caller transaction: otherwise the reservation could remain uncommitted during the external effect. An active transaction must be rejected before ledger mutation and transport invocation, without committing or rolling it back. MySQL errors do not become successful reservations; rollback is permitted only for a transaction owned by the current operation.

The coordinator’s central guard looks like this:

$this->ledger->prepare($operation);
if (!$this->ledger->reserveSend($operation->reference)) {
    return $this->ledger->read($operation->reference);
}

Only a successful reservation opens the path to the first POST. Calling submit() again for outcome_unknown, remote_pending, accepted, or conflict returns the stored state.

This caution has a cost. A controlled interruption between reservation and request leaves outcome_unknown even though the service received nothing. That is an acceptable gap in knowledge: the client does not present an assumption as a proven outcome. An ordinary method return does not establish resilience to power loss; the example considers sequential execution with controlled call boundaries.

Accept the command and hide the response

In the main scenario, a MockHttpClient callback invokes the fake service. The service writes the operation and card, commits, and only then does the callback return a MockResponse that produces a timeout when its body is read. An empty generator chunk is Symfony’s documented timeout simulation.

This controlled model makes no HTTP calls to an external provider; its MySQL connections are real network connections. It places failure at the intended protocol boundary, but does not reproduce packet loss, process termination, or a real replica’s behavior. HttpClient’s lazy responses require transport exception handling around both request() and status/body consumption, as explained in the network errors section.

The intended scenario now has outcome_unknown on the client and one card at the service. If the response arrived immediately, a matching receipt would move the client to accepted. Status 200 alone is insufficient: the client checks the reference, exact payload bytes, recognized state, and expected receipt.

Reconciliation reads the same intent

reconcile() restores the operation from the local ledger and performs a GET using the same reference. The user supplies neither a new key nor an updated payload. The read must bind its response to the original intent, rather than locate any similar card.

Observation during reconciliation Local outcome Next automatic action
Reference, payload, and completed-card receipt match accepted Stop reconciliation
Reference and payload match; the service is still working remote_pending Allow another read within the budget
The key is bound to another payload conflict Stop for investigation
The record is not visible yet; response 404 outcome_unknown Do not create a new command
The read is unavailable or the response is unusable outcome_unknown Preserve uncertainty

The last two rows describe a client that does not yet know whether its intent was accepted. If it previously received a valid pending response, subsequent 404 or 503 responses preserve remote_pending: losing a fresh observation does not erase the known acceptance of the intent. A separate reason records why the latest inspection supplied no new result.

A conflict does not mean that no effect exists either. Another operation may already have created a card under that key. An automatic client must not replace its payload or “fix” the key before the conflict’s origin is established.

Why 404 does not authorize a retry

In the main scenario, the first GET deliberately hides an existing record and returns 404. The second returns 503; the third exposes the service record. These are three explicitly scripted mock-transport responses, not a measurement of eventual-consistency lag.

The expected local sequence is outcome_unknown after POST, outcome_unknown after the hidden record, another outcome_unknown after service unavailability, and accepted after the matching receipt. The entire scenario should produce one POST, three GETs, and one card.

A counterexample explains the danger of changing identity: payload Oak card under a new reference, card-oak-new, is a new operation to our service and can create a second card. Key-based deduplication does not recognize the unwritten human intent that “this was the same action.”

In a real integration, the service contract defines not-found: where the ledger is read, when a record becomes visible, how long a key lives, and whether a definitive “not applied” response exists. With delayed visibility, an ordinary 404 provides no such finality. Without that contract, adding a pause does not turn an assumption into evidence.

A bounded budget preserves an honest state

The lab allows at most three inspections. Each is reserved in the local ledger before GET, so an unsuccessful attempt also consumes the budget. After exhaustion, the client retains outcome_unknown or remote_pending and the inspection_budget_exhausted flag. The counter bounds work; it does not decide the external operation’s outcome.

Further action needs a separate policy: another read by the integration owner, contacting the service, or examining its ledger. The example has no automatic budget reset, replacement key, compensation, or competing scheduler. Hidden HTTP retries are also disabled. Otherwise, the actual POST count would no longer correspond to the local permission.

Reproducing the boundary

The example remains in the same Symfony 8.1 Demo and uses MySQL 8.4/InnoDB through native PDO MySQL. The guarded disposable fixture and App\Infrastructure\MysqlLab prepare separate isolated client and service schemas. A separate migrator performs DDL before business transactions; runtime connections perform DML without CREATE, ALTER, or DROP privileges. Identities use VARCHAR with utf8mb4_0900_bin, while text bodies and titles use LONGTEXT; InnoDB, foreign keys, and CHECK constraints enforce integrity. MySQL DDL can cause an implicit commit, so this is neither an atomic schema upgrade nor an automatic data transfer from old SQLite files.

From the same Demo root, run the feature tests and command through the guarded MySQL fixture. It selects the test server, and the helper creates separate owned temporary client and service schemas; the command’s scratch directory is not a database file. Install the Demo dependencies and PDO MySQL, and configure the shared fixture before running:

bash fixtures/mysql_labs/run.sh php vendor/bin/phpunit tests/UnknownOutcomeLab
lab_parent="$(mktemp -d /tmp/unknown-outcome.XXXXXX)"
bash fixtures/mysql_labs/run.sh php bin/console lab:unknown-outcome --directory "$lab_parent/scenario" --env=test --no-interaction

The main scenario checks outcome_unknown → outcome_unknown → outcome_unknown → accepted, one POST, three GETs, and one card with receipt card/card-oak. Independent native PDO connections read the stored rows in their respective separate MySQL schemas: a local accepted operation with send_attempts=1 and inspections=3 in the client schema, and an accepted service operation and a card with matching payload bytes and receipt in the service schema. These reads check visibility of committed records to another connection, not distributed recovery or resilience to power loss.

A separate regression check protects the caller’s transaction boundary: refusing submit must not send an HTTP request, mutate the ledger, or complete the caller’s uncommitted changes. Visibility of those changes to the owning and independent connections, and the caller’s ability to roll back afterward, are checked separately from the main timeout scenario. This is a transaction-ownership contract, not a nested-transaction abstraction; the old SQLite BEGIN/ROLLBACK probe is not a MySQL instruction.

Beyond the main scenario, the tests cover timeout before acceptance, pending work, payload conflicts, an incorrect receipt, and a local recording failure after the external commit. Their purpose is to compare local state with the actual contents of the separate ledger, including both zero and one external effect under the same outcome_unknown state.

A real provider additionally needs an authentic response source, a defined key-retention period, and concurrent-execution rules. The educational MySQL model does not establish those properties. It makes one practical boundary visible: after a timeout, preserve uncertainty first and reconcile the same operation; wanting a definite answer does not justify inventing a new fact about the external outcome.

The shared MySQL fixture and its files are introduced in the transaction chapter. Run commands from the single article_demo root; do not create a separate Symfony application for each article.

Check the current example against separate owned disposable client and service MySQL schemas:

  1. Distribution Publishing to a channel: draft, approval, delivery and reconciliation
  2. Databases Handler idempotency: repeat the task without duplicating its result
  3. Platform Engineering Who should retry a failed operation: one retry owner

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article