Skip to content
Toolkit

ADR-0097 — A reference the author cleared is a reference removed

Status: Accepted · Date: 2026-08-29 · Track: 007-enforcement, phase 03 close-out

Context

PUT /api/v1/links/{id} decodes its optional fields into pointers, and applies each one only when it is non-nil:

SplashPageID *int64 `json:"splash_page_id"`
...
if input.SplashPageID != nil { existing.SplashPageID = input.SplashPageID }

For a scalar that is right. For a reference it is not, because encoding/json gives a pointer field the same nil for two different requests: the key was absent, or the key was sent as null. The handler cannot tell "say nothing about the splash page" from "this link has no splash page", and it resolves both as the first.

That matters because the link form sends the second. lib/linkForm.ts builds its payload as f.splash_page_id ? Number(f.splash_page_id) : null — clearing the select sends null — and does the same for project_id and domain_id. So the product has a control for detaching each of these three references, the endpoint answers 200 to it, and nothing changes.

It did once work, for one of the three, and for the wrong reason. Before #402, LinkRepository.GetByID did not select splash_page_id, so existing arrived with the field already nil and the UPDATE wrote NULL on every edit — detaching worked as a side effect of the defect that was also silently clearing a link's splash page whenever its author renamed it. #402 widened the select, which was correct, and in doing so removed the only path that detached. Phase 02's live proof caught it: its splash leg detaches the page to show the branch inert on absent data, and that leg went red.

project_id and domain_id were always selected, so for those two the control has never worked at all.

Decision

A key the author sent governs the column; a key they did not send carries it forward. The handler reads the body once, decodes it into the input struct and again into map[string]json.RawMessage, and applies the three reference fields on key presence rather than on the pointer being non-nil:

if sent("splash_page_id") { existing.SplashPageID = input.SplashPageID }

Sent-and-null detaches. Absent carries forward. Sent-with-a-value replaces.

This is the shape pixels_ids already has one cardinality up, chosen deliberately in #402: an empty array detaches every pixel, an absent field carries the stored ids forward. A single reference gets the same rule with null where the empty list is.

All three columns move together. They are one defect in one decode block behind one form, and the form clears all three the same way; fixing the column with the red test and leaving its two siblings would leave the same bug in the same function, which the workstream standard calls a defect in the second place.

Consequences

Clearing the Splash page, Project or Domain select on the link form now takes effect. For splash pages that restores behaviour the product had until #402; for projects and domains it is new, and it is what the form always claimed.

null is now load-bearing on these three keys, which is a compatibility surface: a client that sends "project_id": null as filler — meaning "unchanged" — detaches the project instead. Nothing in this tree does; lib/linkForm.ts is the only writer and it sends null to mean exactly this. An API consumer that wants a field left alone omits it, which is what an absent optional field has always meant everywhere else in this handler.

The rule is scoped to the three reference columns. settings and display_rules keep their own semantics — a blob replaces what was stored, and ADR-0083's password carry-forward lives inside that replacement — and the scalars keep pointer-nil, where null and absent genuinely mean the same thing.

Held by TestLinkHandler_Update_ClearingAReferenceDetachesIt, watched failing on the pre-fix condition: the two carry-forward cases pass and all four detach cases fail, which is the defect exactly. Phase 02's live splash leg is green again, and all thirteen phase-01/02/03 legs pass on one stack.

Source: docs/decisions/0097-a-reference-the-author-cleared-is-a-reference-removed.md

Library