Skip to content

Forward the session scope ref when spawning a shared-scope conversation - #402

Merged
ReganBell merged 1 commit into
mainfrom
upstream-1932
Aug 13, 2026
Merged

Forward the session scope ref when spawning a shared-scope conversation#402
ReganBell merged 1 commit into
mainfrom
upstream-1932

Conversation

@ReganBell

@ReganBell ReganBell commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

POST /v1/conversations with a channel-or group-scoped capability created the session but started the seed turn without the shared scope's channelRef, so the turn was refused and the caller got a 202 with no runId while an orphaned empty conversation stayed behind. The route now parses the validated session scope and forwards its ref as channelRef for channel and group scopes; personal scopes are unchanged. A refused seed turn now discards the just-created session and returns 409 seed_turn_refused instead of persisting an empty conversation. Route-and store-level tests cover the member spawn succeeding and the refusal path cleaning up.

Deployment notes

No schema change; adds SessionStore.deleteSessionIfEmpty implemented in both memory and
pg stores (guarded DELETE, safe on old data)
pg acquireLease now refuses a lease unless the sessions row exists (INSERT ... WHERE EXISTS)
— any out-of-tree caller that acquired a lease before inserting the session would break; in-tree
callers create first
New pg_advisory_xact_lock serialization around lease/delete: during the blue-green window old
instances don't take the lock, so the empty-session-discard race protection is only partial until
the deploy completes (transient, worst case is the pre-fix behavior)
POST /v1/conversations behavior change: a refused seed turn now discards the just-created
empty session instead of leaving it persisted (this is the fix)


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

POST /v1/conversations with a channel-or group-scoped capability created the session but started the seed turn without the shared scope's channelRef, so the turn was refused and the caller got a 202 with no runId while an orphaned empty conversation stayed behind. The route now parses the validated session scope and forwards its ref as channelRef for channel and group scopes; personal scopes are unchanged. A refused seed turn now discards the just-created session and returns 409 seed_turn_refused instead of persisting an empty conversation. Route-and store-level tests cover the member spawn succeeding and the refusal path cleaning up.

Co-authored-by: Hawthorn <217181565+lamenting-hawthorn@users.noreply.github.com>
@ReganBell
ReganBell merged commit 2f6d203 into main Aug 13, 2026
20 checks passed
@ReganBell
ReganBell deleted the upstream-1932 branch August 13, 2026 19:24
ReganBell added a commit that referenced this pull request Aug 13, 2026
…on (#402)

POST /v1/conversations with a channel-or group-scoped capability created the session but started the seed turn without the shared scope's channelRef, so the turn was refused and the caller got a 202 with no runId while an orphaned empty conversation stayed behind. The route now parses the validated session scope and forwards its ref as channelRef for channel and group scopes; personal scopes are unchanged. A refused seed turn now discards the just-created session and returns 409 seed_turn_refused instead of persisting an empty conversation. Route-and store-level tests cover the member spawn succeeding and the refusal path cleaning up.

**Deployment notes**

No schema change; adds SessionStore.deleteSessionIfEmpty implemented in both memory and
pg stores (guarded DELETE, safe on old data)
pg acquireLease now refuses a lease unless the sessions row exists (INSERT ... WHERE EXISTS)
— any out-of-tree caller that acquired a lease before inserting the session would break; in-tree
callers create first
New pg_advisory_xact_lock serialization around lease/delete: during the blue-green window old
instances don't take the lock, so the empty-session-discard race protection is only partial until
the deploy completes (transient, worst case is the pre-fix behavior)
POST /v1/conversations behavior change: a refused seed turn now discards the just-created
empty session instead of leaving it persisted (this is the fix)

<!-- codesmith:footer -->
---
<a href="https://app.blacksmith.sh/yc-software/codesmith/qm/pr/402"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-light-v2.svg"><img alt="View with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v2.svg"></picture></a> <a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1789239161&installation_model_id=19911&pr_number=402&repository=yc-software%2Fqm&return_to=https%3A%2F%2Fgithub.com%2Fyc-software%2Fqm%2Fpull%2F402&signature=32bea3cfc2a051226752fa3c313b61656c3cbfe98d410f25b30dbc5538c57ee0"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"></picture></a>
<sup>Need help on this PR? Tag <code>@codesmith-bot</code> with what you need. Autofix is disabled.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->
ReganBell added a commit that referenced this pull request Aug 14, 2026
The recent batch of squash merges lost their Co-authored-by trailers.
This commit restores the credit. Per merged PR:

- #381: @zlx, @leixf-lab
- #382: @lamenting-hawthorn
- #383: @lamenting-hawthorn
- #385: @lamenting-hawthorn
- #386: @lamenting-hawthorn
- #387: @ianTPE
- #402: @lamenting-hawthorn
- #454: @paucommit
- #470: @lamenting-hawthorn
- #476: @lamenting-hawthorn, @Dhevenddra, @Saidheerajgollu, @mariohercules, @foxytanuki
- #481: @Luke20w, @KateZhang98, @AdamSEY, @rsindall
- #482: @lucassz
- #494: @salluexez, @SomSamantray, @gregario, @yoldaolmak, @lamenting-hawthorn
- #512: @wooheum-xin, @Jackallink, @ianTPE, @lmo-selected, @xieqian0816, @hugo2046
- #515: @mariohercules, @Luke20w, @tchudleigh1, @Restry

Co-authored-by: adamsey <adam.lababidi@gmx.com>
Co-authored-by: Dhevenddra <dhevg20020402@gmail.com>
Co-authored-by: foxytanuki <biz@foxytanuki.dev>
Co-authored-by: Greg Jackson <gregj64@gmail.com>
Co-authored-by: hugo <shen.lan123@gmail.com>
Co-authored-by: Ian Chou <33033541+ianTPE@users.noreply.github.com>
Co-authored-by: Jackallink <61698219+Jackallink@users.noreply.github.com>
Co-authored-by: KateZhang98 <kate@tinyfish.io>
Co-authored-by: Hawthorn <rv.help23@gmail.com>
Co-authored-by: leixf-lab <289300866+leixf-lab@users.noreply.github.com>
Co-authored-by: lmo-selected <lmo-selected@users.noreply.github.com>
Co-authored-by: lucassz <4793515+lucassz@users.noreply.github.com>
Co-authored-by: Luke20w <weidnerluke@gmail.com>
Co-authored-by: Mario <643672+mariohercules@users.noreply.github.com>
Co-authored-by: Pau Garcia <193717438+paucommit@users.noreply.github.com>
Co-authored-by: Restry <restry@users.noreply.github.com>
Co-authored-by: rsindall <rsindall@users.noreply.github.com>
Co-authored-by: Sai Dheeraj Gollu <saidheeraj.gollu@sjsu.edu>
Co-authored-by: Mohd Salauddin <sallumalik1111@gmail.com>
Co-authored-by: Som Samantray <92726151+SomSamantray@users.noreply.github.com>
Co-authored-by: Tom <tchudleigh1@gmail.com>
Co-authored-by: Wooheum Xin <xin98@naver.com>
Co-authored-by: xieqian0816 <260077733+xieqian0816@users.noreply.github.com>
Co-authored-by: yoldaolmak <159899613+yoldaolmak@users.noreply.github.com>
Co-authored-by: Newell Zhu <zlx.star@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant