Skip to content

fix: use session exec in telemetry writer - #13821

Merged
erichare merged 1 commit into
release-1.10.2from
fix/release-1.10.2-telemetry-session-exec
Jun 24, 2026
Merged

fix: use session exec in telemetry writer#13821
erichare merged 1 commit into
release-1.10.2from
fix/release-1.10.2-telemetry-session-exec

Conversation

@erichare

@erichare erichare commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace telemetry writer SQLModel session.execute() calls with session.exec().
  • Align telemetry writer tests with the production SQLModel async session class.
  • Add coverage that turns the SQLModel session.execute deprecation warning into a test failure.

Tests

  • uv run pytest src/backend/tests/unit/services/telemetry_writer/test_service.py
  • uv run ruff check src/backend/base/langflow/services/telemetry_writer/service.py src/backend/tests/unit/services/telemetry_writer/test_service.py
  • uv run ruff format --check src/backend/base/langflow/services/telemetry_writer/service.py src/backend/tests/unit/services/telemetry_writer/test_service.py

Summary by CodeRabbit

  • Bug Fixes

    • Updated telemetry writes and retention cleanup to use the supported database session method, reducing deprecation-related issues.
    • Improved handling of telemetry buffering and cleanup so existing save and prune behavior continues to work reliably.
  • Tests

    • Added coverage to ensure telemetry flushing and retention do not trigger deprecated session warnings.
    • Adjusted existing test setup to match the updated session behavior.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Telemetry writer flush and retention queries now use AsyncSession.exec(...). The unit tests were updated to use SQLModel’s async session class, check for deprecated-session warnings, and align cancellation helpers with the new call path.

Changes

Telemetry writer exec migration

Layer / File(s) Summary
Flush uses exec
src/backend/base/langflow/services/telemetry_writer/service.py
_flush now uses session.exec(...) for transaction and vertex-build inserts, with transaction rows passed via params=tx_batch and dirty flow IDs still tracked per buffered row.
Retention uses exec
src/backend/base/langflow/services/telemetry_writer/service.py
_run_retention_pass now uses await session.exec(...) for transaction deletion, vertex-id selection, per-vertex deletions, and the global-cap delete, while keeping the existing dirty-flow snapshot and restore flow.
Telemetry writer tests
src/backend/tests/unit/services/telemetry_writer/test_service.py
The test session maker now uses SQLModel’s async session class, a new warning-based test checks _flush() and _run_retention_pass(), and cancellation/failure helpers were updated to use exec().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • langflow-ai/langflow#13126: Updates the same telemetry writer paths to use AsyncSession.exec(...) and adds related test coverage.

Suggested reviewers

  • dkaushik94
🚥 Pre-merge checks | ✅ 8 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: switching the telemetry writer to session.exec().
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Test Coverage For New Implementations ✅ Passed Yes: src/backend/tests/unit/services/telemetry_writer/test_service.py adds a regression test for _flush/run_retention_pass and uses the SQLModel async session class; naming matches test*.py.
Test Quality And Coverage ✅ Passed Tests are solid: real async pytest coverage against SQLite, explicit assertions on inserts/retention/failure paths, and a warning-regression check for the exec migration.
Test File Naming And Structure ✅ Passed PASS: backend test file is named test_service.py, uses pytest fixtures/async tests, descriptive names, and structured setup/teardown with positive/negative coverage.
Excessive Mock Usage Warning ✅ Passed Tests use a real in-memory SQLite engine/SQLModel session; only small purpose-built fakes for settings/cancellation, with no mock framework or core-logic mocking.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/release-1.10.2-telemetry-session-exec

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.

@github-actions github-actions Bot added the bug Something isn't working label Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Test Coverage Advisor

No source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉

Advisory check only — never blocks merge.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/backend/tests/unit/services/telemetry_writer/test_service.py (1)

347-361: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Good deprecation guard; consider one behavioral assertion.

This test only fails if the deprecated execute() path emits a warning — it asserts nothing about the flush/retention outcome. Since it already drives both code paths against a real in-memory SQLite, a cheap assertion (e.g. the expected post-retention row counts under max_*_to_keep = 1) would also catch a regression where exec() silently no-ops or the retention query shape breaks. Note this test also implicitly exercises the vertex-build .scalars() path flagged in service.py, so confirm it actually passes in CI.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/backend/tests/unit/services/telemetry_writer/test_service.py` around
lines 347 - 361, The deprecation guard in
test_flush_and_retention_do_not_call_deprecated_session_execute is good, but the
test should also assert the flush/retention result. After calling writer._flush
and writer._run_retention_pass, add a behavioral check on the in-memory DB
state, such as the expected row counts for transactions and vertex builds when
max_transactions_to_keep and max_vertex_builds_to_keep are both 1, so the test
catches silent regressions in writer._flush, writer._run_retention_pass, or the
vertex-build scalars path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/backend/tests/unit/services/telemetry_writer/test_service.py`:
- Around line 347-361: The deprecation guard in
test_flush_and_retention_do_not_call_deprecated_session_execute is good, but the
test should also assert the flush/retention result. After calling writer._flush
and writer._run_retention_pass, add a behavioral check on the in-memory DB
state, such as the expected row counts for transactions and vertex builds when
max_transactions_to_keep and max_vertex_builds_to_keep are both 1, so the test
catches silent regressions in writer._flush, writer._run_retention_pass, or the
vertex-build scalars path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6ad2ddbd-51b8-4904-b52d-caecd74c6826

📥 Commits

Reviewing files that changed from the base of the PR and between a66b75a and f5dd643.

📒 Files selected for processing (2)
  • src/backend/base/langflow/services/telemetry_writer/service.py
  • src/backend/tests/unit/services/telemetry_writer/test_service.py

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.57%. Comparing base (a66b75a) to head (f5dd643).
⚠️ Report is 1 commits behind head on release-1.10.2.

❌ Your project status has failed because the head coverage (54.62%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##           release-1.10.2   #13821      +/-   ##
==================================================
- Coverage           58.63%   58.57%   -0.07%     
==================================================
  Files                2307     2306       -1     
  Lines              220990   220169     -821     
  Branches            34290    32960    -1330     
==================================================
- Hits               129574   128956     -618     
+ Misses              89933    89729     -204     
- Partials             1483     1484       +1     
Flag Coverage Δ
backend 65.87% <100.00%> (-0.04%) ⬇️
frontend 57.68% <ø> (-0.09%) ⬇️
lfx 54.62% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...base/langflow/services/telemetry_writer/service.py 80.61% <100.00%> (ø)

... and 267 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 43%
43.54% (58072/133362) 69.2% (7884/11392) 41.56% (1298/3123)

Unit Test Results

Tests Skipped Failures Errors Time
4978 0 💤 0 ❌ 0 🔥 12m 30s ⏱️

@erichare
erichare merged commit 3b6d154 into release-1.10.2 Jun 24, 2026
120 of 121 checks passed
@erichare
erichare deleted the fix/release-1.10.2-telemetry-session-exec branch June 24, 2026 22:34
erichare added a commit that referenced this pull request Jun 26, 2026
Adapt the warning regression from #13821 for release-1.11.0, which already
uses SQLAlchemy AsyncSession via #13845.

(cherry picked from commit f5dd643)
erichare added a commit that referenced this pull request Jun 26, 2026
* fix: handle invalid session auth tokens (#13823)

* fix: handle invalid session auth tokens

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
(cherry picked from commit cf5c37f)

* test: cover telemetry writer session warning (#13821)

Adapt the warning regression from #13821 for release-1.11.0, which already
uses SQLAlchemy AsyncSession via #13845.

(cherry picked from commit f5dd643)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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