fix: include active root sessions in Recent sidebar

Recent now shows active root sessions immediately, even if they are older than 48 hours
Archived sessions and subtasks still stay out of Recent
Added coverage and documentation for the new recency rules
This commit is contained in:
Bohdan Triapitsyn
2026-07-23 16:46:20 +03:00
parent 89f7c37d60
commit 38222d07c8
4 changed files with 57 additions and 15 deletions
@@ -0,0 +1,39 @@
import { describe, expect, test } from 'bun:test';
import type { Session } from '@opencode-ai/sdk/v2';
import { deriveRecentSessions } from './activitySections';
const NOW = 200_000_000;
const RECENT = NOW - (48 * 60 * 60 * 1000);
const OLD = NOW - (72 * 60 * 60 * 1000);
const session = (id: string, options: { parentID?: string; archived?: number; updated?: number } = {}): Session => ({
id,
parentID: options.parentID,
time: { created: OLD, updated: options.updated ?? OLD, archived: options.archived },
} as Session);
describe('deriveRecentSessions', () => {
test('includes an old root session while it is active', () => {
const oldActive = session('old-active');
expect(deriveRecentSessions([oldActive], new Set([oldActive.id]), NOW)).toEqual([oldActive]);
});
test('does not promote active children or archived sessions into Recent', () => {
const child = session('child', { parentID: 'parent' });
const archived = session('archived', { archived: NOW - 1 });
expect(deriveRecentSessions(
[child, archived],
new Set([child.id, archived.id]),
NOW,
)).toEqual([]);
});
test('keeps inactive membership timestamp-based', () => {
const oldSession = session('old');
const recentSession = session('recent', { updated: RECENT });
expect(deriveRecentSessions([oldSession, recentSession], new Set(), NOW)).toEqual([recentSession]);
});
});