# Request redaction

Off by default; the `privacy.redact_requests` setting turns it on. [Product description](https://fzkuji.github.io/OpenProgram/docs/models/providers.html#redacting-secrets-in-requests).

## Where it sits

```
agent_loop ─ redacting_stream_fn ─ failover_stream_fn ─ snapshot_stream ─ provider
              redact Context  ──────────────────────────────────────▶
              restore events  ◀──────────────────────────────────────
```

Outermost, outside [failover](https://fzkuji.github.io/OpenProgram/docs/reference/design/providers/reliability/llm-fault-tolerance.html): one vault covers every candidate and the reply is restored once. Code: `openprogram/models/providers/utils/redaction.py`.

## Redacting

| Kind | Shapes | Placeholder |
| --- | --- | --- |
| Whole-token secrets | private key blocks, `sk-ant-…`, `sk-…`, `sk-proj-…`, `sk-svcacct-…`, `ghp_…` family, `github_pat_…`, AWS `AKIA`/`ASIA`, Google `AIza…`, Slack `xox?-…`, JWTs | `[[SECRET_n]]` |
| Assigned values | After `Bearer`; after `password`, `passwd`, `pwd`, `api_key`, `secret`, `secret_key`, `access_token`, `auth_token`, `client_secret` with `:` or `=` | `[[SECRET_n]]` |
| Email addresses | `local@domain.tld` | `[[EMAIL_n]]` |

| Rule | Detail |
| --- | --- |
| Covers | System prompt, user text, assistant text and thinking, tool-call arguments, tool results, tool definitions |
| Skips | Image and media `data`, `thought_signature`, `thinking_signature`, ids, `cache_control` |
| Original `Context` | Never changed; unchanged parts are shared |
| Precision | High-precision shapes only: a false positive breaks the request |
| Numbering | By first appearance, one value to one placeholder, so history redacts identically: prompt caches stay valid and reasoning blocks match |
| Nothing to redact | The request passes through unchanged |
| Other users | `remove_secrets` applies the same shapes with a fixed `[secret removed]` and no vault, for [imported sessions](https://fzkuji.github.io/OpenProgram/docs/reference/design/runtime/session/external-import.html), which must never hold the value |

## Restoring

Each event is copied with real values: `partial`, `text_end` and `thinking_end` content, `toolcall_end.tool_call`, the `done` or `error` message. Tools run with real values and the transcript stores them.

A placeholder can split across deltas (`"[["`, `"SECRET_"`, `"1]]"`). `_DeltaRestorer` keeps, per block, a tail that may be the start of one (`[` within `len("[[SECRET_99999]]")` of the end, no closing `]]`) and prepends it to the next delta. The `*_end` event flushes it as one last delta. A delta's `partial` is cut before such a tail too.

## Lifetime

One vault per provider call, in memory only. The next call builds a new one from the real-valued history.

## Limits

- A secret in free text with no recognisable shape or key name is sent as is.
- A model that rewrites a placeholder, such as `[[SECRET 1]]`, gets that text back unchanged.
- Values only a provider-side tool sees, such as hosted web search, never pass through the `Context`.
