Skip to content

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

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

fix(handlers): keep root session span open across session.idle#71
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.

@dialupdisaster

Copy link
Copy Markdown
Contributor

Thanks for the PR. I took another pass on this after merging #74.

My read is:

What #74 did fix:

  • It fixes the main orphaned/fragmented later-turn trace problem that this PR is targeting.
  • Instead of keeping one root opencode.session span open across multiple session.idle events, fix(tracing): key root runs by user message id #74 changed the model so each user turn gets its own root run span.
  • That means later turns no longer depend on the original session span staying open in order for LLM/tool spans to remain connected.

What #74 did not fix:

  • It did not preserve the exact long-lived root-session-span behavior proposed here.
  • It also did not adopt the same session-wide cumulative totals model across multiple idle boundaries.

So I think #74 supersedes this PR for the tracing/orphan-span bug itself, but not for the separate question of whether session.total_* should represent a truly long-lived multi-turn session aggregate across repeated idle cycles.

From my side, that tracing fix is sufficient, and I would probably close this PR as superseded unless you specifically want to propose a follow-up focused only on session-wide accounting/log semantics across turns.

@dialupdisaster dialupdisaster added the bug Something isn't working label Jun 25, 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.

2 participants