The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 25, 17:15 UTC
fix bad decoding
Julius Marminge committed
Feb 26, 2026 at 09:04 UTC
7ad5d03948a27e64bb11f6862d2f23333a0a2bd1
2 files changed
+17
-30
.plans/16c-pr89-remediation-checklist.md
+2
-2
@@ -360,8 +360,8 @@ Counts: active `51` (`valid=33`, `partially-valid=18`), closed-invalid `6`
360
- Threads: PRRT_kwDORLtfbc5wiaR-
361
- Audit note: Decode and SQL errors still collapsed into one persistence error kind.
362
363
-- [ ] `C049` `JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback.
364
- - Status: `TODO`
363
+- [x] `C049` `JSON.stringify(cause)` returns `undefined` for `undefined`, functions, or symbols, violating the `string` return type. Consider coercing the result to a string (e.g., `String(JSON.stringify(cause))`) or adding a fallback.
364
+ - Status: `DONE`
365
- Verdict: `valid`
366
- Severity: `Low`
367
- Area: `Other`
apps/server/src/provider/Layers/ProviderService.ts
+15
-28
@@ -22,7 +22,7 @@ import {
22
type ProviderRuntimeEvent,
23
type ProviderSession,
24
} from "@t3tools/contracts";
25
-import { Effect, Layer, Option, PubSub, Queue, Ref, Schema, Stream } from "effect";
25
+import { Effect, Layer, Option, PubSub, Queue, Ref, Schema, SchemaIssue, Stream } from "effect";
26
27
import { ProviderSessionNotFoundError, ProviderValidationError } from "../Errors.ts";
28
import { ProviderAdapterRegistry } from "../Services/ProviderAdapterRegistry.ts";
@@ -54,30 +54,21 @@ function toValidationError(
54
});
55
}
56
57
-function decodeIssueMessage(cause: unknown): string {
58
- if (cause instanceof Error && cause.message.length > 0) {
59
- return cause.message;
60
- }
61
- try {
62
- return JSON.stringify(cause);
63
- } catch {
64
- return "Invalid provider input.";
65
- }
66
-}
67
-
68
-function decodeInputOrValidationError<S extends Schema.Top>(input: {
57
+const decodeInputOrValidationError = <S extends Schema.Top>(input: {
58
readonly operation: string;
59
readonly schema: S;
60
readonly payload: unknown;
72
-}): Effect.Effect<Schema.Schema.Type<S>, ProviderValidationError> {
73
- try {
74
- return Effect.succeed(
75
- Schema.decodeUnknownSync(input.schema as never)(input.payload) as Schema.Schema.Type<S>,
76
- );
77
- } catch (cause) {
78
- return Effect.fail(toValidationError(input.operation, decodeIssueMessage(cause), cause));
79
- }
80
-}
61
+}) =>
62
+ Schema.decodeUnknownEffect(input.schema)(input.payload).pipe(
63
+ Effect.mapError(
64
+ (schemaError) =>
65
+ new ProviderValidationError({
66
+ operation: input.operation,
67
+ issue: SchemaIssue.makeFormatterDefault()(schemaError.issue),
68
+ cause: schemaError,
69
+ }),
70
+ ),
71
+ );
72
73
function toRuntimeStatus(session: ProviderSession): "starting" | "running" | "stopped" | "error" {
74
switch (session.status) {
@@ -265,9 +256,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
256
provider: existing.provider,
257
threadId: input.binding.threadId,
258
providerThreadId: existingProviderThreadId,
268
- ...(existing.resumeCursor !== undefined
269
- ? { resumeCursor: existing.resumeCursor }
270
- : {}),
259
+ ...(existing.resumeCursor !== undefined ? { resumeCursor: existing.resumeCursor } : {}),
260
});
261
if (existing.sessionId !== input.staleSessionId) {
262
yield* setAlias(input.staleSessionId, existing.sessionId);
@@ -310,9 +299,7 @@ const makeProviderService = (options?: ProviderServiceLiveOptions) =>
299
provider: resumed.provider,
300
threadId: input.binding.threadId,
301
providerThreadId: resumedProviderThreadId,
313
- ...(resumed.resumeCursor !== undefined
314
- ? { resumeCursor: resumed.resumeCursor }
315
- : {}),
302
+ ...(resumed.resumeCursor !== undefined ? { resumeCursor: resumed.resumeCursor } : {}),
303
});
304
305
if (resumed.sessionId !== input.staleSessionId) {