Skip to content

fix(handlers): keep root session span open across session.idle - #71

Closed
schemaitat wants to merge 1 commit into
DEVtheOPS:mainfrom
schemaitat:fix/session-idle-keep-span-open
Closed

schemaitat wants to merge 1 commit into
DEVtheOPS:mainfrom
schemaitat:fix/session-idle-keep-span-open

Conversation

@schemaitat

Copy link
Copy Markdown

Description

The opencode.session span and accumulated session totals were ended and deleted on the first session.idle event. Since a session keeps receiving turns after going idle, every subsequent turn's LLM/tool spans had no local session span to nest under and became orphaned root traces, with their token/cost contributions silently dropped from session.total_*.

Keeps the session span and totals alive across session.idle (only snapshotting attributes), and finalizes them in a new handleSessionDeleted handler, on session.error, or on process shutdown.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Chore (dependency updates, etc.)

Checklist

  • I have read the CONTRIBUTING.md document
  • My code follows the style guidelines of this project
  • bun run lint passes with no errors
  • bun run check:jsdoc-coverage passes with no errors
  • bun run typecheck passes with no errors
  • bun test passes with no errors
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • My commits follow the Conventional Commits specification

Related issues

Supersedes #64 and #70 — same fix, rebased as a single commit on current main on a proper feature branch.

Additional context

bun test — 282 pass, 0 fail.

The opencode.session span and accumulated session totals were ended
and deleted on the first session.idle event. Since a session keeps
receiving turns after going idle, every subsequent turn's LLM/tool
spans had no local session span to nest under and became orphaned
root traces, with their token/cost contributions silently dropped
from session.total_*.

Keep the session span and totals alive across session.idle (only
snapshotting attributes), and finalize them in a new
handleSessionDeleted handler, on session.error, or on process
shutdown.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@schemaitat, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 11 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2193124f-2d1c-4414-bb93-f9779627fc0d

📥 Commits

Reviewing files that changed from the base of the PR and between c9fee7f and 643ddc4.

📒 Files selected for processing (4)
  • src/handlers/session.ts
  • src/index.ts
  • tests/handlers/session.test.ts
  • tests/handlers/spans.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@schemaitat

Copy link
Copy Markdown
Author

Hi, thanks for the comment. I will reconsider. My goal was to track, debug and analyze long lived sessions using a session explorer built on top of the OTEL traces coming from this plugin. Maybe it would be worth enabling this using an env var since it also comes with downsides. What do you think ?

@schemaitat

Copy link
Copy Markdown
Author

Created a new PR for opt-in long running sessions. See #71.

@schemaitat schemaitat closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant