Before clinic opens
Welcome to The Practice of Tomorrow. This is episode six, After the Connection Drops. This script is written for AI narration. Juniper Practice, its records, and today's operating policy are fictional. We are studying a proposed administrative workflow, not sending a real claim or message. The problem begins after the evidence is assembled, the destination is verified, and the current packet is approved. Everything looks ready until the connection disappears.
Nina clicks the authorized send. The request leaves Juniper's system. A few seconds pass, and the screen reports a timeout. There is no receipt in the local record. Maya asks the question that will shape the entire episode: did the action fail, or did the response fail to reach us? Those are different events. If the action succeeded remotely, an immediate new send could create a duplicate.
A timeout is an observation about communication. It does not, by itself, prove that the destination performed no action. This is easy to understand in ordinary life: a payment terminal can lose its connection after a charge has been accepted. The same uncertainty appears in administrative integrations. A worker needs a way to preserve and resolve it rather than converting every missing response into permission to try again.
Our fictional operation is an external packet submission. The job contract permits one approved submission for a particular work item and payload version. The destination supports a status lookup by operation identity. We will later remove that support and see how the recovery plan changes. State those assumptions before designing retries. The destination's actual behavior determines what can be made safe, and a local design cannot invent guarantees the other system does not provide.
Before sending, the system creates a durable intent record. It includes the work-item identity, practice scope, destination, approved payload version, approval reference, and a stable operation identifier. The record says what the system intends to do and why it is permitted. It is saved before the external effect is attempted. If the process disappears, a replacement can inspect the intent rather than reconstructing it from a conversation.
The operation identifier refers to the business attempt we want the destination to recognize. It should not change merely because a network request is retried. If every retry gets a new identity, the destination may reasonably treat it as a new action. Conversely, reusing one identity for materially different payloads can create a different problem. The system must bind the identity to the intended action and reject inconsistent reuse.
AWS's Builders' Library describes idempotent API design as background for this pattern. In this episode, the important operational question is whether repeating the same identified request can produce an unintended additional effect. You must verify the receiving system's contract, including how it handles duplicates, changed payloads, retention, and concurrent attempts. Calling a local field an idempotency key does not create remote idempotency by itself.
Let us walk through a timeline. At 9:00, the job is ready and the approved intent is stored. At 9:01, a worker acquires the job. At 9:02, it records that dispatch is beginning and sends the request. At 9:03, the destination accepts the operation, but the response is lost. At 9:04, the local process times out. The correct local state is outcome unknown, pending reconciliation under our case policy.
Pause for your first decision. A colleague suggests clearing the pending flag so another worker can start fresh. That would make the queue look cleaner. What evidence would justify a fresh send? The absence of a local receipt is not enough. The system should first query the destination using the existing operation identity or use another approved reconciliation path. It should preserve the original intent while resolving what actually happened.
At 9:05, a replacement worker queries the destination. The response says accepted under the same operation identity and payload reference. The worker stores that receipt and advances the job to the appropriate acknowledged state. It does not send again. It also does not label the business outcome complete unless the contract says that acknowledgment is sufficient. A submission receipt is not automatically a final payer or financial result.
Now change one fact. At 9:05, the destination says not found, but its documentation says new operations may take several minutes to appear in status queries. Does not found prove that the send failed? Not yet. The observation may be affected by the destination's consistency delay. The recovery policy needs a bounded wait and another query, or a human escalation, rather than treating a temporarily incomplete view as definitive evidence.
This is why recovery states need more detail than success and failure. You may need prepared, dispatching, outcome unknown, reconciling, acknowledged, rejected, canceled before dispatch, and requiring manual investigation. The exact names can vary. What matters is that each state has a clear meaning, allowed transitions, and an owner. A state should help decide the next action, not merely color a dashboard.
A permanent rejection is different from an unknown result. If the destination returns a definitive rejection tied to the same operation, the worker can record it and follow the specified remediation path. A new submission after a corrected payload may require a new operation identity and fresh approval. The system should make that relationship explicit so that a correction is not confused with a retry of the original action.
Now remove destination idempotency. The external system accepts a request but cannot reliably recognize repeated operation identifiers. Your local system can still reduce duplication by controlling dispatch and recording intent, but it cannot promise exactly one remote effect across every failure. An ambiguous result may need manual reconciliation. That limitation should be visible in the job contract and pilot scope rather than hidden behind a confident retry button.
The safe response may be less automated, but it is still useful. The worker can assemble the attempted payload, destination, timing, available response fragments, and operation record for an authorized operator. It can prevent competing workers from repeatedly sending while the case is unresolved. It can track the investigation and resume after a documented decision. Automation includes managing uncertainty well, not only eliminating human steps.
Let us examine ownership. A worker process can hold a lease on a job for a limited time. The lease says that this process currently owns the attempt to advance the work. If the process dies, the lease eventually expires so another worker can recover the job. Without expiry, work may remain stuck forever. Without controlled ownership, two workers may advance the same job at once.
A lease alone is not enough. Imagine the first process pauses for a long time, its lease expires, and a second process takes over. Then the first process wakes up and tries to write a result. The system must reject stale ownership. One approach uses a monotonically increasing ownership token that the state store checks on updates. The particular implementation may vary, but a stale process should not overwrite the current owner's decisions.
This is often called fencing. The term describes preventing a former owner from acting as though its authority were still current. Fencing local state updates does not automatically fence every external system. If the destination does not check the token or stable operation identity, you still need a dispatch design that accounts for that limitation. Be precise about which boundary a mechanism actually protects.
For the second decision, the first worker returns a valid-looking receipt after its lease expires. Should the system discard the evidence entirely? Not necessarily. It can preserve the observation and let the current owner reconcile it against the operation record. What it should reject is the stale worker's authority to make uncontrolled state transitions. Evidence and ownership are different things. A late observation may be useful without restoring a revoked lease.
Now consider the gap between saving intent and sending. A durable outbox is one common design: the application stores the approved intent in a local transactional record, and a dispatcher processes that record. This helps avoid losing work between a business-state change and the decision to send. It does not magically make the external side effect part of the same local database transaction. Reconciliation and destination behavior still matter.
The dispatcher should treat the outbox item as a governed operation. Before execution, it checks current authority, payload binding, cancellation, and any relevant expiry. If those conditions changed, the item may need review rather than dispatch. A durable queue preserves work; it should not preserve obsolete permission as though time had stopped. Recovery requires both remembering the past and rechecking the conditions that matter now.
Suppose Maya cancels the job after the request has left but before the result is known. The system can stop further attempts, but it may not be able to undo an action already accepted remotely. It should distinguish cancellation requested from confirmed cancellation of the external effect. If a compensating action is available, that action has its own authorization and outcome. A button label should not promise reversal that the integration cannot prove.
This leads to a broader point about undo. Some internal edits can be reversed directly. External messages, submissions, and other effects may require correction, withdrawal, or follow-up rather than erasure. A recovery design should identify these possibilities before the pilot. It should not assume that every mistake can be rolled back like a local draft. The operator needs to know the available remedy and who owns it.
Now add a retry budget. The job allows a limited number of reconciliation queries and an elapsed-time window before escalation. Both are persisted with the work item. A restarted process reads the remaining budget rather than resetting it. This prevents a sequence of individually bounded processes from creating an unbounded overall loop. The limit should reflect the destination's contract and the organization's operating needs, not an arbitrary desire to keep trying.
Retries also need spacing. A service under load can become less available if every client retries immediately. Backoff and jitter are common engineering tools for reducing synchronized bursts, but they must fit the actual service's rate limits and timing behavior. In the course exercise, we use a simple bounded schedule only to illustrate the principle. A production schedule should be based on verified integration behavior and operational requirements.
Do not retry every error. An invalid identifier, revoked grant, rejected payload, or wrong destination may need correction rather than repetition. A transient communication failure may justify another attempt under the same operation contract. An unknown external effect may require reconciliation first. Classifying the failure is part of the work. A generic retry function can be dangerous when it ignores the difference between reading data and creating a consequential effect.
Maya wants to know whether the system can recover from a complete model-context reset. It should. The durable job record must contain the operational facts needed to resume: the job contract, current state, evidence references, pending dependencies, approvals, operation identities, budgets, and ownership history. The replacement worker may need to reason about these facts, but it should not need the original process's hidden mental state to know what happened.
Anthropic's work on long-running agent harnesses offers background on using persistent artifacts across sessions. Our healthcare design applies that general engineering idea to a narrower administrative problem. A saved summary can help orient a worker, but the authoritative record of an external operation should be structured and controlled. A narrative saying probably sent is not an adequate substitute for an operation state and destination evidence.
Now imagine a checkpoint that is too large. It contains every document, every tool response, and a long conversation. The new worker spends most of its effort rediscovering the decisive facts. A compact resumption packet can point to the authoritative records and highlight the next decision. The system should preserve evidence durably while presenting only the context needed for the current step. Storage and active context serve different purposes.
A checkpoint can also be too small. It says waiting for payer, but omits which request, which operation identity, who owns the follow-up, and when another check is due. That is not a recoverable work item. It is a reminder that requires a human to reconstruct the history. The standard should be practical: can a new authorized worker determine the next permitted action without guessing what the previous worker meant?
Let us build a recovery table aloud. For an interrupted read-only lookup, the next step may be a bounded repeat of the lookup. For an interrupted external write with a stable operation identity, the next step is reconciliation under the destination contract. For a rejected payload, the next step is correction and any required new approval. For revoked authority, the next step is a blocked state with an owner. These cases should not share one undifferentiated error handler.
Add a row for an expired lease with a late result. The current owner examines the evidence and decides whether it changes the job state; the old owner cannot directly advance it. Add a row for a canceled job with an unknown external effect. Further dispatch stops, while reconciliation continues as permitted to establish what happened. This distinction prevents cancellation from hiding an unresolved action that still matters operationally.
The third decision is about a duplicate event. The destination sends the same receipt twice. Should the second event create a second completed task or trigger another follow-up? The event handler should recognize the event or operation identity and apply the transition only as appropriate. Duplicate delivery is different from duplicate business effect, but both need handling. The record should remain consistent when the same evidence arrives more than once.
Now reverse the order. A final status arrives before an earlier acknowledgment because messages took different paths. A simplistic handler may move the job backward when the older event finally arrives. A better state model considers event identity, timing, and allowed transitions. It can retain the older observation without overwriting a more advanced supported state. The details depend on the destination's semantics, which must be understood rather than guessed from labels.
There is an important caution about clocks. Different systems may not share perfectly synchronized time, and a timestamp may mean creation, transmission, observation, or effective time. Use the destination's identifiers and documented ordering guarantees where available. Do not infer a causal order from arbitrary timestamps when the integration does not support that inference. In a disputed case, preserve the ambiguity and seek the evidence needed to resolve it.
Nina asks what she should see during recovery. The interface should say that the result is unknown, identify the attempted operation, show the last observation, and explain the next scheduled or manual step. It should avoid a success banner followed by a silent reversal, or a generic failure banner that invites a duplicate send. Clear recovery language reduces the chance that an operator accidentally defeats the safeguards.
The interface should also make ownership visible. If an automatic query is scheduled, say so. If manual investigation is required, name the queue or person responsible. If the job has exhausted its budget, show the reason and the decision needed to continue. A task that is technically persisted but has no owner or next action can still be lost in practice. Durability is necessary, but it is not the whole operating model.
Now consider observability. Measure the number of unknown outcomes, time to reconciliation, duplicate attempts prevented, permanently rejected operations, and items awaiting manual investigation. These are more informative than counting tool calls alone. A rising unknown-outcome queue may indicate a destination problem or a flawed integration. A high number of prevented duplicates may reveal a retrying client that needs repair, even if the guard is successfully protecting the effect.
Separate technical recovery from business completion in the dashboard. The system may recover a receipt successfully while the underlying administrative work remains pending. A reconciled submission is not necessarily a resolved claim. If the dashboard collapses those outcomes, the team may overestimate the value of the worker and underestimate the remaining workload. The metric should follow the job contract and the business question it supports.
Let us introduce an operational tradeoff. A longer reconciliation window may reduce unnecessary manual investigation, but it may also delay a time-sensitive decision. A shorter window may bring a human in sooner, at the cost of more review effort. There is no universal best interval. Choose it based on the destination's behavior, the consequences of duplication, and the time available for the work. Record the assumption so it can be revised with evidence.
For a fictional calculation, imagine twenty ambiguous submissions per week. Each manual investigation takes twelve minutes, so the current burden is four hours. A verified status lookup resolves fifteen of them automatically, but maintaining and reviewing the recovery process takes one hour weekly. The remaining five investigations take another hour. The net saving is two hours, not the three hours represented by the fifteen avoided investigations alone.
That example excludes integration build cost and any changes in error risk. It is a teaching calculation, not a forecast. If the automated lookup sometimes resolves the wrong operation, the apparent time saving may be meaningless or harmful. Always pair efficiency with correctness and consequence. A recovery system should be evaluated on whether it establishes the right outcome for the right work item, not merely whether it clears the queue quickly.
Testing should force the awkward boundaries. Stop the process before intent is saved, after intent is saved, after dispatch begins, after the destination accepts, and before the local receipt is committed. Deliver duplicate and out-of-order events. Let a lease expire while the old process is paused. Revoke permission before a queued dispatch. Each test should have an expected state and next action, with no reliance on a human remembering the hidden sequence.
A useful failure rehearsal can be done without real external effects. Use a controlled simulator that records received operation identities and can deliberately delay, duplicate, reject, or lose responses. The simulator's behavior should be explicit. Passing it proves behavior under those simulated conditions, not universal compatibility with every payer or vendor. Later integration testing must verify the actual destination contract in an appropriate environment.
Now ask what the system should retain after a failed test. Preserve enough evidence to reproduce the failure and distinguish the observed facts from the hypothesis about cause. Do not immediately rewrite the test to match the current behavior. A failing boundary test may be the most valuable information in the pilot. It tells you where the operating promise exceeds the implementation.
One final recovery detail is easy to miss: the identity-retention window. Suppose the destination recognizes duplicate operation identifiers for only a limited period. A job that resumes after that window cannot assume the old duplicate protection still applies. The local record should preserve when the operation was first attempted and the destination contract relevant to recovery. If the protection may have expired, route the case through the approved reconciliation or manual path before considering another effect.
Also distinguish a retry of an identical request from a corrected request that happens to concern the same claim. The corrected payload may need a new identity, but creating that identity does not resolve whether the old action occurred. Reconcile the original operation and follow the correction policy. Otherwise, a well-intended correction can become an unexplained second submission. The history should show the relationship between the two operations and the authority for each.
Bring this to Monday
For your workshop, draw a timeline with six moments: intent saved, ownership acquired, dispatch started, remote effect accepted, local response lost, and replacement worker resumed. At each moment, write what is known locally and what may be true remotely. The difference between those two columns is the uncertainty the recovery design must handle. If the columns always match, you have probably omitted the failure that makes the problem interesting.
Next, write a state transition for every recovery action. State the evidence required, the actor allowed to perform it, the budget it consumes, and the result if it fails. Include a manual route for the case where the destination cannot provide a reliable answer. Avoid a generic instruction to retry safely. The table should tell an implementer what safe means in the specific situation.
For the advanced challenge, change the destination contract halfway through the exercise. Remove its idempotency support, lengthen the status-query delay, or shorten the retention window for operation identities. Which guarantees must you withdraw? Which jobs need a different recovery lane? A strong design exposes these dependencies. A weak design keeps claiming exactly-once behavior because the phrase appears in the architecture document.
Finally, explain the incident to Nina in four sentences. Say what was attempted, what is known, what remains unknown, and who owns the next step. Do not claim failure if the effect may have occurred. Do not claim success from a local send log alone. The explanation should be clear enough that she can avoid duplicate work while the system resolves the uncertainty.
At Juniper, the timeout no longer causes a second send. The operation remains visible, the replacement worker checks the destination, and the matching receipt is saved. In the version of the story without a reliable lookup, the item enters a named manual investigation queue. Both outcomes are more honest than a retry that merely makes the interface look active. Reliable work includes knowing when evidence is insufficient to proceed.
In the next episode, Learning Without Drifting, Nina will correct a worker's conclusion. We will ask how that correction can improve future work without turning one exception into a universal rule. Bring this question to Monday: if the process disappears at the worst possible moment, can another authorized worker determine what happened and what it may do next? If the answer is yes, you are beginning to build a durable team.