Repository navigation
fix(client): a timed-out session check no longer locks the composer #17075
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
Open
sheehanmunim
wants to merge
1
commit into
pingdotgg:main
Choose a base branch
from
sheehanmunim:fix/client-session-check-retry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−1
Open
Changes from all commits
Commits
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
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,104 @@ | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import { EnvironmentId, type AuthSessionState } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Option from "effect/Option"; | ||
| import * as Stream from "effect/Stream"; | ||
| import * as SubscriptionRef from "effect/SubscriptionRef"; | ||
| import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity"; | ||
|
|
||
| import { RelayConnectionTarget, type PreparedConnection } from "../connection/model.ts"; | ||
| import { EnvironmentRegistry } from "../connection/registry.ts"; | ||
| import { EnvironmentSupervisor } from "../connection/supervisor.ts"; | ||
| import * as RpcHttp from "../rpc/http.ts"; | ||
| import { createEnvironmentSessionAtoms } from "./session.ts"; | ||
|
|
||
| const TARGET = new RelayConnectionTarget({ | ||
| environmentId: EnvironmentId.make("environment-1"), | ||
| label: "Environment", | ||
| }); | ||
| const PREPARED: PreparedConnection = { | ||
| environmentId: TARGET.environmentId, | ||
| label: TARGET.label, | ||
| httpBaseUrl: "https://environment.example.test", | ||
| socketUrl: "wss://environment.example.test/ws", | ||
| httpAuthorization: { _tag: "Bearer", token: "bearer-token" }, | ||
| target: TARGET, | ||
| }; | ||
| const SESSION = { | ||
| authenticated: true, | ||
| auth: { | ||
| policy: "remote-reachable", | ||
| bootstrapMethods: ["desktop-bootstrap"], | ||
| sessionMethods: ["bearer-access-token"], | ||
| sessionCookieName: "t3_session", | ||
| }, | ||
| scopes: ["orchestration:read", "orchestration:operate"], | ||
| } satisfies AuthSessionState; | ||
|
|
||
| function makeSessionAtom(reply: (requestNumber: number) => Promise<Response>) { | ||
| let calls = 0; | ||
| const fetchFn: typeof fetch = () => reply(++calls); | ||
| const layer = Effect.gen(function* () { | ||
| const supervisor = { | ||
| target: TARGET, | ||
| prepared: yield* SubscriptionRef.make(Option.some(PREPARED)), | ||
| } as unknown as EnvironmentSupervisor["Service"]; | ||
| const registry = { | ||
| followStream: <A, E, R>(_environmentId: EnvironmentId, stream: Stream.Stream<A, E, R>) => | ||
| stream.pipe(Stream.provideService(EnvironmentSupervisor, supervisor)), | ||
| } as unknown as EnvironmentRegistry["Service"]; | ||
| return Layer.merge( | ||
| Layer.succeed(EnvironmentRegistry, registry), | ||
| RpcHttp.layerRemoteHttpClient(fetchFn), | ||
| ); | ||
| }).pipe(Layer.unwrap); | ||
| const atom = createEnvironmentSessionAtoms(Atom.runtime(layer)).sessionStateAtom( | ||
| TARGET.environmentId, | ||
| ); | ||
| return { atom, calls: () => calls }; | ||
| } | ||
|
|
||
| const settle = ( | ||
| registry: AtomRegistry.AtomRegistry, | ||
| atom: ReturnType<typeof makeSessionAtom>["atom"], | ||
| ) => AtomRegistry.getResult(registry, atom, { suspendOnWaiting: true }).pipe(Effect.result); | ||
|
|
||
| describe("environment session state", () => { | ||
| it.effect("keeps a confirmed grant through a failed refresh and retries it", () => | ||
| Effect.gen(function* () { | ||
| const session = makeSessionAtom(async (requestNumber) => { | ||
| if (requestNumber === 2) throw new TypeError("Failed to fetch"); | ||
| return Response.json(SESSION); | ||
| }); | ||
| const registry = AtomRegistry.make(); | ||
| yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose())); | ||
| const observed: Array<string> = []; | ||
| registry.mount(session.atom); | ||
| registry.subscribe(session.atom, (result) => observed.push(result._tag)); | ||
|
|
||
| expect(yield* settle(registry, session.atom)).toMatchObject({ success: SESSION }); | ||
| registry.refresh(session.atom); | ||
| expect(yield* settle(registry, session.atom)).toMatchObject({ success: SESSION }); | ||
|
|
||
| expect(session.calls()).toBe(3); | ||
| expect(observed).not.toContain("Failure"); | ||
| }).pipe(Effect.scoped), | ||
| ); | ||
|
|
||
| it.effect("reports a failed first load without retrying", () => | ||
| Effect.gen(function* () { | ||
| const session = makeSessionAtom(async () => { | ||
| throw new TypeError("Failed to fetch"); | ||
| }); | ||
| const registry = AtomRegistry.make(); | ||
| yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose())); | ||
| registry.mount(session.atom); | ||
|
|
||
| const result = yield* settle(registry, session.atom); | ||
| expect(result._tag).toBe("Failure"); | ||
| expect(AsyncResult.isFailure(registry.get(session.atom))).toBe(true); | ||
| expect(session.calls()).toBe(1); | ||
| }).pipe(Effect.scoped), | ||
| ); | ||
| }); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
state/session.ts:57Revoked relay access is treated as transient, so a confirmed session keeps its old scopes and retries rejected credentials instead of surfacing the authorization failure; thread controls can remain enabled while the check waits.
mapRemoteEnvironmentErrorclassifies theRemoteEnvironmentAuthFetchErrorwrapper without inspecting its cause, so preserve or classify permanent authorization failures before retrying.🤖 Copy this AI Prompt to have your agent fix this: