Skip to content

Deferred Completion And Await Boundaries ​

Deferred completion models external reality without pretending that waiting is an operation. An ordinary authored operation produces a trusted immediate result. The await: modifier then pauses the same execution until a correlated external observation can be projected into that operation's final output.

text
authored operation: Input → OperationOutput
deferred completion: OperationOutput + Completion → FinalOutput

Typical completions include human approvals, webhook callbacks, brokered provider replies, and long-running jobs. The pipeline owns the operation and continuation. The external participant owns only the fact or decision it submits.

When To Use Deferred Completion ​

Use await: when the operation can start now but its final business result arrives after the current execution turn.

External shapeModel as
Local computation returning nowAuthored service
Inline HTTP/gRPC call returning nowQuery, Command, Connector, or remote operator
Authored request followed by a human decisionAuthored service with await:
Provider accepts now and calls back laterNative Command with await.callback
Independent event starts a new business flowInbound admission, not deferred completion
Another pipeline should own the next lifecycleCheckpoint handoff

Await is not a StepKind, and “interaction” is not another operation category. A human UI, callback provider, webhook, Kafka topic, or SQS queue participates through the completion transport.

Shape The Operation ​

The step's top-level input and output remain its pipeline-visible contract. The authored service returns await.operationOutput, which becomes trusted context for the completion lifecycle.

yaml
steps:
  - name: Create pending approval
    service: com.example.CreatePendingApprovalService
    cardinality: ONE_TO_ONE
    input: ValidatedOrder
    output: RestaurantDecision

    await:
      operationOutput:
        type: PendingRestaurantApproval
        java: com.example.PendingRestaurantApproval
      timeout: PT30M
      idempotency:
        fields: [orderId]
      correlation:
        strategy: interactionId
      transport:
        type: interaction-api
      completion:
        type: RestaurantDecisionSubmission
        projector: com.example.RestaurantDecisionProjector

The service has the ordinary authored signature:

text
ValidatedOrder → PendingRestaurantApproval

The whole step has the pipeline contract:

text
ValidatedOrder → RestaurantDecision

The projector implements AwaitCompletionProjector<PendingRestaurantApproval, RestaurantDecisionSubmission, RestaurantDecision>. It receives the trusted operation output, the untrusted submitted payload, and framework-authored completion metadata such as completedAt. It must be public, constructible, deterministic, and side-effect free.

For a union operation output, await.accepts can select the canonical payload that needs an answer, and await.output names its completed outcome. Other outcomes continue immediately. The final step output union describes the resulting leaf set. See select which operation outcomes await for the supported shape and configuration. Persistence aspects can observe Review and Result payloads at the producing operations before the Await modifier runs.

When no projector is needed, await.completion.type may be omitted and defaults to the selected await.output, or the top-level output when no outcome selector is declared. Idempotency paths resolve against operationOutput, not the original step input or submitted completion.

TPF persists the operation output and projected completion as canonical values. Recovery resumes from the admitted final output; it does not invoke the authored operation or projector again for an already projected canonical completion.

Command Callback Completion ​

A native ONE_TO_ONE Command can select a callback declared in its provider manifest. Its await.operationOutput is the immediate acknowledgement contract; the top-level output is the final pipeline result. The required completion projector receives the original canonical Command input and the callback payload, so it can produce the final result even when dispatch acknowledgement is ambiguous.

TPF registers the durable interaction before dispatch. A callback arriving during dispatch is stored as COMPLETION_OBSERVED and cannot advance the pipeline until the Command outcome settles. Success or ambiguity permits completion; a callback followed by definite rejection fails as contradictory provider evidence. Completing an ambiguous Command does not rewrite its effect history.

Callback selection uses an application binding, signed resume tokens, and explicit endpoint resolver and authenticator classes. It cannot be combined with await.transport or authored Await idempotency fields. Query, dynamic, packaged Block, attended Command, and streaming Command completion are unsupported.

See Command Steps for the declaration and ADR-0037 for the durable outcome table.

The OpenAPI callback example uses this contract as one native Command. Its packaged restart test retains the same signed callback and durable interaction, and completion leaves the recorded effect history unchanged.

Branching And Unions ​

accepts still controls whether the semantic operation runs for a union alternative. It does not create Await-specific routing. The operation's immediate output is the trusted projector input, so the standalone Await-step narrowing described by older releases no longer exists.

Alternatives not accepted by the decorated operation continue through ordinary v3 branch routing. There is no completion-specific pass-through mapper and no implicit collection-to-stream or stream-to-collection conversion.

Cardinality ​

The authored operation retains its ordinary cardinality. Each result it emits gets exactly one deferred completion:

Operation cardinalityDeferred-completion meaning
ONE_TO_ONEone operation result receives one completion
ONE_TO_MANYevery emitted result receives its own completion
MANY_TO_ONEthe operation emits one result, which receives one completion
MANY_TO_MANYevery emitted result receives its own completion

Deferred completion does not introduce aggregate Await cardinality. If an external participant decides on a whole batch or returns a collection, model that batch or collection as an explicit bounded canonical type. Use ordinary expansion and reduction steps when individual items must re-enter a stream.

For brokered per-result completion, the configured in-flight window bounds unresolved interactions. This is provider-facing backpressure, not a hidden batch or a circuit boundary.

Durable Lifecycle ​

The generated completion modifier reuses the existing durable Await runtime. The compiler orders its technical adapters as:

text
ordinary operation adapter
→ operation-scoped aspects
→ deferred completion modifier

The modifier consumes the trusted operation result; it never invokes the operation again. Its durable lifecycle is:

text
OPERATION_INVOKED
→ OPERATION_COMPLETED(OperationOutput)
→ COMPLETION_REGISTERED
→ REQUEST_DISPATCHING
→ COMPLETION_PENDING / WAITING_EXTERNAL
→ COMPLETION_OBSERVED
→ PROJECTED
→ STEP_COMPLETED(FinalOutput)

For an active brokered stream, admitted item completions can continue through the live reactive segment. If the live owner disappears, TPF falls back to durable coordination:

  1. persist each interaction and dispatch state;
  2. park the parent execution as WAITING_EXTERNAL when the transition suspends;
  3. admit completion by signed token or configured correlation;
  4. resume the continuation from the persisted final output;
  5. release the execution when every emitted occurrence has completed;
  6. publish terminal output before marking the execution successful.

The durable identity combines the root execution, qualified semantic step, and item occurrence. LOCAL unary calls retain the suspended operation and caller return positions across deferred completion. On resume, the child finishes, then each caller runs its remaining steps in order.

Replay and topology metadata show one semantic operation with a deferred-completion overlay. Broker and external-provider actors may still appear because they are participants, not pipeline operations.

Proposed separation of coordination and typed execution ​

ADR-0089 describes the proposed mode for independently packaged workers. The authored operation and its await: declaration keep the same meaning. The Coordinator retains the occurrence, request and Release and decides whether completion can commit. The pinned worker knows the application types and converts the reply or projects the final value.

The shared-coordinator-proof example runs an expense approval application alongside an unrelated parcel-processing application. Expense Release A1 prepares Pending request data, waits for an ApprovalReply, and uses its ExpenseCompletionProjector to produce Approved before FinishService creates the receipt. The proof harness supplies the approver's reply through the completion API.

The Coordinator uses neither application's Java classes. The parcel receipt can complete while expense approval is pending. Activating A2 does not change the projector or continuation selected for A1. The executable fixture uses separately packaged JVM processes; the independent AWS packaging work applies this boundary to deployment ownership.

See the shared Coordinator proof for the application definitions and recovery assertions.

A Command acknowledgement and callback can arrive in either order. The Coordinator keeps admitted evidence so it can retry an unavailable projector. Each item of an itemised Await has its own interaction, while the unit owns continuation. A new active Release changes new admissions. Waiting work retains its original binding.

Deferred Completion Versus Checkpoint Handoff ​

ConcernDeferred completionCheckpoint handoff
Execution ownershipsame execution parks and resumesanother pipeline admits independent work
Boundarylifecycle attached to one operationpublication/admission between pipelines
Completioncorrelated external observationdownstream checkpoint admission
Retry and DLQowning execution remains responsibledownstream orchestrator owns them after admission
Use whenthe final result belongs to this operationanother flow should own the next lifecycle

Await inside a nested definition ​

An operation inside a LOCAL ONE_TO_ONE definition can await an external answer. The caller and every intermediate definition must also be unary. In PadelPot, the root calls the named personal-agent definition. Its policy operation produces Review, the persistence aspect records it, and selective Await admits an AnsweredReview. The answer policy can produce TurnState for pipeline: self or complete the negotiation and return through the root's remaining steps.

Repeated visits to the review operation have distinct invocation occurrences. A retry of the same occurrence retains its identity. The root owns the execution and terminal publication throughout suspension and return. See nested Await recovery for the release and continuation information needed during recovery.

Current Support Boundary ​

Authored internal services and native unary Commands accept await:. Ordinary transport Await follows completion of the Command operation; provider callbacks use registration before effect dispatch as described above. Query, nested pipeline invocation, remote/delegated operators, dynamic operation dispatch, and packaged Blocks do not yet accept await:. Object admission, publication, and checkpoint handoff keep their existing ownership models.

Existing deployments with executions waiting on the former standalone Await topology must let those releases finish or cancel them before retiring the old deployment. They are not remapped to the new step identity.

Design Responsibilities ​

For every decorated operation, choose:

  1. an immediate operation-output type containing only trusted request state;
  2. a stable business idempotency key over that output;
  3. an explicit, minimal completion payload owned by the external participant;
  4. a deterministic projector when final output combines trusted and untrusted facts;
  5. a timeout and a policy for late, expired, or duplicate completion;
  6. a transport adapter appropriate for UI, webhook, Kafka, or SQS delivery.

Where To Go Next ​

Diagram