# Protocol API Write Traps
<!--
ref: @protocol/protocol-api-write-traps
tags: [protocol-supply, api, put, patch, publish, impulse, rows, silent-failure, traps, visibility]
triggers: [PATCH returned 200 but nothing changed, PUT vs PATCH on an entry, impulse metadata key will not delete, row update keeps old values, publish returned an empty body, replacing one section clobbered others, edited a fetched entry and the Related footer duplicated, scrubbed a public entry but old versions still leak, appendix file 404, publish landed at the wrong path]
version: 29
updated_at: 2026-12-01T03:48:34.004Z
-->

Write-side semantics of the protocol.supply API that differ from what the verb names suggest, and that fail with a success status. `@protocol/protocol-api` is the endpoint reference; this entry is the set of traps you hit when you write through it. Fetch the one section that matches the symptom (`?section=<slug>`).

**The rule all of these share: a 200 (or `# Updated`) is a receipt for the request, not for the change.** Read back the field you meant to change and compare it; a version bump or an echoed body proves nothing.

| Symptom / situation | Section |
|---|---|
| Updating an entry: which verb, which body shape | `entry-put-vs-patch` |
| Changed `short`, `tags` or `triggers` and it did not stick, or was overwritten | `entry-put-vs-patch` |
| Impulse metadata key will not go away; a nested object lost its siblings | `impulse-patch-is-a-merge-put-is-the-only-way-to-remove-a-key` |
| Updating a registry row returns 200 and the fields are unchanged | `row-patch-takes-flat-fields` |
| Published markdown came back with an empty body | `publish-needs-an-h1` |
| Publish returned 200 but the entry is not where you expected | `publish-path-and-address` |
| "Replace one section" ate neighbouring sections | `section-replace-anchor-on-the-heading` |
| Re-published a fetched entry and Related footers stack up | `fetch-is-not-the-stored-source` |
| Scrubbed a leak from a public entry; is it gone? | `a-scrub-is-not-a-retraction` |
| Attached-file read-back 404s; appendix slug collides; large body rejected | `appendices-and-size-limits` |
| Finding an entry id, version history, pre-render bytes | `finding-ids-and-history` |
| A curly DELETE or POST returned fine but nothing changed | `curly-takes-service-then-path-then-curl-args-flags-before-the-path-are-ignored` |
| You store a key in impulse metadata and it comes back missing or moved | `impulse-metadata-silently-hoists-or-strips-reserved-keys-round-trip-a-key-first` |
| Edited a protocol entry via PATCH and dollar signs in code or prices came out wrong | `a-patch-new_string-containing-is-stored-as-a-single` |
| An impulse list filtered on a nested metadata key returns nothing though rows exist | `the-impulse-list-filter-matches-one-metadata-level-a-nested-key-returns-an-empty-list` |
| Adding a retry to a sync or check that writes to the API | `retry-only-idempotent-verbs-a-retried-post-can-duplicate-the-row` |
| Entry DELETE returned 404 or an error and you must know if the entry is gone | `a-delete-that-returns-404-may-still-have-deleted-confirm-by-lookup` |
| Listing one repo's impulses, or concluding that no impulse exists | `impulsemine-ignores-repoid-and-caps-at-1000-rows-neither-supports-a-negative-claim` |
| A log entry posted to an impulse shows up blank and the request reports success | `an-impulse-log-write-with-the-wrong-field-name-stores-an-empty-note-without-error` |
| A heredoc payload for an impulse filing is written in a command the guard rejects | `an-impulse-guard-that-blocks-a-command-also-blocks-the-heredoc-payload-in-it` |
| A create call returns 502 or times out, and a blind retry might duplicate or lose the row | `a-502-on-an-impulse-create-can-mean-the-row-never-landed-check-before-re-filing` |
| Scheduled row saved with more than one time in its cadence; it never dispatches | `an-impulse-cadence-with-two-times-saves-without-error-and-never-fires` |
| Republishing an appendix or page that bundles several committed files | `republishing-an-appendix-publishes-every-committed-file-not-yet-live-not-only-the-edit` |
| A search or filter with a space in its value returns zero live but works locally | `a-query-string-that-encodes-spaces-as-is-read-as-a-literal-plus-by-the-backend` |
| A page on another origin reads a header that curl shows the API sends | `a-response-header-is-hidden-cross-origin-unless-listed-in-access-control-expose-headers` |
| Designing a naming or version-suffix branch, or a fixture with an underscore slug | `a-slug-cannot-contain-an-underscore-so-a-trailing-_n-always-reads-as-a-version` |
| Search for a literal 'type: x' string returns nothing | `the-search-type-operator-swallows-a-literal-type-x-string-so-search-cannot-find-it` |
| A permission fix on one write route while PUT or publish on it stay unchecked | `a-write-gate-added-to-one-route-leaves-sibling-write-verbs-open` |
| A route test through a connector returns 403 and you read it as the server's scope check | `a-403-from-a-connectors-path-allowlist-is-not-the-servers-authorization-answer` |
| Writing or testing a protocol route that must enforce a token's repo pin | `admin-role-tests-cannot-prove-a-token-pin-check-admins-skip-the-pin-entirely` |
| Counting open impulses with a status=open list filter | `statusopen-on-the-impulse-list-matches-five-statuses-not-the-open-set` |
| Counting live impulses in a repo from the default list | `the-default-impulse-list-is-not-the-live-set-it-returns-terminal-rows-too` |
| Creating many impulses in one call | `post-impulsebulk-updates-existing-impulses-it-does-not-create-them` |
| Adding ?format=json to a list call on the protocol API | `a-list-route-with-a-query-dto-can-reject-formatjson-with-a-400` |
| A POST writes a prefixed id into a column sized for a bare ULID | `a-26-character-id-column-cannot-take-a-27-character-prefixed-id-so-the-insert-never-lands` |
| Auth or sign-in URL or bearer token is built from the request Host header | `a-host-header-is-client-input-build-auth-and-redirect-urls-from-config` |
| Renaming a protocol entry to match a corrected title, when its address must change | `an-entrys-slug-cannot-be-renamed-through-the-api-retitle-it-and-the-old-address-stays` |
| A write with a learning token reports success but the base entry did not change | `a-learning-tokens-edit-returns-200-and-lands-in-a-hidden-shadow-repo-it-can-read` |
| A poll loop calls a rate-limited endpoint once per item on every pass | `a-per-row-probe-that-repeats-every-pass-can-spend-the-shared-token-by-itself` |
| A ledger row was written but the entry still shows the old version | `a-ledger-row-write-leaves-the-entry-version-unchanged-so-version-readers-miss-it` |
| Fetching several protocol entries in one call and counting on all of them coming back | `a-batch-fetch-with-include-can-return-fewer-entries-than-asked-with-excluded-0` |

## Entry PUT vs PATCH

`POST /entry` creates. To update an existing entry there are two different verbs and they do not overlap:

- **`PUT /entry/{id}`** coalesces per field: a field you send is set (including `short`, `summary`, `tags`, `triggers`, metadata); a field you omit is kept. `{"content": "<full markdown>"}` replaces the body; `{"short": "..."}` alone updates only the short. Metadata edits go here, sending the full metadata object, minus any system-managed key (the scrub bookkeeping key is rejected with a 400 and nothing applies). Nested metadata is not coalesced field-by-field.
- **`PATCH /entry/{id}`** is a content string-replace only: `{"old_string": "...", "new_string": "..."}`, top-level, **snake_case**. camelCase (`oldString`) answers "old_string not found" even when the text is present. A multi-occurrence `old_string` is a 400 until you pass `"replace_all": true`. Metadata fields in a PATCH body are silently ignored. The `{"edits": [...]}` batch form was rejected by the validator as of 2026-07-05; send one PATCH per edit. Sending `{"content": ...}` to PATCH is the wrong-tool error.
- PATCH wants the entry **id**, not a `@repo/slug` path (that 404s).
- **Triggers live in `metadata.triggers`.** A PUT with top-level `{"triggers": [...]}` answers 200, bumps nothing and changes nothing (seen 2026-11-17 on @protocol/information-tree v11). Send `{"metadata": <full metadata minus scrub, triggers edited>, "baseVersion": n}` and read `.metadata.triggers` back.
- The five generated fields (`short`, `summary`, `tags`, `triggers`, `trigger_prompt`) are filled by an async pass whose default mode only fills blanks and never overwrites author values. To force re-derivation from content use the admin regeneration, not a PUT. Fields outside those five (`ref`, `type`, `category`, `audience`, `aliases`, ...) persist verbatim.
- The entry's `short` renders as the first body paragraph: do not repeat it as the first line of `content`.
- Impulses and entry rows are different APIs with different semantics. Do not carry any rule across (next two sections).
- `metadata.scrub` is system-managed, not writer-managed: drop it from a PUT body rather than sending back the value you read.
- An internal write that changes content starts an async regeneration of the generated fields, and that pass can land after the write returns. On 2026-11-10 a test that read back straight after `entryService.update` raced it and saw a stale `short` value (the "v2" race). Plant the fixture version with SQL, then call the code under test.

## Impulse PATCH is a merge; PUT is the only way to remove a key

`PATCH /impulse/{id}` merges metadata **one level deep**. Measured 2026-07-27 with a known-answer control: a two-key metadata object sent to an impulse carrying ten keys left all ten and added the new one. (An observation in May 2026 had found PATCH wiping fourteen fields. That was true when written and the API changed under it; a note about someone else's API is a claim with an expiry date nobody writes down.)

| Want | Verb |
|---|---|
| Add or change a key | PATCH |
| Set a key to null | PATCH `{"k": null}`; the key stays, value null |
| Remove a key | PUT `/impulse/{id}` with the full metadata object minus that key |

- Omitting a key in PATCH is a no-op, and explicit `null` does not delete. An engine that believes replace-semantics will "remove" a stale key by omitting it, get `# Updated`, and believe it is gone. Merge and replace agree on add, change and resend-everything, and diverge only on deletion, so nothing in normal use reveals which one you have.
- A **nested object** sent in metadata replaces the stored nested object whole, dropping its siblings. Merge is one level deep, not recursive.
- PUT replaces metadata wholesale and leaves title, status, type, category and assignee untouched (verified 2026-09-11 on a throwaway row, then across 320 rows).
- **Re-fetch immediately before each PUT.** A wholesale PUT built from a dump taken minutes earlier silently reverts anything that changed in between, including the server's own writes. Read-modify-write per row, not per batch.
- Sending the full object on PATCH is correct under both semantics and costs one GET; keep doing it.
- `metadata.type` and `metadata.assignee` are promoted to top-level fields and stripped from metadata in the response. They did not vanish. `metadata.kind` is an ordinary key on impulses since 2026-10-30: it persists and filters with `?metadata.kind=`.
- Building the merged object with shell JSON tools breaks when metadata holds regex strings (`\[y/n\]`, `a|b`): the fetch / `--argjson` / re-PATCH pipeline can PATCH garbage. Round-trip through a real JSON library instead.
- Impulse PATCH also rejected `old_string`/`new_string` patches of the content field in a 2026-11-07 platform session. Send the whole `content` field, then read the impulse back to confirm the change landed.
- Since 2026-11-10 the bulk impulse metadata write takes `unsetMetadata: [keys]` to remove keys, so PUT is no longer the only remover. Use it rather than `null`: `revive: null` is a live retired-revive sentinel, so a null stores null and is not a delete.

## Row PATCH takes flat fields

Registry and charter rows live at `/entry/{entryId}/rows/{rowId}`, a different API from the entry body.

- **PATCH takes the row's fields flat at the top level**: `{"stage": "x", "status": "done"}`. `{"data": {"stage": "x"}}` is silently wrong: it merges a literal nested `data` key into the row, returns 200, **bumps `version`**, and leaves every field you meant to change as it was. Success and failure look identical; only a re-read of the fields tells them apart, never the version.
- **`null` deletes a key** here (`{"data": null}` removed the stray nested key), the opposite of impulse PATCH.
- **There is no PUT** on a row (404). PATCH merges. To REMOVE a stray cell (a nested `data`, or a `baseVersion` sent in the body, which a row PATCH stores as a cell), re-send the whole row via `POST /entry/{id}/rows` `{"rows":[{every cell}]}`: that is a whole-row replace keyed by `key`, so omitted cells are deleted (2026-11-24, zephyr).
- **Create is flat too:** `POST /entry/{id}/rows` with `{"key":"…","status":"…",…}` adds one row (answers `{added:1,rows:[{rowId}]}`). Wrapping the fields in `{"rowKey":…,"data":{…}}` makes `data` a single cell and 400s on the 120-char limit.
- Read: `GET /entry/{id}/rows/{rowId}` returns `{rowId, rowKey, version, data}`. List: `GET /entry/{id}/rows?limit=200` returns `{items: [...]}` with fields under `.data` (default limit 50, so a 56-row table silently returns 50 without `limit`).
- Rendered cells clip at 119 characters; the API returns the full value, so a too-long cell reads fine over the API and is truncated for the human. Measure length before writing.
- Rows are an opt-in capability: the entry must be `type: class` with `metadata.kind = "registry"`, set via PUT.

Three surfaces (entry body, impulse, entry row), three merge semantics. Do not generalise from one to another.
- A row PATCH can fail outright, not just clip on render: on 2026-10-26 a ledger PATCH returned 400 when the `occurrences` cell exceeded 119 characters. Shorten the cell to 119 characters or fewer and re-send; do not retry the same payload, and measure every cell's length before writing rather than reading a 400 as a transient or auth error. A long history belongs in the entry body or an appendix, with the cell holding a short pointer to it.

## Publish needs an H1

`POST /entry/publish` takes `{repoId, content}` where `content` is one markdown string. Start it with a `# ` H1 title line and put metadata in an HTML-comment block directly under it:

```
<H1 line: the title>

<!--
ref: @repo/slug
tags: [...]
triggers: [...]
-->

Body...
```

Observed 2026-06-08: v1 with YAML frontmatter and no H1 stored the metadata but the body came back empty (2517 to 0 chars); v2 with H1 plus comment round-tripped. **The H1 was not the cause** (re-measured 2026-10-31, 7 cases): the trigger is a `short:` line in YAML front-matter with no `title:` line. The parser (`EntryService.parseMarkdown`) never leaves header mode, drops every body line, and answers 201 with `warnings: []` and a 0-char body, with or without an H1 and whatever `?scrub=` says. Front-matter without `short:`, or with both `short:` and `title:`, persists the body. Server issue: foundingstudio/protocol#306. Until it ships, read the body length back after every front-matter publish. Publishing is idempotent on the address, so a bad v1 is fixed by re-publishing, not deleting. Without a `slug`/`ref`, a bulk publish can derive the slug from the body (a 100-character monster): always state the slug.

## Publish path and address

An entry's address is `(repo, path, slug)`. On `POST /entry/publish`, `path` is honoured **only** from the document itself (a `path:` line in frontmatter, or the path inside a `ref:`). Measured 2026-08-15 with one file: `path` in the POST body, or `?path=` on the query string, both landed the entry at root; frontmatter `path:` worked. The wrong-path publish still answers **200 with a real entry id**.

- Compare the `path` in the response with the path you intended and treat a mismatch as failure. A pipeline that uses a path listing as ground truth will treat root-landed content as never published and re-create it forever.
- Dropping the `path:` line on a re-publish creates a **fork** at root while the original stays untouched; read the response `warnings` array every time.
- The publish response echoes your submitted content. Never text-scan the whole response for markers like "error" or "rate limit"; parse the JSON and test fields.
- A repo-wide `PUT /repo/...` ownership check can reject a delegated identity that a raw admin token passes; entry-level writes do not gate on it.
- Slug-addressed PUT/PATCH are exact when `path` is given; an ambiguous slug is a 409 listing the path-qualified refs.

## Section replace: anchor on the heading

Two clobber traps when an engine "replaces only the `## Some Section` section" of an entry:

1. **Anchor on `\n## Heading`, never the first substring.** If a rule elsewhere mentions `## Some Section` in prose, `indexOf("## Some Section")` matches the mention, and the replacement eats the rest of that bullet and every section down to the real heading. This truncated a live charter mid-sentence and swallowed the real heading; the file read fine to a skimmer and grep for the heading returned nothing, so writes landed in a mangled shape for days.
2. **Remove the ambiguity at the source.** Reword the prose mention so the literal heading string occurs exactly once in the entry (say "the Some Section section"). Then even a naive replace is safe.
3. **Audit: `grep -c '^## Some Section'` on the stored source must be exactly 1**, after every write and as a sweep over every entry an engine writes to. A count of 2 breaks the "anchor on the last occurrence" shortcut too: the last one can be a three-line redirect stub left behind by a move, and a character-count assertion passes while the write lands in the stub. If the count is not exactly 1, anchor on a string verified unique in the document, such as a tail phrase of the target section.
- 2026-11-09: a section append doubled its heading. The read-back returned only 103 characters, which exposed it, and the fix was a PATCH to the section. Verify each write by reading the stored section back and checking its length and heading count, not by the write's success response.

## Fetch is not the stored source

A rendered fetch of `@repo/slug` returns render chrome: an H1, the `<!-- ref -->` block, the `short` line, and a server-generated `*Related: ...*` footer that updates with backlinks. Re-publishing or PUTting that output bakes the chrome into the source, and the footer stacks another copy each edit cycle.

- Strip from the first `---` whose next non-blank line starts with `*Related:` to end of file before re-publishing.
- Get the true stored content from `GET /entry/{id}/version` (take the highest version) or `GET /entry/{id}/raw` (pre-scrub bytes; use these for exact `old_string` matching).
- Stored sources for charter-style entries start directly at their first `##`: no H1, no footer.
- Metadata-type header lines and the `short` are generated from fields, not stored in `content`, so PATCH cannot match them.

## A scrub is not a retraction

Public repos are world-readable. Verify visibility the only way that proves it, an unauthenticated fetch: `curl -s -o /dev/null -w "%{http_code}" https://api.protocol.supply/@<repo>/<slug>.md` (200 means world-readable). Do not infer it from the repo name or from your token working.

- **Never put in a public entry:** names of the account holder or customers, publication names or subdomains and their history, database or data-source ids, personal emails in samples, absolute home paths, rates, balances, booking links, anything about a private position or intention. **Do put:** field names, selectors, URL shapes with placeholders, API semantics, lessons stated generically.
- **Until 2026-10-25, `GET /entry/{id}/version` returned every prior body in full, with no auth on a public repo** (now owner-gated; see the update below — the head-side leak through `short`/`summary` remains). Rewriting HEAD changes what the page renders and nothing else: after a "fix", 11 prior versions still carried the leaked material, and reporting it fixed was worse than doing nothing because everyone stopped worrying.
- **Deletion purges history; PATCH does not.** Verified on a disposable probe entry (canary string, PATCH it out, canary survives in `/version`, DELETE the entry, `/version` 404s). Never test destructive behaviour on the artifact you are trying to save.
- Remediation: republish the clean text under a **new slug** (fresh history), delete the leaking entry, repoint references. Generalising the text and deleting the entry are not alternatives; do both.
- Ask "what else can reach this?" before saying fixed: `/version`, caches, search indexes, other endpoints. State the honest limit when disclosing: a scrub stops future reads and does not un-fetch what was pulled or indexed during the exposure window.
- Update 2026-10-25/26, after the platform gated version reads: prior versions of an entry and of a row are now readable only by the owner (and share-link holders and scoped write tokens are refused); owner-only tombstone and hard-delete of a prior version exist, and a stale-body `?version=1` on entry and row GETs is silently ignored and returns current, so it proves nothing about history. The remaining leak after you clean the body is `short` and `summary`: publish copies the opening line of the body into both, while PUT/PATCH/append keep them, so removed text stays readable on head through `/search`, `/fetch(.md)` and `/bootstrap`. After any scrub, clear or rewrite `short` and `summary` too, then re-check those three surfaces. A `/search` hit that merely echoes the query is a false positive. When probing as a non-owner, use a verified non-admin non-member: the ghost-identity header is admin-only, so a probe run by an admin proves nothing.

## Appendices and size limits

Entries carry attached files; the right home for code or payloads that should not be loaded into context.

- `POST /entry/{id}/file` with `{filename, content}` (plain JSON, not multipart); `PUT` and `DELETE /entry/{id}/file/{filename}`; `GET /entry/{id}/files` lists metadata only (content type, filename, hash, size). The OpenAPI body schema for creation is empty, so the shape is not discoverable.
- **Read a file back with the container form, `GET /@repo/<path>/<slug>_/<filename>` (underscore before the slash).** `GET /entry/{id}/file/{filename}` 404s, and looks like "files cannot be read back". Round-trips are byte-exact and the stored hash makes a pull verifiable. Public-repo files read anonymously.
- Filenames must be kebab-case with a single dot before the extension (`^[a-z0-9]+(-[a-z0-9]+)*\.[a-z0-9]+$`).
- Child appendix entries (`POST /entry/appendix`, body `{parentRef, slug, title, short, content, type, ordinal}`) read at `@repo/parent_/slug`. **Appendix slugs are repo-global**: a second `setup` child anywhere in the repo is a 500 unique-constraint error, so namespace them `<parent>-setup`. A file attached to a child appendix is served at the flattened `@repo/<childslug>_/file`; the nested form 404s. Attach files to the top-level entry.
- The ~100 KB body limit (413) applies to **entry content**, not file appendices (a 143 KB JSON body carrying a 138 KB script was accepted). Do not reason from "entries have a size limit" to "the store cannot hold a large file".
- Concurrent `POST /entry` at concurrency 10 returned HTTP 500 on about a quarter of requests (reference-update race): write sequentially.
- Entry path must match `^[a-z0-9]+(-[a-z0-9]+)*(/[a-z0-9]+(-[a-z0-9]+)*)*$` or be empty.
- SVG appendices are exempt from `?max=` and `?trunc=`. A cut SVG is broken XML, so the API serves it whole; budget for the full body.
- Correction: entry bodies of 125,694 and 144,642 characters were published without error on 2026-11-16, so the claim above that entry content is refused (413) at about 100 KB is false. Do not plan around a 100 KB entry cap. When a write is refused, read the actual status and message instead of assuming a size limit.

## Finding ids and history

- `GET /entry/{id}/version` (**singular**; `/versions` 404s) returns the full history as entries sorted by version, descending. There is no `GET /entry/{id}`.
- Finding an entry id: list the repo's entries with `Accept: application/json` (paginated, 100 per page, `?page=N`, sorted by title; no server-side slug filter as of 2026-07) and filter client-side.
- A personal repo's slug is its owner id, immutable. Creating (`POST /entry`, `POST /impulse`) needs the real repo id or slug; a human alias that works for reads can 404 "Repo not found" on create.
- Impulse lifecycle is one field: `status` (or `category`). The old separate `state` field was removed and now 400s. `POST /impulse` has no idempotency, so concurrent writers can create duplicates seconds apart.

## Bulk writes share the token's hourly budget

The rate limit (1,000 requests/hour) is per TOKEN, and a fleet of agents usually shares one token. Pacing a bulk job "just under the limit" therefore starves everyone else. Measured 2026-10-31: a 986-entry PUT rollout paced at 3.8 s (~950/hour) left the rest of the fleet ~50 requests for that hour. Every lane's known-answer reads failed with 429, and the fleet raised `answer-feed-BLIND` because it could not see operator rulings.

- **Budget a bulk job at half the limit or less** (≥ 7.2 s/request for 1,000/hour), or split it across hours.
- **Read `X-RateLimit-Remaining` every ~50 requests and back off** when it falls under ~300. That headroom belongs to every other lane.
- **On a 429, wait out `Retry-After` (else `X-RateLimit-Reset`), then retry once.** If the wait is over ~2 minutes or the retry is also a 429, stop and report `BLIND rate-limited until <reset>`. Never retry immediately (it spends a request the other lanes needed) and never return an empty result. `ticker/bin/lib-ps.sh` implements this (2026-11-16).
- **Signed-out requests have a separate, smaller budget.** Anonymous calls to the API are limited to 300 per hour per IP, apart from the 1,000-per-token limit above. Running a prod browser spec several times back to back exhausts it, and then signed-out checks fail as 'element not found', which reads as a UI regression. Measured 2026-11-07. Have signed-out specs detect a rate-limit response and report 'rate limit hit' before asserting on the page.
- The 1,000-requests-per-hour limit is also spent by a browser test session, not only by a shared token. A magic-link session used for live verification hit the limit during prod checks that loaded the whole app, and had to wait for the hourly reset. Verify rendering against locally served fixtures, keep one prod check at the end of a round, and use a dedicated test session rather than the operator's own cookie.

## curly takes service, then path, then curl args: flags before the path are ignored

Measured 2026-10-19: `curly <service> <path> [curl-args]` is the argument order. A DELETE written with `-X DELETE` before the path had no effect and nothing was deleted, with no error, so the first cleanup pass of 50 fixture rows deleted none. Put curl flags after the path, then re-query to confirm the rows are gone. Verify each row (type, metadata, status, assignee, title) before deleting, because the generating harness kept adding rows.

## Impulse metadata silently hoists or strips reserved keys: round-trip a key first

Measured 2026-10-29 during an impulse-writing audit. `type`, `kind`, `assignee` and `assigned_to` placed in impulse `metadata` are silently hoisted to top-level fields; the only signal is the `X-Impulse-Hoisted-Fields` response header. `metadata.kind` is stripped on impulses, and the entry write path scrubs metadata, so a new metadata key is not safe until proven. **Rule:** round-trip a probe (write, then GET, compare) before building a feature on a metadata key. Also: `POST /impulse` already accepts origin, snoozeUntil, idempotencyKey and more in one call; the gap found was discoverability (no create example in llms.txt), not API capability. The reverse trap (2026-11-15, unknown-key observer): `not_before` sent at the top level of `POST /impulse` is ignored with a 201; the dispatcher reads only `metadata.not_before`, so a one-shot row is offered at once.

## A PATCH new_string containing `$$` is stored as a single `$`

Re-tested 2026-10-18 on a throwaway entry after the earlier `$'` replacement-pattern fix: `PATCH /entry/{id}` with `new_string` containing `$$` still stores `$`, so the server appears to treat `$$` as a regex-replacement escape. The `$'` case is fixed; `$$` is not. Any entry whose text needs a literal `$$` (shell PID `$$`, doubled currency, template code) is silently altered by the edit, and the PATCH still returns success. Fix: after any PATCH on text that contains `$`, read the entry back and diff the exact span; for `$$` content, replace the whole entry body with a full write instead of a string-replace. Related client-side form of the same family: JS `String.replace` expands `$&` and `$'` in the replacement.

## The impulse list filter matches one metadata level; a nested key returns an empty list

2026-10-31: a dedup tool looked up impulses by `metadata.source_block.id` and the list filter returned `[]`, which reads as no matches. The filter only matches top-level metadata keys, so a nested key never matches, even when rows exist. The same limit applies to a gate like `metadata.revive.at`. Fix: store the lookup key flat (`metadata.source_block_id`) alongside any nested object, and query the flat key. Treat an empty result from a nested-key filter as unproven; run a known-answer query on a flat key first. This is the read-side twin of the write rule that metadata merges one level deep.

## Retry only idempotent verbs: a retried POST can duplicate the row

2026-10-17, adding a retry to a sessions-to-impulse sync: a transient connection reset on a POST may already have been applied server-side, so retrying it can create a duplicate row. The retry was added once, and only for GET, PATCH and PUT, whose repeat is harmless; POST was deliberately excluded. If a POST must be retried, look the object up first (by a stable key) and only re-send when it is absent. A retry test must also stub the client: the first draft of the test sent real requests to the live API (a bad id, errors, nothing written), which is a test touching production.
- `curly protocol` create returns Markdown, not JSON. A caller that parses the reply for an id reads the create as failed and retries it. On 2026-11-07 a first create was retried and made a duplicate; check the list for the title before any retry.
- A POST whose response is not JSON may still have created its rows. On 2026-11-10 a create call came back non-JSON, yet all 14 seeded rows existed. Verify by listing the target, not by the response body, and retry only if the list shows nothing was written; a blind retry duplicates the rows.
- An impulse log POST (`POST /impulse/{id}/log`) does not echo the row it wrote: the reply has no `.action`, so a reader that checks `.action` sees null and reads the write as failed. On 2026-11-21 that read made platform post the same blocked row twice on one card, two minutes apart. Confirm with `GET /impulse/{id}/log?tail=1`, never by re-posting.

## A DELETE that returns 404 may still have deleted: confirm by lookup

2026-10-25: a DELETE on a duplicate entry returned 404, yet the entry no longer resolved by name and no longer appeared in search. The status code was not the truth about the state. After any delete (or a delete that errors), confirm with a fetch by id and a search by title, and judge by those. Soft-deleted entries are recoverable through the restore endpoint, so check there before assuming data loss.

**A PATCH-shaped body sent with PUT is a silent 200 that changes nothing.** `PUT /entry/{id}` with `{old_string,new_string}` (no `content`) returned 200 and left the version unchanged (office digest, 2026-11-01). The status code says nothing about whether the write landed: re-fetch and assert the version moved and the new text is present, and match the verb to the body shape (`old_string`/`new_string` = PATCH; `content` + `baseVersion` = PUT).

## /impulse/mine ignores repoId and caps at 1000 rows; neither supports a negative claim

2026-11-02: while triaging 49 impulses filed in the wrong repo, `GET /impulse/mine?repoId=<repo>` silently ignored `repoId` and returned rows from the default repo, so the stranded count looked wrong. `GET /impulse?repoId=<repo>` filters correctly. The same day, `/impulse/mine?limit=1000` returned exactly 1000 rows: the cap was hit, not the end of the list. `/impulse?q=` also ignored its query. Rule: filter by repo with `/impulse?repoId=`. Treat a list response that has exactly the limit's row count as truncated. Never use an empty or capped list as proof that no such impulse exists; page with offset and read `X-Total-Count`.
- Unknown query parameters are dropped without an error, so the call returns the unfiltered list. On 2026-11-10 `GET /impulse/mine?category=` returned all 3,247 rows, and prod ignored `?alerted=` during a census, so its counts were wrong until the deployed filter was confirmed. A returned count equal to the total is the symptom; check it against a known number before trusting a filtered read.

## An impulse log write with the wrong field name stores an empty note without error

2026-11-07: a log line sent to an impulse with `text` as the field name was stored as an empty entry. The log field is `note`, and the request still returned success, so the blank entry looked like a clean write. Read the entry back after each log write, and check the field name against an existing entry before posting a batch.
- 2026-11-19: the same silent loss happens with fields the log does not know. A grade row posted to an impulse carried its evidence as extra structured fields; the server dropped them without an error, so the row landed with no evidence. A second row 30 seconds later carried the evidence in the note text, and the first stays in the log because the log is append-only. Rule: put evidence in the note text, never in ad-hoc fields, and read the row back after posting before calling the write done.

## An impulse guard that blocks a command also blocks the heredoc payload in it

On 2026-11-07 an impulse-filing command built its payload with a heredoc. The impulse guard rejected the whole command, heredoc included, so the payload file was never written and the filing did not happen. The agent re-ran the filing by writing the payload through a wrapper, which also ran the duplicate check. Rule: after a guard refusal, confirm the payload file exists before assuming the filing ran, and file through the wrapper so the duplicate check runs.

## A 502 on an impulse create can mean the row never landed; check before re-filing

2026-11-08: an impulse create returned 502. Re-filing blind risks a duplicate; assuming a 502 means no write risks a silent loss. The session first ran its duplicate check, which showed the impulse absent from a listing of 3,112 rows. A control query for a row known to exist confirmed that the check could see new rows. Only then was the impulse filed again, and no duplicate resulted. Rule: after a 5xx on a create, search for the row you meant to write by title or dedupe key, confirm the search can see a row you know exists, and re-file only when the row is absent. A 5xx does not prove the write was rejected.

## An impulse cadence with two times saves without error and never fires

2026-11-08: a scheduled check was saved with the cadence `daily 12:30 PT, 18:30 PT`. The write returned success. The scheduler accepts one time per cadence and does not validate a cadence on save, so the row never fired: the 12:30 PT run was missed, and the 1pm PT run after it missed too, which ruled out hourly lag. The fix was one row per time, each with a single-time cadence. The scheduler's armed check returns nothing until a row is due, so a new row could only be confirmed by watching it fire. Rule: a success on a schedule write means stored, not valid. Read the row back and treat its first due run as the test.

## Republishing an appendix publishes every committed file not yet live, not only the edit

On 2026-11-09 a republish meant to ship one dropped file also pushed five committed files that were not yet published, bringing the appendix up to main. The operator-side result was accepted, but the publish was broader than the edit. Before republishing, list what is committed but unpublished and confirm each file is meant to go live. A one-file change is not a one-file publish.

## A query string that encodes spaces as + is read as a literal plus by the backend

2026-11-10: a tag filter with a space in its value returned 0 results on production. The client serialised spaces as `+`, and the backend reads `+` as a literal plus on purpose, because some values contain one (a plus-addressed email). Local fixtures passed because they did not go through the client serialiser; only the production pass exposed it. Fix: encode spaces as %20 in the shared request client and leave the backend's parsing alone. Check any filter with a space against the real route, not only a fixture.

## A response header is hidden cross-origin unless listed in Access-Control-Expose-Headers

2026-11-10, an assignee roster. The API sent a new roster header, but its cross-origin settings listed only X-Total-Count as exposed. A browser on another origin hides any response header that is not listed there, so the UI would have shown neither the note nor the marks on production. It was caught before release by reading the cross-origin path. curl and same-origin tests see every header, so they would not have caught it. Rule: when a page on another origin reads a new response header, add it to Access-Control-Expose-Headers and verify with a cross-origin request.

## A slug cannot contain an underscore, so a trailing _N always reads as a version

The entry slug constraint forbids underscores in slugs, locally and in prod. A stored slug therefore cannot end in an underscore and a number, so a parent_/child_N address always reads N as a version and never as part of a literal name. A test fixture that writes a literal child_N slug is refused by the constraint, which means the literal-name-wins case cannot be built as a fixture. Check the constraint before designing a naming branch or an ambiguity test. Measured: the fixture insert was rejected by the check constraint.

## The search type: operator swallows a literal 'type: x' string, so search cannot find it

A search for the literal text 'type: impulse' returned nothing usable, because the search syntax reads 'type:' as its own operator and does not match the literal. The record existed and was found with a read-only query against the store instead. Rule: do not use search operators to find a literal key-value string; query by the field or fetch by id. Measured: the literal search returned no usable match, and the same record came back from a direct read-only query.

## A write gate added to one route leaves sibling write verbs open

A restore endpoint was gated on repo write access, but the protocol's own checklist for the fix said every write goes through the write gate. Checking the sibling verbs showed that PUT on the entry and the publish route had no check at the controller, and the service layer added none. A fix scoped to restore alone would have left both open. A probe with a non-owner credential confirmed the gap, and the gate was then extended to all four entry write routes. When a guard is missing on one verb, list the other verbs on the same resource and probe each with a credential that must be refused before calling the class fixed.

## A 403 from a connector's path allowlist is not the server's authorization answer

2026-11-10, a write test through the protocol MCP connector got a 403 on the token route. The connector refused the call on its own path allowlist before any request reached the server, so the 403 was not an authorization decision. The scope-level 403 . A 403 from a front-end layer proves nothing about the server's check. Before reading a refusal as the server's answer, confirm the request arrived, or test the controller directly.

## Admin-role tests cannot prove a token-pin check: admins skip the pin entirely

2026-11-10, reading the token-pin path showed that admins skip the pin check entirely. A route tested only as an admin passes whether or not the pin is enforced, so the test proves nothing about pins. The fix needs an explicit pin assertion on every route, exercised with a pinned non-admin token. Assert the refusal explicitly for each route instead of inferring it from a green admin run.

## status=open on the impulse list matches five statuses, not the open set

2026-11-10, census of open legacy escalations. The legacy `status=open` filter matched new, captured, parked, active and waiting_external, so it returned 26 rows where about 11 were expected. Before counting, list each status on its own and read the total per status. Any figure built from one status=open call is a sum over five buckets, not the open set. Name the statuses in every count you report.

## The default impulse list is not the live set: it returns terminal rows too

2026-11-10, stranded-impulse check. The session took the default impulse list for one repo as a live set and read 50 live rows. The list returned 51 rows and all were terminal, so every live-status query returned 0. The count matched the other repo, so the query path was fine and the premise was the error. Count live work by querying each status and reading X-Total-Count per status. Treat an unfiltered list as history, not as the current queue, before reporting a backlog.

## POST /impulse/bulk updates existing impulses; it does not create them

2026-11-10, cold-agent fixture seeding. The session tried the bulk route to create impulse rows. `/impulse/bulk` is the bulk-update route, so it did not create them, and the rows were then created one at a time. Check what a bulk route does from its handler or a dry call before assuming it creates rows. Confirm the row count after any bulk call.
- 2026-11-07: three impulses filed in the wrong repo were moved with the bulk update route. It logged `bulk_update` and answered "3 changed", but a read-back showed every row still in the old repo. A single-row `PATCH /impulse/{id}` with the new `repoId` moved each row, and the read-back confirmed it. The bulk answer counts rows it accepted, not rows it wrote. After any bulk write, read each row back through a different path (single GET) and compare the changed field; for a `repoId` move use per-row PATCH.

## A list route with a query DTO can reject ?format=json with a 400

2026-11-10, triage-desk build. The triage list routes rejected `?format=json` with HTTP 400, so the list call returned a validation error instead of rows. Other list routes that take a query DTO can reject the same parameter. Before adding `?format=json` to a list call, check the route's query DTO, or send the call without it and read the default body. A 400 on a list route is a validation message, not an empty result.

## A 26-character ID column cannot take a 27-character prefixed ID, so the insert never lands

2026-11-10 (#339): POST /user-tag could never insert. Its ID columns were VARCHAR(26), the bare ULID length, but the IDs the API generates are 27 characters once the type prefix is added, so every insert failed on the length constraint. When a route fails on insert with no visible error, compare the length the code generates with each target column.

## A Host header is client input: build auth and redirect URLs from config

Measured 2026-11-10 on the protocol backend's /mcp path: the 401 sign-in URL and the forwarding of the bearer token were derived from the request's Host header. A probe through a port-forward with `Host: evil.example` still pointed the 401 at the production API origin, so a caller who sends a forged Host chooses where the token goes. The rule: take the public origin from configuration, never from `Host` or any request-derived value. A probe must send a forged Host to prove the fix, because a correct response to a normal Host proves nothing.

## An entry's slug cannot be renamed through the API; retitle it and the old address stays

On 2026-11-14 a session corrected the title of an entry and tried to rename its address to match. The server refused the address rename. The title and body changed, but the entry kept its old slug, which existing links still use. Treat the slug as fixed once published. Put new wording in the title and body, and point readers at the old address. Plan links around the slug, not the title.

## A learning token's edit returns 200 and lands in a hidden shadow repo it can read

On 2026-11-14 a live proof minted a learning token with write:"shadow" and edited a base entry with it. The edit returned 200, but the change went to the token's hidden shadow repo as a new version, and the token could read both of its writes by ref through search, find and ls. Revoking the token made it return 403, and the owner's view of the base entry was unchanged. Treat a learning-token write as a shadow write, and verify the base entry with the owner's token before counting a change as landed.

## A per-row probe that repeats every pass can spend the shared token by itself

A dispatch pipe fetched the impulse record for every already-seen row with an empty cycle key, on every 30-minute pass. That was about 1,050 calls an hour, enough to exhaust the shared token and draw a 429 for every caller. The first suspect, a changed test, was wrong; the call count pointed at the probe. Fix: cache each probe result per id with a 30-minute TTL, and do not cache failures, or a transient error sticks for the full window. Measure calls per hour from the call log before attributing a 429 to one caller.

## A ledger row write leaves the entry version unchanged, so version readers miss it

On 2026-11-13 a session measured a ledger kept as rows under a protocol entry: after row writes, the entry still rendered the same version with the same updated_at as before. Row writes do not bump the entry's version, so any reader that checks the entry version, or caches by it, treats the ledger as unchanged. Rule: after a row write, read the rows back and judge freshness from the rows themselves, not from the entry header, and do not key a cache or a change check on the entry version when the content lives in rows.

## A batch fetch with ?include= can return fewer entries than asked, with excluded: 0

2026-11-19, a grader reading goal sections from several protocol entries: a batch `fetch?include=` asked for 3 entries and returned 1, with `excluded: 0`, so the response gave no sign anything was missing. The grader switched to reading each entry separately. Rule: after a batch fetch, compare the returned entries to the requested list; a missing one is not evidence the entry does not exist. A grader that cannot read an entry grades that item `unknown`, never `gap` and never `met`.

## Impulse log POST echoes the whole impulse; create with prompt drops the body

**Symptom:** a 1.6 KB `POST /impulse/{id}/log` returns ~59 KB (the full impulse, every prior log row), flooding context. Separately, `POST /impulse` with the body under `prompt` instead of `content` answers 200 and stores an empty body.
**Fix:** send the log POST response to a file and confirm with a bounded read (`/log?tail=1`). Put the body in `content` and read back every create.

## `?section=` does not prefix-match, and its miss list is cut off

**Symptom:** `?section=topic` misses a heading written `## Topic — gloss`, and the 404 lists valid slugs only up to `…N more`, so the heading you need may not be shown.
**Fix:** for a full inventory, fetch `?format=json` to a file and grep `^## ` in `.content`, then request the exact slug.

## Impulse assignee: null is dropped; "" unassigns

`PATCH /impulse/{id}` with `{"assignee": null}` answers `# Updated` and leaves the assignee as it was. `{"assignee": ""}` clears it. Read back `.assignee` after the write. Seen 2026-12-01 while taking two fixture rows off the dispatch path.

---

*Related: `@protocol/shell-and-runtime-traps` · `@protocol/capture` · `@protocol/ask-lifecycle` · `@protocol/example-impulse` · `@protocol/onboarding`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*