-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix(webapp): keep session runs off the legacy realtime streams backend #4564
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
matt-aitken
wants to merge
11
commits into
main
Choose a base branch
from
fix/streams-version-guard
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2eb19be
fix(webapp): never resolve realtime streams v2 without S2 configured
matt-aitken dab2957
fix(webapp): count per-org basins as S2 being configured
matt-aitken 6780a97
fix(webapp): require a basin that resolves, not the per-org flag
matt-aitken 1f90e9c
fix(webapp): keep session runs off the legacy realtime streams backend
matt-aitken 542dcc1
test(webapp): prove session runs route run-scoped streams to S2
matt-aitken 493d283
fix(webapp): follow the session's basin and consolidate the streams-v…
matt-aitken afaf3b4
fix(webapp): resolve a session run's version from the session's own b…
matt-aitken c36fecb
fix(webapp): gate the session run's version on the basin the run will…
matt-aitken ea239f2
test(webapp): cover the basin configuration that hid two bugs in review
matt-aitken e482967
test(webapp): remove assertions that could not fail and claims the te…
matt-aitken ec290c6
refactor(webapp): move the pure streams-version resolver out of the e…
matt-aitken 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,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: fix | ||
| --- | ||
|
|
||
| Realtime streams written inside a chat session run now use the same backend as the session itself, and runs are no longer created against a backend that cannot serve them. |
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
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
44 changes: 44 additions & 0 deletions
44
apps/webapp/app/services/realtime/realtimeStreamsVersion.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,44 @@ | ||
| /** | ||
| * Pure realtime-streams version resolution. Deliberately free of `env` and of | ||
| * any module-scope singletons so it can be tested with injected values, the | ||
| * same split as `nativeRealtimeClient` and `nativeRealtimeClientInstance`. | ||
| * The env-bound wrapper is `determineRealtimeStreamsVersion` in | ||
| * `v1StreamsGlobal.server.ts`. | ||
| */ | ||
|
|
||
| export type RealtimeStreamsVersionConfig = { | ||
| defaultVersion: "v1" | "v2"; | ||
| /** A basin that will actually resolve at read/write time, or undefined if none will. */ | ||
| basin?: string; | ||
| accessToken?: string; | ||
| skipAccessTokens: boolean; | ||
| }; | ||
|
|
||
| /** | ||
| * Resolve the streams version to stamp on a run, falling back to the | ||
| * deployment default when the caller expresses no preference. | ||
| * | ||
| * v2 is only ever returned when S2 can actually serve it. A run stamped v2 on a | ||
| * deployment without S2 is unusable: `getRealtimeStreamInstance` throws for the | ||
| * life of the run, and no read or write against its streams can succeed. v1 is | ||
| * a working backend, so an unsatisfiable v2 degrades to it. | ||
| * | ||
| * The basin must be one that will actually resolve later. Enabling per-org | ||
| * basins is not enough on its own: provisioning is out of band, so an | ||
| * unprovisioned organization has no basin and a global setting may not exist | ||
| * to fall back to. | ||
| */ | ||
| export function resolveRealtimeStreamsVersion( | ||
| streamVersion: string | undefined, | ||
| config: RealtimeStreamsVersionConfig | ||
| ): "v1" | "v2" { | ||
| const requested = streamVersion ?? config.defaultVersion; | ||
|
|
||
| if (requested !== "v2") { | ||
| return "v1"; | ||
| } | ||
|
|
||
| const hasCredentials = Boolean(config.accessToken) || config.skipAccessTokens; | ||
|
|
||
| return hasCredentials && Boolean(config.basin) ? "v2" : "v1"; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| resolveRealtimeStreamsVersion, | ||
| type RealtimeStreamsVersionConfig, | ||
| } from "~/services/realtime/realtimeStreamsVersion"; | ||
|
|
||
| const NO_S2: RealtimeStreamsVersionConfig = { | ||
| defaultVersion: "v1", | ||
| basin: undefined, | ||
| accessToken: undefined, | ||
| skipAccessTokens: false, | ||
| }; | ||
|
|
||
| const GLOBAL_BASIN: RealtimeStreamsVersionConfig = { | ||
| ...NO_S2, | ||
| basin: "a-basin", | ||
| accessToken: "a-token", | ||
| }; | ||
|
|
||
| const ORG_BASIN: RealtimeStreamsVersionConfig = { | ||
| ...NO_S2, | ||
| basin: "an-org-basin", | ||
| accessToken: "a-token", | ||
| }; | ||
|
|
||
| describe("resolveRealtimeStreamsVersion", () => { | ||
| it("honours an explicit v2 when a global basin is configured", () => { | ||
| expect(resolveRealtimeStreamsVersion("v2", GLOBAL_BASIN)).toBe("v2"); | ||
| }); | ||
|
|
||
| it("honours an explicit v2 when only an org basin is resolvable", () => { | ||
| expect(resolveRealtimeStreamsVersion("v2", ORG_BASIN)).toBe("v2"); | ||
| }); | ||
|
|
||
| it("accepts a skip-tokens deployment as credentialed", () => { | ||
| expect( | ||
| resolveRealtimeStreamsVersion("v2", { | ||
| ...NO_S2, | ||
| basin: "a-basin", | ||
| skipAccessTokens: true, | ||
| }) | ||
| ).toBe("v2"); | ||
| }); | ||
|
|
||
| it("degrades an explicit v2 to v1 when S2 is not configured", () => { | ||
| expect(resolveRealtimeStreamsVersion("v2", NO_S2)).toBe("v1"); | ||
| }); | ||
|
|
||
| it("falls back to the default version when the caller expresses no preference", () => { | ||
| expect( | ||
| resolveRealtimeStreamsVersion(undefined, { ...GLOBAL_BASIN, defaultVersion: "v2" }) | ||
| ).toBe("v2"); | ||
| }); | ||
|
|
||
| it("degrades a v2 default to v1 when S2 is not configured", () => { | ||
| expect(resolveRealtimeStreamsVersion(undefined, { ...NO_S2, defaultVersion: "v2" })).toBe("v1"); | ||
| }); | ||
|
|
||
| it("keeps a v2 default on v2 when only an org basin is resolvable", () => { | ||
| expect(resolveRealtimeStreamsVersion(undefined, { ...ORG_BASIN, defaultVersion: "v2" })).toBe( | ||
| "v2" | ||
| ); | ||
| }); | ||
|
|
||
| it("requires credentials, not just a basin", () => { | ||
| const basinOnly = { ...NO_S2, basin: "a-basin", defaultVersion: "v2" as const }; | ||
| expect(resolveRealtimeStreamsVersion(undefined, basinOnly)).toBe("v1"); | ||
| expect(resolveRealtimeStreamsVersion("v2", basinOnly)).toBe("v1"); | ||
| }); | ||
|
|
||
| it("requires a basin, not just credentials", () => { | ||
| const tokenOnly = { ...NO_S2, accessToken: "a-token", defaultVersion: "v2" as const }; | ||
| expect(resolveRealtimeStreamsVersion(undefined, tokenOnly)).toBe("v1"); | ||
| expect(resolveRealtimeStreamsVersion("v2", tokenOnly)).toBe("v1"); | ||
| }); | ||
|
|
||
| it("keeps an explicit v1 on v1 even where S2 is available", () => { | ||
| expect(resolveRealtimeStreamsVersion("v1", { ...GLOBAL_BASIN, defaultVersion: "v2" })).toBe( | ||
| "v1" | ||
| ); | ||
| }); | ||
|
|
||
| it("treats an unrecognised version as v1", () => { | ||
| expect(resolveRealtimeStreamsVersion("v3", GLOBAL_BASIN)).toBe("v1"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveRealtimeStreamsVersion invariant", () => { | ||
| const BASINS = [undefined, "", "a-basin"]; | ||
| const TOKENS = [undefined, "a-token"]; | ||
| const SKIPS = [false, true]; | ||
| const DEFAULTS: Array<"v1" | "v2"> = ["v1", "v2"]; | ||
| const REQUESTED = [undefined, "v1", "v2", "v3"]; | ||
|
|
||
| it("only returns v2 when a basin and credentials are both present, for every configuration", () => { | ||
| const counterexamples: string[] = []; | ||
|
|
||
| for (const basin of BASINS) { | ||
| for (const accessToken of TOKENS) { | ||
| for (const skipAccessTokens of SKIPS) { | ||
| for (const defaultVersion of DEFAULTS) { | ||
| for (const requested of REQUESTED) { | ||
| const config = { defaultVersion, basin, accessToken, skipAccessTokens }; | ||
| const usable = Boolean(basin) && (Boolean(accessToken) || skipAccessTokens); | ||
| if (resolveRealtimeStreamsVersion(requested, config) === "v2" && !usable) { | ||
| counterexamples.push(JSON.stringify({ requested, ...config })); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| expect(counterexamples).toEqual([]); | ||
| }); | ||
| }); |
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.