Skip to content

docs: ADRs 0248-0250 + acceptance plan for the SDK server enablers - #822

Merged
samuv merged 5 commits into
mainfrom
sdk/00-decision-record
Aug 31, 2026
Merged

samuv merged 5 commits into
mainfrom
sdk/00-decision-record

Conversation

@samuv

@samuv samuv commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

What

The frozen decision record and verification contract for the Go-side server enablers that the TypeScript SDK (#821) is built on. Docs only — no production code. The nine implementation PRs stack on top of this one.

Three ADRs and one acceptance plan (9 scenarios / 60 numbered ACs with verify: proofs).

Changed since review

ADRs renumbered 0244–0246 → 0248–0250. main landed its own 0244 (full request + manual compaction), 0245 (safe build diagnostics), and 0246 (goccy YAML parser) while this stack was open, so the SDK three collided with real records. Second move for these — the first was the off-by-one @jhrozek caught in the index.

Review fixes:

  • The blocking index bug: entries read 0243/0244/0245 while linking to 0244-/0245-/0246-, and the "0243" collided with the existing ADR 0243 (JSONL durability). The bodies were correct throughout; only the index was wrong.
  • ADR 0248 decision 7 now pins the gRPC error carrier to google.rpc.ErrorInfo and makes the lower_snake_case-over-AIP-193 casing decision explicit, rather than leaving it for the parity gate to discover.
  • ADR 0249 decision 1 now records the crypto/rand minting that shipped, plus the alternative that was weighed (host label + session-minted counter) and why the random id won.
  • AC2.4 narrowed to what the guard actually covers — the harness-authored halves — with the reason detail/error stay unscrubbed.

One decision the ADRs now record that the review didn't ask for: ADR 0248 originally proposed the RPC name GetServerInfo. main's ADR 0245 took that name for build identity behind a privacy boundary forbidding capabilities and configuration in the response, so Scenario 1 is now GetCompatibilityInfo / GET /v1/compatibility, and build_version is dropped in favour of 0245's build_id. Rationale is in ADR 0248 decision 1 and on #823.

Why this is a separate PR

#821 spans four milestones and mutates the proto contract, the engine public API, the HTTP error contract, and the daemon lifecycle surface. Splitting by contract surface rather than by milestone puts every invariant risk on the Go side first — where task api:check, the layering DAG, the conformance suites, and docs/lint actually have teeth — and lets the SDK be written against a merged, proven server.

These nine decisions get frozen on merge, so they deserve a review of their own rather than being buried inside a code PR.

The decisions

ADR 0248 — compatibility discovery and the typed error contract. GetCompatibilityInfo answers "what may I do with this server?" without a probe session. It keeps capabilities (what the operator enabled) separate from features (what the build implements) — conflating them makes a --no-bash deployment look like version skew. Features and error codes are open strings, not proto enums, so adding one is a minor SDK release rather than a wire-compat event: the discipline the event taxonomy already settled for EvNoProgress/StopBudget.

ADR 0249 — durable run identity. A host-minted, colon-free run_id fed into the existing RunRequest.AskIDDiscriminator, whose ADR 0044 contract is already written in terms of a run id — "A durable host (e.g. a downstream consumer) passes its own RunID" — and which nothing in internal/ or cmd/ supplies today. It's persisted on the snapshot so an awaiting resume is genuinely the same run, and stamped on Event at the relay chokepoint Actor-style, so the loop stays storage-agnostic.

An empty RunID is a meaning — session-scoped, not run-scoped — enforced by a closed set that today holds exactly the three schedule.* types, which appendEvent receives from the scheduler outside any loop. This is why attach() and activity() must be separate operations.

ADR 0250 — durable cursors and the watch transport. port.CursorEventLog is additive; port.EventLog is untouched. The Redis event log moves LIST → Stream: a LIST cannot express a durable cross-process follow, and positional cursors become wrong data the day anyone adds retention. Gap markers are log-record envelope variants surfaced as a delivery phase, never a session.Event — so the event union and the kind-parity gate are untouched.

⚠️ This ADR deliberately ships a weaker guarantee than #821 asked for. #821 says a durable append failure "terminates connected watchers with ActivityGapError". Cross-process, that isn't achievable: a failed append consumes no position, so it leaves nothing for a watcher on another replica to observe. The ADR states the three-tier reality (best-effort durable gap marker / guaranteed process-local termination / stated undetectable residual) rather than an absolute a Redis outage falsifies. #821 explicitly asks for this: "stop and tighten the ADR wording rather than shipping a false guarantee."

Delivery shape

A linear stack of nine PRs — linear because six of the nine units edit contracts/proto/mecatl/v1/harness.proto, five edit internal/adapter/server/http.go, and contracts/gen/ is committed generated output. Parallel branches would churn the same generated files; a stack serializes those edits for free. Only two real dependencies exist (Scenario 4 → 5, Scenarios 4+6 → 7); the rest of the ordering is contention management.

PR Scenario
01 GetCompatibilityInfo + feature registry + --deployment-id
02 RFC 9457 problem details + error-code registry
03 Exact-origin CORS
04 Durable run_id
05 expected_run_id + strict steer
06 port.CursorEventLog + four backends + Redis migration
07 WatchSessionEvents
08 UDS / HTTP-disable / ready-file / lifetime pipe
09 Listener-scoped mcp_servers

Two things reviewers should push on

  1. The Redis LIST → Stream migration (ADR 0250) is the most expensive call here and I'd like a second opinion, especially from anyone who's operated Redis Streams at size. The blocker I expected — miniredis lacking stream support — doesn't exist: v2.38.0 implements XADD/XLEN/XRANGE/XREAD including the blocking path, so offline conformance covers it.
  2. mcp_servers is listener-scoped and server-enforced (ADR 0248 / Scenario 9), not the SDK-side check Prototype @stacklok/mecatl-sdk TypeScript SDK #821 specifies. mcp.ValidateClientURL is a scheme allowlist that permits http://127.0.0.1:* — correct for ACP, whose client is local, but on a network-exposed API a client-side check isn't enforcement. Scoping it to the UDS listener (per ADR 0237) puts the boundary where it can't be bypassed.

Verification

  • go test ./docs/lint/... — green. It caught one real defect (a citation that wasn't repo-root-relative), now fixed.
  • No production code, so task test is unaffected.
  • docs/lint green (ADR number uniqueness included) and matlatl check . --strict green — 271 documents, 2369 references, 0 broken.
  • llms.txt regenerated. Note task docs:llms's > llms.txt redirect truncates the file before go run fails, so a failed invocation silently empties it — worth knowing independently of this PR.

Refs #821, #761.

🤖 Generated with Claude Code

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the three new ADRs and the acceptance plan against AGENTS.md's invariants and the existing proto/port conventions. Flagging three items here — one blocking (a numbering bug), two worth deciding before implementation starts.

Comment thread docs/adr/README.md Resolved
Comment thread docs/adr/0249-durable-run-identity.md Resolved
samuv added a commit that referenced this pull request Aug 31, 2026
Four fixes from the #822 review.

THE BLOCKING ONE: the ADR index numbered the three new entries 0243/0244/0245
while linking to files 0244-/0245-/0246-, and its "0243" collided with the
already-existing ADR 0243 (local JSONL durability boundaries). The ADR bodies
were numbered correctly and cross-referenced each other correctly throughout;
only the index was wrong.

ADR 0244 decision 7 said gRPC "returns the same string in a status detail"
without saying what the detail is. It is now pinned to google.rpc.ErrorInfo,
with the two reasons that made it the right carrier: it authors no new proto in
contracts/proto (harness.proto is touched by most of the stack, and each extra
edit is another conflict surface), and AIP-193's reason+domain+metadata shape is
decodable by generic gRPC tooling with no mecatl-specific knowledge.

That surfaced a casing decision the ADR was leaving for the parity gate to
discover: AIP-193 conventionally spells reason in UPPER_SNAKE_CASE, but AC2.2
requires the IDENTICAL string on both transports. Parity wins, lower_snake_case
on both sides, and the departure from the convention is now stated up front
rather than found as a test failure by whoever implements the second transport.

ADR 0245 decision 1 validated the run id only as colon-free, which moved ADR
0044's CWE-863 replay guard from internally-guaranteed (an atomic r<serial>
counter, uniqueness impossible to violate by construction) to caller-trusted.
The decision now records what was actually built: 128 bits of crypto/rand at one
call site. It also records the alternative that was weighed — a host-supplied
label plus a session-minted monotonic counter — and why the random id is
stronger: a monotonic counter has to survive restarts and replicas to stay
monotonic, which moves the burden onto a persistence scheme that can itself be
got wrong, while 128 random bits collide negligibly however the process is
restarted or replicated.

AC2.4 claimed no problem body carries a secret, but the guard walks only the
harness-authored halves (code, title, type). detail/error carry the server's own
err.Error(), bounded and UTF-8-repaired but not content-scrubbed. The AC now
says that, and says why scrubbing is the wrong control there: it would corrupt
the diagnostic without being a real defence, since the obligation belongs with
the backend that raises the error and knows which value is sensitive.

Gates: docs/lint green; matlatl check --strict green (265 documents, 2320
references, 0 broken).

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
samuv added a commit that referenced this pull request Aug 31, 2026
Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
samuv added 4 commits August 31, 2026 10:19
Design record for the Go-side server contracts the TypeScript SDK (#821)
is built on. No production code yet — this is the frozen decision record
and the verification contract the nine-PR stack is measured against.

ADR 0243 — SDK compatibility discovery and the typed error contract.
GetServerInfo answers "what is this server?" without a probe session, and
keeps `capabilities` (what the operator enabled) separate from `features`
(what the build implements): conflating them makes a --no-bash deployment
look like version skew. Features and error codes are open strings, not
proto enums, so a new one is a minor SDK release rather than a wire-compat
event — the discipline the event taxonomy already settled for
EvNoProgress/StopBudget.

ADR 0244 — Durable run identity. A host-minted, colon-free run id fed into
the existing RunRequest.AskIDDiscriminator, whose ADR 0044 contract is
already written in terms of a run id ("A durable host passes its own
RunID") and which nothing supplies today. Persisted on the snapshot so an
awaiting resume is the SAME run; stamped on Event at the relay chokepoint,
Actor-style, so the loop stays storage-agnostic. An empty RunID is a
meaning — session-scoped, not run-scoped — enforced by a closed set that
today holds exactly the three schedule.* types.

ADR 0245 — Durable cursors and the watch transport. port.CursorEventLog is
additive; the Redis event log moves LIST -> Stream because a LIST cannot
express a durable cross-process follow and positional cursors become wrong
data the day anyone adds retention. Gap markers are log-record envelope
variants surfaced as a delivery phase, never a session.Event, so the event
union and kind-parity gate are untouched. The append-gap guarantee is
deliberately weaker than #821 asked for: cross-process gap detection is not
achievable, and the ADR states the residual rather than shipping an
absolute a Redis outage falsifies.

The acceptance plan carries 9 scenarios / 60 numbered ACs with verify:
proofs, delivered as a linear stack of nine PRs — linear because six units
edit harness.proto and five edit http.go, and contracts/gen is committed.

Refs #821, #761.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
…s plan

llms.txt is generated and goes stale the instant docs change; the CI docs
job caught it on this PR. Regenerated with `task docs:llms`.

Verified with the strict gate: 264 documents, 2312 references — 0 broken
links, 0 broken anchors, 0 ambiguous, 0 orphans, 0 unreachable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
main landed ADR 0243 (Local JSONL durability boundaries, #786) while this
branch was in flight, so both claimed 0243. ADR numbering is monotonic and
records are frozen on merge; the landed one keeps the number and the
unmerged one moves. docs/lint's TestRealADRNumberUniqueness is the gate that
catches this, and it is why the collision surfaced as a test failure rather
than as two files quietly sharing an identity.

Renumbered highest-first so 0244 -> 0245 could not collide with the
0243 -> 0244 it was about to vacate:

  0243 SDK compatibility and error contract -> 0244
  0244 Durable run identity                 -> 0245
  0245 Durable cursors and watch            -> 0246

Also updates every cross-reference and the acceptance plan's verify: test
names (TestADR_0243_* -> TestADR_0244_*, and so on), which ac-trace resolves
against the tree.

llms.txt regenerated; it conflicted because main regenerated it too. Per
AGENTS.md a generated file is never hand-merged — this took main's side and
re-ran task docs:llms.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
Corrects decision 4 before the record freezes. The ADR is Status: Proposed
and unmerged, which is exactly the window this kind of finding is supposed
to land in.

Decision 4 said stamp Event.RunID "at the single relay chokepoint,
Actor-style". Contact with the code says there is no such chokepoint:

  - Service.relayEvent has 4 callers but takes session.Event BY VALUE, so it
    cannot mutate the copy its caller hands to toProto.
  - Five further recorder.Observe sites bypass relayEvent entirely (the gRPC
    drain-to-discard path, three HTTP paths, schedule.go).
  - Actor works only because it is LOG-ONLY: persistence genuinely has one
    chokepoint in appendEvent. RunID must also reach the client wire — the
    SDK resolves a started run on the first run-ID-bearing event — and the
    wire path never passes through appendEvent.

So "stamp at the relay" means stamping at ~9 sites by hand: the per-surface
drift class AGENTS.md records as having already fired three times.

The semantic argument for the Actor precedent does not transfer either.
Actor stays out of the loop because the loop "knows nothing about
principals" — a real domain boundary. A run id is not external metadata: the
run is the loop's own concept, and the loop already labels every event it
emits with run-scoped identity (ev.Seq = r.seq.Add(1)) at exactly the two
sites in question. RunID belongs on the next line.

Decision 2 changes with it: the id now reaches the engine as a new
RunRequest.RunID, and the engine derives the ask discriminator from it when
AskIDDiscriminator is empty. The host still sets ONE field, and ADR 0044's
"a durable host passes its own RunID" is now satisfied literally rather than
by coincidence. AskIDDiscriminator is retained and gains no second writer, so
a future need for a discriminator that is NOT the run id can still set it
explicitly — the derivation is a default, not a constraint.

The cost is recorded honestly in Consequences: engine/agent now carries an
identifier it did not have, and the accepted bound is narrow — the loop may
stamp the id and derive the discriminator from it, and nothing else. It must
never branch on it, log it, send it to a provider, or reach storage with it.

Acceptance plan AC4.2/AC4.3 are updated to match; AC4.3 inverts from "the
loop never stamps RunID" to "every emitted event carries it, stamped at
Run.emit/emitOrAbort".

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
samuv added a commit that referenced this pull request Aug 31, 2026
Four fixes from the #822 review, plus a renumber forced by main.

RENUMBERED 0244-0246 -> 0248-0250. main landed its own 0244 (full request +
manual compaction), 0245 (safe build diagnostics), 0246 (goccy YAML parser)
while this stack was open, so the SDK ADRs collided with three real records.
0248-0250 are the next free numbers. This is the second time these three have
moved; the first was the off-by-one below.

THE BLOCKING REVIEW ITEM: the ADR index numbered the three new entries
0243/0244/0245 while linking to files 0244-/0245-/0246-, and its "0243" collided
with the already-existing ADR 0243 (local JSONL durability boundaries). The ADR
bodies were numbered correctly and cross-referenced each other correctly
throughout; only the index was wrong.

ADR 0248 (was 0244) decision 7 said gRPC "returns the same string in a status
detail" without saying what the detail is. It is now pinned to
google.rpc.ErrorInfo, with the two reasons that made it the right carrier: it
authors no new proto in contracts/proto (harness.proto is touched by most of the
stack, and each extra edit is another conflict surface), and AIP-193's
reason+domain+metadata shape is decodable by generic gRPC tooling with no
mecatl-specific knowledge.

That surfaced a casing decision the ADR was leaving for the parity gate to
discover: AIP-193 conventionally spells reason in UPPER_SNAKE_CASE, but AC2.2
requires the IDENTICAL string on both transports. Parity wins, lower_snake_case
on both sides, and the departure from the convention is now stated up front
rather than found as a test failure by whoever implements the second transport.

ADR 0249 (was 0245) decision 1 validated the run id only as colon-free, which
moved ADR 0044's CWE-863 replay guard from internally-guaranteed (an atomic
r<serial> counter, uniqueness impossible to violate by construction) to
caller-trusted. The decision now records what was actually built: 128 bits of
crypto/rand at one call site. It also records the alternative that was weighed —
a host-supplied label plus a session-minted monotonic counter — and why the
random id is stronger: a monotonic counter has to survive restarts and replicas
to stay monotonic, which moves the burden onto a persistence scheme that can
itself be got wrong, while 128 random bits collide negligibly however the
process is restarted or replicated.

AC2.4 claimed no problem body carries a secret, but the guard walks only the
harness-authored halves (code, title, type). detail/error carry the server's own
err.Error(), bounded and UTF-8-repaired but not content-scrubbed. The AC now
says that, and says why scrubbing is the wrong control there: it would corrupt
the diagnostic without being a real defence, since the obligation belongs with
the backend that raises the error and knows which value is sensitive.

Gates: docs/lint green (ADR number uniqueness included); matlatl check --strict
green (271 documents, 2368 references, 0 broken).

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
@samuv
samuv force-pushed the sdk/00-decision-record branch from 0ac7087 to 7f7a5bc Compare August 31, 2026 08:23
samuv added a commit that referenced this pull request Aug 31, 2026
Four fixes from the #822 review, plus a renumber forced by main.

RENUMBERED 0244-0246 -> 0248-0250. main landed its own 0244 (full request +
manual compaction), 0245 (safe build diagnostics), 0246 (goccy YAML parser)
while this stack was open, so the SDK ADRs collided with three real records.
0248-0250 are the next free numbers. This is the second time these three have
moved; the first was the off-by-one below.

THE BLOCKING REVIEW ITEM: the ADR index numbered the three new entries
0243/0244/0245 while linking to files 0244-/0245-/0246-, and its "0243" collided
with the already-existing ADR 0243 (local JSONL durability boundaries). The ADR
bodies were numbered correctly and cross-referenced each other correctly
throughout; only the index was wrong.

ADR 0248 (was 0244) decision 7 said gRPC "returns the same string in a status
detail" without saying what the detail is. It is now pinned to
google.rpc.ErrorInfo, with the two reasons that made it the right carrier: it
authors no new proto in contracts/proto (harness.proto is touched by most of the
stack, and each extra edit is another conflict surface), and AIP-193's
reason+domain+metadata shape is decodable by generic gRPC tooling with no
mecatl-specific knowledge.

That surfaced a casing decision the ADR was leaving for the parity gate to
discover: AIP-193 conventionally spells reason in UPPER_SNAKE_CASE, but AC2.2
requires the IDENTICAL string on both transports. Parity wins, lower_snake_case
on both sides, and the departure from the convention is now stated up front
rather than found as a test failure by whoever implements the second transport.

ADR 0249 (was 0245) decision 1 validated the run id only as colon-free, which
moved ADR 0044's CWE-863 replay guard from internally-guaranteed (an atomic
r<serial> counter, uniqueness impossible to violate by construction) to
caller-trusted. The decision now records what was actually built: 128 bits of
crypto/rand at one call site. It also records the alternative that was weighed —
a host-supplied label plus a session-minted monotonic counter — and why the
random id is stronger: a monotonic counter has to survive restarts and replicas
to stay monotonic, which moves the burden onto a persistence scheme that can
itself be got wrong, while 128 random bits collide negligibly however the
process is restarted or replicated.

AC2.4 claimed no problem body carries a secret, but the guard walks only the
harness-authored halves (code, title, type). detail/error carry the server's own
err.Error(), bounded and UTF-8-repaired but not content-scrubbed. The AC now
says that, and says why scrubbing is the wrong control there: it would corrupt
the diagnostic without being a real defence, since the obligation belongs with
the backend that raises the error and knows which value is sensitive.

Gates: docs/lint green (ADR number uniqueness included); matlatl check --strict
green (271 documents, 2368 references, 0 broken).

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
@samuv
samuv force-pushed the sdk/00-decision-record branch from 7f7a5bc to 7fe9777 Compare August 31, 2026 08:50
samuv added a commit that referenced this pull request Aug 31, 2026
Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
Four fixes from the #822 review, plus a renumber forced by main.

RENUMBERED 0244-0246 -> 0248-0250. main landed its own 0244 (full request +
manual compaction), 0245 (safe build diagnostics), 0246 (goccy YAML parser)
while this stack was open, so the SDK ADRs collided with three real records.
0248-0250 are the next free numbers. This is the second time these three have
moved; the first was the off-by-one below.

THE BLOCKING REVIEW ITEM: the ADR index numbered the three new entries
0243/0244/0245 while linking to files 0244-/0245-/0246-, and its "0243" collided
with the already-existing ADR 0243 (local JSONL durability boundaries). The ADR
bodies were numbered correctly and cross-referenced each other correctly
throughout; only the index was wrong.

ADR 0248 (was 0244) decision 7 said gRPC "returns the same string in a status
detail" without saying what the detail is. It is now pinned to
google.rpc.ErrorInfo, with the two reasons that made it the right carrier: it
authors no new proto in contracts/proto (harness.proto is touched by most of the
stack, and each extra edit is another conflict surface), and AIP-193's
reason+domain+metadata shape is decodable by generic gRPC tooling with no
mecatl-specific knowledge.

That surfaced a casing decision the ADR was leaving for the parity gate to
discover: AIP-193 conventionally spells reason in UPPER_SNAKE_CASE, but AC2.2
requires the IDENTICAL string on both transports. Parity wins, lower_snake_case
on both sides, and the departure from the convention is now stated up front
rather than found as a test failure by whoever implements the second transport.

ADR 0249 (was 0245) decision 1 validated the run id only as colon-free, which
moved ADR 0044's CWE-863 replay guard from internally-guaranteed (an atomic
r<serial> counter, uniqueness impossible to violate by construction) to
caller-trusted. The decision now records what was actually built: 128 bits of
crypto/rand at one call site. It also records the alternative that was weighed —
a host-supplied label plus a session-minted monotonic counter — and why the
random id is stronger: a monotonic counter has to survive restarts and replicas
to stay monotonic, which moves the burden onto a persistence scheme that can
itself be got wrong, while 128 random bits collide negligibly however the
process is restarted or replicated.

AC2.4 claimed no problem body carries a secret, but the guard walks only the
harness-authored halves (code, title, type). detail/error carry the server's own
err.Error(), bounded and UTF-8-repaired but not content-scrubbed. The AC now
says that, and says why scrubbing is the wrong control there: it would corrupt
the diagnostic without being a real defence, since the obligation belongs with
the backend that raises the error and knows which value is sensitive.

Gates: docs/lint green (ADR number uniqueness included); matlatl check --strict
green (271 documents, 2368 references, 0 broken).

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
@samuv
samuv force-pushed the sdk/00-decision-record branch from 7fe9777 to 746c1bf Compare August 31, 2026 08:52
samuv added a commit that referenced this pull request Aug 31, 2026
Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
@samuv samuv changed the title docs: ADRs 0243-0245 + acceptance plan for the SDK server enablers docs: ADRs 0248-0250 + acceptance plan for the SDK server enablers Aug 31, 2026
@samuv
samuv merged commit 947577b into main Aug 31, 2026
22 checks passed
@samuv
samuv deleted the sdk/00-decision-record branch August 31, 2026 09:02
samuv added a commit that referenced this pull request Aug 31, 2026
Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
samuv added a commit that referenced this pull request Aug 31, 2026
Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>
samuv added a commit that referenced this pull request Aug 31, 2026
…ry (#825)

* feat(server): RFC 9457 problem details and a stable error-code registry

PR 2 of the #821 server-enabler stack. Implements Scenario 2 of
docs/acceptance/sdk-server-enablers.md (AC2.1-AC2.6) per ADR 0243.

HTTP errors were untyped prose: one writeError emitting {"error": "<msg>"}.
A client could read a status and a human string but could not branch on a
stable machine identifier. gRPC callers got a codes.Code, which is far
coarser than the domain — a dozen distinct conditions collapse onto
FailedPrecondition — so the two transports disagreed about what went wrong.
That is fatal for an SDK whose premise is one normalized error surface.

The structural change is collapsing TWO hand-maintained classifiers into
one registry. toStatus (grpc.go) and writeServiceError (http.go) were 49-case
errors.Is chains that had to agree by discipline alone. They did agree — I
verified all 45 shared sentinels before touching them — but nothing enforced
it, and a sentinel added to one and forgotten in the other would silently
report a different class per transport. Both are now one-line registry
lookups.

ORDER IS LOAD-BEARING and the registry is a SLICE, not a map: sentinels wrap
other sentinels (ErrFailedStepRetryIneligible wraps ErrFailedPrecondition),
so errors.Is matches both and the specific row must come first. A map would
randomise iteration and silently reclassify. Pinned by
TestSDKServerEnablers_Scenario2_SpecificSentinelsWinOverGeneral.

The behaviour-preservation proof is a golden table extracted mechanically
from the PRE-refactor source, not retyped. It earned its place immediately:
the first mechanical extraction silently dropped four port.*-qualified cases
(ErrSessionMetadataCursorRestart, ErrSessionMetadataPagingUnsupported,
ErrScheduleNotFound, ErrScheduleUnsupported) because the pattern only matched
unqualified Err* identifiers. The compiler caught that one; the table is what
catches the next.

Codes are open strings, not a proto enum — same discipline as `features` in
PR 1. RFC 9457 `type` is a URN (urn:mecatl:error:<code>) rather than an
https:// URL, because publishing a URL we do not serve is worse documentation
than one that never claimed to be fetchable; the bare code also travels in a
`code` extension so clients branch on a string, not a URI parse.

gRPC carries the same identifier as a google.rpc.ErrorInfo detail
(Reason=code, Domain=mecatl.stacklok.com). Attaching it is best-effort: a
marshal failure degrades to the bare status rather than losing the error.

`detail` is UTF-8-repaired and bounded to 2048 bytes, cutting on a rune
boundary — a truncated multi-byte rune is itself invalid UTF-8, re-creating
the marshal-killing fault the repair exists to prevent. The `error`
compatibility key carries the same repaired text, so old and new clients
never see different messages.

AC2.4's no-secret guard checks the two halves DIFFERENTLY on purpose. `code`
is a machine vocabulary we author, so a bare-word denylist is exact there.
`title` is English prose, and a word denylist on prose is a false-positive
generator — the first run failed on "Management authorization required",
which leaks nothing. The title half therefore checks value SHAPES (bearer
forms, key=value, unbroken opaque runs), and the matcher itself is tested
against both leaks it must catch and prose it must not, so it cannot be
quietly defanged.

Blast radius: only ERROR bodies moved to application/problem+json; success
responses stay application/json (pinned). There are no in-repo non-test HTTP
consumers — mecatui is a gRPC client.

Gates: task lint 0 issues across all modules; Scenario 2 tests green.
go.mod: genproto/googleapis/rpc promoted indirect -> direct (no version
change) for errdetails.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>

* test(server): close the review gaps on the error-code registry

Three fixes from the #825 review, plus one thing found while making them.

STALE COMMENT. toStatus carried a //nolint:gocyclo justifying "a flat error→code
classifier; a switch is the correct shape". The 49-case switch it described is
gone — the body is now a one-line delegation to classifyError. Dropped.

THE CASING CHOICE IS NOW ON THE RECORD AT THE SITE. ErrorInfo.Reason carries the
code in lower_snake_case, against AIP-193's UPPER_SNAKE_CASE convention, because
AC2.2 requires the identical string on both transports and the HTTP side is
lowercase to match RFC 9457 style. That was a deliberate trade with nothing at
the code to say so, and a future reader "fixing" the casing would silently
reintroduce exactly the divergence #822 raised the concern about. The comment
names the trade and points at the parity test that fails if it is undone.

A GENERIC NO-SHADOWING GATE. SpecificSentinelsWinOverGeneral protects the one
known wrapping pair BY NAME, so any future pair depends on the next author
remembering to hand-write another test. TestADR_0244_NoRegistryRowIsShadowed
walks the registry itself and asserts every row's own sentinel resolves back to
that row, so a mis-ordered pair fails with no test edit. Mutation-verified:
swapping the two real rows produces "registry row 25
(failed_step_retry_ineligible) is SHADOWED".

It asserts row IDENTITY, and that is the part worth reading twice. The obvious
spelling is errors.Is — and errors.Is is VACUOUS here. A specific sentinel wraps
the general one, so errors.Is(specific, general) is true, which means an
errors.Is assertion holds both when the row resolves correctly and when it has
been shadowed by the very row it wraps. It would pass in precisely the case it
exists to catch. Only pointer identity separates them. The test carries its own
bite check against a deliberately mis-ordered table so it cannot rot into
theatre.

AC2.4's SCOPE IS NOW TESTED, NOT ASSUMED. The no-secret walk covers code, title,
and type — the halves mecatl authors — but the AC claimed "no problem body
carries a secret", which reads as covering detail/error too. Those carry the
caller's err.Error(), bounded and UTF-8-repaired but not scrubbed. Rather than
weaken the test to match the words or strengthen the code to match the claim,
the pass-through is now asserted explicitly, with the reason: a denylist over
free-text error prose is the same false-positive generator the existing comment
describes for titles, and this layer does not know which substring is sensitive
— only the backend that raised the error does, which is where today's risky ones
already sanitize. A future author adding scrubbing now has to delete an
assertion that explains why it was not wanted. (The AC wording itself is
narrowed in the plan doc, on the ADR commit.)

Gates: go test green on internal/adapter/server; gofmt clean.

Refs #821.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

Signed-off-by: Samuele Verzi <[email protected]>

---------

Signed-off-by: Samuele Verzi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants