Repository navigation
fix(cmd): keep cmd output per session - #141
Conversation
A cmd's output was cached by command line and directory only, so sessions in the same directory overwrote each other's output even though each run gets its own session's payload on stdin. Key the cache by session id too, and pass it to the background refresh.
Reviewer's GuideCommand output caches are now isolated by session in addition to command and working directory, with session context propagated through rendering, background refreshes, and the refresh-cmd CLI. This prevents sessions sharing a directory from overwriting each other’s session-dependent output while retaining the existing behavior when no session ID is available. Sequence diagram for session-isolated command output cachingsequenceDiagram
participant Session as Session
participant Metric as metrics::custom::cmd
participant Cache as cmd_cache::output
participant Refresh as ccline refresh-cmd
participant Store as Session-keyed cache
Session->>Metric: cmd(ctx, opts)
Metric->>Cache: output(Job{run, cwd, session, stdin})
Cache->>Store: lookup(run + cwd + session)
alt cache is fresh
Store-->>Cache: cached output
else cache is stale or missing
Cache->>Refresh: refresh-cmd --cwd --session -- run
Refresh->>Store: refresh(run, cwd, session, timeout)
Store-->>Cache: session-specific output
end
Cache-->>Metric: output for this session
Flow diagram for session-aware command cache keysflowchart LR
Job[Job with run, cwd, session] --> Key["file_key(run + cwd + session)"]
Key --> Cache[Session-specific output cache]
Cache --> Render[Render command output]
Job --> Refresh[refresh-cmd with --session]
Refresh --> Cache
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/state/cmd_cache.rs" line_range="32" />
<code_context>
pub cwd: Option<&'a Path>,
+ /// The session the payload comes from: each session keeps its own
+ /// output, as the command may read session details from stdin.
+ pub session: Option<&'a str>,
/// The status line payload, passed on stdin.
pub stdin: &'a str,
</code_context>
<issue_to_address>
**Downstream Rust callers stop compiling**
When a downstream crate uses the public `ccometixline::state::cmd_cache` API, downstream crates that construct `Job` with the previous fields or call `cmd_cache::refresh` with its previous arguments fail to compile; the new required field and changed function arity are breaking public API changes.
Preserve the existing public entry points and add session-aware alternatives, or treat this as an intentional breaking API change with an appropriate major-version release.
Also at `src/state/cmd_cache.rs:175`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and including the session in the cache key makes each session keep a separate command result and can cause the command to run separately for each one. If the keying or cached output is wrong, a session may see the wrong result until the cache is refreshed; rerunning or clearing the cache repairs it.
Blocking findings: src/state/cmd_cache.rs:32
| pub cwd: Option<&'a Path>, | ||
| /// The session the payload comes from: each session keeps its own | ||
| /// output, as the command may read session details from stdin. | ||
| pub session: Option<&'a str>, |
There was a problem hiding this comment.
🟡 Medium · Downstream Rust callers stop compiling
When a downstream crate uses the public ccometixline::state::cmd_cache API, downstream crates that construct Job with the previous fields or call cmd_cache::refresh with its previous arguments fail to compile; the new required field and changed function arity are breaking public API changes.
Preserve the existing public entry points and add session-aware alternatives, or treat this as an intentional breaking API change with an appropriate major-version release.
Also at src/state/cmd_cache.rs:175.
Prompt for AI agents
In `src/state/cmd_cache.rs` at line 32:
**Downstream Rust callers stop compiling**
When a downstream crate uses the public `ccometixline::state::cmd_cache` API, downstream crates that construct `Job` with the previous fields or call `cmd_cache::refresh` with its previous arguments fail to compile; the new required field and changed function arity are breaking public API changes.
Preserve the existing public entry points and add session-aware alternatives, or treat this as an intentional breaking API change with an appropriate major-version release.
Also at `src/state/cmd_cache.rs:175`.
Summary
A
cmditem gets the session's status line payload on stdin, but its output was cached by command line and directory only. Sessions in the same directory therefore overwrote each other's output, and each one showed whichever session refreshed last.With no
session_id, the key isrun + cwd + "", the same for render and refresh.Evidence
Setup: two sessions open in the same directory. The
cmdreads.transcript_pathfrom stdin and prints the time of that session's last user message:cmd_cache::tests::sessions_keep_their_own_output: samerunandcwdgive the same path for the same session, and different paths for different sessions or no session.cargo fmt --check,cargo clippy -- -D warningsandcargo testpass.Merge Danger
Door: two-way
Only cache keys change. Old cache files are no longer read, and the existing sweep removes them after a day.
Blast Radius: small
kubectl config current-context) now run once per session instead of once per directory. A new session's first render can come up empty while its first background run finishes.local-review: 81c72ac055cd826633abb17f4b096f92804a0467 · P0 0 · P1 0 · nit 0Summary by Sourcery
Isolate command output caches by session to ensure each status line displays results for its own session.
Bug Fixes:
cmdoutput isolated per session so sessions in the same directory no longer overwrite or display each other’s results.Enhancements:
Tests: