feat(session): allow setting custom session ID when creating a session#13004
Open
sjawhar wants to merge 1 commit intoanomalyco:devfrom
Open
feat(session): allow setting custom session ID when creating a session#13004sjawhar wants to merge 1 commit intoanomalyco:devfrom
sjawhar wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
a847ac4 to
9ad4fbb
Compare
Author
|
@adamdotdevin this is ready for review: CI is passing and PR is mergeable. Could you review when you have a chance? |
806f7db to
c2b4476
Compare
141a273 to
e482f0a
Compare
Add optional `id` field to Session.create() with strict format validation (ses_ + 12 lowercase hex + 14 Base62). Duplicate IDs return 409 Conflict. - Add `id` field with regex validation to Session.create schema - Add duplicate session ID check before creation - Add DuplicateIDError (NamedError) with 409 status mapping - Update OpenAPI spec and regenerate SDK with id field + 409 response - Add 6 tests: custom ID, default behavior, duplicate, invalid prefix/format Closes anomalyco#12916 resolve: custom session id conflicts
e482f0a to
f5aa54b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds support for clients to provide a custom session ID when creating a session via
POST /session.POST /session {"id": "ses_<valid>"}creates a session with that exact IDPOST /session {}still auto-generates an ID (unchanged)^ses_[0-9a-f]{12}[0-9A-Za-z]{14}$— invalid formats return 400Changes
Source (4 files, +32 lines)
packages/opencode/src/session/index.ts— Addidfield with strict regex toSession.create()schema, duplicate check viaSession.get(), newDuplicateIDError(NamedError)packages/opencode/src/server/server.ts— MapDuplicateIDErrorto HTTP 409packages/opencode/src/server/error.ts— Add 409 to OpenAPI ERRORS map (lazy getter to avoid circular import at init time)packages/opencode/src/server/routes/session.ts— Document 409 in session.create route specTests (1 file, +77 lines)
packages/opencode/test/session/session.test.ts— 6 new tests: custom ID accepted, default behavior preserved, duplicate returns error, invalid prefix/format/charset rejectedGenerated (3 files)
./script/generate.tsTesting
bun test test/session/session.test.ts)bun run typecheck)curlagainst local server: 200/409/400 responses all correctCloses #2159