Skip to content

fix: move session roots filter from client-side to SQL layer#24383

Open
heimoshuiyu wants to merge 2 commits intoanomalyco:devfrom
heimoshuiyu:fix/session-roots-filter
Open

fix: move session roots filter from client-side to SQL layer#24383
heimoshuiyu wants to merge 2 commits intoanomalyco:devfrom
heimoshuiyu:fix/session-roots-filter

Conversation

@heimoshuiyu
Copy link
Copy Markdown
Contributor

@heimoshuiyu heimoshuiyu commented Apr 25, 2026

Issue for this PR

Closes #16270
Closes #20238

Type of change

  • Bug fix

What does this PR do?

In TUI /session dialog, sdk.client.session.list() was called without roots: true, so subagent child sessions filled up the LIMIT 100 before root sessions. The TUI then filtered client-side, leaving almost nothing visible for heavy subagent users.

Fix: pass roots: true so the SQL adds WHERE parent_id IS NULL before the LIMIT. Remove the now-redundant client-side filter.

It make sense to do the filter at SQL level.

How did you verify your code works?

  • bun test test/session/session.test.ts — 4 pass
  • bun test test/project/project.test.ts — 32 pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

… from crowding out the LIMIT

Previously the TUI fetched all sessions (including subagent child
sessions) with LIMIT 100 and filtered client-side. This meant child
sessions could fill the limit, leaving few or no root sessions visible.

Now passes `roots: true` to the backend so `parent_id IS NULL` is
applied in the SQL query, reserving the full limit for root sessions.

Related anomalyco#16270, anomalyco#20238
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found:

  1. PR fix(tui): pass roots:true in session list bootstrap to fix child session dilution #16273 - "fix(tui): pass roots:true in session list bootstrap to fix child session dilution"

    • Likely related: Addresses the same issue of child sessions diluting root sessions in the UI, using the roots:true parameter
  2. PR fix(tui): request root sessions in switch session dialog #23276 - "fix(tui): request root sessions in switch session dialog"

    • Possibly related: Also deals with requesting root sessions in the TUI, suggesting the roots filtering is a recurring concern

Why they're related: These PRs appear to be addressing the same underlying problem of session listing being filled with child/subagent sessions before root sessions are visible. The current PR (24383) moves the filtering from client-side to the SQL layer, which may supersede or complement the earlier approaches in #16273 and #23276.

…bagent session leaks

The d7dfc72 commit moved the roots filter to SQL (roots: true) but
removed the client-side .filter((x) => x.parentID === undefined) guard.
While SQL filtering correctly reserves the LIMIT quota for root sessions,
subagent sessions can still enter the store via session.updated SSE events
which bypass the SQL layer. Adding the filter back as a defensive measure.
@heimoshuiyu
Copy link
Copy Markdown
Contributor Author

Just noticed removing the client-side filter means subagent sessions can show in /session via realtime SSE events. Pushed a follow-up commit to add it back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session list missing in TUI mode /sessions TUI only shows recent sessions, ignores historical ones

1 participant