# Answers that come later

Source: https://pushary.com/docs/agents/build/answers-later
Last updated: 2026-12-05

> Handle an approval that arrives after your request ends. Create a decision, save its id, resume from a poll or a signed webhook, and treat expiry as no.

`decisions.ask()` waits up to 55 seconds. Many people answer later than that. This page shows how to save the question, pick up the answer when it comes, and never run the action without a yes.

You need this when your code runs in a serverless function, a job that may restart, or any request that cannot wait a minute.

## 1. Create a decision and save its id [#1-create-a-decision-and-save-its-id]

`decisions.create()` returns at once by default.

```ts
const decision = await pushary.decisions.create({
  externalId: user.id,
  question: "Publish this video to your public profile?",
  type: "confirm",
  toolName: "video.publish",
  toolTarget: video.id,
  context: runId,
  idempotencyKey: `${runId}:publish:${video.id}`,
  expiresInSeconds: 3600,
  callbackUrl: "https://yourapp.com/webhooks/pushary",
})

// Save decision.decisionId against this run and its exact proposed action.
// Mark the run as waiting and return from the request.
```

A new decision normally returns `status: "pending"` and `answered: false`. Handle whatever state comes back: a retry can return a decision that is already answered, and a stopped workspace returns `status: "stopped"`. Stopped means no decision was opened: the `decisionId` in that response cannot be polled, and no callback will come. It is never an approval.

### Idempotency keys [#idempotency-keys]

Use the **same idempotency key for retries of one operation**, and a new key for a new operation. Keys are scoped to your site and the recipient. On Partner Launch, Growth and Scale a key lasts as long as the decision is kept, and a retry with the same key and changed content returns HTTP 409 with the code `idempotency_conflict`. On other plans and on the sandbox the window is 24 hours. Do not build the key from the question text alone, and do not reuse it for a changed action. `decisions.ask()` makes a fresh key for each call if you omit one, so it does not deduplicate a later call after your process restarts.

If idempotency storage is unavailable, a create with an idempotency key returns HTTP 503 instead of risking a duplicate decision. Honor `Retry-After` and retry with the same key. A retry after a failed insert can complete the originally reserved id. A reservation alone is never returned as a pending decision.

### REST equivalent [#rest-equivalent]

```bash
curl --fail-with-body https://pushary.com/api/v1/server/decisions \
  -H "Authorization: Bearer $PUSHARY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: run-42-publish-video-7" \
  -d '{
    "externalId": "user-123",
    "question": "Publish this video to your public profile?",
    "type": "confirm",
    "toolName": "video.publish",
    "toolTarget": "video-7",
    "expiresInSeconds": 3600
  }'
```

## 2. Read the answer with the saved id [#2-read-the-answer-with-the-saved-id]

Poll the saved decision id from a worker or scheduled job. `wait` holds the request open for up to that many seconds while the decision is pending.

```ts
const state = await pushary.decisions.get(decisionId, { wait: 30 })

if (state.status === "answered" && state.value === "yes") {
  // Atomically claim your saved workflow step, then execute the saved action.
} else if (state.status === "pending") {
  // Keep the action paused; schedule another read of this same decision ID.
} else {
  // Denied, expired, or cancelled: do not execute the action.
}
```

This example is for `type: "confirm"`. For `select` or `input`, check the returned value against what your workflow accepts. An answer is not permission to run any action.

## 3. Get a webhook when the answer arrives [#3-get-a-webhook-when-the-answer-arrives]

Pass `callbackUrl` on create, as above. Pushary posts this body when the decision is answered:

```json
{
  "correlationId": "the-decision-id",
  "answer": "yes",
  "value": "yes",
  "answeredAt": "2026-09-04T12:00:00Z",
  "context": "run-42"
}
```

`correlationId` is the `decisionId` you saved. `answer` is canonical and `value` is an alias. `context` is optional and goes through secret redaction.

With your full-access key, fetch the site's signing secret once with `pushary.decisions.getWebhookSecret()` and store its `webhookSecret` securely on your server.

```ts
import { parseDecisionCallback, TIMESTAMPED_SIGNATURE_HEADER, verifyTimestampedWebhookSignature } from "@pushary/server"

const webhookSecret = process.env.PUSHARY_WEBHOOK_SECRET
if (!webhookSecret) {
  throw new Error("Set PUSHARY_WEBHOOK_SECRET to the webhookSecret from pushary.decisions.getWebhookSecret()")
}

export async function POST(request: Request) {
  const rawBody = await request.text()
  const signature = request.headers.get(TIMESTAMPED_SIGNATURE_HEADER)
  if (!verifyTimestampedWebhookSignature(rawBody, signature, webhookSecret)) {
    return new Response("invalid signature", { status: 401 })
  }
  const callback = parseDecisionCallback(rawBody)
  if (!callback) return new Response("not a decision", { status: 400 })

  await enqueueRecheck(callback.correlationId)
  return new Response("ok")
}
```

Verify the raw body before you parse it. Do not parse and reserialize the JSON first. `enqueueRecheck` is your own durable job. Every callback carries two signature headers, made with the same secret:

| Header                | Value                                                       |
| --------------------- | ----------------------------------------------------------- |
| `Pushary-Signature`   | `t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">` |
| `X-Pushary-Signature` | Hex HMAC-SHA256 of the raw body alone                       |

Pass `Pushary-Signature` (`TIMESTAMPED_SIGNATURE_HEADER`) to `verifyTimestampedWebhookSignature`, from `@pushary/server` 2.10.0. It refuses the header when the timestamp is more than 300 seconds from now, and refuses any value without a timestamp, so a captured callback cannot be replayed later. Change the window with `{ toleranceSeconds }`. In Python, use `verify_timestamped_webhook_signature` from `pushary` 2.8.0 (`tolerance_seconds`). `X-Pushary-Signature` is still sent for existing integrations, but it has no timestamp: it gives no replay protection. The older `verifyWebhookSignature` (`verify_webhook_signature` in Python) accepts either format in either header, so a captured `X-Pushary-Signature` value placed in `Pushary-Signature` passes it at any time later. If you verify with it, switch to the timestamped verifier. Pushary never sends a callback without a signature: if your site's secret cannot be read, the callback waits and is retried.

Look up `correlationId` in your saved decision-to-operation mapping. Do not trust callback `context` to select a customer or action. Persist a job to recheck the decision before returning a success response. Duplicate delivery must not enqueue the action twice, and a storage failure must return a retryable error.

The [runnable webhook receiver and tests](/blog/verify-agent-approval-webhooks) demonstrate this with a durable local inbox. The worker then retrieves the decision and checks the saved customer, status, type and answer before acting. The receiver itself grants no approval.

Keep polling as a backup for missed callbacks and to discover expiry. A webhook alone does not restart your agent or guarantee the side effect runs once.

## 4. When nobody answers [#4-when-nobody-answers]

The decision stays open for **1 hour by default**. You can set anything from **60 seconds to 24 hours** with `expiresInSeconds`. Expired and cancelled decisions are not approvals.

For a long-lived worker, `decisions.ask()` combines create and polling. Its default wait is **55 seconds**. When it returns `approved: false`, the decision may still be pending. Save its id and poll later, or cancel it with `pushary.decisions.cancel(decisionId)` if you abandon the action. `create({ wait: true })` holds one HTTP request for 30 seconds by default, capped at 55 seconds. Neither wait changes the decision's expiry.

## Next steps [#next-steps]

<Cards>
  <Card title="Test it" description="A sandbox key settles each question as approve, deny or no answer. Then one test on a real phone." href="/docs/agents/embed-testing" />

  <Card title="Partner reference" description="Bound keys, answers from your own app, policy rules, receipts, Slack and disconnect events." href="/docs/agents/embed" />
</Cards>