Skip to content

fix(web): allow directory collapse during session search - #1797

Open
techotaku39 wants to merge 2 commits into
tiann:mainfrom
techotaku39:investigate/session-search-folder-collapse
Open

techotaku39 wants to merge 2 commits into
tiann:mainfrom
techotaku39:investigate/session-search-folder-collapse

Conversation

@techotaku39

@techotaku39 techotaku39 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep matching directory groups expanded by default while filtering
  • allow users to explicitly collapse or expand a directory group during search
  • restore the directory's pre-filter collapse state when filtering is cleared, including when the selected session is temporarily filtered out

Problem / Motivation

When session search was active, directory groups were always forced open. The directory header remained clickable, but clicking it had no visible effect because the filtering state overrode the user's collapse choice. Selected-session auto-expansion could also rewrite the persistent collapse state after a filtered session group returned.

Validation

Final HEAD validation:

  • bun run --cwd web test -- src/components/SessionList.directory-action.test.tsx src/components/SessionList.test.ts src/components/SessionList.machine-filter.test.ts — 89 passed
  • bun typecheck — passed
  • bun run build — passed
  • pwsh -NoProfile -File .\scripts\Invoke-HapiTaskPlaywright.ps1 -Name investigate-session-search-folder-collapse -Suite Root terminal-wrap-fidelity.spec.ts — 2 passed

Baseline full-suite runs before the follow-up review fix:

  • bun run test — 28 unrelated Windows/CLI baseline failures; 2584 of 2612 tests passed
  • bun run test:web — 77 unrelated CRLF fixture serialization failures; 2871 of 2948 tests passed

Related Issues

Refs #1068

AI Disclosure

OpenAI Codex (GPT-5.6)

@github-actions github-actions Bot 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.

Findings

  • [Major] Selected-session auto-expansion can overwrite the pre-filter collapse state — the new filtered-state lookup at web/src/components/SessionList.tsx:1400 is bypassed by the existing unconditional persistent-map write at web/src/components/SessionList.tsx:1751. Collapse the currently selected group, search so that selected session disappears, then clear search: the effect resets its guard while filtered and writes false into collapseOverrides when the group returns, reopening it instead of restoring the collapsed state.

    Suggested fix:

    if (!group) {
        if (!isFiltering) autoExpandedSelectedSessionKeyRef.current = null
        return
    }
    
    const setOverrides = isFiltering ? setFilterCollapseOverrides : setCollapseOverrides
    setOverrides(prev => expandSelectedSessionCollapseOverrides(prev, group))

Questions

  • None.

Summary
Review mode: initial
One major correctness issue found in pre-filter state restoration. The added test uses selectedSessionId={null}, so it does not cover the normal selected-session interaction that triggers the issue.

Testing

  • Not run (automation): bun is unavailable in this runner. Static review of the full diff and surrounding session-group effects completed.

HAPI Bot

const isGroupCollapsed = (group: SessionGroup): boolean => {
if (isFiltering) return false
const override = collapseOverrides.get(group.key)
const override = isFiltering

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MAJOR] Selected-session auto-expansion bypasses the temporary filter state

isGroupCollapsed now reads filterCollapseOverrides during filtering, but the selected-session effect still calls setCollapseOverrides unconditionally at web/src/components/SessionList.tsx:1751. Reproduction: collapse the group containing the selected session, enter a query that removes that session/group, then clear the query. While filtered, the effect clears autoExpandedSelectedSessionKeyRef; when the group returns, it writes false to the persistent map and reopens the group, so the promised pre-filter collapsed state is lost. The new test avoids this path by rendering with selectedSessionId={null} at web/src/components/SessionList.directory-action.test.tsx:795.

Suggested fix:

if (!group) {
    if (!isFiltering) autoExpandedSelectedSessionKeyRef.current = null
    return
}

const setOverrides = isFiltering ? setFilterCollapseOverrides : setCollapseOverrides
setOverrides(prev => expandSelectedSessionCollapseOverrides(prev, group))

Also add a regression test with a selected session that is excluded and then restored by clearing the query.

@github-actions github-actions Bot 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.

Findings

  • None.

Questions

  • None.

Summary
Review mode: follow-up after new commits
No issues found in the latest full diff at ≥80% confidence. The prior selected-session state-restoration issue is addressed by keeping filtered auto-expansion in temporary state and preserving the guard while the selected session is filtered out (web/src/components/SessionList.tsx:1743, web/src/components/SessionList.tsx:1753); the added regression covers clearing that filter (web/src/components/SessionList.directory-action.test.tsx:825). Residual risk: runtime behavior was not independently exercised in this runner.

Testing

  • Not run (automation): bun is unavailable in this runner. Static review of the full latest diff, prior review context, and surrounding collapse/filter effects completed.

HAPI Bot

@heavygee heavygee added bug Something isn't working area:web Web PWA / React client community-pr PR from non-collaborator contributor labels Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:web Web PWA / React client bug Something isn't working community-pr PR from non-collaborator contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants