The issue is that:
- Cron sessions are hidden by
_hide_from_default_sidebar() in api/models.py
- The cron sessions are also filtered by
_cron_hide when CLI sessions are shown
- But when a project is selected, cron sessions assigned to that project should appear
The key problem is that cron sessions are filtered out before the project filtering happens. The all_sessions() function filters out cron sessions via _hide_from_default_sidebar(), and then the frontend filters by project. So cron sessions never make it to the frontend for project-based filtering.
Let me look more closely at how the frontend handles this. The frontend filters sessions by project using _activeProject. Let me see where the filtering happens and how the sessions are fetched.
Looking at the code flow:
all_sessions() is called which returns sessions filtered by _hide_from_default_sidebar() - this removes cron sessions
- The result is sent to the frontend
- The frontend filters by project_id using
_activeProject
So the fix should be to NOT hide cron sessions when a specific project is selected. The filtering should happen at the frontend level, not the backend level.
Wait, let me re-read the issue:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected."
So the issue is that cron sessions with a project_id assigned should show up when that project is selected.
Looking at the frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
The frontend filters sessions by project_id, but if the cron sessions are never returned from the API because of _hide_from_default_sidebar(), they can't be filtered by project.
The fix should be to allow cron sessions to pass through to the frontend when they have a project_id assigned, OR to change the frontend to not filter them based on project_id.
Let me look more closely at the _hide_from_default_sidebar function and understand what "default" means in this context.
The function _hide_from_default_sidebar returns True for cron sessions, meaning they are hidden from the "default" sidebar view. But the issue says that when a project is selected, these cron sessions should appear.
Looking at the code more carefully:
- In
all_sessions(), the result goes through _hide_from_default_sidebar() which filters out cron sessions
- Then
_preserve_messageful_sidebar_discoverability() tries to rescue hidden sessions but it explicitly skips cron sessions:
if _is_intentionally_background_sidebar_session(session):
continue
So cron sessions are completely excluded from the sidebar response.
The issue is that the backend (all_sessions()) filters out all cron sessions regardless of whether they have a project_id assigned. The frontend then tries to filter by project, but there are no cron sessions to filter.
The fix should be one of:
- Don't filter out cron sessions in the backend if they have a project_id
- Pass the filter criteria to the backend so it knows whether to filter cron sessions
- Handle the filtering in the frontend only
Let me look at how the session list endpoint receives the project filter:
From the frontend code, I see:
if(_activeProject&&_activeProject!==NO_PROJECT_FILTER) reqBody.project_id=_activeProject;
So the frontend sends project_id in the request body. Let me check if the backend uses this.
Looking at the /api/sessions endpoint, I don't see it using a project_id filter from the request. The filtering by project happens in the frontend.
So the solution should be:
- The backend should return cron sessions that have a project_id
- The frontend can then filter them by the selected project
Let me look at the all_sessions() function again to understand the flow better.
Actually, looking more closely at _preserve_messageful_sidebar_discoverability:
if _is_intentionally_background_sidebar_session(session):
continue
This explicitly skips cron/background sessions, even when trying to rescue messageful sessions.
The fix should be:
- In
all_sessions(), don't filter out cron sessions that have a project_id
- OR, make the filtering conditional based on whether a project is selected
Actually, the simplest fix is probably:
- Modify
_hide_from_default_sidebar() to NOT hide cron sessions that have a project_id
- This way, they will be included in the sidebar response
- The frontend will then filter them correctly when a project is selected
Wait, but the issue says "They remain hidden in default, unassigned, empty, and unrelated-project views." So the current behavior of hiding them in default views is correct. The issue is that they should appear when their assigned project is selected.
Let me think about this more carefully. The all_sessions() function in the backend filters out all cron sessions. These filtered sessions are never sent to the frontend. So when the frontend tries to filter by project, there are no cron sessions to show.
The fix could be:
- Change the backend to include cron sessions in the response
- Let the frontend handle all filtering
Or:
- Pass a flag to the backend indicating whether a specific project is selected
- If a specific project is selected, don't filter out cron sessions with that project_id
Actually, looking at the code flow again:
The frontend fetches sessions, then filters them by project. So if the backend returns all cron sessions (not just non-project ones), the frontend can properly filter them.
Let me look at what the _hide_from_default_sidebar function is supposed to do. It says "Return True for internal/background sessions hidden from the default list."
The key word is "default" - meaning sessions without a specific project filter should hide cron sessions, but when a specific project IS selected, cron sessions assigned to that project should show.
So the cleanest solution is:
- Don't filter out cron sessions in the backend
- Let the frontend handle all filtering based on the selected project
This means removing or modifying the _hide_from_default_sidebar call in all_sessions().
But wait, there might be a reason why cron sessions are hidden from the default view. Let me think...
The _hide_from_default_sidebar function hides cron sessions because they are "internal/background" sessions. They shouldn't clutter the default view. But when a user specifically selects a project that has cron sessions assigned, those sessions should appear.
Looking at the frontend filtering:
const projectFiltered =
_activeProject === NO_PROJECT_FILTER
? profileFiltered.filter(s => !s.project_id)
: (_activeProject ? profileFiltered.filter(s => s.project_id === _activeProject) : profileFiltered);
The frontend filters by project, but if the backend has already hidden the cron sessions, the frontend can't show them.
So the fix should be:
- In the backend, don't filter out cron sessions
- In the frontend, the project filtering will naturally hide cron sessions in the default view (when no project is selected) because they won't match the filter
Actually wait, looking at the frontend filtering more carefully:
: (_activeProject ? profileFiltered.filter(s => s.project_id === _activeProject) : profileFiltered);
When _activeProject is null (no project selected), it just returns profileFiltered without any additional filtering. So if the backend returns cron sessions, they would show in the default view.
Hmm, but the issue says cron sessions should be hidden in the default view. So we can't just include all cron sessions.
Let me re-read the issue:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected. They remain hidden in default, unassigned, empty, and unrelated-project views."
So the expected behavior is:
- Default view (no project selected): cron sessions are hidden
- Unassigned view: cron sessions are hidden (correct, they have a project)
- Empty view: cron sessions are hidden (correct, they're non-empty)
- Unrelated-project view: cron sessions are hidden (correct, they're assigned to a different project)
- Assigned-project view: cron sessions should be shown
The current behavior is that cron sessions are hidden in ALL views because the backend filters them out.
So the fix needs to:
- Include cron sessions in the backend response
- Let the frontend filter them based on the selected project
But how do we ensure cron sessions are hidden in the default view?
Looking at the frontend code again, the _activeProject is null when no project is selected. So profileFiltered.filter(s => s.project_id === _activeProject) would never match anything.
Wait, but when _activeProject is null:
: (_activeProject ? profileFiltered.filter(s => s.project_id === _activeProject) : profileFiltered);
It returns profileFiltered without any project filtering. So cron sessions would show up in the default view.
The issue is that we need to:
- Show cron sessions when their specific project is selected
- Hide cron sessions in the default view (when no project is selected)
One way to do this:
- Include all sessions (including cron) in the backend response
- Add a
_hide_from_default_sidebar flag to each session in the backend
- In the frontend, after project filtering, also apply this flag when no project is selected
Actually, I think the simpler approach is:
- In the backend
all_sessions(), don't filter out cron sessions based on project_id
- The frontend already has the logic to filter by project
But we need to ensure cron sessions are hidden in the default view. Let me look at the frontend code more carefully.
Actually, I just realized something. Looking at the frontend code:
const projectFiltered =
_activeProject === NO_PROJECT_FILTER
? profileFiltered.filter(s => !s.project_id)
: (_activeProject ? profileFiltered.filter(s => s.project_id === _activeProject) : profileFiltered);
When _activeProject is null (no project selected), it returns profileFiltered as-is. This means if the backend returns cron sessions, they would show in the default view.
But the issue says cron sessions should be hidden in the default view. So we need to ensure they're hidden.
The solution could be:
- Backend includes cron sessions in the response (without filtering by project)
- Frontend, when
_activeProject is null, applies an additional filter to hide cron sessions
Or:
- Backend includes cron sessions only if they have a non-null project_id
- Frontend filters based on project, and when no project is selected, cron sessions are hidden because they don't match the "no project" filter... wait, that doesn't work either.
Hmm, let me think about this differently. The issue is specifically about cron sessions with a project_id. What if:
- Backend always returns cron sessions (they have a project_id)
- Frontend, when no project is selected, applies
_hide_from_default_sidebar logic to hide cron sessions
- Frontend, when a project IS selected, shows cron sessions assigned to that project
Actually, I think the cleanest solution is simpler:
- Backend should not filter out cron sessions in
all_sessions()
- Frontend should handle the hiding/showing of cron sessions based on whether a specific project is selected
Let me look at the frontend filtering code more closely to understand where to add the fix.
From the frontend code around line 3289-3295:
// Filter by active project. NO_PROJECT_FILTER sentinel asks for sessions
// with no project_id; otherwise filter to the matching project_id, or
// show all.
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null, it returns all profileFiltered sessions. To hide cron sessions in this case, we need to add an additional filter.
But wait, the backend also filters cron sessions using _hide_from_default_sidebar. This function checks for cron sessions based on the source being 'cron' or session_id starting with 'cron_'.
So the fix could be:
- Backend: Remove the
_hide_from_default_sidebar call from all_sessions()
- Backend: Still call
_preserve_messageful_sidebar_discoverability() which tries to rescue hidden sessions (but it skips cron sessions)
- Frontend: Apply
_hide_from_default_sidebar logic only when no specific project is selected
Actually, I think the cleanest solution is:
- Backend: Include cron sessions in the response (remove
_hide_from_default_sidebar filtering)
- Frontend: When
_activeProject is null, filter out cron sessions from the result
Wait, but then we'd be duplicating logic. Let me think about this more.
Actually, the simplest solution might be:
- Backend: Modify
_hide_from_default_sidebar to NOT filter out cron sessions that have a project_id
- This way, cron sessions with a project_id will be included in the response
- The frontend will filter them correctly based on the selected project
Let me look at this approach:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
return True # Always hide cron sessions
...
If I change this to:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
# Only hide cron sessions in the default view (no project filter)
# Cron sessions with a project_id should be shown so the frontend
# can filter them by the selected project
return True # Still need to think about this
...
Hmm, this still doesn't work because the backend doesn't know whether a project filter is active.
Let me look at the backend endpoint handling again. When the frontend sends a request to /api/sessions, does it include the project filter?
Looking at the frontend:
if(_activeProject&&_activeProject!==NO_PROJECT_FILTER) reqBody.project_id=_activeProject;
So the frontend does send project_id in the request body. But the backend /api/sessions endpoint doesn't use it for filtering - it only uses all_profiles and the active profile.
Let me check if there's a way to pass this information to the backend.
Actually, I just realized something. The issue says:
"The behavior must be consistent across supported session retrieval modes."
This suggests there are multiple modes of retrieving sessions. Let me look at what those modes are.
Looking at all_sessions(), there are two paths:
- Index path (using
_index.json)
- Full scan path (scanning SESSION_DIR)
Both paths apply the same filtering. So the fix should be applied in all_sessions() which is used by both paths.
Let me think about this again. The issue is:
- Cron sessions are filtered out in
all_sessions()
- These filtered sessions never reach the frontend
- The frontend can't filter by project because the sessions are already gone
The fix should be to not filter out cron sessions in all_sessions(), so the frontend can filter them.
But we need to ensure cron sessions are hidden in the default view. This is where the frontend comes in.
Looking at the frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null, it returns profileFiltered as-is. If we want to hide cron sessions in this case, we need to add an additional filter.
But here's the thing - the frontend doesn't currently hide cron sessions. It relies on the backend to do that. If we let the backend return cron sessions, we need to also update the frontend to hide them in the default view.
So the fix involves:
- Backend: Don't filter out cron sessions in
all_sessions()
- Frontend: Add logic to hide cron sessions when no project is selected
Actually, let me re-read the issue more carefully:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected."
The key word is "assigned to a project". So the fix should be:
- Cron sessions WITH a project_id should be shown when that project is selected
- Cron sessions WITHOUT a project_id (unassigned) should remain hidden (or shown in the unassigned view?)
Actually, looking at the _hide_from_default_sidebar function, it doesn't check for project_id at all. It just checks if the session is a cron session and hides it regardless.
So the fix should be:
- In
all_sessions(), don't filter out cron sessions
- In the frontend, filter out cron sessions when no project is selected (default view)
Wait, but looking at the issue again:
"They remain hidden in default, unassigned, empty, and unrelated-project views."
This is describing the CURRENT behavior (bug), not the expected behavior. The expected behavior is:
- Default view: cron sessions are hidden (correct)
- Unassigned view: cron sessions are hidden (correct, they have a project)
- Empty view: cron sessions are hidden (correct, they're non-empty)
- Unrelated-project view: cron sessions are hidden (correct, they're assigned to a different project)
- Assigned-project view: cron sessions should be shown (BUG - currently hidden)
So the fix is to make cron sessions visible when their assigned project is selected.
Now, the question is: how to implement this?
Option 1: Backend returns all sessions (including cron), frontend filters
- Backend: Remove
_hide_from_default_sidebar filtering
- Frontend: Add logic to hide cron sessions when no project is selected
Option 2: Backend conditionally returns cron sessions based on project filter
- Backend: Accept a project filter parameter
- Backend: Only filter out cron sessions if no project filter is active
- Frontend: Pass the project filter to the backend
Option 3: Backend conditionally returns cron sessions based on project_id
- Backend: Only filter out cron sessions if they don't have a project_id
- Frontend: Already filters by project, so cron sessions will be shown correctly
Let me think about Option 3:
- If a cron session has a project_id, it's included in the backend response
- If a cron session doesn't have a project_id, it's filtered out
- Frontend filters by project_id, so cron sessions with a matching project_id are shown
This seems like the simplest fix. Let me verify by looking at the backend code:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
return True
...
If I change this to:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if (source == 'cron' or sid.startswith('cron_')) and not session.get('project_id'):
return True
...
This would include cron sessions with a project_id in the backend response. The frontend would then filter them correctly based on the selected project.
But wait, there's another place where cron sessions are filtered: _preserve_messageful_sidebar_discoverability():
def _preserve_messageful_sidebar_discoverability(
candidates: list[dict],
visible: list[dict],
) -> list[dict]:
...
for session in candidates:
...
if _is_intentionally_background_sidebar_session(session):
continue # Skip cron sessions
...
This also skips cron sessions. So even if I fix _hide_from_default_sidebar, the rescue logic won't rescue cron sessions.
But actually, the rescue logic is for rescuing hidden messageful sessions. If cron sessions with a project_id are no longer hidden (because _hide_from_default_sidebar returns False for them), the rescue logic won't apply to them.
Let me trace through the code again:
all_sessions() returns sessions
result = [s for s in result if not _hide_from_default_sidebar(s)] filters out cron sessions
visible_result = [s for s in result if not _hide_from_default_sidebar(s)] filters again
result = _preserve_messageful_sidebar_discoverability(result, visible_result) tries to rescue hidden sessions
If I change _hide_from_default_sidebar to not filter out cron sessions with a project_id:
- Cron sessions with a project_id will pass through
_hide_from_default_sidebar
- They will be included in
result and visible_result
- They won't be rescued by
_preserve_messageful_sidebar_discoverability because they're already visible
- They will be returned to the frontend
- The frontend will filter them correctly
This seems like the right fix. Let me verify by looking at the full all_sessions() function to make sure I understand the flow.
Looking at all_sessions() again:
result = sorted(index_map.values(), ...) # Sort
result = [s for s in result if not (s.get('title', 'Untitled') == 'Untitled' ...)] # Filter empty untitled
result = _prefer_fuller_snapshots_for_sidebar(result) # Prefer fuller snapshots
visible_result = [s for s in result if not _hide_from_default_sidebar(s)] # Hide cron sessions
result = _preserve_messageful_sidebar_discoverability(result, visible_result) # Rescue hidden sessions
_strip_sidebar_internal_flags(result)
So the flow is:
result = all sessions (after sorting, filtering empty untitled, preferring fuller snapshots)
visible_result = result with cron sessions hidden
result = result + rescued sessions from _preserve_messageful_sidebar_discoverability
If I change _hide_from_default_sidebar to not hide cron sessions with a project_id:
- Cron sessions with a project_id will be in
result and visible_result
- The rescue logic won't apply to them (they're already visible)
- They'll be returned to the frontend
This seems correct. Let me also check if there are any other places where cron sessions are filtered.
Looking at the /api/sessions endpoint in routes.py:
from api.models import _hide_from_default_sidebar as _cron_hide
deduped_cli = [s for s in cli if s["session_id"] not in webui_ids and is_cli_session_row_visible(s) and not _cron_hide(s)]
This also uses _hide_from_default_sidebar to filter CLI sessions. If I change _hide_from_default_sidebar to not filter out cron sessions with a project_id, CLI cron sessions with a project_id will also be included.
Wait, but this is for CLI sessions (from get_cli_sessions()), not WebUI sessions. Let me understand the difference:
- WebUI sessions: created from the WebUI
- CLI sessions: created from the command-line agent
Both types can be cron sessions. The issue says "Non-empty cron or background sessions assigned to a project", so it applies to both.
Let me also check _prefer_fuller_snapshots_for_sidebar:
for session in sessions:
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
continue # Skip cron sessions
This function doesn't include cron sessions in its logic. This is for pre-compression snapshots, which is a different concern.
OK, so my fix should be:
- Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- Change
_is_intentionally_background_sidebar_session to not skip cron sessions with a project_id (in _preserve_messageful_sidebar_discoverability)
Actually, wait. Let me re-read the issue:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected."
So the fix is specifically about cron sessions that are:
- Non-empty (have messages)
- Assigned to a project
Let me also check _is_intentionally_background_sidebar_session:
def _is_intentionally_background_sidebar_session(session: dict) -> bool:
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
return source == 'cron' or sid.startswith('cron_')
This is used in _preserve_messageful_sidebar_discoverability to skip cron sessions:
if _is_intentionally_background_sidebar_session(session):
continue
If I change _hide_from_default_sidebar but not _is_intentionally_background_sidebar_session, cron sessions with a project_id will still be skipped by the rescue logic. But this should be fine because they're already visible (not hidden by _hide_from_default_sidebar).
Actually, let me trace through the code again:
result = all sessions (after sorting, filtering empty untitled, preferring fuller snapshots)
visible_result = result with cron sessions hidden (via _hide_from_default_sidebar)
_preserve_messageful_sidebar_discoverability(result, visible_result) is called with:
candidates = result (includes cron sessions)
visible = visible_result (excludes cron sessions)
Inside _preserve_messageful_sidebar_discoverability:
for session in candidates:
sid = str(session.get('session_id') or '')
if not sid or sid in visible_ids:
continue # Skip if already visible
if _sidebar_message_count(session) <= 0:
continue # Skip empty sessions
if _is_intentionally_background_sidebar_session(session):
continue # Skip cron sessions
...
So the rescue logic:
- Skips sessions that are already visible (in
visible_ids)
- Skips empty sessions
- Skips cron sessions
If I change _hide_from_default_sidebar to not hide cron sessions with a project_id:
- Cron sessions with a project_id will be in
visible_ids
- The rescue logic will skip them because they're already visible
- They'll be included in
result and returned to the frontend
This is the correct behavior.
But there's a problem: the rescue logic also skips cron sessions regardless of whether they're visible. This is intentional - the rescue logic is for "messageful hidden sessions", and cron sessions are intentionally hidden.
If I change _hide_from_default_sidebar to not hide cron sessions with a project_id:
- Cron sessions with a project_id are not hidden, so they're in
visible_ids
- The rescue logic skips them because they're in
visible_ids
- They're returned to the frontend
- The frontend filters them by project
This is the correct behavior.
So my fix should be:
- Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- (Optional) Change
_is_intentionally_background_sidebar_session to match the new logic (but this shouldn't be necessary because the sessions will already be visible)
Actually, let me also consider _prefer_fuller_snapshots_for_sidebar:
for session in sessions:
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
continue # Skip cron sessions
This function processes sessions in groups by lineage root. It skips cron sessions. This is for pre-compression snapshots.
If a cron session has a project_id and is a continuation of a pre-compression snapshot, this function might not handle it correctly. But I think this is a separate concern from the issue at hand.
Let me focus on the main fix:
- Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
This will allow cron sessions with a project_id to pass through to the frontend. The frontend will then filter them correctly based on the selected project.
Actually, let me re-read the issue one more time:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected."
So the fix should make cron sessions visible when their project is selected. The current issue is that they're hidden regardless of whether a project is selected.
My fix (changing _hide_from_default_sidebar to not hide cron sessions with a project_id) should work for this case. When the user selects the project that the cron session is assigned to, the session will be included in the backend response and will be shown by the frontend.
Let me also consider edge cases:
-
What if a cron session doesn't have a project_id? It should still be hidden in the default view.
- My fix handles this:
_hide_from_default_sidebar will return True for cron sessions without a project_id.
- The frontend will filter them out when no project is selected.
-
What if a cron session has a project_id but the user doesn't select that project?
- My fix allows the cron session to pass through to the frontend.
- The frontend filters by project_id, so the cron session won't be shown.
-
What if a cron session has a project_id and the user selects that project?
- My fix allows the cron session to pass through to the frontend.
- The frontend filters by project_id, so the cron session will be shown.
This all looks correct. Let me implement the fix.
Wait, I just realized there might be another place where cron sessions are filtered. Let me check the _prefer_fuller_snapshots_for_sidebar function:
def _prefer_fuller_snapshots_for_sidebar(sessions: list[dict]) -> list[dict]:
"""Expose a hidden snapshot when it is the fuller transcript for a lineage."""
...
for session in sessions:
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
continue # Skip cron sessions
This function is for handling pre-compression snapshots. It skips cron sessions. This might be an issue if a cron session has a pre-compression snapshot that should be shown.
But looking at the issue description, it says "Non-empty cron or background sessions", not "pre-compression snapshots". So I think this is a separate concern.
Let me also check if there are any tests that I need to update.
OK, let me now implement the fix:
- Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- (Optional) Update
_is_intentionally_background_sidebar_session to match
Actually, I realize I should look at the code more carefully to understand the full picture. Let me look at the all_sessions function again and trace through the code flow.
Actually, I think I've analyzed this enough. Let me just implement the fix and test it.
Wait, there's another consideration. The frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null (no project selected), it returns profileFiltered as-is. If I include cron sessions with a project_id in the backend response, they will show in the default view (because they don't match the "no project" filter for the unassigned view).
Wait, no. Let me re-read this:
const projectFiltered =
_activeProject === NO_PROJECT_FILTER
? profileFiltered.filter(s => !s.project_id) // Filter to sessions with no project
: (_activeProject ? profileFiltered.filter(s => s.project_id === _activeProject) : profileFiltered);
- When
_activeProject === NO_PROJECT_FILTER: Filter to sessions with no project_id (unassigned view)
- When
_activeProject is a string (a specific project): Filter to sessions with matching project_id (project view)
- When
_activeProject is null (default view): Return profileFiltered as-is (no filtering)
So in the default view, if I include cron sessions with a project_id, they will show in the default view.
This is a problem because the issue says cron sessions should be hidden in the default view.
So I need to update the frontend to hide cron sessions in the default view. Let me look at the frontend code more carefully.
Actually, wait. Let me re-read the issue:
"They remain hidden in default, unassigned, empty, and unrelated-project views."
This describes the CURRENT behavior. But the question is: is this the expected behavior?
Looking at the issue again:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected. They remain hidden in default, unassigned, empty, and unrelated-project views."
The first sentence says they MUST be shown when their project is selected. The second sentence says they remain hidden in other views. This is describing the CURRENT BUGGY behavior, not the expected behavior.
So the expected behavior is:
- Default view: cron sessions should be hidden (currently hidden - correct)
- Unassigned view: cron sessions should be hidden (currently hidden - correct)
- Empty view: cron sessions should be hidden (currently hidden - correct)
- Unrelated-project view: cron sessions should be hidden (currently hidden - correct)
- Assigned-project view: cron sessions should be shown (currently hidden - BUG)
So the fix should:
- Make cron sessions visible when their assigned project is selected
- Keep cron sessions hidden in other views
To achieve this, I need to:
- Include cron sessions with a project_id in the backend response
- Update the frontend to hide cron sessions in the default view (when no project is selected)
Let me implement this.
Actually, thinking about this more, I wonder if the current behavior of hiding cron sessions in all views (including assigned-project views) is intentional. Maybe the system doesn't want cron sessions to clutter the sidebar at all. But the issue says they should be shown when their project is selected.
So the fix is:
- Backend: Don't filter out cron sessions with a project_id
- Frontend: Hide cron sessions in the default view (when no project is selected)
Let me implement this.
Actually, let me first check if there's a simple way to do this. Looking at the frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null, the frontend returns profileFiltered as-is. To hide cron sessions in this case, I can add an additional filter:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered.filter(s=>!isCronSession(s)));
But this is getting complicated. Let me think about this differently.
Actually, I think the cleanest fix is:
- Backend: Include cron sessions in the response (don't filter them out)
- Frontend: Apply the
_hide_from_default_sidebar logic after project filtering
Wait, but the frontend doesn't currently hide cron sessions. It relies on the backend to do that.
OK, here's my plan:
- Backend: Change
_hide_from_default_sidebar to NOT filter out cron sessions with a project_id
- Frontend: After project filtering, apply an additional filter to hide cron sessions in the default view (when no project is selected)
Actually, let me look at the frontend code again to see where the project filtering happens and where I should add the additional filter.
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
I can add an additional filter after this:
// Hide cron/background sessions in the default view (when no specific project is selected)
const defaultCronFilter =
!_activeProject
? projectFiltered.filter(s => !(s.source === 'cron' || s.session_id?.startsWith('cron_')))
: projectFiltered;
And then use defaultCronFilter instead of projectFiltered for subsequent processing.
Actually, let me look at the frontend code more carefully to understand the full flow.
OK, I think I've analyzed this enough. Let me start implementing the fix.
Actually, wait. Let me look at the backend code one more time. In all_sessions():
result = [s for s in result if not _hide_from_default_sidebar(s)]
visible_result = [s for s in result if not _hide_from_default_sidebar(s)]
result = _preserve_messageful_sidebar_discoverability(result, visible_result)
Wait, visible_result is the same as result after the first filter. This doesn't make sense. Let me re-read this...
Actually, I think the code is:
result = [s for s in result if not _hide_from_default_sidebar(s)]
After this, result contains all sessions except cron sessions. Then:
visible_result = [s for s in result if not _hide_from_default_sidebar(s)]
This is redundant - visible_result is the same as result.
Hmm, let me re-read the code...
Oh wait, I think the second line uses a different variable. Let me look at the code again:
result = sorted(index_map.values(), key=lambda s: ...)
result = [s for s in result if not (s.get('title', 'Untitled') == 'Untitled' ...)]
result = _prefer_fuller_snapshots_for_sidebar(result)
visible_result = [s for s in result if not _hide_from_default_sidebar(s)]
result = _preserve_messageful_sidebar_discoverability(result, visible_result)
So:
result = sessions after sorting, filtering empty untitled, preferring fuller snapshots
visible_result = result with cron sessions hidden
result = result + rescued sessions
After _preserve_messageful_sidebar_discoverability, result contains:
- All sessions from
visible_result (non-cron sessions)
- Any rescued sessions (messageful hidden sessions)
If I change _hide_from_default_sidebar to not hide cron sessions with a project_id:
visible_result will include cron sessions with a project_id
- The rescue logic will skip them because they're already visible
- The final
result will include cron sessions with a project_id
This is the correct behavior.
But then, in the default view (when no project is selected), the frontend will show cron sessions with a project_id. This is not the desired behavior.
So I need to:
- Backend: Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- Frontend: Hide cron sessions in the default view
Wait, actually, there's another consideration. Looking at the frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null (default view), it returns profileFiltered as-is. But profileFiltered is:
const profileFiltered =
settings.hide_cli_sessions
? _allSessions.filter(s => !s.is_cli_session)
: _allSessions;
So profileFiltered is _allSessions (with or without CLI sessions). And _allSessions comes from the API response.
If I include cron sessions in the API response, they'll be in _allSessions. And in the default view, they'll be returned by projectFiltered.
So I need to add an additional filter to hide cron sessions in the default view.
OK, let me now look at where in the frontend code I should add this filter.
Actually, I think a cleaner approach is to handle this entirely in the backend. Instead of:
- Backend: Include cron sessions with a project_id
- Frontend: Hide cron sessions in the default view
I can do:
- Backend: Return ALL sessions (including cron)
- Backend: Include a
_hide_from_default_sidebar flag for each session
- Frontend: Use this flag to decide whether to show the session in the default view
This way, the frontend can apply the same logic as the backend to determine which sessions to show.
Actually, this is getting complicated. Let me just implement the simpler fix:
- Backend: Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- Frontend: Add a filter to hide cron sessions in the default view
Let me implement this now.
Wait, I just realized there's another consideration. The issue says:
"The behavior must be consistent across supported session retrieval modes."
What are the supported session retrieval modes? Looking at the backend code:
- Index path (using
_index.json)
- Full scan path (scanning SESSION_DIR)
Both paths use all_sessions(), so my fix will apply to both.
But there's also the CLI session retrieval. Looking at the /api/sessions endpoint:
if show_cli_sessions:
cli = get_cli_sessions()
...
deduped_cli = [s for s in cli if s["session_id"] not in webui_ids and is_cli_session_row_visible(s) and not _cron_hide(s)]
So CLI cron sessions are also filtered by _cron_hide (which is _hide_from_default_sidebar). If I change _hide_from_default_sidebar, CLI cron sessions with a project_id will also be included.
This is the correct behavior - CLI cron sessions with a project_id should also be shown when their project is selected.
OK, I think I've analyzed this enough. Let me implement the fix now.
Let me first look at the current state of the code to make sure I understand it correctly.
Actually, let me just start by looking at the exact code and making the necessary changes. I'll start with the backend changes.
Let me look at _hide_from_default_sidebar again:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if source == 'cron' or sid.startswith('cron_'):
return True
if bool(session.get('pre_compression_snapshot')):
return not bool(session.get('_show_pre_compression_snapshot'))
return False
I need to change it to not hide cron sessions with a project_id:
def _hide_from_default_sidebar(session: dict) -> bool:
"""Return True for internal/background sessions hidden from the default list."""
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
if (source == 'cron' or sid.startswith('cron_')) and not session.get('project_id'):
return True
if bool(session.get('pre_compression_snapshot')):
return not bool(session.get('_show_pre_compression_snapshot'))
return False
And I need to update _is_intentionally_background_sidebar_session:
def _is_intentionally_background_sidebar_session(session: dict) -> bool:
sid = str(session.get('session_id') or '')
source = session.get('source_tag') or session.get('source')
return source == 'cron' or sid.startswith('cron_')
Actually, should I update this? Let me think...
This function is used in _preserve_messageful_sidebar_discoverability:
for session in candidates:
...
if _is_intentionally_background_sidebar_session(session):
continue # Skip cron sessions
The rescue logic skips cron sessions. If I change _hide_from_default_sidebar to not hide cron sessions with a project_id, then:
- Cron sessions with a project_id will be in
visible_ids
- The rescue logic will skip them because they're already visible (the first check is
if not sid or sid in visible_ids: continue)
So I don't need to update _is_intentionally_background_sidebar_session. The rescue logic will skip cron sessions with a project_id because they're already visible.
Wait, let me trace through the rescue logic:
def _preserve_messageful_sidebar_discoverability(
candidates: list[dict],
visible: list[dict],
) -> list[dict]:
sessions_by_id = {
str(session.get('session_id')): session
for session in candidates
if session.get('session_id')
}
covered_roots = {
_sidebar_lineage_root_id(session, sessions_by_id)
for session in visible
if _sidebar_message_count(session) > 0
}
visible_ids = {
str(session.get('session_id'))
for session in visible
if session.get('session_id')
}
rescue_by_root: dict[str, dict] = {}
for session in candidates:
sid = str(session.get('session_id') or '')
if not sid or sid in visible_ids:
continue # Skip if already visible
if _sidebar_message_count(session) <= 0:
continue # Skip empty sessions
if _is_intentionally_background_sidebar_session(session):
continue # Skip cron sessions
...
If I change _hide_from_default_sidebar to not hide cron sessions with a project_id:
- Cron sessions with a project_id will be in
visible
visible_ids will include their session IDs
- The rescue logic will skip them because
sid in visible_ids
So the rescue logic will correctly skip cron sessions with a project_id. This is the correct behavior.
OK, I'm confident in my fix. Let me implement it now.
Actually, wait. Let me also check the frontend code to make sure I understand where the project filtering happens.
From the frontend code:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
When _activeProject is null (default view), it returns profileFiltered as-is. If I include cron sessions with a project_id in the backend response, they'll be in profileFiltered. And in the default view, they'll be returned by projectFiltered.
So I need to add an additional filter in the frontend to hide cron sessions in the default view.
Let me find the exact location in the frontend code where I should add this filter.
Looking at the code, I think the filter should be added right after the project filtering:
const projectFiltered=
_activeProject===NO_PROJECT_FILTER
?profileFiltered.filter(s=>!s.project_id)
:(_activeProject?profileFiltered.filter(s=>s.project_id===_activeProject):profileFiltered);
// Hide cron/background sessions in the default view (when no specific project is selected)
const isDefaultView = !_activeProject && _activeProject !== NO_PROJECT_FILTER;
const projectAndCronFiltered = isDefaultView
? projectFiltered.filter(s => !(s.source === 'cron' || s.source_tag === 'cron' || s.session_id?.startsWith('cron_')))
: projectFiltered;
Actually, let me look at the frontend code more carefully. Let me search for where _activeProject is used.
OK, I think I have enough information to implement the fix. Let me start with the backend changes and then move to the frontend.
Let me re-read the issue description:
"Non-empty cron or background sessions assigned to a project must be shown when that project is selected. They remain hidden in default, unassigned, empty, and unrelated-project views. The behavior must be consistent across supported session retrieval modes."
So:
- Non-empty cron sessions assigned to a project must be shown when that project is selected
- They should remain hidden in other views (default, unassigned, empty, unrelated-project)
My fix:
- Backend: Change
_hide_from_default_sidebar to not hide cron sessions with a project_id
- Frontend: Add a filter to hide cron sessions in the default view
Let me implement this now.
Wait, I also need to check if there are any tests I need to update. Let me look at the tests directory.
Actually, let me first reproduce the issue and then fix it.
Let me look at the tests to understand how the issue can be reproduced.
Actually, let me just look at the test files that might be related to this issue.
Let me search for tests related to "cron" or "project":