---
title: "Webhook to partner: put it together"
description: Admit a webhook, validate and deduplicate it, then exercise bounded
  partner retries with privacy, secret and cost evidence.
url: https://docs.rastok.com/examples/04-webhook-to-partner
source_revision: v0.2.0-alpha
---

# Webhook to partner: put it together

This program accepts a webhook, rejects invalid or duplicate events and sends accepted events to a partner.

You know how to replace an effect, route its outcomes and isolate state. Now
use those ideas for a familiar integration: receive a webhook and deliver it
to a partner that is not always available. Build the flow and its fault
scenarios together, before you need a live partner environment.

All six scenarios have versioned goldens. The captures below show native
Retry retaining a failed attempt and publishing the final outcome.

The [file formats](/guide/09-command-line.md#file-formats) are `.rkg` for
the program and Lab, `.rkc` for a reviewed scenario reference and `.rkr`
for a real execution recording.

## Run

From the repository root:

```sh
env RASTOK_SHOWCASE_PARTNER_TOKEN=lab-only-not-a-credential \
    RASTOK_SHOWCASE_PARTNER_TOKEN_VERSION=fixture-v1 \
    rastok simulate examples/webhook-to-partner.rkg \
      --deployment examples/webhook-to-partner.deployment.json \
      --compare examples/traces/webhook-to-partner
```

```text
PASS webhook.nominal
PASS webhook.timeout_then_success
PASS webhook.partner_dead
PASS webhook.duplicate
PASS webhook.invalid_payload
PASS webhook.http_500
6 scenario(s), 0 failed
```

Add `--ui` to inspect the same graph.

```sh
env RASTOK_SHOWCASE_PARTNER_TOKEN=lab-only-not-a-credential RASTOK_SHOWCASE_PARTNER_TOKEN_VERSION=fixture-v1 rastok simulate examples/webhook-to-partner.rkg --deployment examples/webhook-to-partner.deployment.json --compare examples/traces/webhook-to-partner --ui
```

This requires `hosted-ui`. Open the private loopback URL printed by the CLI. No HTTP listener, real partner or paid
API is started. The value above is a **fictional fixture**, not a credential.
For real deployments, supply secret material out of band, never in source,
profile JSON or shell command text. The profile contains only its coordinate
and version. The same Contract is used with a scripted or physical Driver.

For the controls and source view, see [the debugger tour](/debugger.md).

## Read the program

Follow the main path first: `listener`, an [HttpServer](/reference/connectors/http-server.md), admits, `validate` checks the business
data, `deduplicate` owns a `seen` flag per event, and `deliver` contains the
bounded partner retry. Open that scope to find `request`,
`partner : HttpClient + Retry` ([HttpClient](/reference/connectors/http-client.md)) and `decide`. The response type `Receipt`
annotates the charge where the Connector retains it, before any decision to
hold or publish the attempt.
`decide` classifies the final business outcome; it contains no retry logic.

`var seen: bool = false` declares mutable state inside `deduplicate`.
Each `data.event_id` selects an Operator instance with its own flag,
initialized to `false` when that instance is created. The first event sets
it to `true` and is forwarded; a later arrival with the same key reads that
committed value and takes the duplicate branch. The assignment and emission
commit together. This is not a global variable or durable deduplication:
after the instance closes, a new generation starts with `false` again.
See [Values and mutable state](/guide/06-instances-state-and-time.md#values-and-mutable-state)
before changing the handler.

The `deliver` Graph is also keyed by event id. Like `deduplicate`, it closes
after five minutes without an admission. A Retry can finish within that
window, but the App does not keep a delivery instance for every event forever.

Then read the declarations that constrain the path: the idle lifetime, the
partner's idempotency key, the exhaustive destinations, `@personal` and the
secret reference. These are reviewable parts of the program and deployment,
not separate conventions the reader must guess from the happy path.

The [Lab reference](/reference/lab.md) explains mock responses, expectations
and observation windows. `advance` supplies virtual time; a mock's terminal
response ends its simulated exchange, not the whole scenario.

<a id="graph"></a>

Source: `examples/webhook-to-partner.rkg`

```rkg
// A webhook acknowledges requests, skips repeat deliveries and retries a partner call.
// The Lab supplies fictional requests and partner replies without opening a socket.
type Webhook = struct {
  event_id: string
  email: string @personal(identifier = true)
  amount: int
}
type Delivered = struct { event_id: string, status: int }
type Failure = union {
  Rejected { reason: string }
  PartnerFailed { event_id: string, terminal: HttpClientExit }
}
type Receipt = struct {
  charge: decimal(38,18) @measure(id = amount, unit = "USD")
}
type Charge = decimal(38,18)

graph webhook_to_partner : App {
  output done: Delivered
  output failed: Failure
  output duplicate: string

  connector listener : HttpServer {
    listen = "127.0.0.1:8080"
    path = "/events"
    codec = json
    max_body = "16 KiB"
  }

  operator validate {
    input in: variant
    output out: Webhook
    output failed: Failure
    on in match {
      data is Webhook => match {
        data.amount > 0 && size(data.event_id) > 0 => out = data as Webhook
        _ => failed = Rejected { reason = "positive amount and event id required" }
      }
      _ => failed = Rejected { reason = "expected event_id, email and integer amount" }
    }
  }

  operator deduplicate {
    input in: Webhook
    output out: Webhook
    output duplicate: string
    instance = { key = data.event_id }
    lifetime = { kind = idle; max = duration("5m") }
    var seen: bool = false
    on in match {
      seen => duplicate = data.event_id
      _ => {
        seen = true
        out = data
      }
    }
  }

  graph deliver {
    input in: Webhook
    output done: Delivered
    output failed: Failure
    instance = { key = data.event_id }
    lifetime = { kind = idle; max = duration("5m") }
    closing = { drain_for = duration("1s"); settle_for = duration("1s") }

    operator request {
      input in: Webhook
      output out: variant
      on in {
        // JSON erases the field schema: retain personal-data policy on the
        // opaque body, while the non-personal event id remains a typed key.
        out = {
          data = data as variant
          meta.app.event_id = data.event_id
        }
      }
    }

    connector partner : HttpClient + Retry {
      url = env("PARTNER_URL")
      auth_bearer = secret("showcase/partner/token")
      method = "POST"
      codec = json
      output out: Receipt
      timeout = duration("1s")
      max_body = "16 KiB"
      idempotency_key = meta.app.event_id
      // Required partner contract: honour this key for the identical request.
      // This declaration does not prove that a real service honours that contract.
      idempotent = true
      behavior = deterministic
      Retry.attempts = 2
      Retry.on = [ServerError, TimeoutExpired, DnsFailed, ConnectFailed]
      Retry.delay = { kind = fixed; after = duration("1s") }
    }

    operator decide {
      input in: HttpClientExit
      output done: Delivered
      output failed: Failure
      on in match {
        data is Completed && data.status >= 200 && data.status < 300 => done = {
          event_id = meta.app.event_id as string
          status = data.status
        }
        _ => failed = PartnerFailed {
          event_id = meta.app.event_id as string
          terminal = data
        }
      }
    }

    in -> request -> partner
    partner.out -> nothing
    // On a lost answer, decide keeps the terminal case in the failure it reports.
    partner.exit -> match {
      BodyTooLarge | DecodeFailed | OutcomeUnknown | ProtocolFailed | TimeoutExpired -> decide
      Completed | ConnectFailed | DnsFailed | ServerError | TlsFailed -> decide
    }
    decide.done -> done
    decide.failed -> failed
  }

  listener.out -> validate -> deduplicate -> deliver
  listener.exit -> nothing
  validate.failed -> failed
  deduplicate.duplicate -> duplicate
  deliver.done -> done
  deliver.failed -> failed
}

lab webhook {
  mock deliver.partner {
    on in where data is Webhook && data.event_id == "dead" {
      out = nothing
    }
    on in where data is Webhook && data.event_id == "retry" && now() == timestamp("1970-01-01T00:00:00Z") {
      out = nothing
    }
    on in where data is Webhook && data.event_id == "http-500" && now() == timestamp("1970-01-01T00:00:00Z") {
      out = { charge = decimal("0.01") as Charge }
      exit = ServerError { status = 500 }
    }
    on in {
      out = { charge = decimal("0.02") as Charge }
      exit = Completed { status = 201 }
    }
  }

  scenario nominal {
    listener.out = { event_id = "ok"; email = "alice@example.test"; amount = 12 }
    expect listener.exit == Completed { status = 202 }
    expect app.done == { event_id = "ok", status = 201 }
    expect deliver.partner.in
    expect deliver.partner.out where data.charge == (decimal("0.02") as Charge)
    expect app.failed == nothing
  }

  scenario timeout_then_success {
    listener.out = { event_id = "retry"; email = "alice@example.test"; amount = 12 }
    expect listener.exit == Completed { status = 202 }
    expect app.done == nothing
    advance duration("1s")
    expect deliver.partner.exit == TimeoutExpired {}
    expect deliver.partner.in == nothing
    expect deliver.decide.in == nothing
    advance duration("1s")
    expect deliver.decide.in where data is Completed
    expect app.done == { event_id = "retry", status = 201 }
    expect app.failed == nothing
  }

  scenario partner_dead {
    listener.out = { event_id = "dead"; email = "alice@example.test"; amount = 12 }
    advance duration("1s")
    advance duration("1s")
    advance duration("1s")
    expect app.failed where data is PartnerFailed
    expect app.done == nothing
    advance duration("10s")
    expect deliver.partner.in == nothing
    expect app.failed == nothing
  }

  scenario duplicate {
    listener.out = { event_id = "same"; email = "alice@example.test"; amount = 12 }
    expect app.done
    listener.out = { event_id = "same"; email = "alice@example.test"; amount = 12 }
    expect listener.exit == Completed { status = 202 }
    expect app.duplicate == "same"
    expect deliver.partner.in == nothing
    expect app.done == nothing
    advance duration("5m")
    listener.out = { event_id = "same"; email = "alice@example.test"; amount = 12 }
    expect app.done
    expect app.duplicate == nothing
  }

  scenario invalid_payload {
    listener.out = json! { "unexpected": true }
    expect listener.exit == Completed { status = 202 }
    expect app.failed where data is Rejected
    expect deliver.partner.in == nothing
    listener.out = { event_id = "invalid"; email = "alice@example.test"; amount = -1 }
    expect listener.exit == Completed { status = 202 }
    expect app.failed where data is Rejected
    expect deliver.partner.in == nothing
  }

  scenario http_500 {
    listener.out = { event_id = "http-500"; email = "alice@example.test"; amount = 12 }
    expect deliver.partner.exit == ServerError { status = 500 }
    expect deliver.partner.out where data.charge == (decimal("0.01") as Charge)
    expect deliver.decide.in == nothing
    expect app.done == nothing
    advance duration("1s")
    expect app.done == { event_id = "http-500", status = 201 }
    expect app.failed == nothing
  }
}
```

## Expected result

In `webhook.nominal`, admission produces the ACK before business validation;
the scripted partner then completes the first attempt.

```mermaid
sequenceDiagram
    participant lab as Lab: webhook.nominal
    participant listener as listener: HttpServer
    participant validate as validate
    participant dedup as deduplicate
    participant request as deliver.request
    participant partner as deliver.partner: HttpClient + Retry
    participant decide as deliver.decide
    participant app as webhook_to_partner
    lab->>listener: Decoded request: event_id = ok
    Note over listener: Admission ACK: Completed(202), disposed to nothing
    listener->>validate: out = decoded payload
    validate->>dedup: out = validated Webhook
    dedup->>request: First event_id: set seen, forward
    request->>partner: Body and meta.app.event_id
    partner->>lab: Scripted POST with idempotency key
    lab-->>partner: Receipt charge 0.02 USD, then Completed(201)
    Note over partner: Receipt measured in journal, out disposed to nothing
    partner->>decide: exit = Completed(201)
    decide-->>app: done = event_id ok, status 201
```

`6 scenario(s), 0 failed` covers:

- `nominal`: one `202` ACK and one partner Call ending with `201`;
- `timeout_then_success`: one second to timeout, one second of backoff,
  then success on the second attempt;
- `partner_dead`: two timed-out Calls, then the final `TimeoutExpired`
  inside the business `PartnerFailed` response, with
  no further Call even after another ten seconds;
- `duplicate`: an explicit `seen` state suppresses a second request with
  the same event id; after five minutes idle, a fresh instance admits it again;
- `invalid_payload`: decoded JSON with the wrong shape, then a negative
  amount, both rejected after ACK and without contacting the partner;
- `http_500`: `ServerError { status: 500 }` is a decoded response; the
  static `Retry.on` policy selects it, and the second response is `201`.

The email field is `@personal`. The deployment must attest the in-memory
processing before admission; having a valid secret binding alone is not
enough. Debugger views redact before formatting. Personal data can remain in
the in-memory causal journal: presentation masking is not erasure. The bearer
is different: its clear bytes never enter the journal at all.

The declared `output out: Receipt` interprets the fictional partner's `charge`
field as an exact amount with `@measure(id = amount, unit = "USD")`.
That declaration names a quantity and its unit, not a billing policy. No downstream accounting
Operator is run or replayed to extract it. The nominal reply reports
`0.02`; the `500` and successful replies retain two separate samples, `0.01`
and `0.02`, with their causal references. The first is Held by Retry and
never reaches `decide`; it remains inspectable in the journal. M1 computes no
total or price and the debugger displays the original DATA, not a cost report. A timed-out Call
supplies no charge: missing evidence is **unknown cost, not a zero bill**.

## Break it

Change the single `Retry.attempts = 2` to `Retry.attempts = 1`. The timeout and
`500` scenarios can no longer succeed on a second attempt. Run the comparison below.

```sh
env RASTOK_SHOWCASE_PARTNER_TOKEN=lab-only-not-a-credential RASTOK_SHOWCASE_PARTNER_TOKEN_VERSION=fixture-v1 rastok simulate examples/webhook-to-partner.rkg --deployment examples/webhook-to-partner.deployment.json --compare examples/traces/webhook-to-partner
```

```text
FAIL webhook.nominal
     golden divergence: record 12: retry_protocol(43) . parent_id(2)[0][4]; expected [REDACTED]; got [REDACTED]; cause: [REDACTED]
FAIL webhook.timeout_then_success
     expect [REDACTED]  (webhook-to-partner.rkg:167)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     expect [REDACTED]  (webhook-to-partner.rkg:169)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     expect [REDACTED]  (webhook-to-partner.rkg:170)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     golden divergence: record 12: retry_protocol(43) . parent_id(2)[0][4]; expected [REDACTED]; got [REDACTED]; cause: [REDACTED]
FAIL webhook.partner_dead
     expect [REDACTED]  (webhook-to-partner.rkg:179)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     golden divergence: record 12: retry_protocol(43) . parent_id(2)[0][4]; expected [REDACTED]; got [REDACTED]; cause: [REDACTED]
FAIL webhook.duplicate
     golden divergence: record 12: retry_protocol(43) . parent_id(2)[0][4]; expected [REDACTED]; got [REDACTED]; cause: [REDACTED]
PASS webhook.invalid_payload
FAIL webhook.http_500
     expect [REDACTED]  (webhook-to-partner.rkg:215)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     expect [REDACTED]  (webhook-to-partner.rkg:218)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     golden divergence: record 12: retry_protocol(43) . parent_id(2)[0][4]; expected [REDACTED]; got [REDACTED]; cause: [REDACTED]
6 scenario(s), 5 failed
```

Restore the checked-in source (this discards your edits to this example):

```sh
git checkout -- examples/webhook-to-partner.rkg
```

## Read the golden difference

Add
`--compare examples/traces/webhook-to-partner`.
The CLI names the first differing record and field, expected versus actual,
and recorded causal context. This classified graph deliberately redacts
values in divergence messages. Recorded operation facts can differ before
the final answer does.
The versioned goldens contain **only the synthetic fixture data**; they are
not sanitized exports suitable for real personal data.

### Why five attempts also fail this comparison

`Retry.attempts` is a maximum including the first Call, not a promise that
the partner eventually answers. The `partner_dead` mock stays silent on
every attempt. Its scenario expects the final failure after two one-second
timeouts and one second of backoff, then expects no further activity.
With five attempts, the operation is still waiting at that first assertion:
the additional attempts move the final failure into the later observation
window. The scenario no longer describes the configured policy.

There is a separate reason for a golden divergence. Retry facts record the
original plan's semantic hash. Changing the attempt bound changes that hash,
even in a scenario whose final business value stays the same. A golden
comparison checks those facts, not just the last value on `app.done`.

With `Retry.attempts = 5`, this command checks only the scenario assertions:

```sh
env RASTOK_SHOWCASE_PARTNER_TOKEN=lab-only-not-a-credential RASTOK_SHOWCASE_PARTNER_TOKEN_VERSION=fixture-v1 rastok simulate examples/webhook-to-partner.rkg --deployment examples/webhook-to-partner.deployment.json
```

```text
PASS webhook.nominal
PASS webhook.timeout_then_success
FAIL webhook.partner_dead
     expect [REDACTED]  (webhook-to-partner.rkg:179)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
     expect [REDACTED]  (webhook-to-partner.rkg:183)
     observed: [REDACTED]
     Assertion evidence is redacted because this program carries classified data.
PASS webhook.duplicate
PASS webhook.invalid_payload
PASS webhook.http_500
6 scenario(s), 1 failed
```

Adding `--compare examples/traces/webhook-to-partner` also detects changed
Retry facts in every scenario that opens a partner operation. Restore the
reviewed two-attempt policy after this experiment:

```sh
git checkout -- examples/webhook-to-partner.rkg
```

If five attempts are an intended policy change, update the exhaustion
scenario's time advances and expectations, review the changed journal,
then save the new reference. Do not overwrite references just to remove a
divergence. [Loops and retries](/guide/07-loops-and-retries.md) explains
the attempt bound and closure-based delay.

### Inspect the recorded retry

The following 30-second sequence visits recorded states of
`webhook.timeout_then_success`: admission, timeout, backoff and successful
second attempt. During the backoff, Retry retains the failed batch without
delivering it to `decide`; only the final result is published. These are real
debugger views of a simulation, not live HTTP requests or an edited branch.
The graph is shown at Readable size, where the view follows the Node of each
transition; Fit graph shows the complete drawing.

![Thirty seconds through the recorded timeout and retry transitions](/assets/webhook-tour.png)

Three stills make the checkpoints easier to inspect:

- [Before admission, transition 0](/assets/webhook-before.png).
- [Retry backoff scheduled, transition 20](/assets/webhook-backoff.png).
- [Success after two attempts, transition 34](/assets/webhook-completed.png).

<details id="golden" class="raw-trace">
<summary>Inspect the raw sealed trace (.rkc)</summary>

The versioned reference stores one hex-encoded causal record per line, with an optional final seal line. Use the chapter's comparison commands to explain a divergence.

Source: `examples/traces/webhook-to-partner/webhook.nominal.rkc`

```rastok-trace
a9070108a40150f09d9a552439b865d3e4c81c1d1153130350f09d9a552439b865d3e4c81c1d11531304010582025839820f838266616d6f756e7482020c8265656d61696c820672616c696365406578616d706c652e7465737482686576656e745f69648206626f6b09686c697374656e65720a000b000c636f75740d818278186c697374656e65722e6f75743e76616c69646174652e696e824c82816876616c696461746580000f81686c697374656e6572108250f09d9a552439b865d3e4c81c1d115313824c8281686c697374656e65728000
a7070211601282438280800013676c3a737461727414801780181a50f09d9a552439b865d3e4c81c1d115313
a8070211686c697374656e657212824c8281686c697374656e6572800013676c3a737461727414801780181a50f09d9a552439b865d3e4c81c1d1153131822824382808000
a80702116876616c696461746512824c82816876616c6964617465800013676c3a737461727414801780181a50f09d9a552439b865d3e4c81c1d1153131822824382808000
a8070211686c697374656e657212824c8281686c697374656e6572800013676c3a7265706c791480178183646578697400a501503fafcc12ed987e27f9b7b5d1f8f4478d0250f09d9a552439b865d3e4c81c1d1153130350f09d9a552439b865d3e4c81c1d1153130401058202581c82138269436f6d706c65746564820f818266737461747573820218ca181a50f09d9a552439b865d3e4c81c1d115313182650f09d9a552439b865d3e4c81c1d115313
a70702116876616c696461746512824c82816876616c696461746580001364703a696e14818378186c697374656e65722e6f75743e76616c69646174652e696e824c8281686c697374656e6572800001178183636f757400a5015017381d0576454a378d6103ff771e6d060250f09d9a552439b865d3e4c81c1d1153130350f09d9a552439b865d3e4c81c1d11531304010582025839820f838266616d6f756e7482020c8265656d61696c820672616c696365406578616d706c652e7465737482686576656e745f69648206626f6b181981835017381d0576454a378d6103ff771e6d06781b76616c69646174652e6f75743e64656475706c69636174652e696e82582582816b64656475706c69636174658183816b64656475706c69636174650182078206626f6b00
a80702116b64656475706c69636174651282582582816b64656475706c69636174658183816b64656475706c69636174650182078206626f6b0013676c3a737461727414801780181a5017381d0576454a378d6103ff771e6d061822824382808000
a80702116b64656475706c69636174651282582582816b64656475706c69636174658183816b64656475706c69636174650182078206626f6b001364703a696e148183781b76616c69646174652e6f75743e64656475706c69636174652e696e824c82816876616c6964617465800001168182647365656e8201f5178183636f757400a5015037374515af1bad8312f98b4daa42b538025017381d0576454a378d6103ff771e6d060350f09d9a552439b865d3e4c81c1d11531304010582025839820f838266616d6f756e7482020c8265656d61696c820672616c696365406578616d706c652e7465737482686576656e745f69648206626f6b181981835037374515af1bad8312f98b4daa42b538782264656475706c69636174652e6f75743e64656c697665722e726571756573742e696e82582582826764656c6976657267726571756573748183816764656c697665720182078206626f6b00
a80702116764656c697665721282581d82816764656c697665728183816764656c697665720182078206626f6b0013676c3a737461727414801780181a5037374515af1bad8312f98b4daa42b5381822824382808000
a80702116f64656c697665722e726571756573741282582582826764656c6976657267726571756573748183816764656c697665720182078206626f6b0013676c3a737461727414801780181a5037374515af1bad8312f98b4daa42b538182282581d82816764656c697665728183816764656c697665720182078206626f6b00
a80702116f64656c697665722e726571756573741282582582826764656c6976657267726571756573748183816764656c697665720182078206626f6b001364703a696e148183782264656475706c69636174652e6f75743e64656c697665722e726571756573742e696e82582582816b64656475706c69636174658183816b64656475706c69636174650182078206626f6b0001178183636f757400a601508123dbaa681417af92bf1d659477f59e025037374515af1bad8312f98b4daa42b5380350f09d9a552439b865d3e4c81c1d11531304010582025839820f838266616d6f756e7482020c8265656d61696c820672616c696365406578616d706c652e7465737482686576656e745f69648206626f6b06818363617070686576656e745f69648206626f6b181881820150f68b7eb0b2ef76045c336f9390debc9218198183508123dbaa681417af92bf1d659477f59e782664656c697665722e726571756573742e6f75743e64656c697665722e706172746e65722e696e82582582826764656c6976657267706172746e65728183816764656c697665720182078206626f6b00
a80702116f64656c697665722e706172746e65721282582582826764656c6976657267706172746e65728183816764656c697665720182078206626f6b0013676c3a737461727414801780181a508123dbaa681417af92bf1d659477f59e182282581d82816764656c697665728183816764656c697665720182078206626f6b00
a80702116f64656c697665722e706172746e65721282582582826764656c6976657267706172746e65728183816764656c697665720182078206626f6b0013676c3a726574727914801780181a508123dbaa681417af92bf1d659477f59e182ba10282870150c8fa3674c4ed0eab3192771f1392030850f68b7eb0b2ef76045c336f9390debc9262696e58204583fb2221dac2d4c535ef23eb79b2682fb02d8aafe91e8ace4e365738c854aa717374642f687474702d636c69656e74403184508123dbaa681417af92bf1d659477f59e58208c3c3e457b61b7ba324420aa9ea838dd5667bdbdb36420401e19becaab3ba2f281826f6964656d706f74656e63795f6b65798206626f6bf6850250c8fa3674c4ed0eab3192771f1392030801a601508123dbaa681417af92bf1d659477f59e025037374515af1bad8312f98b4daa42b5380350f09d9a552439b865d3e4c81c1d11531304010582025839820f838266616d6f756e7482020c8265656d61696c820672616c696365406578616d706c652e7465737482686576656e745f69648206626f6b06818363617070686576656e745f69648206626f6b50f68b7eb0b2ef76045c336f9390debc92
a70703181b508123dbaa681417af92bf1d659477f59e181c6f64656c697665722e706172746e6572181e58208c3c3e457b61b7ba324420aa9ea838dd5667bdbdb36420401e19becaab3ba2f2181f011821782664656c697665722e726571756573742e6f75743e64656c697665722e706172746e65722e696e182ba1018250c8fa3674c4ed0eab3192771f1392030801
a80703181b508123dbaa681417af92bf1d659477f59e181c6f64656c697665722e706172746e6572181e58208c3c3e457b61b7ba324420aa9ea838dd5667bdbdb36420401e19becaab3ba2f2181f02182082018282636f7574820257820f81826663686172676582088247470de4df820000128264657869748202581c82138269436f6d706c65746564820f818266737461747573820218c91821782664656c697665722e726571756573742e6f75743e64656c697665722e706172746e65722e696e182ba1018250c8fa3674c4ed0eab3192771f1392030801
a80702116f64656c697665722e706172746e65721282582582826764656c6976657267706172746e65728183816764656c697665720182078206626f6b001364703a696e148183782664656c697665722e726571756573742e6f75743e64656c697665722e706172746e65722e696e82582582826764656c6976657267726571756573748183816764656c697665720182078206626f6b0001178283636f757400a60150827242f9de6b67f5bfcf5d6f6462d6f702508123dbaa681417af92bf1d659477f59e0350f09d9a552439b865d3e4c81c1d115313040105820257820f81826663686172676582088247470de4df8200001206818363617070686576656e745f69648206626f6b83646578697400a6015018b1f25dbecdd81fc5ac7139611721e502508123dbaa681417af92bf1d659477f59e0350f09d9a552439b865d3e4c81c1d1153130401058202581c82138269436f6d706c65746564820f818266737461747573820218c906818363617070686576656e745f69648206626f6b181981835018b1f25dbecdd81fc5ac7139611721e5782664656c697665722e706172746e65722e657869743e64656c697665722e6465636964652e696e82582482826764656c69766572666465636964658183816764656c697665720182078206626f6b00182ba2018250c8fa3674c4ed0eab3192771f13920308010282850650c8fa3674c4ed0eab3192771f1392030801501ec22e92983fdfaa9c62b22b6d57acba8250827242f9de6b67f5bfcf5d6f6462d6f75018b1f25dbecdd81fc5ac7139611721e5840750c8fa3674c4ed0eab3192771f139203080101
a80702116e64656c697665722e6465636964651282582482826764656c69766572666465636964658183816764656c697665720182078206626f6b0013676c3a737461727414801780181a5018b1f25dbecdd81fc5ac7139611721e5182282581d82816764656c697665728183816764656c697665720182078206626f6b00
a60702116e64656c697665722e6465636964651282582482826764656c69766572666465636964658183816764656c697665720182078206626f6b001364703a696e148183782664656c697665722e706172746e65722e657869743e64656c697665722e6465636964652e696e82582582826764656c6976657267706172746e65728183816764656c697665720182078206626f6b000117818364646f6e6500a60150d041f8468dc1be645ee0473d4b2d292d025018b1f25dbecdd81fc5ac7139611721e50350f09d9a552439b865d3e4c81c1d1153130401058202581e820f8282686576656e745f69648206626f6b8266737461747573820218c906818363617070686576656e745f69648206626f6b
seal 15ab14a07ba6e7bd0b44195b6da8f7c9aae3b23d44b36e9f508e3936aae7db48
```

</details>

## Carry forward

Read [Connectors and outcomes](/guide/03-connectors-and-outcomes.md) for the
admission boundary and [Running for real](/guide/05-running-for-real.md)
for deployment settings, secrets and diagnostic evidence.

This is the central exercise: one integration, several possible worlds, and
a recorded explanation when a revision changes behavior. Keep the timeout,
duplicate and 500 scenarios alongside the nominal one. Each describes a case
the next change must still handle; passing them is evidence under their stated
world assumptions, not proof that every real partner will behave that way.

Previous: [Two tenants](/examples/03-two-tenants.md). Next:
[Sensor alarm](/examples/05-sensor-alarm.md). The same approach can test an event that
never arrives, without making the test wait in real time.

## Limits

Malformed JSON, failed authentication and an excessive wire body are refused
before a root or ACK exists. A decoded Lab injection cannot exercise that
decoder. The separate physical loopback proof is:

```sh
cargo test -p rastok --lib --features hosted-http12 auth_codec_and_body_refusals_never_invent_an_inbound_call
```

The filtered test result was:

```text
test connector::drivers::network::http_server::tests::auth_codec_and_body_refusals_never_invent_an_inbound_call ... ok
```

An instance key isolates state; `seen` does the deduplication. This is
accept-once within an **idle** retention window: duplicates extend that
window, and a permanently failed job is still considered seen until expiry.
It is not exactly-once delivery, a durable outbox, or automatic resubmission
after a fault. A restart loses that state. The partner must honor the stable
idempotency key, upsert by `event_id`; the request and key remain identical
between attempts. Both retry paths rely on that external property. The example
does not test a real partner's idempotence.

The supplied privacy profile describes a local synthetic demonstration, not
legal authority for production processing. Real purposes, recipients,
transfers and retention require deployment-specific review. No persistent
personal-data journal or `run --record` is admitted by this example. A message broker
and SQL are not shown. Modify the scenario on disk to try another world;
there is no debugger branch or payload editor.
