-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(webapp): per-org S2 basin migration #3516
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
ericallam
merged 13 commits into
main
from
feature/tri-9073-stop-s2-chat-input-streams-from-being-deleted-while-sessions
May 5, 2026
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0f9d1de
feat(webapp,run-engine): per-org S2 basin migration
ericallam a1d4564
chore(webapp): server-changes file for per-org basin migration
ericallam 692a257
fix(webapp): address coderabbit review on per-org basin migration
ericallam d6d3586
refactor(webapp): drop plan vocabulary from streamBasinProvisioner
ericallam 054d1af
fix(webapp): address review on per-org basin migration
ericallam fc88017
refactor(webapp): per-org basins for paid orgs only
ericallam 97eb08e
fix(webapp): address review on per-org basin migration
ericallam 871b993
fix(webapp): early-return reconcile when per-org basins disabled
ericallam b065509
fix(webapp): row-optional session-channel routes default to org basin
ericallam f55746d
docs(webapp): clarify reconfigure admin route's default vs retention …
ericallam 684fc2e
chore(webapp): trim per-org-basin comments
ericallam 9cb611d
refactor(webapp): cloud-driven basin sync, drop reconcile worker
ericallam 4ce5998
fix(webapp): match writer basin in session-stream wait race-check
ericallam 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
fix(webapp): address review on per-org basin migration
- Use `org.id` (cuid, fixed-length, unique-by-construction) as the basin-name suffix instead of a truncated `org.slug`. The slug approach could silently collide two orgs whose slugs share a prefix past the truncation point, since the create call treats S2's 409 as success — a real cross-tenant isolation risk. - `resolveRetentionForOrg` now distinguishes "billing not configured" from "billing call failed". OSS / self-hosted installs (no billing client) get `defaultRetention()` and the worker job converges; cloud installs that experience a transient billing failure throw and get retried by redis-worker. Previously every install without billing hit a permafail loop. - `reconfigureBasinForOrg` throws when no S2 access token is configured instead of silently returning, so a misconfigured cloud install surfaces as a worker failure rather than stale retention. - Duration env vars (`*_RETENTION*`, `*_DELETE_ON_EMPTY_MIN_AGE`) validated at boot via a `durationString()` Zod schema, so a misconfigured value fails fast at startup instead of at first basin operation. - Admin reconfigure route's `retention` body field validated against the same duration shape — bad input is now a clean 400 rather than a 500 from `parseDuration`. - Extract duration parsing into a shared `duration.server.ts` so the env validator and the provisioner share one source of truth. Verified end-to-end with chat.agent locally — fresh chat lands in the per-org basin, no leakage to the global fallback.
- Loading branch information
commit 054d1afcdb8260e0951d57007d8f4b91a78cb27c
Some comments aren't visible on the classic Files Changed page.
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
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,49 @@ | ||
| /** | ||
| * Duration string parsing for stream-basin retention / delete-on-empty | ||
| * configuration. Used by `streamBasinProvisioner` (to convert to S2's | ||
| * integer-seconds wire format) and by `env.server.ts` (to validate | ||
| * duration-shaped env vars at boot rather than at first use). | ||
| * | ||
| * Accepts the short forms (`7d`, `30d`, `365d`, `1h`, `90m`, `45s`, | ||
| * `2w`, `1y`) and the human forms (`7days`, `1week`, `1year`). | ||
| */ | ||
|
|
||
| const PATTERN = | ||
| /^(\d+)\s*(s|sec|secs|seconds?|m|min|mins|minutes?|h|hour|hours?|d|day|days?|w|week|weeks?|y|year|years?)$/; | ||
|
|
||
| export function isValidDuration(input: string): boolean { | ||
| return PATTERN.test(input.trim().toLowerCase()); | ||
| } | ||
|
|
||
| /** | ||
| * Parse a duration string into seconds. Throws on garbage so a | ||
| * misconfigured env var fails loudly. Use {@link isValidDuration} | ||
| * for non-throwing validation (e.g. inside a Zod `.refine()`). | ||
| */ | ||
| export function parseDuration(input: string): number { | ||
| const trimmed = input.trim().toLowerCase(); | ||
| const match = trimmed.match(PATTERN); | ||
| if (!match) { | ||
| throw new Error(`Invalid duration string: ${input}`); | ||
| } | ||
| const value = parseInt(match[1]!, 10); | ||
| const unit = match[2]!; | ||
| const multiplier = | ||
| /^s/.test(unit) | ||
| ? 1 | ||
| : /^m(?:in|ins|inute|inutes)?$/.test(unit) | ||
| ? 60 | ||
| : /^h/.test(unit) | ||
| ? 3600 | ||
| : /^d/.test(unit) | ||
| ? 86400 | ||
| : /^w/.test(unit) | ||
| ? 604800 | ||
| : /^y/.test(unit) | ||
| ? 31_536_000 | ||
| : NaN; | ||
| if (!Number.isFinite(multiplier)) { | ||
| throw new Error(`Invalid duration unit: ${unit}`); | ||
| } | ||
| return value * multiplier; | ||
| } |
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.
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.