Repository navigation
[codex] Structure Codex app-server request errors #3258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b25fd94
structure Codex app-server request errors
juliusmarminge dcb2646
fix: classify app-server input termination
juliusmarminge 5cecba9
Classify app server protocol parse stages
juliusmarminge f8c426f
Classify app server runtime failures
juliusmarminge 798661f
Structure Codex protocol parse failures
juliusmarminge 7a27805
test: align notification decode assertions
juliusmarminge 9cfc7c8
fix: retain resume failure stack in logs
juliusmarminge 0d26774
fix(codex): redact schema payload diagnostics
juliusmarminge 7821d64
fix(codex): redact protocol failure logs
juliusmarminge 306576f
fix(codex): keep turn schema diagnostics structural
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
packages/effect-codex-app-server/src/_internal/shared.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { assert, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| import * as CodexError from "../errors.ts"; | ||
| import * as Shared from "./shared.ts"; | ||
|
|
||
| it.effect("preserves schema decode diagnostics without deriving the message from the cause", () => | ||
| Effect.gen(function* () { | ||
| const error = yield* Shared.decodeOptionalPayload("thread/start", Schema.String, 42).pipe( | ||
| Effect.flip, | ||
| ); | ||
|
|
||
| assert.instanceOf(error, CodexError.CodexAppServerRequestError); | ||
| assert.equal(error.code, -32602); | ||
| assert.equal(error.method, "thread/start"); | ||
| assert.equal(error.operation, "decode-payload"); | ||
| assert.equal( | ||
| error.message, | ||
| "Invalid payload for method 'thread/start' during 'decode-payload'", | ||
| ); | ||
| assert.isTrue(Schema.isSchemaError(error.cause)); | ||
|
|
||
| const protocolError = error.toProtocolError(); | ||
| assert.equal(protocolError.code, -32602); | ||
| assert.equal(protocolError.message, error.message); | ||
| assert.property(protocolError, "data"); | ||
| assert.notProperty(protocolError, "method"); | ||
| assert.notProperty(protocolError, "operation"); | ||
| assert.notProperty(protocolError, "cause"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("preserves schema encode diagnostics", () => | ||
| Effect.gen(function* () { | ||
| const error = yield* Shared.encodeOptionalPayload( | ||
| "thread/start", | ||
| Schema.Number, | ||
| "not-a-number" as never, | ||
| ).pipe(Effect.flip); | ||
|
|
||
| assert.equal(error.method, "thread/start"); | ||
| assert.equal(error.operation, "encode-payload"); | ||
| assert.equal( | ||
| error.message, | ||
| "Invalid payload for method 'thread/start' during 'encode-payload'", | ||
| ); | ||
| assert.isTrue(Schema.isSchemaError(error.cause)); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("does not invent a cause when a method has no payload schema", () => | ||
| Effect.gen(function* () { | ||
| const error = yield* Shared.decodeOptionalPayload<never, never>( | ||
| "initialized", | ||
| undefined, | ||
| "unexpected", | ||
| ).pipe(Effect.flip); | ||
|
|
||
| assert.equal(error.method, "initialized"); | ||
| assert.equal(error.operation, "decode-payload"); | ||
| assert.isUndefined(error.cause); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("retains the request-handler error as the internal error cause", () => | ||
| Effect.gen(function* () { | ||
| const rootCause = new Error("socket closed"); | ||
| const source = new CodexError.CodexAppServerTransportError({ | ||
| detail: "Codex App Server transport failed", | ||
| cause: rootCause, | ||
| }); | ||
| const error = yield* Shared.runHandler( | ||
| (_payload: void) => Effect.fail(source), | ||
| undefined, | ||
| "thread/start", | ||
| ).pipe(Effect.flip); | ||
|
|
||
| assert.equal(error.code, -32603); | ||
| assert.equal(error.method, "thread/start"); | ||
| assert.equal(error.operation, "handle-request"); | ||
| assert.equal( | ||
| error.message, | ||
| "Codex App Server request handler failed for method 'thread/start'", | ||
| ); | ||
| assert.strictEqual(error.cause, source); | ||
| assert.strictEqual(source.cause, rootCause); | ||
| assert.notInclude(error.message, source.message); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("passes request errors through without adding a wrapper", () => | ||
| Effect.gen(function* () { | ||
| const source = CodexError.CodexAppServerRequestError.invalidParams("Invalid thread id"); | ||
| const error = yield* Shared.runHandler( | ||
| (_payload: void) => Effect.fail(source), | ||
| undefined, | ||
| "thread/start", | ||
| ).pipe(Effect.flip); | ||
|
|
||
| assert.strictEqual(error, source); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("retains the full notification payload decode cause chain", () => | ||
| Effect.gen(function* () { | ||
| const error = yield* Shared.decodeNotificationPayload( | ||
| "item/agentMessage/delta", | ||
| Schema.String, | ||
| 42, | ||
| ).pipe(Effect.flip); | ||
|
|
||
| assert.equal(error.method, "item/agentMessage/delta"); | ||
| assert.equal(error.operation, "decode-notification-payload"); | ||
| assert.equal(error.detail, "Invalid notification payload"); | ||
| assert.instanceOf(error.cause, CodexError.CodexAppServerRequestError); | ||
| assert.isTrue(Schema.isSchemaError(error.cause.cause)); | ||
| }), | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.