fix(playground): optimize canvas performance by limiting chat history fetch#13647
fix(playground): optimize canvas performance by limiting chat history fetch#13647gmrnlg1971 wants to merge 2 commits into
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe pull request extends the message history endpoint with pagination and ordering controls, while updating the frontend to conditionally fetch messages only when the session is visible and to pass the new pagination parameters. ChangesMessage History Pagination and Conditional Fetching
🎯 2 (Simple) | ⏱️ ~12 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error, 2 warnings, 1 inconclusive)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/backend/base/langflow/api/v1/monitor.py`:
- Around line 229-231: In get_messages validate the three query params at the
API boundary: replace the direct getattr(MessageTable, order_by) use with an
allow-list (e.g., acceptable_fields = {"id","timestamp","user_id",...}) and
return HTTP 400 if order_by is not in that set; validate order by normalizing to
upper() and only accept "ASC" or "DESC" (return HTTP 400 on other values) and
apply the corresponding ascending/descending ordering; validate limit to a safe
integer range (e.g., min 1, max reasonable cap like 1000), return HTTP 400 for
out-of-range or non-positive values, and only call stmt.limit(validated_limit)
with the sanitized value—make these checks in get_messages before building the
SQLAlchemy statement so invalid inputs are rejected at the API boundary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1715ebbe-b46d-4e92-a7a8-5d4890265248
📒 Files selected for processing (2)
src/backend/base/langflow/api/v1/monitor.pysrc/frontend/src/components/core/playgroundComponent/chat-view/chat-messages/hooks/use-chat-history.ts
| order_by: Annotated[str | None, Query()] = "timestamp", | ||
| order: Annotated[str | None, Query()] = "ASC", | ||
| limit: Annotated[int | None, Query()] = None, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify there is no existing validation/coverage gap around these params
rg -n -C3 'def get_messages\(|order_by|order:|limit:' src/backend/base/langflow/api/v1/monitor.py
rg -n -C3 'Invalid order_by field|get_messages\(|/messages' src/backend/tests src/backend/base/langflow/testsRepository: langflow-ai/langflow
Length of output: 50376
Validate /monitor/messages query params (order_by, order, limit) at the API boundary.
- In
src/backend/base/langflow/api/v1/monitor.py(get_messages, lines 229-267),order_byis used directly ingetattr(MessageTable, order_by)with no allow-list (unlike/messages/shared, which rejects invalid fields with HTTP 400). orderis treated as DESC only whenorder.upper() == "DESC"; any other value silently becomes ASC.limitis applied viastmt.limit(limit)with no bounds, enabling pathological values.
Add an allow-list for order_by, restrict order to ASC|DESC, and enforce min/max (or reasonable caps) for limit, returning 400 on invalid input instead of letting exceptions/expensive queries reach the DB layer.
🤖 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/base/langflow/api/v1/monitor.py` around lines 229 - 231, In
get_messages validate the three query params at the API boundary: replace the
direct getattr(MessageTable, order_by) use with an allow-list (e.g.,
acceptable_fields = {"id","timestamp","user_id",...}) and return HTTP 400 if
order_by is not in that set; validate order by normalizing to upper() and only
accept "ASC" or "DESC" (return HTTP 400 on other values) and apply the
corresponding ascending/descending ordering; validate limit to a safe integer
range (e.g., min 1, max reasonable cap like 1000), return HTTP 400 for
out-of-range or non-positive values, and only call stmt.limit(validated_limit)
with the sanitized value—make these checks in get_messages before building the
SQLAlchemy statement so invalid inputs are rejected at the API boundary.
f1b92c0 to
7555025
Compare
Fixes #13460
Description
Resolves canvas performance degradation after repeated Playground runs by limiting the number of messages fetched initially and only enabling the fetch when the playground is visible.
Changes
limitandorderquery parameters toGET /monitor/messagesto allow retrieving the latest N messages efficiently.useChatHistoryto conditionally enable the message fetch only whenvisibleSessionis true, preventing unnecessary background fetches on canvas changes.Summary by CodeRabbit
Release Notes