Skip to content

fix(logs): include subfolders when filtering logs by folder - #4525

Merged
waleedlatif1 merged 3 commits into
stagingfrom
waleedlatif1/fix-log-folder-filter
May 8, 2026
Merged

fix(logs): include subfolders when filtering logs by folder#4525
waleedlatif1 merged 3 commits into
stagingfrom
waleedlatif1/fix-log-folder-filter

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Folder filter on Logs page returned no results when a parent folder was selected because the SQL only matched workflows whose direct folderId was in the selected set
  • Added expandFolderIdsWithDescendants helper that expands selected folder IDs to include all descendant folders in the workspace, then wired it into the list, stats, and export endpoints before buildFilterConditions
  • Reported by Brandon Tarr — selecting ITSM_PUX showed an empty list even though logs existed in nested subfolders

Type of Change

  • Bug fix

Testing

Tested manually — selecting a parent folder now returns logs from the parent and every descendant; leaf folders behave the same as before. bun run check:api-validation passes.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@cursor

cursorBot commented May 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Adds server-side folder tree expansion that introduces an extra DB query on logs list/stats/export requests; main risk is performance/regression in filtering behavior for large folder hierarchies.

Overview
Fixes folder-based log filtering to include workflows in nested subfolders when a parent folder is selected.

Adds a server-only helper expandFolderIdsWithDescendants that loads the workspace’s folder tree and expands the folderIds CSV to include all descendants, then applies this expansion in the logs list, stats, and CSV export endpoints before calling buildFilterConditions.

Reviewed by Cursor Bugbot for commit 970299f. Configure here.

@vercel

vercelBot commented May 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedMay 8, 2026 11:48pm

Request Review

@greptile-apps

greptile-appsBot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a bug where filtering logs by a parent folder returned no results, because the SQL only matched workflows whose direct folderId was in the selected set. A new expandFolderIdsWithDescendants helper is introduced and wired into all three log endpoints (list, stats, export) to expand selected folder IDs to include all descendant folders before the filter condition is built.

  • folder-expansion.ts: Fetches all non-archived folders in the workspace, builds a parent→children adjacency map, then does a DFS from the seed IDs using a stack (O(n) traversal).
  • 3 route files updated: expandFolderIdsWithDescendants is called before buildFilterConditions in /api/logs, /api/logs/stats, and /api/logs/export, ensuring the descendant expansion applies consistently across all log views.

Confidence Score: 5/5

Safe to merge — the fix is well-scoped and the expansion helper is correctly integrated across all three log endpoints.

The new helper correctly fetches only non-archived workspace folders, builds the adjacency map once per request, and does a clean DFS traversal. The params mutation is safe (plain Zod-parsed object), all three endpoints apply the expansion before buildFilterConditions, and the hasWorkflowSpecificFilters check in the list route continues to behave correctly after expansion.

No files require special attention.

Important Files Changed

FilenameOverview
apps/sim/lib/logs/folder-expansion.tsNew helper that expands a CSV of folder IDs to include all descendant folders via DFS; correctly scoped to non-archived folders in the workspace.
apps/sim/app/api/logs/route.tsAdds folder ID expansion before buildFilterConditions; params.folderIds mutation on the Zod-parsed object is safe and the hasWorkflowSpecificFilters check downstream still behaves correctly.
apps/sim/app/api/logs/stats/route.tsExpansion applied consistently before filter condition build; no issues found.
apps/sim/app/api/logs/export/route.tsExpansion applied consistently before filter condition build; no issues found.

Sequence Diagram

sequenceDiagram
participant Client
participant LogsRoute as /api/logs (list|stats|export)
participant FolderExpansion as expandFolderIdsWithDescendants
participant DB_Folders as workflowFolder table
participant FilterBuilder as buildFilterConditions
participant DB_Logs as workflowExecutionLogs table
Client->>LogsRoute: "GET ?folderIds=parentId,..."
LogsRoute->>LogsRoute: "Parse & validate params"
alt params.folderIds is set
LogsRoute->>FolderExpansion: expandFolderIdsWithDescendants(workspaceId, folderIdsCsv)
FolderExpansion->>DB_Folders: "SELECT id, parentId WHERE workspaceId=? AND archivedAt IS NULL"
DB_Folders-->>FolderExpansion: all workspace folders
FolderExpansion->>FolderExpansion: Build parent-children map
FolderExpansion->>FolderExpansion: DFS from seed IDs (stack, pop)
FolderExpansion-->>LogsRoute: expanded CSV (parent + all descendants)
LogsRoute->>LogsRoute: "params.folderIds = expanded CSV"
end
LogsRoute->>FilterBuilder: buildFilterConditions(params)
FilterBuilder-->>LogsRoute: SQL inArray(workflow.folderId, expandedIds)
LogsRoute->>DB_Logs: Query with expanded folder filter
DB_Logs-->>LogsRoute: logs from all nested subfolders
LogsRoute-->>Client: response
Loading

Reviews (3): Last reviewed commit: "fix(logs): move folder expansion to serv..." | Re-trigger Greptile

Comment threadapps/sim/lib/logs/filters.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d13d662. Configure here.

@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 970299f. Configure here.

@waleedlatif1
waleedlatif1 merged commit 50d4afd into stagingMay 8, 2026
14 checks passed
@waleedlatif1
waleedlatif1 deleted the waleedlatif1/fix-log-folder-filter branch May 8, 2026 23:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@waleedlatif1