Skip to content

Commit b596b15

Browse files
committed
fix(server): log aborted environment requests at debug, not as failures
Since library requests pass their abort signal, every request a client aborts (a superseded search, a fast switch, React's dev double-mount) reached annotateEnvironmentRequest's finalizer as a failure and was logged at WARN with a full interrupt stack. An interrupt-only exit is now logged at debug without the cause; any other failure still logs at WARN with its cause. A test shows an aborted request logs no warning while a real failure still does. The connections CONTEXT.md notes that in development the first of each pair of preview requests usually reaches DAM before its abort, and that production mounts the panel once. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01A1D6J2UMPo7YBWQFvbg1br
1 parent 3e066dd commit b596b15

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

‎apps/server/src/auth/http.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import * as Context from "effect/Context";
1010
import * as Crypto from "effect/Crypto";
1111
import * as Effect from "effect/Effect";
1212
import * as Layer from "effect/Layer";
13+
import * as Logger from "effect/Logger";
1314
import * as Redacted from "effect/Redacted";
1415
import * as Schema from "effect/Schema";
1516
import * as Etag from "effect/http/Etag";
1617
import * as HttpPlatform from "effect/http/HttpPlatform";
1718
import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder";
1819
import * as HttpApi from "effect/http-api/HttpApi";
1920
import * as HttpRouter from "effect/http/HttpRouter";
21+
import * as HttpServerRequest from "effect/http/HttpServerRequest";
2022

2123
import * as ServerConfig from "../config.ts";
2224
import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
@@ -155,3 +157,29 @@ it.effect("sets the selected browser session cookies through the HTTP route", ()
155157
);
156158
}).pipe(Effect.provide(NodeServices.layer)),
157159
);
160+
161+
it.effect("logs a failed request as a warning but not one its client aborted", () =>
162+
Effect.gen(function* () {
163+
const warnings: Array<unknown> = [];
164+
const logger = Logger.make(({ logLevel, message }) => {
165+
if (logLevel === "Warn") warnings.push(message);
166+
});
167+
const request = HttpServerRequest.fromWeb(
168+
new Request("http://127.0.0.1/api/synthos/connections", { method: "POST" }),
169+
);
170+
const handle = (outcome: Effect.Effect<void, string>) =>
171+
Effect.scoped(
172+
AuthHttp.annotateEnvironmentRequest("synthos.connections").pipe(Effect.andThen(outcome)),
173+
).pipe(
174+
Effect.provideService(HttpServerRequest.HttpServerRequest, request),
175+
Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
176+
Effect.exit,
177+
);
178+
// An aborted request reaches the handler as an interrupt.
179+
yield* handle(Effect.interrupt);
180+
expect(warnings).toEqual([]);
181+
yield* handle(Effect.fail("storage unreachable"));
182+
expect(warnings).toHaveLength(1);
183+
expect(JSON.stringify(warnings[0])).toContain("environment api request failed");
184+
}),
185+
);

‎apps/server/src/auth/http.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import type { AuthEnvironmentScope, DpopFailureReason } from "@t3tools/contracts";
2121
import { parseOAuthScope } from "@t3tools/shared/oauthScope";
2222
import { causeErrorTag } from "@t3tools/shared/observability";
23+
import * as Cause from "effect/Cause";
2324
import * as Clock from "effect/Clock";
2425
import * as DateTime from "effect/DateTime";
2526
import * as Effect from "effect/Effect";
@@ -75,14 +76,17 @@ export const annotateEnvironmentRequest =
7576
const traceId = yield* currentEnvironmentTraceId;
7677

7778
yield* Effect.addFinalizer((exit) =>
78-
exit._tag === "Failure"
79-
? Effect.logWarning("environment api request failed", {
80-
endpoint,
81-
traceId,
82-
errorTag: causeErrorTag(exit.cause),
83-
cause: exit.cause,
84-
})
85-
: Effect.void,
79+
exit._tag === "Success"
80+
? Effect.void
81+
: // A client that aborts its request interrupts the handler: expected, not a failure.
82+
Cause.hasInterruptsOnly(exit.cause)
83+
? Effect.logDebug("environment api request interrupted", { endpoint, traceId })
84+
: Effect.logWarning("environment api request failed", {
85+
endpoint,
86+
traceId,
87+
errorTag: causeErrorTag(exit.cause),
88+
cause: exit.cause,
89+
}),
8690
);
8791
yield* Effect.annotateLogsScoped({ "environment.endpoint": endpoint, traceId });
8892
yield* Effect.annotateCurrentSpan({

‎apps/server/src/synthos-connections/CONTEXT.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ DAM is the asset library's system of record. SynthOS reads it only through DAM's
1212

1313
The cockpit reaches remote environments, so a client built before a connection may talk to a server that has it. The shared `status` list therefore keeps the ids old clients can decode: DAM reports its status through `library.status` instead, and current clients drop list ids they do not know.
1414

15+
The library aborts superseded requests, and the server answers them 499. In development React mounts the panel twice, so the first of each pair of preview requests usually reaches DAM before its abort; production mounts once, so this is not a leak.
16+
1517
Mail delivery uses an immutable reviewed envelope. An unknown send result requires reconciliation before retry; a failed observation does not establish failed delivery. See [knowledge and mail](../../../../docs/user/synthos.md#connect-knowledge-and-mail).

0 commit comments

Comments
 (0)