Skip to content

fix(session-manager): let agents find and read archived sessions - #7128

Open
richard-fairthorne wants to merge 1 commit into
code-yeongyu:devfrom
richard-fairthorne:fix/session-search-archived-sessions
Open

fix(session-manager): let agents find and read archived sessions#7128
richard-fairthorne wants to merge 1 commit into
code-yeongyu:devfrom
richard-fairthorne:fix/session-search-archived-sessions

Conversation

@richard-fairthorne

@richard-fairthorne richard-fairthorne commented Aug 22, 2026

Copy link
Copy Markdown

Fixes #7125

What changed

Agents lost access to knowledge the moment a user archived a session: session_search silently skipped archived sessions (no opt-in existed) and session_list could not show them. This PR makes archived history discoverable again, following the approach recommended in the issue thread:

  • session_search includes archived sessions by default (opt-out via include_archived: false). Search is a discovery operation; the caller is rarely the same agent that archived the session, so a default-off flag would not fix the failure mode.
  • Active-first scan ordering. SDK sessions are partitioned by time.archived; archived ids are appended after active ids. Within the existing MAX_SESSIONS_TO_SCAN budget, archived sessions can never displace active ones, and every result findable before this change remains findable (strict superset).
  • session_list keeps its default (archived hidden, sidebar semantics) and gains include_archived: true to include them.
  • [archived] provenance marker on hits and rows, so the calling agent knows restore semantics may apply.
  • No changes to session_read / session_info (read path already fixed via the messages probe).

Implementation notes: getSdkAllSessions() now returns { active, archived } partitioned client-side; the stable SDK Session type does not declare time.archived yet (wire field), so the read is defensive. On servers that do filter archived sessions from GET /session, archived ids simply stay absent and behavior degrades gracefully to the pre-fix state.

Observed behavior (live QA)

Driven on real opencode 1.18.15 in an isolated XDG sandbox (HOME + XDG_* redirected, sandbox DB seeded with one active + one archived session containing a unique needle; archived session deliberately given the newer time_updated to stress ordering):

Call Result
session_search({query: needle}) Both sessions found; archived hit rendered [ses_qa_archived] [archived] ...; active hit listed before archived despite older time_updated
session_list({include_archived: true}) Both rows, archived row marked [archived], active first
session_list({}) Only the active session (unchanged default)

Also verified against the server: GET /session on 1.18.15 returns archived sessions with time.archived set, so the client-side partition works on the current release line. Full evidence (transcripts, isolation proof) in .omo/evidence/2026-08-22-session-search-archived/EVIDENCE.md.

Verification

  • bun test packages/omo-opencode/src/tools/session-manager/ — 74/74 pass (incl. new tests: search default-on, explicit opt-out, list default-off/opt-in, active-first append order, legacy sessions without time.archived treated as active, marker propagation, result-limit behavior)
  • tsgo --noEmit -p packages/omo-opencode/tsconfig.json — clean
  • Root-suite and full typecheck:packages cannot fully run in a fresh worktree (senpi/codex vendored artifacts are install-generated, not git-tracked); the failing tests there fail identically on clean dev in this environment and pass in a fully installed checkout. Not touched by this diff.
  • Live-surface QA per repo protocol (see Evidence above).

Residual risk

  • MAX_SESSIONS_TO_SCAN still bounds the scan (by design, unchanged); archived sessions consume the remaining budget after actives.
  • Behavior on servers that filter /session degrades to pre-fix (never worse).

Summary by cubic

Restore archived session discoverability for agents. Previously, session_search silently skipped archived sessions and session_list could not show them; now search includes archived by default (opt-out), and lists can include them with a flag, with clear [archived] markers.

  • Reviewer notes:
    • Active-first scan ordering: SDK sessions are partitioned by time.archived; archived IDs append after active IDs within MAX_SESSIONS_TO_SCAN, so archived never displace active.
    • session_search: new arg include_archived (default true). Matches from archived sessions are marked [archived].
    • session_list: default unchanged (archived hidden). New arg include_archived: true to include them; rows from archived sessions are marked [archived].
    • Storage API adjustments: SDK getSdkAllSessions() returns { active, archived }; getAllSessions() returns { ids, archivedIds }. Callers updated; file-backed fallback unchanged.
    • Compatibility: if servers omit archived sessions from GET /session, behavior degrades to pre-fix. Extensive tests cover defaults, opt-in/out, ordering, and marker propagation.

Written for commit 3495e08. Summary will update on new commits.

Review in cubic

Agents could no longer find content in sessions the user archived from
the UI. session_search silently skipped archived sessions with no way to
opt in, so research done weeks ago simply stopped existing for the
assistant. session_list had no way to show archived sessions either.

session_search now scans archived sessions by default (matches marked
[archived], active sessions always scanned first so archived ones never
displace them from the scan window). session_list keeps its old default
and gains include_archived: true to list archived sessions with the same
marker.

Fixes code-yeongyu#7125
@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

@github-actions github-actions Bot added the opencode OpenCode edition: packages/omo-opencode label Aug 22, 2026
@richard-fairthorne

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

opencode OpenCode edition: packages/omo-opencode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: session_search cannot find archived sessions — session.list() scan set silently drops time_archived sessions

1 participant