Skip to content

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

Merged
samuv merged 2 commits into
mainfrom
sdk/02-problem-details
Aug 31, 2026
Merged

samuv merged 2 commits into
mainfrom
sdk/02-problem-details

Conversation

@samuv

@samuv samuv commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #823 → #822. Review those first.

What

PR 2 of 9 in the #821 server-enabler stack. Implements Scenario 2 of docs/acceptance/sdk-server-enablers.md — AC2.1–AC2.6 — per ADR 0244.

RFC 9457 application/problem+json on HTTP, google.rpc.ErrorInfo details on gRPC, and one stable error-code registry feeding both.

Why

HTTP errors were untyped prose — a single 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). The two transports therefore disagreed about what went wrong — fatal for an SDK whose premise is one normalized error surface (#821 AC3).

The structural change

toStatus (grpc.go) and writeServiceError (http.go) were two hand-maintained 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 — turning a 409 into a 412 for anyone branching on it. Pinned by TestSDKServerEnablers_Scenario2_SpecificSentinelsWinOverGeneral.

The golden table earned its place immediately

The behaviour-preservation proof is a table extracted mechanically from the pre-refactor source, not retyped. My 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 (an import went unused). The table is what catches the next.

Notable choices

  • Codes are open strings, not a proto enum — same discipline as features in PR 1.
  • type is a URN (urn:mecatl:error:<code>), not an https:// URL. Publishing a URL we don't serve is worse documentation than one that never claimed to be fetchable. The bare code also rides a code extension so clients branch on a string, not a URI parse.
  • gRPC carries google.rpc.ErrorInfo (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.
  • instance is omitted, not fabricated — mecatl has no request-id concept, and a field that correlates to nothing is worse than an absent one.

The AC2.4 secret guard checks 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. So the title half checks value shapes (bearer forms, key=value, unbroken opaque runs) instead of vocabulary.

The matcher is itself tested — against leaks it must catch and prose it must not — so it can't be quietly defanged by the next person who trips it. (Its "opaque run" class also had to exclude _/-: those are word separators in our own vocabulary, and including them matched long snake_case codes.)

Blast radius

Only error bodies moved to application/problem+json; success responses stay application/json (pinned by TestSDKServerEnablers_Scenario2_SuccessResponsesAreUnchanged). There are no in-repo non-test HTTP consumers — mecatui is a gRPC client.

Acceptance criteria

AC Test
2.1 problem+json shape + error compat key TestSDKServerEnablers_Scenario2_ProblemJSONShape
2.2 same code on both transports TestSDKServerEnablers_Scenario2_ErrorCodeTransportParity
2.3 registry total and unambiguous TestADR_0244_ErrorRegistryIsTotalAndUnambiguous
2.4 no secrets in problem bodies TestADR_0244_ProblemDetailsCarryNoSecrets
2.5 unregistered failure degrades TestSDKServerEnablers_Scenario2_UnregisteredFailureDegrades
2.6 detail bounded + valid UTF-8 TestSDKServerEnablers_Scenario2_DetailIsBoundedAndValidUTF8
— behaviour preservation TestSDKServerEnablers_Scenario2_RegistryPreservesPreRefactorMappings

Verification

task lint 0 issues across all modules. go test -race ./... green on root and engine, all four provider modules, both standalone hygiene proofs, and mecademo.

go.mod: genproto/googleapis/rpc promoted indirect → direct (no version change) for errdetails.

⚠️ Two pre-existing issues on main found while running the gates

  1. task test fails on macOS — #786's new jsonlstore durability check rejects TMPDIR because macOS puts it under /var, a symlink to /private/var: jsonlstore: create store dir: path "/var" is not a directory. Reproduced on a clean origin/main worktree; passes with a resolved TMPDIR. CI is Linux so it stays green there, but it breaks the suite on every macOS dev machine.
  2. test:authn-standalone and task tidy both fail — authn/oidc/fixture_test.go:12 imports internal/adapter/server, breaking the GOWORK=off standalone hygiene proof. Also on origin/main.

Neither is addressed here; folding them in would hide them.

Refs #821.

🤖 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 with three parallel specialist passes (security on the secret-guard scope, duplication-elimination check on the chain consolidation, gRPC ErrorInfo wiring/casing). The consolidation itself is clean — genuine single source of truth, no residual duplication, real byte-identical codes across transports (verified by a proper test oracle, not two constants that happen to match), and this closes exactly what was recommended on #822 for the gRPC error mechanism. Four comments below, nothing blocking — approving.


all := append(append([]errorCodeEntry{}, errorRegistry...), genericErrorEntry)
for _, e := range all {
doc := newProblem(e, "detail text")

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.

This test checks code/title/type for secret-shaped content on every registry row, but always passes a fixed, harmless "detail text" literal — it never verifies detail/error (which carry the caller's real err.Error(), only UTF-8-repaired and length-clamped, no content scrubbing). Not a regression from this PR — writeError already passed err.Error() straight through before this, and today's known risky backends (migration/cleanup/storage-health) sanitize at their own boundary — but the PR's AC2.4 language ("no problem body carries a secret... across every registered code's rendered output") reads as a stronger guarantee than what's actually tested. Worth either narrowing that claim's wording, or extending this test to also probe detail with a secret-shaped value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, and I took the "narrow the claim" half as well as the test half, because they were disagreeing about different things.

AC2.4's wording is narrowed on the ADR commit to say the guard covers the harness-authored halves only. And TestADR_0244_DetailIsPassedThroughNotScrubbed now asserts the pass-through explicitly with secret-shaped values, so the boundary is a decision on the record rather than an untested assumption — and a future author adding scrubbing has to come delete an assertion that explains why it wasn't wanted.

The reason it stays unscrubbed is in the test comment: a denylist over free-text error prose is the same false-positive generator the existing comment already describes for titles, and this layer doesn't know which substring is sensitive — only the backend that raised the error does. Redacting there is precise; redacting here is a guess that corrupts diagnostics.

// BOTH. If the registry were a map (or if someone reordered it), this would
// classify as the general precondition failure and the HTTP status would change
// from 409 to 412 — a silently different contract for a client branching on it.
func TestSDKServerEnablers_Scenario2_SpecificSentinelsWinOverGeneral(t *testing.T) {

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.

This protects the one known wrapping pair (ErrFailedStepRetryIneligible/ErrFailedPrecondition) by name. There's no generic/structural check that would catch a future wrapping pair inserted in the wrong order in errorRegistry — correctness for any new pair depends on the next author remembering to hand-write another test like this one. Not asking for a fix now, just flagging so it doesn't get forgotten as the registry grows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not forgotten — fixed generically in feb83b5. TestADR_0244_NoRegistryRowIsShadowed walks errorRegistry itself and asserts each row's own sentinel resolves back to that row, so a future pair in the wrong order fails with no test edit. Mutation-verified by swapping the two real rows: registry row 25 ("failed_step_retry_ineligible") is SHADOWED.

Worth flagging what writing it turned up, though. The obvious spelling of that assertion is errors.Is, and errors.Is is vacuous here — a specific sentinel wraps the general one, so errors.Is(specific, general) is true whether the row resolved correctly or was shadowed by the very row it wraps. It passes in exactly the case it's checking. Only pointer identity separates them.

That matters beyond the new test: #828 replaced this PR's count-equality with a shadow check spelled with errors.Is, which had the same hole. Fixed there too in 1680c9a, so the golden-table check now compares by identity.

Comment thread internal/adapter/server/grpc.go Outdated
@@ -1475,131 +1476,39 @@ func toProtoCleanupJob(job CleanupJob) *mecatlv1.CleanupJob {
//
//nolint:gocyclo // a flat error→code classifier; a switch is the correct shape.

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.

Stale — this justified the old 49-case switch, which is now a one-line delegation to classifyError. Safe to drop.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Dropped.

func statusForEntry(entry errorCodeEntry, err error) error {
st := status.New(entry.GRPC, session.ToValidUTF8(err.Error()))
withDetail, derr := st.WithDetails(&errdetails.ErrorInfo{
Reason: entry.Code,

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.

Nice — this is exactly what was suggested on #822 (use google.rpc.ErrorInfo instead of a mecatl-authored detail message), and Reason is genuinely the same lowercase code as the HTTP side rather than converted to the AIP-193-conventional UPPER_SNAKE_CASE, verified byte-for-byte by TestSDKServerEnablers_Scenario2_ErrorCodeTransportParity. Worth one line of comment here saying that's deliberate (parity across transports beats the casing convention) so a future reader doesn't "fix" the casing and silently reintroduce the divergence #822's comment was worried about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added. The comment names the trade (AC2.2's identical-string requirement beats the AIP-193 convention, and the HTTP side is lowercase to match RFC 9457 style) and points at TestSDKServerEnablers_Scenario2_ErrorCodeTransportParity as the thing that fails if it's undone. ADR 0244 decision 7 now records it too, so it's discoverable from either end.

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 force-pushed the sdk/02-problem-details branch from efcf93d to feb83b5 Compare August 31, 2026 08:11
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 force-pushed the sdk/02-problem-details branch from feb83b5 to 59d2fa9 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]>
@samuv
samuv force-pushed the sdk/02-problem-details branch from 59d2fa9 to 469f4cf Compare August 31, 2026 08:53
@samuv
samuv force-pushed the sdk/02-problem-details branch from 469f4cf to e8afa3d Compare 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
samuv force-pushed the sdk/02-problem-details branch from e8afa3d to ba2f760 Compare August 31, 2026 09:16
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 force-pushed the sdk/02-problem-details branch from ba2f760 to dca21e8 Compare August 31, 2026 10:18
Base automatically changed from sdk/01-server-info to main August 31, 2026 10:31
samuv added 2 commits August 31, 2026 12:31
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]>
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 force-pushed the sdk/02-problem-details branch from dca21e8 to dcbd311 Compare August 31, 2026 10:31
@samuv
samuv merged commit 74764c9 into main Aug 31, 2026
6 checks passed
@samuv
samuv deleted the sdk/02-problem-details branch August 31, 2026 10:32
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