fix(langfuse): stop paging when the cursor stops advancing - #5
Merged
Conversation
The page walk ended only on a falsy `meta.cursor`. An API that echoes back the cursor just sent — a server quirk, a partial-outage response, a proxy replaying a cached page — turned that into an unbounded loop: the same page re-requested forever, `rows` growing without limit, no output and no error. End the walk when the cursor repeats. The test drives a fake whose pages share a cursor and which raises past its last page, so an unguarded walk fails loudly instead of hanging the suite. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Closes #4.
LangfuseClient.observations()ended its page walk only on a falsymeta.cursor. If the API answers with a cursor echoing the one just sent — a server quirk, a partial-outage response, a proxy replaying a cached page — the loop never terminates. Every page is appended torows, so this is unbounded rather than merely slow: the same page is re-requested forever, memory grows without limit, and the caller sees no output and no error explaining why.Change
postflight/adapters/langfuse.py— read the next cursor intonxtand end the walk when it is falsy or equal to the current one.tests/test_langfuse_adapter.py— a fake client whose two pages return the same cursor, raisingIndexErrorpast the last page so an unguarded walk fails loudly instead of hanging the suite. Asserts the request count stops at two, both rows are kept, and the second request actually carried the cursor.Verification
98 tests pass. The new test fails with
IndexErrorwhen the one-line fix is reverted.No behaviour change to any detector.
🤖 Generated with Claude Code