You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Speed up cwd-filtered listing and tidy up with clippy - #65
ah log in a project directory (the default, cwd-filtered listing) spent most of its time on work the result did not need. This PR removes that work, and tidies the code with clippy and a duplicate-code scan.
Performance
Sessions are mapped after the cwd/agent filters. Every session file used to be mapped before the filters ran, although most are rejected. Plugins that read the cwd from those bytes say so through the new AgentPlugin::cwd_in_session_bytes (pi).
The Claude cwd is read from the first 32 KiB instead of mapping the whole file. When those bytes do not decide it (a longer file whose complete lines name no cwd, or not a regular file), the previous path is used.
Running sessions are looked up while the files are scanned, one thread per plugin. This step used to run serially after the parallel stage and took about 30 ms.
Model lines are found by searching for the needle (LinesWith) instead of splitting the file into lines and searching each line.
Refactoring
ah project: projects that tie on the sort field are ordered by name. They used to follow hash map order, so the output changed between runs. This is the only intended change in output.
remote.rs: the two functions that forward filters to the remote ah share push_value / push_flag / push_limit. Order and conditions are unchanged.
search.rs: search_prompts and search_texts share match_context.
The remaining byte-at-a-time line splits over session data use jsonl_lines.
A selected set of clippy pedantic/nursery fixes (map_or, let … else, redundant clones, Eq derives, raw string hashes). Lints that only produce churn (use_self, inlined format args) were left out.
Performance
About 9,800 session files, 32 threads, warm page cache, hyperfine:
command
before
after
ah log
118 ms
48 ms
ah -q tokio log
116 ms
48 ms
ah -a project
66 ms
45 ms
ah -a log
694 ms
642 ms
ah -a -q tokio log
577 ms
557 ms
With RAYON_NUM_THREADS=4, ah log went from 122 ms to 80 ms (measured before the last two fixes of this branch).
Known limitations
-a commands gain little: they are bound by reading about 10 GB of JSONL on every run. Going further needs a per-file result cache, which is not part of this PR.
A Claude session whose cwd is not within the first 32 KiB (about 3% on the test host) is read twice: the head, then the mapping.
pi has no sessions on the test host, so its path was checked by reading the code and its unit tests only.
Release builds of main and this branch give identical output on real data for log (with and without -a, --json, -q, -p -q, --raw-search, --running, --subagents, -o id,cwd,project, -o id,model,models, -o id,turns,first_prompt), memory, agent and show. project differs only in the order of tied rows.
New unit tests: LinesWith against a line-by-line scan, the Claude cwd from the head against the whole file (including the 32 KiB boundary), and a FIFO as a session path.
- Map session files only after the cwd/agent filters, unless the plugin
reads the cwd from those bytes.
- Read the Claude cwd from the first 32 KiB instead of mapping the file.
- Look up running sessions while the files are scanned, one thread per
plugin.
- Find model lines by searching for the needle instead of splitting the
file into lines first.
- Sort projects by name before the stable sort, so ties no longer follow
hash map order.
- Share the option forwarding of the remote commands and the match
context of the searches; use `jsonl_lines` for every line split.
- Apply a selected set of clippy pedantic/nursery fixes.
Claude-Session: https://claude.ai/code/session_013M2MLyLFJxdYU9rz7M7Utt
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical issue in src/agents/claude.rs can cause cwd resolution to reopen a FIFO and block indefinitely; non-regular files must return Some(None) to avoid the mapping fallback.
This PR speeds up directory-filtered listing in the cross-agent history CLI by avoiding unnecessary session reads and overlapping running-session detection with scanning. It also makes tied project ordering deterministic and applies targeted cleanup.
Changes:
Delay session mapping until after early filters, read Claude cwd from a bounded prefix, and accelerate model-line searches.
Run plugin running-session lookups concurrently.
Share filtering and search helpers, standardize JSONL iteration, and simplify code with clippy fixes.
File
Description
tests/search.rs
Simplify a raw-string fixture.
tests/cloud.rs
Add a closure statement terminator.
tests/cli.rs
Clean up fixture syntax.
src/subcmd.rs
Simplify agent lookup defaults.
src/show.rs
Simplify field access and statement syntax.
src/search.rs
Share match-context extraction.
src/resume.rs
Simplify resume-command lookup.
src/resolver.rs
Simplify defaults and remove a prompt clone.
src/remote.rs
Share remote argument helpers.
src/projects.rs
Order tied projects by name.
src/pipeline.rs
Delay mapping and overlap running detection.
src/pager.rs
Simplify stdin extraction control flow.
src/output.rs
Simplify output field defaults.
src/memory.rs
Simplify metadata and parsing expressions.
src/mcp/tools.rs
Remove a clone and simplify body sizing.
src/fuzzy.rs
Simplify field access and patterns.
src/config.rs
Simplify configuration handling.
src/cloud/providers.rs
Simplify coverage fallback and fixture ownership.
src/cli.rs
Add equality derives and simplify expressions.
src/agents/pi.rs
Declare byte-backed cwd resolution.
src/agents/opencode.rs
Simplify a JSONC matching pattern.
src/agents/mod.rs
Add cwd capability and concurrent running lookups.
src/agents/gemini.rs
Standardize JSONL iteration and simplify replay.
src/agents/dsh.rs
Use shared JSONL iteration.
src/agents/copilot.rs
Simplify workspace fallback and test syntax.
src/agents/common.rs
Add needle-based line lookup and tests.
src/agents/codex.rs
Accelerate model scanning and standardize iteration.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Agent-only filters still unnecessarily map Pi sessions before rejecting them because the cwd plugin opt-in is not gated on a cwd filter being present.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Avoid mapping sessions for agent-only filters
src/pipeline.rs:195
With an agent-only filter such as ah -a --agent claude log, Pi's cwd_in_session_bytes() still makes load_early true for every pi session. Resolving Field::Agent needs no cwd or session bytes, so these rejected sessions are unnecessarily mapped before filtering. Gate the plugin opt-in on a cwd filter actually being present so agent-only listings also benefit from deferred mapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ah login a project directory (the default, cwd-filtered listing) spent most of its time on work the result did not need. This PR removes that work, and tidies the code with clippy and a duplicate-code scan.Performance
AgentPlugin::cwd_in_session_bytes(pi).LinesWith) instead of splitting the file into lines and searching each line.Refactoring
ah project: projects that tie on the sort field are ordered by name. They used to follow hash map order, so the output changed between runs. This is the only intended change in output.remote.rs: the two functions that forward filters to the remoteahsharepush_value/push_flag/push_limit. Order and conditions are unchanged.search.rs:search_promptsandsearch_textssharematch_context.jsonl_lines.map_or,let … else, redundant clones,Eqderives, raw string hashes). Lints that only produce churn (use_self, inlined format args) were left out.Performance
About 9,800 session files, 32 threads, warm page cache,
hyperfine:ah logah -q tokio logah -a projectah -a logah -a -q tokio logWith
RAYON_NUM_THREADS=4,ah logwent from 122 ms to 80 ms (measured before the last two fixes of this branch).Known limitations
-acommands gain little: they are bound by reading about 10 GB of JSONL on every run. Going further needs a per-file result cache, which is not part of this PR.Verification
cargo test(486 tests),cargo clippy --all-targets -- -D warnings,cargo fmt --check.mainand this branch give identical output on real data forlog(with and without-a,--json,-q,-p -q,--raw-search,--running,--subagents,-o id,cwd,project,-o id,model,models,-o id,turns,first_prompt),memory,agentandshow.projectdiffers only in the order of tied rows.LinesWithagainst a line-by-line scan, the Claude cwd from the head against the whole file (including the 32 KiB boundary), and a FIFO as a session path.https://claude.ai/code/session_013M2MLyLFJxdYU9rz7M7Utt