Skip to content

fix(cli): Resolve a reused Local session name to its newest open session - #2435

Merged
MathurAditya724 merged 6 commits into
mainfrom
fix/local-session-label-reuse
Nov 19, 2026
Merged

MathurAditya724 merged 6 commits into
mainfrom
fix/local-session-label-reuse

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Every sentry local run --session web creates a new session, so after the second run the name web matched two sessions and every lookup by name failed, even when the first run had already finished. Agents restart dev servers all the time, so this came up a lot.

Now reading by name just works. A name picks its open session, or the newest one if none is open. If several are open, reads use the newest and print one short note saying which one, with the others' IDs and ages. Session IDs work exactly as before.

Changing a session by name is stricter, because guessing wrong there can close someone's live run in another terminal. session close, reset and retention refuse a name that several open sessions share and list them with their state and age, so you can pick by ID. With only one open session under that name, closing by name still works.

Before:

$ sentry local event list web
Error: Local session name "web" matches more than one session.   (exit 23)

After:

$ sentry local event list web
2 open sessions share that name; using the newest, 019a…e1. Pass a session ID to use another: 019a…7c (open, started 4m ago).
ID         LEVEL  MESSAGE
…

$ sentry local session close web
Error: Local session name "web" matches more than one session.
  Use session ID 019a…e1 (open, started 1m ago)
  Use session ID 019a…7c (open, started 4m ago)

This lives in the one place in the daemon that already resolves session names, so event list, event view, session view, session close and the other session routes all follow the same rule. The note names at most five other sessions plus a count, so a pile of runs that were killed and never closed can't make it huge. A daemon started by an older CLI still returns its old error for any shared name, and the CLI still reports that as a normal user error. The --session docs and the Local design rules now describe how names resolve.

Possible follow-up: run --session could reuse a session that is still open under the same name instead of creating a new one each run. This PR doesn't change that.

via @MathurAditya724.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 19, 2026 17:58
Every `local run --session web` creates a new session, so after two runs
`web` matched two sessions and every lookup by that name failed with
"matches more than one session", even when the older run had closed.

The session store now resolves a name to its newest open session, or to
its newest session when none is open; session IDs still resolve exactly.
When several open sessions share the name, control responses name the
chosen session and the others in a header, and the CLI prints one stderr
note with each other session's ID, state, and age. The CLI still reports
an older daemon's 409 for a shared name as a user error.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 19, 2026 8:19pm UTC
sentry-local Ready Ready Preview Nov 19, 2026 8:19pm UTC

Request Review

Reads by a name that several open sessions share still use the newest,
but close, reset, and retention changes now answer 409 ambiguous_session
with each match's state and age, so a second `session close <name>`
cannot close a live run in another terminal. The CLI lists them as hints.

The choice header now names at most five other sessions plus a `more`
count, so a pile of runs that were killed and never closed cannot push
it past fetch's header limit. Each route resolves its session once, the
note also prints on error responses and only once per session, and the
header name lives in the session store instead of the Hono app module.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ea9be5d. Configure here.

Viewer UI actions authenticate with the session's stream capability, not
the control token, so the ambiguous-name 409 now lists the matching
sessions only for control clients, as the read-side choice header does.
@MathurAditya724

Copy link
Copy Markdown
Member

Review update: #2432 and #2433 are now on main. A merge preview for this exact head conflicts in packages/cli/src/commands/local/control-plane.ts, around session ingest. Please rebase on current main and preserve both the new ID-pinned session selection and #2432’s structured HTTP 200/JSON acknowledgement (including recordActivity on accepted outcomes). I am testing the session-store/control-plane/management behavior separately, but this PR needs a conflict-free updated head before it can be retested and merged.

sentry-junior Bot and others added 2 commits November 19, 2026 20:16
Keep #2432's 200 JSON acknowledgement for session ingest, recording
activity only for accepted envelopes, on the session ID resolved once
at the top of the handler.

Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
Co-Authored-By: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
@sentry-junior

sentry-junior Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the conflict. Both changes are kept: ingest still pins the session ID once at the top, and it now uses #2432's 200 JSON ack, recording activity only for accepted envelopes. I merged main in instead of rebasing, so the existing history stays as it was. #2434 came in clean in the same pass. Ready to retest.

@MathurAditya724 MathurAditya724 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed b578e8f integrated with current main after #2430. Checked deterministic newest-open selection, retained fallback, ID-pinned async routes, capability isolation, bounded choice headers, and ambiguous-write protection. The rebase preserves the accepted-ingest response and activity behavior.

Full workspace tsc, lint and test passed. Independent real daemon/CLI testing passed 13 scenarios: repeated-name reads, all three ambiguous mutations, exact-ID reads, selecting the next open session after close, and newest-retained fallback. No remaining actionable findings.

@MathurAditya724
MathurAditya724 merged commit a4b3ed2 into main Nov 19, 2026
43 checks passed
@MathurAditya724
MathurAditya724 deleted the fix/local-session-label-reuse branch November 19, 2026 20:58

This branch was successfully deployed

2 active deployments
Preview – sentry-local — b578e8fb Deployed Nov 19, 2026 by vercel[bot]
Preview – cli — b578e8fb Deployed Nov 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant