Repository navigation
fix(cli): Reuse the open session in sentry local run --session - #2484
Conversation
`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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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>
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
There was a problem hiding this comment.
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.
…-reuse Co-Authored-By: Aditya Mathur <aditya.mathur@sentry.io>
There was a problem hiding this comment.
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).
❌ 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.
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
left a comment
There was a problem hiding this comment.
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.
|
The ingest-race fix is verified and approved. The remaining merge blocker is the full repository lint gate after integrating with current main.
The verified fix is to remove the unnecessary non-null assertion in - 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 For context, #2484 already passed typecheck, the full workspace test suite (13,807 CLI tests), hosted checks on |
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>
|
Done in 129aff3. I merged current Quality gate on the merged tree:
|
MathurAditya724
left a comment
There was a problem hiding this comment.
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.

sentry local run --session webused to create a new session every time, so two runs gave you twowebsessions, 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 fromsession createstays open until you close it. Reads by name still use the newest open session, and close/reset/retention still refuse an ambiguous name.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 adsn:run --sessionsets it asSENTRY_DSNwhen you haven't set one, for Go, Rust, Elixir, and Ruby commands, for detected Rails, Rack, Cargo, and Go apps, and forbin/scripts,foreman, orovermindin a project with aGemfile. It warns if a.envfile also setsSENTRY_DSN.Trade-off: Node.js and Python apps, and Deno apps on
npm:@sentry/node, get onlySENTRY_SPOTLIGHT, because those SDKs read both variables and would send every event twice.@sentry/denonever readsSENTRY_DSN, and compiled binaries aren't detected, so for those takedsnfromsession view <name> --json.via @MathurAditya724.
--
View Session [Sentry]