Skip to content

fix(cli): Reuse the open session in sentry local run --session - #2484

Merged
MathurAditya724 merged 14 commits into
mainfrom
fix/local-run-session-reuse
Nov 25, 2026
Merged

MathurAditya724 merged 14 commits into
mainfrom
fix/local-run-session-reuse

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

sentry local run --session web used to create a new session every time, so two runs gave you two web sessions, name lookups warned about it, and a failed app start left an empty session behind.

Now runs (and serve --session) join the open session with that name and only create one when none is open. Each holds a lease. A session that runs created closes when the last one exits, including a run that was killed or lost its terminal: the daemon ends a run's lease once the run's event stream has stayed disconnected for 15 seconds, so a stream that drops and reconnects keeps it. A session from session create stays open until you close it. Reads by name still use the newest open session, and close/reset/retention still refuse an ambiguous name.

# before
$ sentry local run --session web -- node a.mjs &
$ sentry local run --session web -- node b.mjs
$ sentry local session list        # two "web" sessions

# after
$ sentry local run --session web -- node b.mjs
Joining open session web (0198…)
$ sentry local session list        # one "web" session with both apps' events

DSN-only SDKs (Go, Rust, Elixir, and Ruby, which drops the session path from SENTRY_SPOTLIGHT) had no working way in; the old help text pointed at a DSN the daemon 404s. Session create/view now include a dsn:

$ sentry local session view web --json | jq -r .dsn
http://key@127.0.0.1:8969/_local/v1/sessions/<id>/ingest/<cap>/0

run --session sets it as SENTRY_DSN when you haven't set one, for Go, Rust, Elixir, and Ruby commands, for detected Rails, Rack, Cargo, and Go apps, and for bin/ scripts, foreman, or overmind in a project with a Gemfile. It warns if a .env file also sets SENTRY_DSN.

Trade-off: Node.js and Python apps, and Deno apps on npm:@sentry/node, get only SENTRY_SPOTLIGHT, because those SDKs read both variables and would send every event twice. @sentry/deno never reads SENTRY_DSN, and compiled binaries aren't detected, so for those take dsn from session view <name> --json.

via @MathurAditya724.

--

View Session [Sentry]

`local run --session <name>` now joins the open session with that name
and creates one only when none is open, so concurrent runs share one
session instead of making look-alikes that trigger the "N open sessions
share that name" note. The daemon tracks a lease per run: a session runs
created closes when the last run exits, one made with `session create`
stays open, and a run whose app never starts removes the empty session
it created.

Session create and view now return a `dsn` for SDKs that only take a
DSN, on the address the daemon listens on. `run --session` sets
SENTRY_DSN to it when it is unset and the command is go, cargo, deno,
mix, iex, elixir, ruby, bundle, or rails. Node.js and Python apps keep
only SENTRY_SPOTLIGHT, because they read both and would send every event
twice. The help text no longer points session users at a DSN that the
daemon rejects.

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

vercel Bot commented Nov 24, 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 25, 2026 12:15pm UTC
sentry-local Ready Ready Preview Nov 25, 2026 12:15pm UTC

Request Review

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/cli/src/commands/local/run.ts Resolved
A run takes its session lease before it attaches to the stream, opens
the UI, and configures Wrangler. An error in any of those steps left
the lease held, so a session that runs created never closed. Give the
lease back, and drop the empty session, on those errors too.
The e2e stand-in for a Go app was a shebang script, which Windows can't
start. Write it as a .cmd wrapper there, like the batch-file tests do.
Comment thread packages/cli/src/commands/local/run.ts Resolved
Newer Rails apps start through sh or bash bin/dev, so the program name
alone missed them and the Ruby SDK could not reach the session. Treat a
detected Rails app as DSN-only too.
A killed run, a closed terminal, or an interrupt during setup left its
lease held, so the session stayed open and every later run joined it.
The daemon now ends a lease when the run's event stream disconnects, and
drops one whose stream never opened after 30 seconds.

serve --session joins and leases the session like run, so it no longer
closes a session a run still uses. Deno no longer gets SENTRY_DSN, Ruby
projects get it for bin/ scripts and process managers, detection marks
DSN-only apps with a typed field, and a run warns when a dotenv file also
sets SENTRY_DSN or when --max-envelopes can't change a joined session.

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>

@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.

Stale Bugbot comment from a previous run.

Ending the lease the moment a run's stream dropped closed the session
under a run that was still up, because the tail reconnects after a lost
stream. The daemon now counts the run's stream connections and ends the
lease only after 15 seconds with none, so a killed run still lets the
session close and a reconnecting run keeps it.

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>
…-reuse

# Conflicts:
#	design/sentry-local.md
…-reuse

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>

# Conflicts:
#	packages/cli/src/commands/local/run.ts
#	packages/cli/test/commands/local/server.test.ts

@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.

Requesting changes for the in-flight ingest cleanup race in the inline comment. Latest checked head: eb1c9b7. Its integration with current main c9929ac is exactly the tree retested with all five preceding merges included. The conflict resolutions are good; the cleanup code is unchanged and the data-loss race still reproduces 8/10 over real HTTP in this combined run (the two other deliveries completed before cleanup): release 204, ingest 500, session lookup 404, and one envelope in the orphaned buffer. Close and drain admitted receiver requests before deciding whether the session is empty enough to discard, and add the overlap regression test.

Other validation passed: 271 focused lifecycle/receiver tests before these rebase-only updates; real Node SDK/CLI checks for shared concurrent sessions, final-lease close, persistent manual sessions, failed startup and killed-run grace; and real Ruby SDK DSN delivery. These green checks do not cover the reproduced overlap. This data-loss finding is the remaining blocker; the PR is left unmerged.

@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.

Stale Bugbot comment from a previous run.

…-reuse

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>

@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 using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

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 eb1c9b7. Configure here.

sentry-junior Bot and others added 2 commits November 24, 2026 11:40
A failed run's release removed its empty session at once, while an
envelope already admitted could still be decoding. That ingest then
wrote into an orphaned buffer and failed with a 500. Release now closes
the session first, waits for admitted requests and writes, and removes
the session only if it is still empty and no run holds it.

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>
…-reuse

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>
serve --session now joins an open session, whose limit --max-envelopes
does not change. Serve now prints the same note as run, from one shared
helper.

@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.

The reported data-loss race is fixed on head f7bdb16. Reviewed the close/drain/recheck sequence and all release/discard call sites. The original real HTTP gzip reproducer now passes 10/10: ingest 200, release 200, session remains readable with its envelope. Independent edge probes pass for concurrent duplicate cleanup, active sibling leases, manual sessions, partial-body drain/rejection, and oversized decode cleanup. Real CLI/Node SDK tests pass for shared concurrent runs, failed spawn, manual-session persistence and killed-run grace; real Ruby SDK DSN delivery also passes. Integrated with current main 713b680: typecheck and full workspace tests passed (CLI: 13,807 tests), as did CLI lint, formatting, AST rules and dependency checks. All hosted checks on this head are green.

The PR is approved. I have not merged it because the required full root lint command fails on untouched main as well: packages/mcp-cloudflare/src/server/oauth/client-metadata-failure.integration.test.ts:33 has an unnecessary non-null assertion on handler.fetch. This file is unchanged by #2484. I verified that removing that one ! makes the full lint command pass, then restored it; that separate baseline repair is not included in this PR.

@MathurAditya724

Copy link
Copy Markdown
Member

The ingest-race fix is verified and approved. The remaining merge blocker is the full repository lint gate after integrating with current main.

pnpm run lint fails on untouched main (713b680d) as well as the PR integration:

packages/mcp-cloudflare/src/server/oauth/client-metadata-failure.integration.test.ts:33:10
typescript(no-unnecessary-type-assertion): This assertion is unnecessary since it does not change the type of the expression.

The verified fix is to remove the unnecessary non-null assertion in authorize():

-  return handler.fetch!(new Request(url), workerEnv, createExecutionContext());
+  return handler.fetch(new Request(url), workerEnv, createExecutionContext());

I temporarily applied this one-character change in the isolated review checkout and the complete pnpm run lint command passed, including formatting, AST rules and dependency checks; I then restored it. Please incorporate the fix with the latest main and rerun the quality gate before merge. No separate repair PR has been opened.

For context, #2484 already passed typecheck, the full workspace test suite (13,807 CLI tests), hosted checks on f7bdb166, the original real-HTTP race reproducer in all 10 attempts, additional cleanup edge cases, and real Node/Ruby SDK checks. Leaving this PR open for Junior to finish the lint repair.

sentry-junior Bot and others added 2 commits November 25, 2026 12:02
handler.fetch is already typed as defined, so the assertion trips
typescript(no-unnecessary-type-assertion) and fails the root lint gate
on main.

Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>
@sentry-junior

sentry-junior Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Done in 129aff3. I merged current main (713b680) in, which applied cleanly, then removed the unnecessary ! on handler.fetch in client-metadata-failure.integration.test.ts.

Quality gate on the merged tree:

  • pnpm run lint: passes. Without the fix, the same tree fails with that one no-unnecessary-type-assertion error.
  • pnpm run typecheck: passes.
  • pnpm run test: everything passed except 4 tests in the CLI's test/lib/telemetry-credentials.test.ts. They failed only in the full serial run, where the outgoing event envelope never arrived. That file passes 9/9 on its own, and fix(cli): Reuse the open session in sentry local run --session #2484 doesn't touch telemetry, so it looks like a timing flake under load.
  • Hosted checks on 129aff3: all green.

@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.

Re-reviewed exact head 129aff3 integrated with current main d064a2d. The remaining lint blocker is fixed by removing the unnecessary non-null assertion in the CIMD integration test. Full root typecheck, lint and workspace tests now pass. No remaining actionable findings.

Independent real HTTP QA reran the original compressed-envelope cleanup race: all 10 attempts returned ingest 200 and release 200, with the session and envelope readable. Additional probes passed for concurrent duplicate cleanup, active sibling leases, manual sessions, partial-body drain and clean 410 rejection, and oversized decode returning 413 before empty-session removal. Real CLI/Node SDK checks passed for shared concurrent runs, final-lease close, manual-session persistence, failed-start cleanup and killed-run grace; real Ruby SDK DSN delivery passed. All hosted checks and review threads were refreshed on this exact head before squash merge. The merged tree is verified against the tested integration tree.

@MathurAditya724
MathurAditya724 merged commit ade7299 into main Nov 25, 2026
45 checks passed
@MathurAditya724
MathurAditya724 deleted the fix/local-run-session-reuse branch November 25, 2026 13:35

This branch was successfully deployed

2 active deployments
Preview – sentry-local — 129aff34 Deployed Nov 25, 2026 by vercel[bot]
Preview – cli — 129aff34 Deployed Nov 25, 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