fix: bundle event inconsistency and other fixes
Summary
Two extension-events fixes plus one API-key migration:
- Reject
?keyspace=onGET /extensions/events— the route already derived keyspace server-side from the authenticated user, but a client-suppliedkeyspacequery param was silently dropped. Now returns a typed422 extension-events-keyspace-forbiddenso the contract is explicit. No CLI / frontend consumer sends this param today, so no integration impact. - Warnings parity on
bundle_reloadedevents — the polling hook'sbundle_reloadedhandler ignoredpayload.warnings, so a tab that picked up a warning-bearing reload via cross-tab polling (or the 30s mount-lookback after a refresh) saw only the green success toast while the clicking tab saw green + blue. Extracted the renderer to a shared module and wired the hook to emit the samesetSuccessData(with diagnostics inline) +setNoticeDatapair the click path already does. - api_key
expires_at→ TIMESTAMPTZ — naiveDateTimecolumn was breaking comparisons againstnow(); widen to timezone-aware on Postgres, no-op on SQLite. Phase: EXPAND (non-destructive widening, existing values reinterpreted as UTC).
Test plan
- [ ]
uv run pytest src/backend/tests/unit/api/v1/test_extension_events_endpoint.py src/backend/tests/unit/api/v1/test_extensions_route_guard.py— keyspace 422 + route-guard regression. - [ ]
cd src/lfx && uv run pytest tests/unit/extension/test_errors.py— newextension-events-keyspace-forbiddensnapshot. - [ ]
cd src/frontend && npx jest src/hooks/extensions/__tests__/use-extension-events.test.ts src/pages/FlowPage/components/flowSidebarComponent/components/__tests__/bundleHeaderActions.test.tsx— warnings notice on polled events + click-path parity. - [ ] Manual, warnings parity: with
LANGFLOW_ENABLE_EXTENSION_RELOAD=true, temporarily force a warning by making_fire_post_swap_hooksinlfx/extension/reload.pyreturn onereload-post-swap-hook-failedwarning. Click Reload on a bundle in tab A with tab B also open on the Flow page — both tabs should show green success toast + blue "Reloaded {bundle} with warnings" notice. Revert the forcing edit before pushing. - [ ] Manual, keyspace:
curl -H "x-api-key: $KEY" 'http://localhost:7860/api/v1/extensions/events?since=0&keyspace=user:other'→ 422 withcode=extension-events-keyspace-forbidden. Same call withoutkeyspace=→ 200. - [ ] Manual, migration (Postgres only):
make alembic-upgrade;\d apikeyshowsexpires_at timestamp with time zone.make alembic-downgrade; column reverts totimestamp without time zone.
Testing code reviewers can use (I'd advise QA against it to ensure they try to break this):
Set base + auth (api key from Settings → API Keys in the Langflow UI)
BASE="http://localhost:7860"
KEY="sk-..." # your Langflow API key
- Positive control: no keyspace → 200, returns events envelope
curl -sS -w '\nHTTP %{http_code}\n' \
-H "x-api-key: $KEY" \
"$BASE/api/v1/extensions/events?since=0"
- Rejection: client-supplied keyspace → 422 with typed envelope
curl -sS -w '\nHTTP %{http_code}\n' \
-H "x-api-key: $KEY" \
"$BASE/api/v1/extensions/events?since=0&keyspace=user:other-id"
- Empty-string keyspace is also rejected (still indicates client intent)
curl -sS -w '\nHTTP %{http_code}\n' \
-H "x-api-key: $KEY" \
"$BASE/api/v1/extensions/events?since=0&keyspace="
- Pretty-print just the typed error body for the rejection case
curl -sS -H "x-api-key: $KEY" \
"$BASE/api/v1/extensions/events?since=0&keyspace=global" \
| python -m json.tool
To force a warning add:
# TEMP: manual test for warning notice — revert before commit.
return (
ExtensionError(
code="reload-post-swap-hook-failed",
message=f"Synthetic warning for bundle {record.bundle!r}",
location=record.bundle,
content=record.bundle,
hint="This is a forced warning for manual UI testing; revert reload.py before committing.",
),
)
in the _fire_post_swap_hooks method first thing. IT should fire warnings every time you reload a bundle through CLI or UI Click.
Any of the cURL calls that work with an API key is a good test for the expires_at field TZ change.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID:
4241f258-d978-49f7-a2b7-2c2aaf820641You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- [ ] 🔍 Trigger review
Walkthrough
This PR introduces timezone-aware API key expiration handling and adds explicit validation/diagnostics to the extension events endpoint. The API key changes update the schema and add a centralized expiration check that handles naive timestamps as UTC. The extension events work rejects client keyspace parameters and shares warning/error formatting helpers between the frontend hook and bundle reload component.
Changes
API Key Timezone-Aware Expiration
| Layer / File(s) | Summary |
|---|---|
Model Schema and Database Migration src/backend/base/langflow/services/database/models/api_key/model.py, src/backend/base/langflow/alembic/versions/c35e9db03a66_make_api_key_expires_at_timezone_aware.py |
ApiKeyBase.expires_at column is defined as DateTime(timezone=True) and a new Alembic migration converts the PostgreSQL column from TIMESTAMP to TIMESTAMP WITH TIME ZONE, reinterpreting existing values as UTC. |
Centralized Expiration Check Logic src/backend/base/langflow/services/database/models/api_key/crud.py |
New _is_expired helper normalizes naive timestamps as UTC and treats None as not expired, replacing direct datetime comparisons in both hash-based and legacy authentication paths. |
Secrets Detection Baseline Refresh .secrets.baseline |
Line number for the crud.py hashed secret detection updated from 102 to 112 and generated_at timestamp refreshed. |
Extension Events Keyspace Validation and Warning Diagnostics
| Layer / File(s) | Summary |
|---|---|
Endpoint Keyspace Parameter Rejection and Error Definition src/backend/base/langflow/api/v1/extensions.py, src/lfx/src/lfx/extension/errors.py |
GET /extensions/events adds a keyspace query parameter that rejects any non-None value with typed 422 extension-events-keyspace-forbidden error; error rendering template added to the registry. |
Error Code Snapshot Expectation src/lfx/tests/unit/extension/test_errors.py |
Snapshot expectation entry added for extension-events-keyspace-forbidden error formatting validation. |
Endpoint Keyspace Validation Test Coverage src/backend/tests/unit/api/v1/test_extension_events_endpoint.py |
Unit tests verify keyspace parameter (including empty string) is rejected with typed 422 before service invocation, normal flow uses server-derived user:{id} keyspace, and validation occurs even when service is unavailable. |
Frontend Error and Warning Formatting Utilities src/frontend/src/hooks/extensions/typed-error-formatting.ts |
Introduces TypedErrorAlertList type and helpers renderTypedErrorList (formats error/warning arrays into titled diagnostic lists) and extractTypedErrorList (defensively validates event payload diagnostics). |
Hook Integration for Event Warnings and Diagnostics src/frontend/src/hooks/extensions/use-extension-events.ts |
useExtensionEvents now imports formatting helpers, extracts warnings from bundle_reloaded events, renders diagnostics into the success toast, and conditionally emits a notice when warnings are present. |
Component Refactoring to Use Shared Formatting src/frontend/src/pages/FlowPage/components/flowSidebarComponent/components/bundleHeaderActions.tsx |
Removes local renderTypedErrorList implementation and imports the shared helper from the formatting utilities module. |
Hook Test Coverage for Warning Diagnostics src/frontend/src/hooks/extensions/__tests__/use-extension-events.test.ts |
Tests verify bundle_reloaded events with payload.warnings emit success-toast diagnostics and a separate notice, empty warnings arrays produce no notice, and malformed payloads do not crash the hook. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- langflow-ai/langflow#13330: Introduces the initial
expires_atfield and expiration checking that this PR extends with timezone-aware handling. - langflow-ai/langflow#13253: Establishes the extension events service and event-bus groundwork that this PR builds upon for keyspace validation and warning diagnostics.
Suggested labels
bug, lgtm
Suggested reviewers
- erichare
- viktoravelino
- Jkavia
[!IMPORTANT]
Pre-merge checks failed
Please resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error, 3 warnings, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Test Coverage For New Implementations | ❌ Error | Frontend test claims to test "empty or missing" warnings but only tests empty array case; truly missing field case is not covered. | Add test case verifying hook handles bundle_reloaded events with warnings field completely omitted, or rename test to match actual coverage. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
| Test Quality And Coverage | ⚠️ Warning | Test "empty or missing" only tests empty array; doesn't verify payload without warnings field. Implementation handles both but test is incomplete. | Add test case with warnings field omitted from payload to verify missing field handling. |
| Test File Naming And Structure | ⚠️ Warning | Frontend test at line 240 claims to test "empty or missing" payload.warnings but only validates empty-array case, not missing-key case, overstating coverage. | Add test case for missing payload.warnings key, or rename test to "should NOT emit a warnings notice when payload.warnings is empty". |
| Title check | ❓ Inconclusive | The title 'fix: bundle event inconsistency and other fixes' is vague and uses the catch-all phrase 'other fixes', which does not clearly convey the specific changes (keyspace rejection, warnings parity, API key timezone awareness). | Revise the title to be more specific about the primary change, such as 'fix: enforce keyspace parameter rejection on events endpoint' or 'fix: add warnings parity for bundle reload events and API key expiry timezone awareness'. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| 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. |
| Excessive Mock Usage Warning | ✅ Passed | Mocks appropriately isolate units from external dependencies. Backend mocks service, frontend mocks API/stores. Both test real logic with isolated dependencies—standard unit testing practice. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
bundle-events-bug-fixes
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
✅ Migration Validation Passed
All migrations follow the Expand-Contract pattern correctly.
✅ Test Coverage Advisor
No source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉
Advisory check only — never blocks merge.
Codecov Report
:x: Patch coverage is 99.00990% with 1 line in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 56.44%. Comparing base (aafce55) to head (45f3362).
:warning: Report is 3 commits behind head on release-1.10.0.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| .../langflow/services/database/models/api_key/crud.py | 87.50% | 1 Missing :warning: |
:x: Your project check has failed because the head coverage (52.21%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files
@@ Coverage Diff @@
## release-1.10.0 #13374 +/- ##
==================================================
+ Coverage 56.37% 56.44% +0.07%
==================================================
Files 2208 2209 +1
Lines 209304 209374 +70
Branches 31408 29648 -1760
==================================================
+ Hits 117991 118182 +191
+ Misses 89951 89830 -121
Partials 1362 1362
| Flag | Coverage Δ | |
|---|---|---|
| backend | 61.49% <90.90%> (+0.12%) |
:arrow_up: |
| frontend | 56.24% <100.00%> (+0.07%) |
:arrow_up: |
| lfx | 52.21% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/backend/base/langflow/api/v1/extensions.py | 72.54% <100.00%> (+13.36%) |
:arrow_up: |
| ...langflow/services/database/models/api_key/model.py | 100.00% <100.00%> (ø) |
|
| ...end/src/hooks/extensions/typed-error-formatting.ts | 100.00% <100.00%> (ø) |
|
| ...ntend/src/hooks/extensions/use-extension-events.ts | 86.66% <100.00%> (+0.85%) |
:arrow_up: |
| ...idebarComponent/components/bundleHeaderActions.tsx | 93.03% <100.00%> (-1.05%) |
:arrow_down: |
| src/lfx/src/lfx/extension/errors.py | 88.00% <ø> (ø) |
|
| .../langflow/services/database/models/api_key/crud.py | 90.90% <87.50%> (+1.34%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.