Background
The problem started when we noticed an inconsistency between two surfaces that should have rendered identically. The fix turned out to involve three subsystems and a small philosophical question about who owns the canonical view.
Before we go further, a quick reminder: every change in this codebase ships through the same review pipeline. No exceptions.
What we tried first
Our first instinct was the obvious one: add a flag, paper over the difference, move on. That works for a sprint or two. It does not work for a year.
- The flag would have to propagate into three layers.
- The flag's default would surprise anyone reading the code cold.
- The flag would never get removed.
So we went looking for the underlying invariant instead.
The fix
The real fix was structural. We extracted the rendering decision into a single function that both surfaces consume, and removed the duplicated logic. Net change: 28 lines removed, 19 added, one test file replaced.
Pseudocode:
function decide(Context $ctx): Decision
{
if ($ctx->isStaff()) {
return Decision::Show;
}
return $ctx->audience->canSee($ctx->post)
? Decision::Show
: Decision::Hide;
}
Trade-offs
The same call across languages
Pick your stack:
$res = $client->post("https://loginseal.com/api/v1/anonymous-sessions", [
"json" => ["client_id" => $id, "scope" => "anon:ephemeral"],
]);res = requests.post("https://loginseal.com/api/v1/anonymous-sessions",
json={"client_id": id, "scope": "anon:ephemeral"})const res = await fetch(url, {
method: "POST",
body: JSON.stringify({ client_id, scope: "anon:ephemeral" }),
});res, _ := http.Post(url, "application/json", body)Centralising the decision means the function now has both reads. We accept that: the alternative, two slightly-different implementations, was strictly worse.
What is next
Two follow-up items: an audit of every other place we duplicated a decision, and a short post explaining the test we added so it does not regress.
Video walk-through
A two-minute screen capture of the flow: