Skip to content

feat: add session_exists and delete_session to SessionStore#2999

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

feat: add session_exists and delete_session to SessionStore#2999
JiataiWang wants to merge 1 commit into
ultraworkers: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

@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.

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@JiataiWang JiataiWang force-pushed the feat/session-store-delete-exists branch from 40bcf6d to 034e31a Compare May 11, 2026 05:50
@JiataiWang
Copy link
Copy Markdown
Author

Rebased on latest origin/main and force-pushed. Conflicts resolved by narrowing the PR scope to just the SessionStore feature (dropped the bundled clippy fixes that were tangential to #160). cargo fmt, cargo clippy --workspace, and cargo test -p runtime are clean. Ready for another look.

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