Skip to content

Commit 1f62d3d

Browse files
cemililikclaude
andcommitted
fix(skills): make the resilience the adapter configures actually fire
Review findings on the PR, verified against current code. Seven were real; four were not, and are listed at the bottom with the check that settled them. **The provider-adapter example configured resilience that could never trigger.** The pipeline classifies by exception type — its `ShouldHandle` matches `ProviderException`, `InfrastructureException` and `TimeoutRejectedException`. The example translated SDK exceptions in a `try/catch` *around* `Pipeline.ExecuteAsync`, so the pipeline saw raw `LiveKit.RoomAlreadyExistsException` and `HttpRequestException`, matched nothing, and retried nothing. Every adapter written from this skill would have shipped four configured policies and zero live ones. Translation now happens inside the callback, so the pipeline sees a typed `ProviderException` and `IsClientError` decides retry. The outer catch keeps a job the callback cannot do: Polly's own outcomes — `BrokenCircuitException`, `TimeoutRejectedException`, `RateLimiterRejectedException` — carry no `Error` and would surface as 500; wrapped in a bare `ProviderException` they inherit `dependency_unavailable` → 503. Caller cancellation is rethrown unchanged so it still maps to 499. The 88-line fence was extracted from the markdown verbatim and compiled against the real `ProviderException` and `IProviderResilience<TPort>`. **`maxAttempts` survived the rename in four documented config samples** — both `add-provider-adapter` blocks, ADR-0032's Implementation Notes and Standards 09. The sweep covered `.cs` and `appsettings.json` and stopped there, so the corpus taught a key the binder no longer reads. ADR-0032's Amendment 2 records the change; its Decision section is byte-identical to `main` (same md5). **The container_name correction was appended and its contradiction left in place.** Two lines apart, the delivery record said projects still cannot run concurrently and then "so compose projects isolate". The second sentence is the one the first was written to replace. **`make dev` does not do what the skill said.** It is `docker compose up -d` plus a status line — it does not start the API or the web app and it runs no migrations. The skill claimed it "wraps docker-compose + dotnet + pnpm" and that its first run applies migrations and seeds Keycloak. The host commands are now spelled out; the seed steps are labelled as `scripts/seed.sh`'s Phase 02a placeholder, which is what they are. Also: the ports table's last row was orphaned below the paragraph that followed it, breaking the table; `ToLower()` is culture-sensitive and `ToLowerInvariant()` is what the documented lowercase contract needs; `add-mediatr-handler` enqueued an unversioned `EnrollmentCreatedIntegrationEvent` while its own pitfalls section requires the `V1` suffix; and `SensitiveTokenCatalog` had `authheader` but not `authenticationheader`. Not changed, with the reason: - **"Normalize Polly exceptions to 503 instead of 500"** — already true. `ProviderException`'s default `Error` is `lockey_dependency_unavailable` and `HttpStatusMap` maps it to `ServiceUnavailable`. Verified in the source rather than assumed; the adapter restructure above preserves it. - **"Clarify that the approval deferral covers the two-approval rule"** — it already does. The deferral sentence follows both clauses of the same bullet. - **"Condense the entity-equality section, move rationale to ADR-0023"** — a restructuring preference, not a defect. The section is accurate, and the measurements it carries are the reason the rule is believed; moving them into an ADR that must then be amended to change them makes the rule harder to maintain, not easier. - **"Restructure the catalogue assertion into nested bullets"** — style only. 227 tests green (was 224), build 0/0, format clean, all 80 skill C# fences parse except the `<Name>` templates that predate this branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent ba7b851 commit 1f62d3d

9 files changed

Lines changed: 105 additions & 41 deletions

File tree

‎.claude/skills/add-integration-event/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ await outbox.EnqueueAsync(new EnrollmentCreatedIntegrationEventV1
8787
EnrollmentId = enrollment.Id.Value,
8888
LearnerId = request.LearnerId.Value,
8989
CourseVersionId = request.CourseVersionId.Value,
90-
Source = request.Source.ToString().ToLower(),
90+
Source = request.Source.ToString().ToLowerInvariant(),
9191
}, cancellationToken);
9292

9393
await db.SaveChangesAsync(cancellationToken); // atomic

‎.claude/skills/add-mediatr-handler/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public sealed class CreateEnrollmentCommandHandler(
143143

144144
db.Enrollments.Add(enrollment);
145145

146-
await outbox.EnqueueAsync(new EnrollmentCreatedIntegrationEvent
146+
await outbox.EnqueueAsync(new EnrollmentCreatedIntegrationEventV1
147147
{
148148
TenantId = tenantContext.TenantId,
149149
OrganizationId = tenantContext.OrganizationId,

‎.claude/skills/add-provider-adapter/SKILL.md‎

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,43 +167,78 @@ internal sealed class LiveKitClient(
167167
public async Task<LiveRoom> CreateRoomAsync(
168168
CreateRoomCommand cmd, CancellationToken ct)
169169
{
170+
// MapToSdkRequest / MapToDomain are this adapter's own private helpers —
171+
// translation is the adapter's whole job.
172+
var sdkRequest = MapToSdkRequest(cmd);
173+
170174
try
171175
{
172-
// Every outbound call goes through the pipeline. There is no
173-
// decorator doing this for you — see Step 4.
174-
// MapToSdkRequest / MapToDomain are this adapter's own private
175-
// helpers — translation is the adapter's whole job.
176-
var sdkRequest = MapToSdkRequest(cmd);
177176
var room = await resilience.Pipeline.ExecuteAsync(
178-
async token => await _sdk.CreateRoom(sdkRequest, token), ct);
177+
async token =>
178+
{
179+
// Translation happens INSIDE the callback. The pipeline's
180+
// ShouldHandle predicates match ProviderException,
181+
// InfrastructureException and TimeoutRejectedException — an SDK
182+
// exception matches none of them, so translating outside the
183+
// pipeline means retry and the circuit breaker never fire and
184+
// the configuration in Step 5 is inert.
185+
try
186+
{
187+
return await _sdk.CreateRoom(sdkRequest, token);
188+
}
189+
catch (global::LiveKit.RoomAlreadyExistsException ex)
190+
{
191+
throw new LiveClassProviderException(
192+
ex.Message, isClientError: true, innerException: ex);
193+
}
194+
catch (global::LiveKit.QuotaExceededException ex)
195+
{
196+
throw new LiveClassProviderException(
197+
ex.Message, isClientError: true, innerException: ex);
198+
}
199+
// .NET 5+ exposes HttpRequestException.StatusCode as
200+
// HttpStatusCode?. A raw 4xx is the caller's fault, so it is a
201+
// client error and must not be retried.
202+
catch (HttpRequestException ex)
203+
when (ex.StatusCode is not null && (int)ex.StatusCode < 500)
204+
{
205+
throw new LiveClassProviderException(
206+
ex.Message, isClientError: true, innerException: ex);
207+
}
208+
// null StatusCode = transport failure (DNS, connection refused);
209+
// 5xx = the provider's infra. Both are retryable.
210+
catch (HttpRequestException ex)
211+
{
212+
throw new LiveClassProviderException(
213+
"Live-class provider unavailable.",
214+
isClientError: false, innerException: ex);
215+
}
216+
},
217+
ct);
218+
179219
return MapToDomain(room);
180220
}
181-
catch (global::LiveKit.RoomAlreadyExistsException ex)
182-
{
183-
throw new LiveClassProviderException(
184-
ex.Message, isClientError: true, innerException: ex);
185-
}
186-
catch (global::LiveKit.QuotaExceededException ex)
221+
catch (LiveClassProviderException)
187222
{
188-
throw new LiveClassProviderException(
189-
ex.Message, isClientError: true, innerException: ex);
223+
// Already translated inside the callback; the pipeline re-raises the
224+
// final attempt's exception unchanged.
225+
throw;
190226
}
191-
// .NET 5+ exposes `HttpRequestException.StatusCode` as `HttpStatusCode?`.
192-
// `null` = transport failure (DNS, connection refused, timeout) which is
193-
// an infra fault → isClientError: false. 5xx upstream → isClientError: false.
194-
// 4xx upstream is handled by the SDK-specific catches above; if a raw 4xx
195-
// reaches this clause it falls through to the catch-all below.
196-
catch (HttpRequestException ex)
197-
when (ex.StatusCode is null || (int)ex.StatusCode >= 500)
227+
catch (OperationCanceledException) when (ct.IsCancellationRequested)
198228
{
199-
throw new LiveClassProviderException(
200-
"Live-class provider unavailable.",
201-
isClientError: false, innerException: ex);
229+
// Caller-initiated cancellation is not a provider failure. Rethrow
230+
// unchanged so the L1 handler maps it to 499 rather than 503.
231+
throw;
202232
}
203233
catch (Exception ex)
204234
{
235+
// Polly's own outcomes reach here: BrokenCircuitException,
236+
// TimeoutRejectedException, RateLimiterRejectedException. Wrapping
237+
// them in a bare ProviderException gives them the default
238+
// `dependency_unavailable` Error, which HttpStatusMap turns into 503.
239+
// Left untranslated they would surface as a generic 500.
205240
throw new LiveClassProviderException(
206-
"Unexpected live-class provider failure.",
241+
"Live-class provider unavailable.",
207242
isClientError: false, innerException: ex);
208243
}
209244
}
@@ -221,7 +256,15 @@ Rules:
221256
- The adapter is `internal sealed` — the composition root sees only the port
222257
interface.
223258
- Every public method is wrapped in a `try / catch` whose only purpose is
224-
exception translation.
259+
exception translation, and the **SDK-facing half of it sits inside the pipeline
260+
callback**. The pipeline classifies by exception type, so it has to see a
261+
`ProviderException`; hand it a raw SDK exception and every policy in Step 5 is
262+
configured, loaded, and never triggered.
263+
- The **outer** `catch` exists for Polly's own outcomes —
264+
`BrokenCircuitException`, `TimeoutRejectedException`,
265+
`RateLimiterRejectedException` — which the callback cannot produce. They carry
266+
no `Error`, so untranslated they map to 500; wrapped, they inherit
267+
`dependency_unavailable` → 503.
225268
- Provider SDK exception types (`LiveKit.RoomAlreadyExistsException`,
226269
`Stripe.StripeException`, `Meilisearch.MeilisearchApiError`, …) **never**
227270
leave the adapter's namespace. The architecture test
@@ -266,7 +309,7 @@ Add to `appsettings.json`:
266309
"Resilience": {
267310
"liveclass": {
268311
"retry": {
269-
"maxAttempts": 3,
312+
"maxRetryAttempts": 2,
270313
"delaySeconds": 1,
271314
"useJitter": true
272315
},
@@ -286,7 +329,7 @@ Add to `appsettings.json`:
286329
Tune per port based on the upstream's known characteristics. Document the
287330
chosen values in the adapter's README (under
288331
`backend/src/LearnStack.Infrastructure.<X>/README.md`) so reviewers know
289-
*why* `maxAttempts: 3` and not 5.
332+
*why* `maxRetryAttempts: 2` and not 5.
290333

291334
### Step 6: Map provider 4xx vs 5xx correctly
292335

‎.claude/skills/local-dev-setup/SKILL.md‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,20 @@ pnpm install --frozen-lockfile
8282
### Step 3: Bring up the stack
8383

8484
```bash
85-
make dev # the canonical orchestrator; wraps docker-compose + dotnet + pnpm
85+
make dev # brings the containers up — and only the containers
8686
```
8787

88-
Equivalent without the make wrapper:
88+
`make dev` is `docker compose up -d` plus a status line. It does **not** start
89+
the API or the web app, and it does not run migrations or seeds; those are
90+
separate commands you run yourself:
91+
92+
```bash
93+
dotnet run --project backend/src/LearnStack.Api # API on 5080
94+
pnpm --filter @learnstack/web dev # web on 3000
95+
make seed # health gate + demo credentials
96+
```
97+
98+
What `make dev` expands to:
8999

90100
```bash
91101
# One file holds the whole stack. --env-file is not optional: Compose resolves
@@ -116,16 +126,19 @@ The components and their default ports:
116126

117127
Every one of these binds to `127.0.0.1`, never `0.0.0.0` — see
118128
[Infrastructure Standards § Published ports](../../../docs/standards/12-infrastructure.md).
119-
The backend host is **not** a compose service: `LearnStack.Api` runs on the
120-
workstation via `dotnet run`, on the `ASPNETCORE_URLS` port in `.env.example`.
121-
Regenerate this table from the stack itself rather than by hand —
129+
Regenerate the table from the stack itself rather than by hand —
122130
`docker compose --env-file .env -f infra/compose/dev.yml config --format json`
123131
is the source of truth.
124-
| LearnStack Web (`apps/web`) | 3000 | Frontend dev server. |
132+
133+
Neither application host is a compose service. `LearnStack.Api` runs on the
134+
workstation via `dotnet run` on the `ASPNETCORE_URLS` port in `.env.example`
135+
(5080), and `apps/web` runs via `pnpm dev` on 3000.
125136

126137
### Step 4: First-run bootstrap
127138

128-
The first `make dev` run additionally:
139+
`make seed` verifies the stack is healthy and prints the demo credentials. The
140+
steps below are its **Phase 02a** scope — `scripts/seed.sh` carries them as a
141+
documented placeholder and does not run them yet:
129142

130143
1. Applies every module's EF migrations.
131144
2. Seeds Keycloak's `learnstack` realm with a platform admin and two demo tenants

‎backend/src/LearnStack.SharedKernel/Secrets/SensitiveTokenCatalog.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static class SensitiveTokenCatalog
7878
"apikey", // api_key / ApiKey
7979
"cardnumber", // card_number / CardNumber
8080
"authheader", // auth_header / AuthHeader
81+
"authenticationheader", // authentication_header / AuthenticationHeader
8182
"connectionstring", // connection_string / ConnectionString
8283
"creditcard", // credit_card / CreditCard
8384
"encryptionkey", // encryption_key / EncryptionKey

‎backend/tests/LearnStack.Tests.Unit/SharedKernel/Secrets/SensitiveTokenCatalogTests.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public sealed class SensitiveTokenCatalogTests
6161
// count of signatures redacts too. Losing a count is cheaper than
6262
// shipping an HMAC that lets someone forge the envelope it signed.
6363
[InlineData("SignatureCount")]
64+
[InlineData("AuthenticationHeader")]
65+
[InlineData("authentication_header")]
66+
[InlineData("authenticationheader")]
6467
public void IsSensitive_True_For_Token_Segments(string name)
6568
{
6669
SensitiveTokenCatalog.IsSensitive(name).Should().BeTrue();

‎docs/decisions/0032-exception-handling-logging-and-observability.md‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ None of the three changes a sub-decision; all three correct text that would misl
2727
Amendment, which is what carries it. The Decision section is untouched. Its
2828
copy in `.claude/skills/wire-cross-cutting-foundation/SKILL.md` is corrected with
2929
it — that copy is an executable instruction, so it was the one that would have
30-
produced non-compiling code.
30+
produced non-compiling code. The same § Implementation Notes `Resilience:`
31+
sample carried `retry.maxAttempts`; the shipped option is
32+
`ResilienceOptions.Retry.MaxRetryAttempts`, which maps 1:1 onto Polly v8's
33+
retry count. `maxAttempts` read as a total and behaved as a retry count, so
34+
every configured value issued one more call than the name promised. The
35+
sample now uses the shipped key.
3136
2. **The "Hub HTTPS contract is closed at four endpoints" decision driver is
3237
superseded** by [ADR-0034](0034-hub-contract-surface-invariant.md), which replaces
3338
the count with two invariants (the Hub stores no tenant content; every crossing goes
@@ -703,7 +708,7 @@ SDK creates and disposes warm-up `Activity` instances during startup).
703708
{
704709
"Resilience": {
705710
"liveclass": {
706-
"retry": { "maxAttempts": 3, "delaySeconds": 1, "useJitter": true },
711+
"retry": { "maxRetryAttempts": 2, "delaySeconds": 1, "useJitter": true },
707712
"circuitBreaker": { "failureRatio": 0.5, "samplingDurationSeconds": 30, "minimumThroughput": 10, "breakDurationSeconds": 30 },
708713
"timeout": { "totalSeconds": 10 }
709714
},

‎docs/roadmap/phase-02a-kernel-tenancy.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,6 @@ plan turned out wrong — a repair packet that hides its misses teaches nothing.
16361636
> does **not** make two projects concurrently runnable: the host ports are fixed
16371637
> literals, so a second project now fails on a port bind instead of a name clash.
16381638
> `make dev` and `make e2e-up` are still mutually exclusive.
1639-
> The 14 `container_name:` literals are gone, so compose projects isolate.
16401639
>
16411640
> **Frontend.** The Vitest harness replaces `--passWithNoTests`, verified by deleting
16421641
> the test rather than by running it. `jsdom` is capped at `^26` and `jest-dom` at

‎docs/standards/09-error-handling.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ Configuration shape (excerpt):
393393
{
394394
"Resilience": {
395395
"liveclass": {
396-
"retry": { "maxAttempts": 3, "delaySeconds": 1, "useJitter": true },
396+
"retry": { "maxRetryAttempts": 2, "delaySeconds": 1, "useJitter": true },
397397
"circuitBreaker": { "failureRatio": 0.5, "samplingDurationSeconds": 30, "minimumThroughput": 10, "breakDurationSeconds": 30 },
398398
"timeout": { "totalSeconds": 10 }
399399
}

0 commit comments

Comments
 (0)