feat: add session_exists and delete_session to SessionStore#2999
Open
JiataiWang wants to merge 1 commit intoultraworkers:mainfrom
Open
feat: add session_exists and delete_session to SessionStore#2999JiataiWang wants to merge 1 commit intoultraworkers:mainfrom
JiataiWang wants to merge 1 commit intoultraworkers:mainfrom
Conversation
SessionStore lacked the ability to check whether a session exists by ID
or delete one by reference. Claws had to resort to filesystem hacks
(listing .claw/sessions/<fingerprint>/ directly) to answer "does this
session exist?" or "clean up this session", which bypassed the
workspace-fingerprint namespace and broke portably.
Changes:
- SessionStore::session_exists(session_id) — checks primary and legacy
namespace; O(1) path probe, no deserialization
- SessionStore::delete_session(reference) — accepts any reference the
store resolves (ID, alias "latest"/"last"/"recent", or path)
- Free-function wrappers: managed_session_exists_for / managed_session_exists
and delete_managed_session_for / delete_managed_session, matching the
existing module-level API pattern
- Six tests covering: exists-true, exists-false, delete removes file,
delete via "latest" alias, free-function mirroring, error on unknown ref
Also fixes three pre-existing clippy errors unrelated to session_store:
- bash.rs: format!("{}", now) → format!("{now}")
- plugin_lifecycle.rs: &&str inefficient to_string (×3)
- commands/src/lib.rs: render_mcp_report_for / render_mcp_report_json_for
unnecessarily wrapped in Result — both now return String/Value directly
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Collaborator
|
This PR has merge conflicts with the latest main. Please rebase on |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
SessionStorehad no way to check whether a session exists by ID, or todelete a session by reference. Any claw that needed to answer "is this
session already running?" or "clean up this session" had to fall back to
raw filesystem probes against
.claw/sessions/<fingerprint>/, bypassingthe workspace-fingerprint namespace and breaking cross-platform portability.
Tracked as ROADMAP #160.
Changes
runtime/src/session_control.rsSessionStore::session_exists(session_id: &str) -> boolProbes the primary namespace and legacy fallback root with O(1) path
existence checks — no deserialization, no allocation.
SessionStore::delete_session(reference: &str) -> Result<(), SessionControlError>Accepts any reference the store already resolves: a bare session ID,
an alias (
"latest","last","recent"), or a direct file path.Delegates to
resolve_referenceso alias semantics are consistentwith
load_session.Module-level free-function wrappers following the existing pattern:
managed_session_exists/managed_session_exists_foranddelete_managed_session/delete_managed_session_for.Six new tests:
session_existsreturns true for a persisted session and false for an unknown IDmanaged_session_exists_formirrors store behaviourdelete_sessionremoves the file and the session no longer appears inlist_sessionsdelete_sessionvia"latest"alias removes the most recent sessiondelete_managed_session_forfree-function mirrors store behaviourdelete_sessionreturns an error for an unknown referencePre-existing clippy errors fixed (unrelated files, caught during CI check):
runtime/src/bash.rs:format!("{}", now)→format!("{now}")runtime/src/plugin_lifecycle.rs: three&&strinefficient.to_string()callscommands/src/lib.rs:render_mcp_report_forandrender_mcp_report_json_forwere typed as
Result<String/Value, ConfigError>but always returnedOk(...)—unwrapped to return the inner type directly; public wrappers and test call-sites updated
Test plan
cargo fmt --all --check— cleancargo clippy --workspace— zero errorscargo test --workspace— all pass (flakyrepl_executes_python_codeandweb_fetchare pre-existing environment-dependent tests unrelated to this change)🤖 Generated with Claude Code