Skip to content

fix(ai-vault): prune remote OpenClaw discovery - #11395

Closed
Turtle-Hwan wants to merge 5 commits into
stablyai:mainfrom
Turtle-Hwan:agent/bound-remote-openclaw-discovery
Closed

Turtle-Hwan wants to merge 5 commits into
stablyai:mainfrom
Turtle-Hwan:agent/bound-remote-openclaw-discovery

Conversation

@Turtle-Hwan

@Turtle-Hwan Turtle-Hwan commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When loading OpenClaw history over SSH, Orca now searches the standard session folders while skipping unrelated caches. This avoids unnecessary directory scans and keeps the supported session history available.

Details

SSH AI Vault history scanned every subtree under .openclaw/agents and .clawdbot/agents, including embedded Codex homes and sibling caches. A fixture with 512 cache branches required 1,540 directory listings and exposed unrelated JSONL as OpenClaw history. Discovery now lists three directories for that fixture and returns only its canonical session.

Keep every agent directory, then descend only into its sessions subtree. Recursion within that subtree remains intact. The existing source/walker handles paths, cancellation and errors; unreadable canonical directories still report an issue while healthy agents remain visible. This covers current and legacy JSONL archive locations. It does not add support for OpenClaw's newer SQLite transcript store.

Fixes #11394.

Validation against main ef6eeab26e4a2ba817b19e8d68b37546f58d293e:

  • 1,133 tests passed across 126 AI Vault, IPC and remote-platform test files.
  • New scanner tests cover Linux/macOS/Windows remote path layouts, both state roots, multiple agents, nested canonical sessions, sibling pruning and partial read failures. Remote hosts are represented by the existing in-memory filesystem provider; no live Windows/SSH run is claimed.
  • Restoring baseline source fails four new regressions. The work-count check observes 1,540 listings on baseline versus 3 with the fix.
  • Node typecheck and all three changed-code quality gates pass. Tests ran with ORCA_BACKGROUND_LAUNCH=1.

The original contributor history is preserved and current main is merged into this branch. No rendered UI change or Electron launch. The remote provider owns all filesystem reads; this changes no RPC fields or process-status decisions. Existing scope-path handling supports folder workspaces as well as Git worktrees.

Supported folders and compatibility

Compatibility requires preserving the standard supported JSONL archive folders: ~/.openclaw/agents/<agent>/sessions/** and legacy ~/.clawdbot/agents/<agent>/sessions/**, including every agent and nested archives. The implementation and regression tests preserve both.

Manually relocated JSONL archives outside an agent's standard sessions subtree are no longer discovered by this scan. Their files are not deleted. Canonical nested session archives remain included; custom archive locations would need explicit support.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 109373d7-46dd-4ea5-9c54-2ee00512cd26

📥 Commits

Reviewing files that changed from the base of the PR and between 13462cc and 36a9e35.

📒 Files selected for processing (10)
  • src/main/ai-vault/remote-openclaw-discovery.test.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/remote-session-scanner-sources.ts
  • src/main/ai-vault/remote-session-scanner-types.ts
  • src/main/ai-vault/session-scanner-agent-sources.ts
  • src/main/ai-vault/session-scanner-discovery.ts
  • src/main/ai-vault/session-scanner-openclaw-layout.ts
  • src/main/ai-vault/session-scanner-openclaw-prune.test.ts
  • src/main/ai-vault/session-scanner-source-discovery.ts
  • src/shared/ai-vault-types.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change adds directory-level notice callbacks to local and remote session scanners. OpenClaw sources now descend only into each agent’s canonical sessions directory. Shared helpers report pruned transcript content while ignoring runtime-only directories. Local and remote tests cover canonical, nested, relocated, unreadable, and cross-platform paths.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 36a9e

OpenClaw discovery now limits scanning to canonical session directories while retaining nested session archives and reporting pruned transcript content. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.08% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: pruning remote OpenClaw discovery.
Description check ✅ Passed The description clearly explains the change, motivation, linked issue, compatibility impact, testing, platform coverage, and absence of UI changes. It does not reproduce every template heading or chec…
Linked Issues check ✅ Passed Issue #11394 requires discovery of every agent directory, descent only through that agent's canonical sessions directory, recursive discovery below it, and exclusion of sibling trees such as embedde…
Out of Scope Changes check ✅ Passed The changed discovery plumbing supports the linked objective. The shared OpenClaw predicate applies the same canonical layout to local, WSL, and remote scans. The directoryNotice path reports delibe…
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/ai-vault/remote-session-scanner.test.ts (1)

261-269: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover recursion inside the canonical sessions subtree.

The fixture only places the valid JSONL directly under main/sessions. Add a transcript below a nested directory there and assert it is discovered; otherwise a regression that stops recursion at sessions would still pass, despite the requirement to preserve recursive discovery.

Based on the PR objective to preserve recursive JSONL discovery within the canonical sessions subtree.

Also applies to: 280-285


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 998f1362-9dc4-4745-95b4-fea58ed46e6d

📥 Commits

Reviewing files that changed from the base of the PR and between 363e478 and c3f0328.

📒 Files selected for processing (2)
  • src/main/ai-vault/remote-session-scanner-sources.ts
  • src/main/ai-vault/remote-session-scanner.test.ts

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes excessive remote filesystem traversal in the OpenClaw discovery path by adding a directoryPredicate that prunes every depth-1 subdirectory of each agent folder except sessions, while still allowing unlimited recursion inside sessions/ itself (for date-bucketed JSONL layouts).

  • Source change: remoteOpenClawSources is refactored from jsonlSource (which has no directoryPredicate parameter) to the underlying source function, adding (name, depth) => depth !== 1 || name === 'sessions' as the directory gate — agent dirs (depth 0) and anything inside sessions/ (depth 2+) remain unrestricted; only sibling caches, plugin dirs, and nested runtime homes at depth 1 are pruned.
  • Regression test: The new test directly asserts both the discovered session IDs and the exact set of directories visited (provider.readDirPaths), confirming that agent/codex-home/sessions is never entered and that sessions/2026-07 is correctly traversed.

Confidence Score: 5/5

Safe to merge — the change narrows traversal scope with no risk of dropping legitimate sessions.

The predicate logic is correct at every depth: agent dirs (depth 0) are always entered, sessions is the only allowed entry at depth 1, and traversal inside sessions/ (depth 2+) is completely unrestricted. The regression test validates both discovered session IDs and the exact set of directories visited.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/ai-vault/remote-session-scanner-sources.ts Switches remoteOpenClawSources from jsonlSource to source, adds ['.jsonl'] explicitly, and introduces a directoryPredicate that prunes all depth-1 siblings of "sessions" while leaving agent-level (depth 0) and deeper (depth 2+) traversal unrestricted.
src/main/ai-vault/remote-session-scanner.test.ts Adds a regression test that verifies the canonical sessions subtree is walked (including date subdirectories) while nested agent homes (e.g. agent/codex-home/sessions) are never entered; a new messageGraphTranscript helper supplies parseable JSONL content for OpenClaw/Pi/OMP format tests.

Reviews (2): Last reviewed commit: "test(ai-vault): cover recursion inside t..." | Re-trigger Greptile

@AmethystLiang

Copy link
Copy Markdown
Contributor

looking into it

Review feedback. The fixture only placed a transcript directly under
main/sessions, so a regression that stopped recursing at sessions would still
have passed. Add one under a date directory and assert both the transcript and
the nested readdir.
@Turtle-Hwan

Copy link
Copy Markdown
Contributor Author

Addressed the review nitpick in 13462cc.

The fixture placed its only valid transcript directly under main/sessions, so a regression that stopped recursing at sessions would still have passed. Added one under a date directory (main/sessions/2026-07/) and asserted both that the transcript is discovered and that the nested directory is read — the readdir assertion now requires the extra level rather than allowing it.

m4air and others added 3 commits September 11, 2026 23:24
- Apply the same per-agent `sessions` directory predicate to the local
  OpenClaw source (local host and every WSL home) so local and SSH
  discovery agree for the same tree; shared in
  session-scanner-openclaw-layout.ts.
- Emit a 'notice' scan issue when an agent directory is pruned but holds
  transcripts outside <agent>/sessions, on both local and remote hosts.
- Regression tests: session-scanner-openclaw-prune.test.ts (local + WSL)
  and a pruned-archive case in remote-openclaw-discovery.test.ts.
@nwparker
nwparker marked this pull request as draft September 13, 2026 04:37
@nwparker nwparker added the wip Actively being worked on label Sep 13, 2026
@nwparker

Copy link
Copy Markdown
Contributor

Parking this for now — needs more thought, and it is not a priority.

Reviewed with the full readiness checklist and adversarially verified; no correctness defect was found. What is holding it is a deliberate product trade-off, not a bug, so it wants a decision rather than another round of patching.

The trade-off: the fix restricts OpenClaw discovery to each agent's canonical sessions/ subtree. Applied to the remote source only, local and SSH show different history for the same directory tree. Applied to both (the current state of the branch), parity is restored — but by extending the data loss to local: relocated archives such as ~/.openclaw/agents/main/archive/sessions/old.jsonl then disappear from local AI Vault and from search too, where before they only disappeared over SSH.

So: which is worse, an asymmetry between local and SSH, or uniform invisibility of relocated transcripts? A third option worth considering is keeping the fast canonical walk but emitting a scan issue when an agent directory containing candidate JSONL is pruned, so rows do not vanish silently.

Relay note for whoever picks this up: the host runs the scan, so a server that updates ahead of its clients silently narrows what every paired client sees, including older ones — no wire change involved, only published content. See docs/reference/remote-wire-compatibility.md.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks for putting this together, and sorry for the slow turnaround. The area has since been reworked and this is now covered on main by #27089 (bounded OpenClaw session discovery), so we're closing this as superseded. If you still see the problem on the latest build, please open a fresh report or reopen with a current repro. Thanks for the PR.

@nwparker nwparker closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip Actively being worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSH Agent Session History scans non-session OpenClaw subtrees

4 participants