beads/internal/httpapi
Julian Knutsen 2c06c76b51
Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596)
* Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm)

Settings are read-only over v0: `WorkspaceConfig.SetSetting` and `UnsetSetting`
have no wire operation, which leaves the infra-over-http surface able to see that
a workspace is configured and unable to configure it. These are those operations.
The role, its contract and all three legs already exist; this slice wires them.

Spec first, then `make api-gen`, then the handlers.

PUT AND DELETE ON THE KEY'S OWN PATH, and the methods ARE the argument rather
than a preference. The resource has a canonical URI, the caller names it, and the
request carries the value that becomes its whole state — that is what PUT already
means, and the write is idempotent in the strict sense. `POST /v0/beads/memories`
is the operation this is deliberately NOT: that one posts to the COLLECTION
because its key may be derived from the content, so the caller cannot always name
the resource it is creating. Here it always can. The removal is
`DELETE /v0/beads/memories/{key}`'s shape unchanged — one named resource, no body,
no flags — and all three rows share one pattern, differing only in method, which
ServeMux registers together.

THE KEY IS THE PATH'S AND APPEARS NOWHERE IN THE BODY, so `SetSettingRequest`
carries exactly one member. A body spelling the anchor a second time is one
request with two anchors and a question about what to do when they disagree; the
parity test asserts the absence from both sides.

## The redaction doctrine, and what the write half owes it

A KEY WHOSE NAME MARKS IT CREDENTIAL-BEARING IS WRITABLE, resolved from the
facade's actual behavior rather than from the shape of the read. `ValidateSettingWrite`
refuses an empty key, `issue_prefix` in either spelling, and a `status.custom`
that does not parse — and nothing else; `config.IsSecretKey` appears nowhere in
the write path. The CLI's own secret guard is `CheckSecretKeyGitSafety`, which is
gated on `IsYamlOnlyKey` and protects a git-tracked **config.yaml** — a different
plane with a different hazard, a credential in git history — and returns clean for
every key this operation reaches. The role states the asymmetry itself: the reads
are a firewall, the writes are not, and a write discloses nothing. Refusing here
would be a refusal the role does not have, invented by the projection, and it
would leave a workspace's credentials visible as PRESENT and permanently
unconfigurable through this door.

WHAT THE WIRE OWES INSTEAD IS THE RESPONSE. Redaction is caller-independent and
decided on the KEY, and `Setting.value` says in one place that a `redacted: true`
entry withholds a value that may well be stored — so a write answering with both
would make one schema mean two different things depending on which operation
produced it. The write is therefore projected by `wireSetting`, the SAME function
the read is projected by, and the test states that as an equality rather than as
two assertions that could drift: the body of a PUT is byte-for-byte the body of
the GET that follows it. It costs the caller nothing, because the role promises
the stored value equals the value sent for every key this plane accepts, so the
echo carries no information the caller does not already hold.

The removal publishes `key` and nothing else. No `removed` flag — the storage seam
discards the affected-row count on all three legs, so the member would be a value
one of them had to invent — and no `value`, which on the one settings operation
that withholds nothing would publish exactly the credential the read redacts.

## Absent-vs-empty, and the 404 that is not here

REMOVING A KEY NOTHING SET SUCCEEDS. This is where the operation parts company
with the memory delete it otherwise copies: that role reports Found, and `bd recall`
already has an exit-code contract for the miss. This one cannot — an absent key
and a key stored as the empty string are one answer on this plane, the same
conflation `GET /v0/beads/config/{key}` has no 404 for — so the operation states
an intended END STATE, and the same request twice is 200 and then 200. The
document also records what the removal does NOT undo: `status.custom`'s
projection survives the row it came from, on all three implementations
(bd-yby99.33), as does the protected key's write-refused/remove-permitted
asymmetry (bd-yby99.34).

The empty string is a legal VALUE and is stored, not read as a removal: a caller
that meant "remove it" has DELETE, and conflating the two would make one request
mean whichever the handler guessed.

## The one bound that is the write's alone

`config.key` is VARCHAR(255) and the PUT INSERTS into it, so an over-long key is
an error from the column — a 500 for a request the caller could have fixed. The
GET and the DELETE COMPARE the same value and never store it, so a key no column
could hold matches nothing and already has an answer, and refusing it there would
be a refusal the role does not have. That is `releaseExpectedAssignee`'s rule
applied to the other keyed plane, and the asymmetry is asserted in both
directions.

THE ROLE'S 400 CARRIES NO `param`, and that is the depguard rule doing its job
rather than a shortcut. Two of the role's refusals are reachable and they name
different members — the protected key, and a value that does not parse — and
telling them apart takes the role's protected-key VOCABULARY, which this package
cannot hold: `httpapi-transport-boundary` denies internal/workapi from every
non-test file here, precisely so a second copy of a shared rule cannot exist to
drift. `detail` carries the role's own sentence, which names what to send instead;
every refusal this handler owns names its member.

ONE STALE SENTENCE FIXED ON THIS SURFACE. `listSettings` justified redaction with
"this API has no authentication", which stopped being true when #5516 landed the
optional bearer and which #5545 rewrote everywhere except here; settings.go's file
comment carried the same sentence. Both now say what is actually load-bearing — a
configured bearer is a single shared token that decides WHO may call and never
what a caller who is let in may read — which is the statement this whole slice
depends on. `forgetMemory`'s description carries the same staleness and is left
for that surface's own change.

CENSUS +1 EACH, twice over: two spec paths on one existing path item;
SetSettingRequest and RemovedSetting; the document's no-query-parameter list and
its two counts; two route rows on the pattern the read already registers; two
capability tokens in the ContextResponse prose (the only hand edit — Capabilities()
is derived); OpSetSetting and OpUnsetSetting; two operationCodes rows
(getSetting's vocabulary, no code minted). NOTHING new in the role plumbing:
Config.Settings, sourceRoles, roleSourceNames and s.workspaceConfig() already
carry this role, and the hook decorator's WorkspaceConfig accessor deliberately
wraps nothing — the workspace hook vocabulary hands a script an ISSUE, and a
settings write has none to name, so there is no RoleFiresHooks case to add.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Bound the settings value at the edge, and pin PUT's idempotence and the no-leak in bytes

Review found this branch shipping the exact hazard its own key bound was written
to prevent, plus two properties driven live and pinned by nothing.

## `config.value` had no bound, and it is a TEXT column

`settingWriteKey` refuses an over-long KEY with a 400 naming the member, and the
comment on it says why: an over-long key would be "a 500 for a request the caller
could have fixed". The VALUE beside it had no such check and lands in a `TEXT`
column. Measured before the fix: a 100 KiB `PUT` is a generic 500 out of the
column — the one code that tells the caller nothing about how to fix it — on the
same operation, in the same PR.

Bounded at the edge, keyed on a storage constant rather than a literal, refusing
with `param: "value"` before the role is asked.

BYTES, NOT CHARACTERS, which is why this is `types.CheckTextLen` beside
`CheckFieldLen` rather than the same helper with a bigger number: MySQL and Dolt
bound a TEXT column by ENCODED length, so 40000 two-byte characters overflow it
while 65000 ASCII ones do not. A rune-counting bound would have accepted the
former and handed the 500 back. Both directions are pinned — exactly
`MaxTextBytes` is accepted and reaches the role, one byte more is refused, and
the multi-byte case is its own test — and all three mutations (bound removed,
runes instead of bytes, one byte too strict) fail it.

NOT WIDENED, deliberately, and this is the opposite call from the ephemeral
comment column in the commit before it. A comment is a DOCUMENT — a stack trace,
a diff, a transcript — and the two comment planes disagreeing about one was a
bug. A setting is a VALUE: nothing this plane holds is a megabyte of
configuration, so the narrow bound is the honest description of what a settings
row is for rather than a limitation to widen later. The spec now states the
number and the contrast instead of claiming the 1 MiB body cap is the only limit.

## Two properties that were driven live and pinned by nothing

PUT'S IDEMPOTENCE. The method's whole argument is that the same request twice
leaves the same row, and the E2E exercised it while no test asserted it. Now
pinned on both halves: the second response is byte-for-byte the first, and BOTH
calls reach the role — the second half matters because the role performs its
write and its projection unconditionally (a no-op detection would make repairing
a drifted table depend on the row having changed, which is the state that needs
repairing), so this surface must not short-circuit either. Verified with a
compiling short-circuit mutation, which the "want 2" assertion catches.

THE NO-LEAK GREP NOW READS RAW RESPONSE BYTES rather than the decoded map. The
integration test already greps marshaled JSON; the unit test was checking members
it had thought to name, which an extension member, a duplicated key or an echo
inside a `detail` string would all walk past. Demonstrated: a mutation that adds
a `stored_preview` member carrying the credential passes every member assertion
in that test and is caught only by the byte grep — which is also what a client, a
proxy log and an access log actually receive.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Review Sim <ci@beads.test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 19:47:21 -07:00
..
apigen Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
spec Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
auth.go feat(serve): optional bearer auth and a Host allowlist for bd serve (#5516) 2026-08-09 18:05:56 -07:00
auth_test.go feat(serve): optional bearer auth and a Host allowlist for bd serve (#5516) 2026-08-09 18:05:56 -07:00
batch_apply.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
batch_apply_test.go Add issueops.BatchApplier: one plan, one transaction (#5480) 2026-08-09 06:59:34 -07:00
batch_close.go claimNext + batchClose + incremental labels: the three role-backed ops with no wire (ga-g3gg8) (#5510) 2026-08-09 16:02:52 -07:00
batch_close_test.go Make the next serve role a compile error, and check the one role with a positional result (#5539) 2026-08-10 04:34:15 -07:00
batch_create.go feat(httpapi): serve closeIssue over v0 2026-08-07 22:25:38 +00:00
batch_create_test.go feat(httpapi): serve closeIssue over v0 2026-08-07 22:25:38 +00:00
blocking.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
blocking_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
brief_projection_test.go feat(list,ready,httpapi): reach the Brief projection from both front doors (#5586) 2026-08-10 13:05:00 -07:00
claim.go Publish POST /v0/beads/issues/{id}/comments, the wire half of issueops.Commenter (ga-rslox) (#5594) 2026-08-10 18:59:57 -07:00
claim_next.go claimNext + batchClose + incremental labels: the three role-backed ops with no wire (ga-g3gg8) (#5510) 2026-08-09 16:02:52 -07:00
claim_next_test.go claimNext + batchClose + incremental labels: the three role-backed ops with no wire (ga-g3gg8) (#5510) 2026-08-09 16:02:52 -07:00
claim_test.go Publish POST /v0/beads/issues/{id}:release: give a claim back (ga-lzcuv) (#5507) 2026-08-09 14:41:28 -07:00
close.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
close_test.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
comments.go Publish POST /v0/beads/issues/{id}/comments, the wire half of issueops.Commenter (ga-rslox) (#5594) 2026-08-10 18:59:57 -07:00
comments_test.go Publish POST /v0/beads/issues/{id}/comments, the wire half of issueops.Commenter (ga-rslox) (#5594) 2026-08-10 18:59:57 -07:00
context_test.go feat(serve): bd serve skeleton — lifecycle, mode gate, /healthz, /v0/beads/context (bd-60z) 2026-07-31 10:07:14 +00:00
count_test.go Publish GET /v0/beads/issues:count, with the role's whole filter surface (#5508) 2026-08-09 19:39:13 -07:00
create.go Publish POST /v0/beads/issues: the single create, with the whole vocabulary (#5483) 2026-08-09 09:21:56 -07:00
create_test.go Publish POST /v0/beads/issues: the single create, with the whole vocabulary (#5483) 2026-08-09 09:21:56 -07:00
cursor.go feat(issueops): add the Reader role and wire both front doors through it 2026-07-31 18:37:25 +00:00
cycles.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
cycles_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
delete.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
delete_test.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
dependency_edit.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
dependency_edit_test.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
doc.go docs(httpapi): stop the orientation prose enumerating a surface it no longer has 2026-08-08 01:34:33 +00:00
edge_counts_test.go Publish GET /v0/beads/dependencies:count, the wire half of issueops.GraphCounter (#5536) 2026-08-10 02:06:57 -07:00
edges.go Publish GET /v0/beads/dependencies:count, the wire half of issueops.GraphCounter (#5536) 2026-08-10 02:06:57 -07:00
edges_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
events.go feat(httpapi): stream the events journal over SSE (bd-opisf) 2026-08-09 07:55:23 +00:00
events_test.go feat(httpapi): publish the events journal on the v0 surface (bd-opisf) 2026-08-09 06:01:23 +00:00
events_watch.go feat(httpapi): stream the events journal over SSE (bd-opisf) 2026-08-09 07:55:23 +00:00
events_watch_test.go feat(httpapi): stream the events journal over SSE (bd-opisf) 2026-08-09 07:55:23 +00:00
get_issue_test.go feat(show,httpapi): reach BriefDeps from both front doors, with conformance coverage (#5549) 2026-08-10 08:40:32 -07:00
handlers.go refactor(context): one snapshot-to-fields projection for both context surfaces 2026-07-31 22:35:09 +00:00
memories.go Put the memory plane behind memoryops, conformance-tested at three backends (#5387) 2026-08-07 03:57:04 -07:00
memories_test.go feat(httpapi): serve closeIssue over v0 2026-08-07 22:25:38 +00:00
metadata_cas.go Add issueops.MetadataCAS: compare-and-set over one metadata key (#5473) 2026-08-09 04:15:34 -07:00
metadata_cas_test.go Add issueops.MetadataCAS: compare-and-set over one metadata key (#5473) 2026-08-09 04:15:34 -07:00
pinning.go feat(httpapi): publish the events journal on the v0 surface (bd-opisf) 2026-08-09 06:01:23 +00:00
problem.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
problem_test.go feat(httpapi): OpenAPI v0 spec, types-only codegen, and the drift gates (bd-ilb) 2026-07-31 08:37:34 +00:00
project_stamp_test.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
query.go feat(httpapi): publish the events journal on the v0 surface (bd-opisf) 2026-08-09 06:01:23 +00:00
reads.go feat(list,ready,httpapi): reach the Brief projection from both front doors (#5586) 2026-08-10 13:05:00 -07:00
reads_test.go feat(serve): optional bearer auth and a Host allowlist for bd serve (#5516) 2026-08-09 18:05:56 -07:00
ready_count_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
related.go Publish GET /v0/beads/issues/{id}/related, the wire half of issueops.Relations (ga-81p36) (#5540) 2026-08-10 05:23:30 -07:00
related_test.go Publish GET /v0/beads/issues/{id}/related, the wire half of issueops.Relations (ga-81p36) (#5540) 2026-08-10 05:23:30 -07:00
release.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
release_test.go Publish POST /v0/beads/issues/{id}:release: give a claim back (ga-lzcuv) (#5507) 2026-08-09 14:41:28 -07:00
reopen.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
reopen_test.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
roles.go Publish POST /v0/beads/issues/{id}/comments, the wire half of issueops.Commenter (ga-rslox) (#5594) 2026-08-10 18:59:57 -07:00
roles_test.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
routes.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
server.go Publish POST /v0/beads/issues/{id}/comments, the wire half of issueops.Commenter (ga-rslox) (#5594) 2026-08-10 18:59:57 -07:00
server_test.go feat(httpapi): per-request project-id enforcement (Bd-Project-Id header) 2026-08-10 01:26:42 -07:00
settings.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
settings_write_test.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
spec_parity_test.go Publish PUT and DELETE /v0/beads/config/{key}, the write half of issueops.WorkspaceConfig (ga-098zm) (#5596) 2026-08-10 19:47:21 -07:00
stats.go Merge branch 'facade/wave-3' into facade/wave-4 2026-08-06 21:39:05 +00:00
stats_test.go Merge branch 'facade/wave-3' into facade/wave-4 2026-08-06 21:39:05 +00:00
sweep.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
sweep_test.go docs: the ext-api-store documentation tranche — post-#5516 auth sweep, wave doc coherence, role checklist refresh (#5545) 2026-08-10 08:05:07 -07:00
timed_provider_binding_test.go feat(httpapi): publish removeDependency on the v0 surface 2026-08-08 00:19:48 +00:00
tree.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
tree_test.go Trim this series' comments toward the repo's own density 2026-08-06 08:06:59 +00:00
update.go Publish the row-version guard on close, reopen and delete (#5506) 2026-08-09 17:02:53 -07:00
update_test.go claimNext + batchClose + incremental labels: the three role-backed ops with no wire (ga-g3gg8) (#5510) 2026-08-09 16:02:52 -07:00
wire_bijection_test.go feat(httpapi): publish the events journal on the v0 surface (bd-opisf) 2026-08-09 06:01:23 +00:00