Delivery and failures
This page shows how to test the parts of a platform apps most often get wrong: retried and redelivered events, forged requests, rate limits, dropped connections and an uninstall. Everything here works against the fakes only. In live mode an action has no delivery to test, so these tests need a guard to skip there: see Fake only.
What the fakes send#
Each fake delivers events the way its platform does: signed over the exact bytes it sends, within the platform's ack window, and retried on the platform's schedule.
| Platform | Signature | Replay protection | Ack window | Retries | Same event, again |
|---|---|---|---|---|---|
| Slack | X-Slack-Signature: v0=…, an HMAC-SHA256 of v0:<timestamp>:<body> with the signing secret | X-Slack-Request-Timestamp; receivers refuse one more than 5 minutes old | 3 s | Right after a failed attempt, then after 1 and 5 minutes, with X-Slack-Retry-Num and X-Slack-Retry-Reason. An answer with X-Slack-No-Retry: 1 ends them | Same event_id |
| GitHub | X-Hub-Signature-256: sha256=… with the webhook secret, and the older X-Hub-Signature | None | 10 s | None; redelivery comes from the App's delivery log | Same X-GitHub-Delivery GUID |
| Linear | Linear-Signature, a hex HMAC-SHA256 of the body | webhookTimestamp in the body; receivers refuse one more than a minute old | 5 s | After 1 minute, 1 hour and 6 hours, stamped and signed again | Same Linear-Delivery id |
| Notion | X-Notion-Signature: sha256=… with the verification token | None | 5 s | Up to 8 times over about a day, with attempt_number in the body | Same event id |
| Resend | Svix's: svix-signature: v1,…, a base64 HMAC-SHA256 of <svix-id>.<svix-timestamp>.<body> with the whsec_ secret | svix-timestamp; receivers refuse one more than 5 minutes old | 15 s | After 5 seconds, 5 and 30 minutes, 2, 5, 10 and 10 hours, signed again each time | Same svix-id |
Authorization: Bearer <OIDC token>, RS256, from Pub/Sub's push service account, for the push endpoint as audience; checked with verifyIdToken against GOOGLE_CERTS_URL | The token's exp: an hour after it was issued, with 5 minutes' skew | 10 s | Pub/Sub's push backoff, from 100 ms up to a minute. Gmail pushes at most once a second per mailbox (Google) | Same Pub/Sub message id |
Over Slack's Socket Mode there is no signature, because the connection is the app's own, and a retry carries retry_attempt and retry_reason in the envelope.
Deliveries in a test#
An action that reaches the app gives you the delivery it caused:
const msg = await ana.say("@my-agent hi", { channel });msg.delivery; // the app_mention event_callbackconst comment = await ben.comment("@my-agent investigate", { issue });comment.delivery; // the issue_comment webhookconst session = await mo.delegate(linear.app, { issue: ticket });session.delivery; // the AgentSessionEvent that opened the sessionconst command = await ana.runCommand("/deploy web staging", { channel });// a slash command, click, shortcut or modal submission resolves to its deliverymsg = await ana.say("@my-agent hi", channel=channel)msg.delivery # the app_mention event_callbackcomment = await ben.comment("@my-agent investigate", issue=issue)comment.delivery # the issue_comment webhooksession = await mo.delegate(linear.app, issue=ticket)session.delivery # the AgentSessionEvent that opened the sessioncommand = await ana.run_command("/deploy web staging", channel=channel)# a slash command, click, shortcut or modal submission resolves to its deliverylet msg = ana.say("@my-agent hi").channel(&channel).await?;msg.delivery(); // the app_mention event_callbacklet comment = ben.comment("@my-agent investigate").issue(&issue).await?;comment.delivery(); // the issue_comment webhooklet session = mo.delegate(&linear.app()).issue(&ticket).await?;session.delivery(); // the AgentSessionEvent that opened the sessionlet command = ana .run_command("/deploy web staging") .channel(&channel) .await?;// a slash command, click, shortcut or modal submission resolves to its deliveryA delivery has its attempts, each with the request headers, the app's response status and body, and how long the app took. Its status is the latest attempt's:
| Status | Meaning |
|---|---|
pending | Queued or in flight |
acknowledged | The app answered 2xx in time |
failed | The app answered, but not 2xx |
timed_out | The app didn't answer within the ack window |
unreachable | The app's URL couldn't be reached |
delivery.settled() waits until the latest attempt has a final status. msg.delivery is undefined when nothing was sent: the app isn't in the channel, isn't installed or connected, or the server has no URL for the app (connecting your app).
Slack's retry#
- Slack delivers the event. Without an answer within 3 seconds it counts the delivery as failed.
- It sends the same event again, with the attempt number and the reason in its retry headers.
- An app that remembers the event id acknowledges the retry and does nothing else.
- The thread gets one reply. An app that doesn't check answers twice.
Slack expects an acknowledgement within 3 seconds. An app that does its work before answering the HTTP request misses that window, and Slack sends the same event again. An app that doesn't notice answers twice.
test("survives Slack's 3s retry without answering twice", async ({ slack }) => { const ana = await slack.createUser({ name: "Ana" }); const channel = await slack.createChannel({ participants: [ana, slack.app] }); const msg = await ana.say("@my-agent hi", { channel }); await msg.delivery!.retry({ after: "3s", reason: "http_timeout" }); await expect(msg.thread).toHaveRepliesFrom("my-agent", { count: 1 });});async def test_survives_slacks_3s_retry_without_answering_twice(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") channel = await slack.create_channel(participants=[ana, slack.app]) msg = await ana.say("@my-agent hi", channel=channel) assert msg.delivery await msg.delivery.retry(after="3s", reason="http_timeout") await expect(msg.thread).to_have_replies_from("my-agent", count=1)let ana = slack.create_user().name("Ana").await?;let channel = slack .create_channel() .participants(vec![&ana as &dyn Handle, &slack.app()]) .await?;let msg = ana.say("@my-agent hi").channel(&channel).await?;let delivery = msg.delivery().expect("the fake delivered the message");delivery.retry().after("3s").reason("http_timeout").await?;expect(&msg.thread()) .to_have_replies_from("my-agent", 1) .await?;retry() sends the event again the way Slack does: the same payload and event_id, with X-Slack-Retry-Num and X-Slack-Retry-Reason. after defaults to 3 seconds, Slack's first retry, and reason to http_timeout (http_error and too_many_redirects are the others). The exact-count check then waits for the app to be quiet, so a second answer has time to show up.
The test proves the app is idempotent on event_id. The usual fix is to acknowledge at once and remember the event ids already handled. Bolt for JavaScript acknowledges events as they arrive unless processBeforeResponse is on, which is common on serverless hosts; with it on, a slow handler misses the window.
Redelivery#
A redelivery is the same event again, without anything that marks it as a retry. GitHub sends one when someone clicks Redeliver in the App's settings, Linear, Notion and Resend when the first delivery failed, Pub/Sub when a push wasn't acknowledged, and Discord's Gateway when a bot resumes a dropped connection and is sent what it missed:
test("a redelivered comment doesn't produce a second answer", async ({ github }) => { const ana = await github.createUser({ login: "ana" }); const repo = await github.createRepo({ collaborators: [ana], apps: [github.app] }); const issue = await ana.openIssue({ title: "Flaky test" }, { repo }); const comment = await ana.comment("@my-agent investigate", { issue }); await expect(issue).toHaveCommentFrom(github.app); await comment.delivery!.redeliver(); await expect(issue).toHaveCommentsFrom(github.app, { count: 1, quietFor: "2s" });});async def test_a_redelivered_comment_doesnt_produce_a_second_answer(github: GitHubFixture) -> None: ana = await github.create_user(login="ana") repo = await github.create_repo(collaborators=[ana], apps=[github.app]) issue = await ana.open_issue({"title": "Flaky test"}, repo=repo) comment = await ana.comment("@my-agent investigate", issue=issue) await expect(issue).to_have_comment_from(github.app) assert comment.delivery await comment.delivery.redeliver() await expect(issue).to_have_comments_from(github.app, count=1, quiet_for="2s")let ana = github.create_user().login("ana").await?;let repo = github .create_repo() .collaborators(vec![&ana as &dyn Handle]) .apps(vec![&github.app()]) .await?;let issue = ana .open_issue(json!({ "title": "Flaky test" })) .repo(&repo) .await?;let comment = ana.comment("@my-agent investigate").issue(&issue).await?;expect(&issue).to_have_comment_from(&github.app()).await?;let delivery = comment.delivery().expect("the fake delivered the comment");delivery.redeliver().await?;expect(&issue) .to_have_comments_from(&github.app(), 1) .quiet_for("2s") .await?;| Platform | Call | What the app gets |
|---|---|---|
| Slack | delivery.resend() | The same event, same event_id, no retry headers |
| GitHub | delivery.redeliver() | The same webhook with the same X-GitHub-Delivery GUID, as from the delivery log |
| Linear | delivery.redeliver() | The same webhook, stamped with a new webhookTimestamp and signed again |
| Notion | delivery.redeliver() | The same event again |
| Resend | delivery.redeliver() | The same webhook with the same svix-id, signed again at its own time |
delivery.redeliver() | The same push with the same message id, with a fresh token |
For Linear, check that the work doesn't start over:
test("a redelivered webhook doesn't duplicate activities", async ({ linear }) => { const ana = await linear.createUser({ name: "Ana" }); const team = await linear.createTeam({ members: [ana] }); const issue = await ana.createIssue({ title: "Anything" }, { team }); const session = await ana.delegate(linear.app, { issue }); await expect(session).toHaveActivity({ type: "thought" }); const before = (await session.activities()).length; await session.delivery!.redeliver(); await expect(issue).toHaveSessionState("complete"); const thoughts = (await session.activities()).filter((a) => a.type === "thought"); expect(thoughts.length).toBeLessThanOrEqual(before);});async def test_a_redelivered_webhook_doesnt_duplicate_activities(linear: LinearFixture) -> None: ana = await linear.create_user(name="Ana") team = await linear.create_team(members=[ana]) issue = await ana.create_issue({"title": "Anything"}, team=team) session = await ana.delegate(linear.app, issue=issue) await expect(session).to_have_activity(type="thought") before = len(await session.activities()) assert session.delivery await session.delivery.redeliver() await expect(issue).to_have_session_state("complete") thoughts = [a for a in await session.activities() if a.type == "thought"] assert len(thoughts) <= beforelet ana = linear.create_user().name("Ana").await?;let team = linear.create_team().members(vec![&ana]).await?;let issue = ana .create_issue(json!({ "title": "Anything" })) .team(&team) .await?;let session = ana.delegate(&linear.app()).issue(&issue).await?;expect(&session) .to_have_activity() .r#type("thought") .await?;// The Rust SDK returns the activities as JSON.let before = session.activities().await?.as_array().map_or(0, Vec::len);let delivery = session.delivery().expect("the fake delivered the webhook");delivery.redeliver().await?;expect(&issue).to_have_session_state("complete").await?;let activities = session.activities().await?;let thoughts = activities .as_array() .into_iter() .flatten() .filter(|a| a["type"] == "thought") .count();assert!(thoughts <= before);Bad signatures and stale timestamps#
An app must refuse a request it can't verify. resend sends the delivery again with a twist, and toBeRejected checks that the app answered it with a 4xx:
test("rejects a bad signature and a stale timestamp", async ({ slack }) => { const ana = await slack.createUser({ name: "Ana" }); const msg = await ana.say("hi", { to: slack.app }); await msg.delivery!.resend({ badSignature: true }); await expect(msg.delivery!).toBeRejected(); await msg.delivery!.resend({ stale: true }); await expect(msg.delivery!).toBeRejected();});async def test_rejects_a_bad_signature_and_a_stale_timestamp(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") msg = await ana.say("hi", to=slack.app) assert msg.delivery await msg.delivery.resend(bad_signature=True) await expect(msg.delivery).to_be_rejected() await msg.delivery.resend(stale=True) await expect(msg.delivery).to_be_rejected()let ana = slack.create_user().name("Ana").await?;let msg = ana.say("hi").to(&slack.app()).await?;let delivery = msg.delivery().expect("the fake delivered the message");delivery.resend().bad_signature(true).await?;expect(&delivery).to_be_rejected().await?;delivery.resend().stale(true).await?;expect(&delivery).to_be_rejected().await?;| Option | What it sends | Platforms |
|---|---|---|
badSignature: true | The same body, signed with a secret that isn't the app's | Slack, GitHub, Linear, Notion, Resend, Google (a token another key signed), Discord (an interaction over HTTP, signed with another Ed25519 key) |
stale: true | Signed correctly, but with a time outside the replay window: 6 minutes old on Slack and Resend, 2 minutes on Linear; on Google, a token that has expired | Slack, Linear, Resend, Google |
wrongAudience: true | Signed correctly, but a token for another endpoint than the app's | |
headers | Extra or replaced headers for this attempt | Slack |
toBeRejected reads the latest forged attempt. It fails when the app answered 2xx, and it tells you to call resend first when no forged attempt was sent. A forged attempt never counts toward toBeAccepted or toBeRetried.
Most SDKs verify signatures for you (Bolt, Probot, @octokit/webhooks, LinearWebhookClient), so these tests mostly catch an app that turned verification off, or one that reads the body before the SDK can check it.
Acknowledging in time#
toBeAccepted checks that the app answered 2xx, and with within, that it did so that fast:
test("a slash command is acknowledged within 3 seconds", async ({ slack }) => { const ana = await slack.createUser({ name: "Ana" }); const channel = await slack.createChannel({ participants: [ana, slack.app] }); const command = await ana.runCommand("/deploy web staging", { channel }); await expect(command).toBeAccepted({ within: "3s" }); await expect(channel).toContainText(/deploying web to staging/i);});async def test_a_slash_command_is_acknowledged_within_3_seconds(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") channel = await slack.create_channel(participants=[ana, slack.app]) command = await ana.run_command("/deploy web staging", channel=channel) await expect(command).to_be_accepted(within="3s") await expect(channel).to_contain_text(re.compile("deploying web to staging", re.I))let ana = slack.create_user().name("Ana").await?;let channel = slack .create_channel() .participants(vec![&ana as &dyn Handle, &slack.app()]) .await?;let command = ana .run_command("/deploy web staging") .channel(&channel) .await?;expect(&command).to_be_accepted().within("3s").await?;expect(&channel) .to_contain_text(Regex::new("(?i)deploying web to staging")?) .await?;It reads the first real attempt. Without within, the platform's ack window is the limit, because an attempt answered after it is timed_out, not acknowledged. The same check works on a modal submission (await modal.submit(…)), a click and a shortcut.
toBeRetried is the other side: the delivery needed more than one attempt, because the app didn't acknowledge the first in time. { times } makes it exact, and an exact check waits for quiet. .not.toBeRetried() is a short way to say the app was fast enough that the platform never retried. Retries you sent yourself with retry() count as attempts too.
Faults#
slack.fault makes the fake Slack Web API misbehave in a way the app has to handle:
test("backs off on rate limits and still answers", async ({ slack }) => { const ana = await slack.createUser({ name: "Ana" }); const fault = await slack.fault({ type: "rate_limit", operation: "chat.postMessage", retryAfter: "1s", times: 1 }); const msg = await ana.say("hi", { to: slack.app }); await expect(msg.thread).toHaveRepliesFrom("my-agent", { count: 1 }); await expect(slack).toHaveReceivedCall("chat.postMessage", { times: 2 }); await fault.undo();});async def test_backs_off_on_rate_limits_and_still_answers(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") fault = await slack.fault(type="rate_limit", operation="chat.postMessage", retry_after="1s", times=1) msg = await ana.say("hi", to=slack.app) await expect(msg.thread).to_have_replies_from("my-agent", count=1) await expect(slack).to_have_received_call("chat.postMessage", times=2) await fault.undo()let ana = slack.create_user().name("Ana").await?;let fault = slack .fault() .r#type("rate_limit") .operation("chat.postMessage") .retry_after("1s") .times(1) .await?;let msg = ana.say("hi").to(&slack.app()).await?;expect(&msg.thread()) .to_have_replies_from("my-agent", 1) .await?;expect(&slack) .to_have_received_call("chat.postMessage") .times(2) .await?;fault.undo().await?;| Fault | Options | What the app sees |
|---|---|---|
rate_limit | operation, retryAfter (default 1 s), times | HTTP 429 with Retry-After. The session stays busy until the app retries, so the checks wait for it (waiting and quiet) |
error | operation (required), error (default internal_error), times | The call fails with that Slack error code, for example msg_too_long |
latency | operation, delay | Each call takes delay longer |
drop_socket | after (default: now) | The Socket Mode connection drops once. A Socket Mode app should reconnect |
Without operation, a fault applies to every Web API method; without times, to every call until it's undone.
test("reconnects after the Socket Mode connection drops", async ({ slack }) => { const ana = await slack.createUser({ name: "Ana" }); await slack.fault({ type: "drop_socket" }); const msg = await ana.say("still there?", { to: slack.app }); await expect(msg.thread).toHaveReplyFrom("my-agent", { timeout: "20s" });});async def test_reconnects_after_the_socket_mode_connection_drops(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") await slack.fault(type="drop_socket") msg = await ana.say("still there?", to=slack.app) await expect(msg.thread).to_have_reply_from("my-agent", timeout="20s")let ana = slack.create_user().name("Ana").await?;slack.fault().r#type("drop_socket").await?;let msg = ana.say("still there?").to(&slack.app()).await?;expect(&msg.thread()) .to_have_reply_from("my-agent") .timeout("20s") .await?;A fault lasts until fault.undo(), the end of an await using scope, or the end of the test's session, whichever comes first.
The uninstall#
When a workspace removes the app, Slack sends app_uninstalled and tokens_revoked. The app should acknowledge both and drop what it stored for the workspace:
test("the uninstall is handled", async ({ slack }) => { const deliveries = await slack.uninstallApp(); for (const delivery of deliveries) await expect(delivery).toBeAccepted();});async def test_the_uninstall_is_handled(slack: SlackFixture) -> None: deliveries = await slack.uninstall_app() for delivery in deliveries: await expect(delivery).to_be_accepted()// The Rust SDK returns the deliveries as JSON: make them handles to check them.let deliveries = SlackDelivery::wrap_vec(slack.ctx(), slack.uninstall_app().await?)?;for delivery in &deliveries { expect(delivery).to_be_accepted().await?;}The app is installed again, with the same tokens, when the test's session closes. Like a fault, the uninstall affects every test running at the same moment, so run it on its own. On GitHub, repo.uninstallApp(github.app) removes the App from one repository and resolves to the installation_repositories delivery.
Fake only#
Live, the real platform delivers to your app and channelstack isn't in the path. An action has no delivery: msg.delivery, comment.delivery and session.delivery are undefined, so nothing is refused and nothing skips on its own. The ! in the examples above throws a TypeError live. A test that must also run live checks first, and skips:
test("survives Slack's retry", async ({ slack, skip }) => { const ana = await slack.createUser({ name: "Ana" }); const msg = await ana.say("@my-agent hello", { to: slack.app }); const delivery = msg.delivery ?? skip("live: the platform delivers to the agent itself"); await delivery.retry({ after: "3s", reason: "http_timeout" }); await expect(msg.thread).toHaveRepliesFrom(slack.app, { count: 1 });});async def test_survives_slacks_retry(slack: SlackFixture) -> None: ana = await slack.create_user(name="Ana") msg = await ana.say("@my-agent hello", to=slack.app) if msg.delivery is None: pytest.skip("live: the platform delivers to the agent itself") await msg.delivery.retry(after="3s", reason="http_timeout") await expect(msg.thread).to_have_replies_from(slack.app, count=1)let ana = slack.create_user().name("Ana").await?;let msg = ana.say("@my-agent hello").to(&slack.app()).await?;// Rust's test harness can't skip at run time: the test says why and passes.let Some(delivery) = msg.delivery() else { eprintln!("skipped: live: the platform delivers to the agent itself"); return Ok(());};delivery.retry().after("3s").reason("http_timeout").await?;expect(&msg.thread()) .to_have_replies_from(&slack.app(), 1) .await?;The rest is refused, and Vitest and pytest skip the test with the reason:
slack.fault()andfault.undo()withaction_requires: a fault needs proxy mode, which live doesn't read the app's calls back yet (#24).slack.uninstallApp(), and reading or resending deliveries (slack.deliveries(),linear.deliveries(),notion.deliveries(),resend.deliveries(),google.deliveries(),discord.deliveries(),delivery.retry(),delivery.resend()), withunsupported_in_live.
The same test runs in full against the fake on every pull request.
GitHub is the exception, because its App delivery log has an API: live, github.deliveries(), toBeAccepted and delivery.redeliver() work on the deliveries it lists, against a real test org, a few seconds after GitHub delivered. A comment's own comment.delivery is still undefined live. See live mode.