Skip to content

feat: add session_exists and delete_session to SessionStore#2999

Open
JiataiWang wants to merge 1 commit intoultraworkers:mainfrom
JiataiWang:feat/session-store-delete-exists
Open

feat: add session_exists and delete_session to SessionStore#2999
JiataiWang wants to merge 1 commit intoultraworkers:mainfrom
JiataiWang:feat/session-store-delete-exists

Conversation

@JiataiWang
Copy link
Copy Markdown

Problem

SessionStore had no way to check whether a session exists by ID, or to
delete 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>/, bypassing
the workspace-fingerprint namespace and breaking cross-platform portability.

Tracked as ROADMAP #160.

Changes

runtime/src/session_control.rs

  • SessionStore::session_exists(session_id: &str) -> bool
    Probes 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_reference so alias semantics are consistent
    with load_session.

  • Module-level free-function wrappers following the existing pattern:
    managed_session_exists / managed_session_exists_for and
    delete_managed_session / delete_managed_session_for.

  • Six new tests:

    • session_exists returns true for a persisted session and false for an unknown ID
    • managed_session_exists_for mirrors store behaviour
    • delete_session removes the file and the session no longer appears in list_sessions
    • delete_session via "latest" alias removes the most recent session
    • delete_managed_session_for free-function mirrors store behaviour
    • delete_session returns an error for an unknown reference

Pre-existing clippy errors fixed (unrelated files, caught during CI check):

  • runtime/src/bash.rs: format!("{}", now)format!("{now}")
  • runtime/src/plugin_lifecycle.rs: three &&str inefficient .to_string() calls
  • commands/src/lib.rs: render_mcp_report_for and render_mcp_report_json_for
    were typed as Result<String/Value, ConfigError> but always returned Ok(...)
    unwrapped to return the inner type directly; public wrappers and test call-sites updated

Test plan

  • cargo fmt --all --check — clean
  • cargo clippy --workspace — zero errors
  • cargo test --workspace — all pass (flaky repl_executes_python_code and web_fetch are pre-existing environment-dependent tests unrelated to this change)
  • New tests cover the happy path, alias resolution, list-after-delete, and the error path for unknown references

🤖 Generated with Claude Code

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]>
@code-yeongyu
Copy link
Copy Markdown
Collaborator

This PR has merge conflicts with the latest main. Please rebase on origin/main and force-push. The code changes look good and we're ready to merge once conflicts are resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants