fix(cosh): preserve user dirs in auto-memory workspace cleanup#548
Open
kongche-jbw wants to merge 1 commit into
Open
fix(cosh): preserve user dirs in auto-memory workspace cleanup#548kongche-jbw wants to merge 1 commit into
kongche-jbw wants to merge 1 commit into
Conversation
- add WorkspaceContext.removeDirectory for targeted cleanup
- track each added dir to remove only what auto-memory added
- prevent setDirectories(initial) from wiping user-added dirs
- also fix partial-add leak when memoryDir add fails
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.
Description
The auto-memory background extraction adds
chatsDirandmemoryDirtothe shared
WorkspaceContext, then on cleanup callssetDirectories(getInitialDirectories()).initialDirectoriesis asnapshot frozen at constructor time and is never updated, so any
directory the user added at runtime via the
/directoryslash commandgets wiped when the background extraction finishes — and any subsequent
file access in those user directories silently fails the workspace
boundary check.
This change introduces
WorkspaceContext.removeDirectory(path)andmakes the cleanup remove only the two directories auto-memory itself
added, leaving every other directory in the context untouched. The
extracted directories are tracked individually as they are added, which
also closes a partial-add leak: previously, if
addDirectory(chatsDir)succeeded but the subsequent
mkdir/addDirectory(memoryDir)threw,addedExtraDirsstayedfalseand thechatsDirentry leaked.Related Issue
no-issue: bug fix surfaced during review of cba22cb
Type of Change
Scope
cosh(copilot-shell)sec-core(agent-sec-core)skill(os-skills)sight(agentsight)tokenless(tokenless)Checklist
cosh: Lint passes, type check passes, and tests passsec-core(Rust):cargo clippy -- -D warningsandcargo fmt --checkpasssec-core(Python): Ruff format and pytest passskill: Skill directory structure is valid and shell scripts pass syntax checksight:cargo clippy -- -D warningsandcargo fmt --checkpasstokenless:cargo clippy -- -D warningsandcargo fmt --checkpasspackage-lock.json/Cargo.lock)Testing
workspaceContext.test.tsgains six TDD-driven tests coveringremoveDirectory: removal, leaving initial directories intact, no-opon non-member, symlink resolution, listener notification, and throwing
on a non-existent path. Red-green confirmed: all six tests fail with
removeDirectory is not a functionbefore the implementation, and passafter. Full suite for the touched modules: 60/60 pass
(
workspaceContext40 +autoMemory/*20).Additional Notes
This fix is independent of #547 (the
read_file/absolute_patharg-keybug); both issues live in the auto-memory subsystem introduced in
cba22cb but touch disjoint files.