fix: allow session id reuse after delete#2331
Open
QuentinBisson wants to merge 1 commit into
Open
Conversation
UpsertSession resurrects a soft-deleted (id, user_id) as a fresh incarnation: deleted_at is cleared, created_at restarts, and the previous incarnation's events, owned tasks, and shares are purged so the recreated session starts empty. Fixes kagent-dev#2279 Signed-off-by: QuentinBisson <quentin@giantswarm.io>
QuentinBisson
force-pushed
the
fix/session-recreate-after-delete
branch
from
July 25, 2026 13:21
0916d70 to
4ef9dc4
Compare
QuentinBisson
marked this pull request as ready for review
July 25, 2026 13:26
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue in the Go/Postgres persistence layer where a session ID could not be reused after a soft delete. It updates the UpsertSession SQL to properly “resurrect” a soft-deleted (id, user_id) session while preventing the recreated session from inheriting prior history.
Changes:
- Update
UpsertSessionto cleardeleted_at, resetcreated_atonly when resurrecting, and purge prior incarnation data (events, owned tasks, shares) in the same statement. - Regenerate SQLC outputs to reflect the new query and add doc comments on the generated Go interface/methods.
- Add database client tests covering session recreation after delete and ensuring live-session upserts preserve history.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| go/core/internal/database/queries/sessions.sql | Adjusts UpsertSession to resurrect soft-deleted sessions and purge prior data atomically. |
| go/core/internal/database/gen/sessions.sql.go | SQLC-generated Go wrapper updated for the new UpsertSession query and docs. |
| go/core/internal/database/gen/querier.go | SQLC-generated interface comment updated for UpsertSession. |
| go/core/internal/database/client_test.go | Adds tests validating recreate-after-delete behavior and no-op behavior for live upserts. |
Files not reviewed (2)
- go/core/internal/database/gen/querier.go: Generated file
- go/core/internal/database/gen/sessions.sql.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Discussed a similar case in this thread, related to resurrecting tasks. |
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.
Fixes #2279.
What
DeleteSessionsoft-deletes, butUpsertSession'sON CONFLICTupdate never cleareddeleted_at, so recreating a previously deleted session id upserted an invisible row: the create handler's own reload failed with 500 "Failed to load created session", forever. This breaks any client that derives session IDs deterministically from an external key.UpsertSessionnow resurrects a soft-deleted (id, user_id) as a fresh incarnation, in one statement:deleted_atand restartscreated_atNULL-owned tasks are left alone: the
created_atrestart already hides them from the new incarnation via the ownership bound in tasks.sql, and they may still resolve to another user's same-id session. Upserts of live sessions are unchanged (no purge,created_atpreserved).Tests
TestSessionRecreateAfterDelete(recreate succeeds; events/tasks/shares empty; another user's same-id session untouched) andTestUpsertLiveSessionKeepsHistory(no purge / nocreated_atreset on live upsert).