# Lifecycle and expiry

> The states of a Request, the receipts of a Notification, and an expiry that happens only when you ask for one.

A Request is `pending` until something ends it. Then it is in one of four terminal states, for good. A Notification has no states: it is delivered, and then it is read.

## The states of a Request

- `pending`: waiting for the person.
- `answered`: the person chose an action. The Request carries their Response.
- `expired`: its `expiresAt` passed with no answer.
- `dismissed`: the person declined it without answering, by deleting it from their Inbox.
- `cancelled`: your agent withdrew it, with `DELETE /v1/requests/{id}` or the SDK's `request.cancel()`.

The four terminal states are kept apart because they tell your agent four different things: the person chose, time ran out, the person said no, you no longer need the answer. Only `answered` has a Response.

The first one to happen wins, atomically. If the person taps **File it** in the same instant your agent cancels, the Request ends one way, and the phone and your agent see the same one. A terminal Request never changes again.

Nothing is deleted when a Request ends. `GET /v1/requests/{id}` reads it in whatever state it reached, and each terminal state is also a [webhook event](https://nibify.app/docs/webhook-events): `message.answered`, `message.expired`, `message.dismissed`, `message.cancelled`.

## An outcome is not an error

`expired`, `dismissed` and `cancelled` are outcomes, not failures. `GET /v1/requests/{id}/response` answers `200` in every state, and `ask()` resolves with them instead of throwing. Read `status` and decide what your agent does next.

## No expiry by default

A Request without an `expiresAt` waits for ever, like an unread email. The app shows its age instead: *waiting 3 days*. Set `expiresAt` only when the answer stops being useful after a while.

`research-agent` is putting a report together. Three of its sources need a login, and it asks whether to include them, but it will not hold the report for more than an hour:

TypeScript:

```ts
import { Button, Card, Column, Nibify, Row, Text } from '@nibify/sdk';

const nibify = new Nibify({ apiKey: 'sk_test_…' });

const surface = {
  root: 'root',
  dataModel: {},
  components: [
    Card('root', { child: 'body' }),
    Column('body', { children: ['title', 'text', 'actions'] }),
    Text('title', { text: 'Include paywalled sources?', variant: 'h4' }),
    Text('text', { text: 'Three of the twelve sources need a login.' }),
    Row('actions', { justify: 'end', children: ['button-0', 'button-1'] }),
    Button('button-0', {
      variant: 'primary',
      child: 'button-0-label',
      action: { event: { name: 'include', context: {} } },
    }),
    Text('button-0-label', { text: 'Include them' }),
    Button('button-1', {
      variant: 'default',
      child: 'button-1-label',
      action: { event: { name: 'skip', context: {} } },
    }),
    Text('button-1-label', { text: 'Skip them' }),
  ],
};

const result = await nibify.ask(surface, {
  sender: { name: 'research-agent' },
  notification: {
    title: 'Include paywalled sources?',
    body: 'Three of the twelve sources need a login.',
    quickActions: [
      { name: 'include', label: 'Include them' },
      { name: 'skip', label: 'Skip them' },
    ],
  },
  expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString(),
});

if (result.status === 'expired') {
  // nobody answered in time: go on without it
}
```

With curl, `expiresAt` is an absolute time in ISO 8601 with an offset, such as `2026-10-12T10:00:00Z`, and it must be in the future: a time already past is refused with `422 invalid_request_body`.

Nibify expires a Request within a minute of its `expiresAt`, and at once whenever something reads that Request: once the time has passed, a read never says `pending`. When nobody answered in time, the long poll returns:

```json
{
  "requestId": "msg_…",
  "status": "expired",
  "createdAt": "2026-10-12T09:00:00Z",
  "expiresAt": "2026-10-12T10:00:00Z",
  "environment": "test",
  "deliveredAt": "2026-10-12T09:00:02Z",
  "readAt": null,
  "contentDeletedAt": null,
  "response": null
}
```

The phone shows the card as expired, and an answer given after that is refused. To ask again, send a new Request.

## Waiting is not expiring

Your code waiting for an answer and the Request waiting for the person run on two different clocks. The Wait window is your code's: `?wait=30` on `GET /v1/requests/{id}/response`, or `timeout` in the SDK. When it runs out, the Request is still `pending`. The long poll returns `"status": "pending"`, `ask()` returns `"status": "timeout"`, and you can wait again. Only `expiresAt` makes a Request `expired`. [Wait for the answer](https://nibify.app/docs/wait-for-the-answer) shows how to wait, and how to be called back instead.

## Changing a Request

A Request is never edited after it is sent. To change what you asked, withdraw it and send a new one, or send a new Message in its Thread.

To remind the person without changing anything, nudge it: `POST /v1/requests/{id}/nudge`, or `request.nudge()`, sends the push again for the same Request, in the same state.

Withdrawing and nudging both need a `pending` Request. On a terminal one they answer `409`, with a [code](https://nibify.app/docs/errors-and-rate-limits) that names the state that won: `request_already_answered`, for example.

## Delivered and read

Requests and Notifications both have two receipts. Delivered is when the first of the person's phones confirmed the push arrived; read is when the person first opened the Message. A Request carries them as `deliveredAt` and `readAt`. For a Notification they are the `message.delivered` and `message.read` webhook events, and they are its whole life.

`deliveredAt: null` means not confirmed yet, never not sent: a phone that is switched off has not confirmed anything.

## Next

- [Wait for the answer](https://nibify.app/docs/wait-for-the-answer): Get the answer back by waiting for it with ask() or the long poll, or by a callback when your code cannot wait.
- [Environments](https://nibify.app/docs/environments): Every Project has a test half and a live half, and the prefix of the API key says which one you are in.
