Skip to content

fix(sleep): match a symlinked project directory when harvesting - #465

Open
ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/harvest-symlinked-project
Open

ni (nniiovoo) wants to merge 1 commit into
microsoft:mainfrom
nniiovoo:fix/harvest-symlinked-project

Conversation

@nniiovoo

Copy link
Copy Markdown

Fixes #464

_project_matches compared the session's cwd with the project using os.path.abspath only. Claude Code records the physical cwd, while --project keeps the path as typed. So --project "$(pwd)" from a symlinked ~/code/app (or /tmp/x on macOS) found none of the project's sessions, and a run still moved the checkpoint.

What changes:

  • If the plain comparison fails, the same exact/descendant/ancestor checks now run again on the realpath of both paths. The same applies to an explicit scope list. The Codex and Copilot CLI harvesters use _project_matches, so they get this too.
  • A session with no recorded cwd is not resolved, since an empty path would stand for the harvesting process's cwd. A path that realpath rejects (a NUL in a malformed record) falls back to abspath instead of aborting the harvest.
  • _ancestor_in_scope now refuses the realpath of $HOME as well as its abspath. Otherwise a symlinked $HOME would let $HOME sessions back into every project below it (sleep: --scope invoked harvests every $HOME-rooted session into every project (unbounded ancestor match) #294).

Tests:

  • New file: tests/test_harvest_symlinked_project.py. It covers:
    • both spellings matching in either direction, including a subdirectory;
    • a scope list;
    • an end-to-end harvest() with the typed (logical) project path.
  • Guards: other projects still don't match, a symlinked $HOME stays out of scope, a NUL path doesn't raise, and a session with no cwd isn't matched through the symlink. The 3 bug tests fail on main, and the 4 guards pass on both.
  • Full suite on macOS: 2438 passed. The 2 failures in tests/test_sleep_adopt_skill_subset.py also fail on main.

_project_matches compared the session's cwd with the project using
os.path.abspath only. Claude Code records the physical cwd, while
--project keeps the path as typed, so --project "$(pwd)" from a
symlinked ~/code/app (or /tmp/x on macOS) found none of the project's
sessions, and a run still moved the checkpoint.

When the plain comparison fails, the same checks now run on the realpath
of both paths, for an explicit scope list too. A session with no
recorded cwd is not resolved, a path realpath rejects falls back to
abspath, and _ancestor_in_scope also refuses the realpath of $HOME so a
symlinked $HOME stays out of scope (microsoft#294).

Fixes microsoft#464

Signed-off-by: NNIIOVO <haimingni44@gmail.com>

This branch has not been deployed

No deployments
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.

sleep: --project "$(pwd)" from a symlinked directory harvests none of its sessions

1 participant