The scenario: a client retries after losing the answer to an AI turn
A person can send a conversation turn, lose connectivity and retry without knowing whether the first attempt completed. Sending the text directly to a provider again can create another response before the application has resolved the first attempt’s identity and state.
The inspected Movo-X route asks its authoritative API to reserve the turn before provider work. It can replay a completed result or proceed with leased work, then submit the generated reply through a separate completion call. Four synthetic route tests and selected SQL source explain those decisions without using a real provider or database.
Keep client input separate from internal operation fields
The route accepts a defined message shape including scope, client turn identifier, text, language and selected attachments. It does not accept a client-supplied assistant reply, lease, private path or internal operation as part of that public shape.
The selected injection fixture supplies those unsupported fields and checks HTTP refusal before the mocked database adapter is invoked. This demonstrates the selected route boundary. It does not establish every endpoint’s input policy or permit the public caller to make a valid-looking lease by using an accepted request identifier.
Make reservation refusal stop provider work
The first authoritative operation is message reservation. The route evaluates its result before asking the provider to generate a reply. A fixture returns a scoped authorization refusal and makes any provider invocation fail the test; the route surfaces the refusal without invoking it.
That ordering matters because storage and provider work can be expensive or privacy-sensitive. The fixture verifies the order against an injected refusal, not the correctness of real database permissions. The installed authorization function, current session state and person/clinic scope still need their own acceptance.
Bind a retried turn identifier to the original payload
The reviewed SQL looks up an existing patient message by session and client identifier. It compares a stored payload fingerprint with one constructed from selected turn fields before deciding whether an existing turn can be reused. A changed payload under the same identity has a separate refusal path in that source.
This is the authoritative counterpart to a client outbox retaining the original request. It should not be described as semantic equivalence of arbitrarily edited text or reordered attachment choices. The SQL branch was inspected without execution, so this chapter does not claim that real concurrent transactions or every serialization edge case were tested.
Replay an accepted completed result without generating another reply
When the reservation result says the turn is already complete, the inspected route builds a replay response from saved conversation and metadata. The selected fixture verifies that its provider callback is never invoked and that the expected response-shape fields are present.
That is evidence of avoiding an additional provider invocation in this synthetic completed-retry path. It is not an invoice audit or a guarantee that every uncertain attempt incurs exactly one charge. A previous provider call can have its own uncertain completion, network retry and billing semantics outside the application’s stored-response branch.
Treat a lease as work authority with a completion condition
For an unfinished turn, the reviewed SQL supplies a message and lease identifier under selected attempt, expiry and outstanding-turn rules. The route uses the reserved history for provider input rather than allowing the client to send an internal completion payload.
The completion source checks the matching message/session/lease and expiry before storing the assistant response. These are source-level conditions, not a demonstrated distributed lock or full concurrency proof. Provider deadlines, lease extension and actual database transaction behaviour need focused tests against the authoritative implementation.
Do not convert successful generation into accepted application state
The selected completion fixture returns a valid synthetic provider reply and then makes the authoritative completion call refuse because the session is no longer accepted. The route surfaces that refusal, and the fixture checks the reserve-then-complete operation sequence.
This separates generating bytes from accepting them into the application’s current conversation state. The inspected route also has selected completion-conflict handling that can extend a lease and retry completion once; that branch was not exercised by these four cases. It must not be promoted to an unlimited persistence guarantee merely because its source comment describes the intention to retain a fully generated reply.
Keep exactly-once language out of unproven boundaries
A payload fingerprint, completed-response replay and a lease each constrain a different part of the lifecycle. Together they still do not prove that provider execution, network delivery, persistence and billing form a single exactly-once transaction. The client can also lose the completion response after the server accepts it.
A useful protocol specifies what a later retry reads, which identity it must reuse and how uncertain outcomes are reconciled. It should distinguish completed replay from still-leased work, refused payload reuse and terminal authorization loss. The current evidence covers selected route decisions and reviewed SQL, not every interleaving of those states.
A practical AI-turn acceptance package
Retain unsupported-field, pre-provider-refusal, completed-replay and completion-refusal fixtures. Add authoritative fingerprint/concurrency tests, lost-response cases and the selected lease-renewal path in an authorized test environment. Verify actual provider request and billing evidence separately when making operational claims.
For a CTO, the result is a lifecycle whose work and acceptance boundaries are explicit. A retry can reuse stable intent without treating a generated reply as automatically committed. The pinned source and four scoped cases explain the selected design while real permissions, transaction behaviour and provider-side outcomes remain separately verifiable.
Compare the reviewed boundaries
Different boundaries in one AI turn
On smaller screens, scroll across to compare every column. Keyboard users can focus the table and use the arrow keys.
| Stage | Evidence in this case | Separate acceptance |
|---|---|---|
| Public request validation | Selected internal fields refused before API call | All route shapes and session authority |
| Reservation | Injected refusal stops provider invocation | Real DB authorization and fingerprint concurrency |
| Completed replay | Saved response path avoids mock provider call | Actual provider/billing uncertainty |
| Completion | Injected refusal surfaces after generation | Authoritative lease, renewal and lost-response cases |
Illustrative control flow
Pseudocode summarizing the decision boundary. It is not copied production code or a deployment instruction.
validate_public_turn_shape(request)
reserved = authoritative_reserve(scope, client_id, payload)
if reserved.completed:
return_saved_turn_shape(reserved)
else:
reply = generate_from_reserved_history(reserved)
return_authoritative_completion_result(reserved.lease, reply)
# Generation, persisted acceptance and delivery are distinct outcomes.About this engineering series
Written by Omer Muneer Qazi from a review of Movo-X implementation and dated engineering records. This article explains source behaviour and historical observations; current production, clinical outcomes and store availability require their own verification. Examples are synthetic and proposed test cases are identified as such.
Explore the Movo-X engineering series → · Related implementation experience →
Discuss a similar engineering problem
Send the workflow, current platform and the decision your team needs to make. I can help define an implementation or review scope with concrete acceptance evidence.
Discuss your project on WhatsApp ↗