claw-code/rust/crates/runtime/src
YeonGyu-Kim 7bc66e86e8 feat: #151 — canonicalize workspace path in SessionStore::from_cwd/data_dir
## Problem

`workspace_fingerprint(path)` hashes the raw path string without
canonicalization. Two equivalent paths (e.g. `/tmp/foo` vs
`/private/tmp/foo` on macOS) produce different fingerprints and
therefore different session stores. #150 fixed the test-side symptom;
this fixes the underlying product contract.

## Discovery path

#150 fix (canonicalize in test) was a workaround. Q's ack on #150
surfaced the deeper gap: the function itself is still fragile for
any caller passing a non-canonical path:

1. Embedded callers with a raw `--data-dir` path
2. Programmatic `SessionStore::from_cwd(user_path)` calls
3. NixOS store paths, Docker bind mounts, case-insensitive normalization

The REPL's default flow happens to work because `env::current_dir()`
returns canonical paths on macOS. But any caller passing a raw path
risks silent session-store divergence.

## Fix

Canonicalize inside `SessionStore::from_cwd()` and `from_data_dir()`
before computing the fingerprint. Kept `workspace_fingerprint()` itself
as a pure function for determinism — canonicalization is the entry
point's responsibility.

```rust
let canonical_cwd = fs::canonicalize(cwd).unwrap_or_else(|_| cwd.to_path_buf());
let sessions_root = canonical_cwd.join(".claw").join("sessions").join(workspace_fingerprint(&canonical_cwd));
```

Falls back to the raw path if canonicalize fails (directory doesn't
exist yet).

## Test-side updates

Three legacy-session tests expected the non-canonical base path to
match the store's workspace_root. Updated them to canonicalize
`base` after creation — same defensive pattern as #150, now
explicit across all three tests.

## Regression test

Added `session_store_from_cwd_canonicalizes_equivalent_paths` that
creates two stores from equivalent paths (raw vs canonical) and
asserts they resolve to the same sessions_dir.

## Verification

- `cargo test -p runtime session_store_` — 9/9 pass
- `cargo test --workspace` — all green, no FAILED markers
- No behavior change for existing users (REPL default flow already
  used canonical paths)

## Backward compatibility

Users on macOS who always went through `env::current_dir()`:
no hash change, sessions resume identically.

Users who ever called with a non-canonical path: hash would change,
but those sessions were already broken (couldn't be resumed from a
canonical-path cwd). Net improvement.

Closes ROADMAP #151.
2026-04-21 21:06:09 +09:00
..
bash.rs feat: wire ship.prepared provenance emission at bash execution boundary 2026-04-20 17:03:28 +09:00
bash_validation.rs feat: bash validation module + output truncation parity 2026-04-03 19:31:49 +09:00
bootstrap.rs feat(runtime): add tests and improve error handling across runtime crate 2026-04-02 18:10:12 +09:00
branch_lock.rs Close the clawability backlog with deterministic CLI output and lane lineage 2026-04-05 18:41:02 +00:00
compact.rs Remove the deprecated Claude subscription login path and restore a green Rust workspace 2026-04-11 17:24:44 +00:00
config.rs fix: #149 — eliminate parallel-test flake in runtime::config tests 2026-04-21 20:54:12 +09:00
config_validate.rs feat(config): add trustedRoots to RuntimeConfig 2026-04-08 02:35:19 +09:00
conversation.rs Retire the stale dead-session opacity backlog item with regression proof 2026-04-11 18:47:37 +00:00
file_ops.rs fix(tools): support brace expansion in glob_search patterns 2026-04-10 11:22:38 +09:00
git_context.rs feat: b5-git-aware — batch 5 wave 2 2026-04-07 15:19:45 +09:00
green_contract.rs feat(runtime): green-ness contract 2026-04-04 00:42:41 +09:00
hooks.rs Improve malformed hook failures so operators can diagnose broken JSON 2026-04-13 12:44:52 +00:00
json.rs fix: auto compaction threshold default 200k tokens 2026-04-01 03:55:00 +00:00
lane_events.rs ROADMAP #4.44.5: Ship/provenance events — implement §4.44.5 2026-04-20 15:06:50 +09:00
lib.rs ROADMAP #4.44.5: Ship/provenance events — implement §4.44.5 2026-04-20 15:06:50 +09:00
lsp_client.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
mcp.rs feat(mcp): add toolCallTimeoutMs, timeout/reconnect/error handling 2026-04-02 18:24:30 +09:00
mcp_client.rs feat(mcp): add toolCallTimeoutMs, timeout/reconnect/error handling 2026-04-02 18:24:30 +09:00
mcp_lifecycle_hardened.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
mcp_server.rs style: cargo fmt — fix CI formatting failures 2026-04-08 11:21:13 +09:00
mcp_stdio.rs Close the clawability backlog with deterministic CLI output and lane lineage 2026-04-05 18:41:02 +00:00
mcp_tool_bridge.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
oauth.rs fix(startup): fall back to USERPROFILE when HOME is not set (Windows) 2026-04-10 08:33:35 +09:00
permission_enforcer.rs feat: ultraclaw droid batch — ROADMAP #41 test isolation + #50 PowerShell permissions 2026-04-12 03:06:24 +09:00
permissions.rs docs: describe the runtime public API surface 2026-04-04 15:23:29 +00:00
plugin_lifecycle.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
policy_engine.rs feat(policy): add lane reconciliation events and policy support 2026-04-04 16:12:06 +09:00
prompt.rs style: cargo fmt — fix CI formatting failures 2026-04-08 11:21:13 +09:00
recovery_recipes.rs Implement startup-no-evidence evidence bundle + classifier (US-001) 2026-04-16 09:05:33 +00:00
remote.rs fix: auto compaction threshold default 200k tokens 2026-04-01 03:55:00 +00:00
sandbox.rs fix(sandbox): probe unshare capability instead of binary existence 2026-04-03 16:24:02 +09:00
session.rs Keep latest-session timestamps increasing under tight loops 2026-04-12 10:51:19 +00:00
session_control.rs feat: #151 — canonicalize workspace path in SessionStore::from_cwd/data_dir 2026-04-21 21:06:09 +09:00
sse.rs feat(runtime): add tests and improve error handling across runtime crate 2026-04-02 18:10:12 +09:00
stale_base.rs feat: bridge directory metadata + stale-base preflight check 2026-04-07 15:55:38 +09:00
stale_branch.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
summary_compression.rs feat(runtime): actionable summary compression for lane event streams 2026-04-04 00:43:30 +09:00
task_packet.rs Fix formatting in task_packet.rs for CI 2026-04-16 09:35:18 +00:00
task_registry.rs US-005: Typed task packet format with TaskScope enum 2026-04-16 09:28:42 +00:00
team_cron_registry.rs Restore a fully green workspace verification baseline 2026-04-05 18:46:06 +00:00
trust_resolver.rs feat(runtime): trust prompt resolver 2026-04-04 00:44:08 +09:00
usage.rs docs: describe the runtime public API surface 2026-04-04 15:23:29 +00:00
worker_boot.rs Implement startup-no-evidence evidence bundle + classifier (US-001) 2026-04-16 09:05:33 +00:00