fix(runtime): flush pending telemetry at process exit - #108
Merged
kxzk merged 3 commits intoAug 17, 2026
Conversation
kxzk
force-pushed
the
feature/aai-388-flush-pending-spans-and-scores-at-process-exit
branch
from
August 17, 2026 14:41
14dba71 to
6badd09
Compare
kxzk
force-pushed
the
feature/aai-388-flush-pending-spans-and-scores-at-process-exit
branch
from
August 17, 2026 17:53
6badd09 to
29cf976
Compare
kxzk
changed the base branch from
feature/aai-389-make-langfuse-background-threads-fork-safe
to
main
August 17, 2026 17:56
kxzk
changed the base branch from
main
to
feature/aai-389-make-langfuse-background-threads-fork-safe
August 17, 2026 17:58
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 29cf976. Configure here.
kxzk
changed the base branch from
feature/aai-389-make-langfuse-background-threads-fork-safe
to
main
August 17, 2026 18:30
kxzk
changed the base branch from
main
to
feature/aai-389-make-langfuse-background-threads-fork-safe
August 17, 2026 18:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

TL;DRNormal process exit now flushes queued Langfuse spans and scores automatically.
WhyShort-lived tasks and one-off scripts could exit before SDK background workers delivered pending telemetry.
ChecklistCloses #
Note
Kade's words:
Summary
Normal process exit now flushes pending spans and scores. Applications do not need to register their own
at_exitcallback. ExplicitLangfuse.shutdownandLangfuse.reset!disable the pending callback for the current lifecycle.The callback runs once and catches shutdown errors. The callback inherits the fork-safe synchronization from the base PR. This PR targets the fork-safety branch so the unsafe exit-only behavior cannot land first.
Change diagram
flowchart LR accTitle: Automatic telemetry flush during process exit accDescr: A normal process exit runs one SDK callback that flushes queued spans and scores without allowing errors to escape. E["Normal process exit"] --> H["Run one SDK callback"] H --> T["Flush pending spans"] H --> S["Flush pending scores"] H --> G["Catch shutdown errors"] X["Explicit SDK shutdown"] --> D["Disable pending callback"]Verification
I ran the complete RSpec suite locally. All 1,581 examples passed. Line coverage was 96.51%.
I ran RuboCop against 101 files. RuboCop reported no offenses.
I ran a separate Ruby process with the SDK and did not call
Langfuse.shutdown. The process exited normally. The exit callback delivered trace93999b473b9b9d18d22d0e1537004e64and its queuedsdk-exit-hookscore. The Langfuse CLI read back both records.I did not test abrupt termination because
SIGKILLcannot run process-exit callbacks. I did not preview the rendered Mermaid diagram in GitHub. I reviewed the Mermaid source and syntax locally.Note
Medium Risk
Changes global process exit and configuration assignment behavior; failures are contained but every configured process now attempts shutdown on exit.
Overview
Adds automatic flushing of pending spans and scores on normal process exit, so scripts and short-lived processes no longer need their own
at_exit { Langfuse.shutdown }.A new
Langfuse::ExitHookregisters a singleKernel.at_exitcallback that runsLangfuse.shutdownonce, swallows shutdown errors (warns instead), and resets its mutex after fork viaForkSafety. The hook is enabled when configuration is first built (configuration/configuration=) and disabled by explicitLangfuse.shutdownorLangfuse.reset!so double-flush is avoided. Assigningconfiguration=now callsreset!first and starts a fresh lifecycle.CONFIGURATION.md documents the Process Exit behavior and updates the shutdown example away from manual
at_exit.Reviewed by Cursor Bugbot for commit f380f48. Bugbot is set up for automated code reviews on this repo. Configure here.