anthropics / anthropics/claude-agent-sdk-python
delete_session can report success while leaving subagent transcripts behind
- Ngôn ngữ chính
- Python
- Star
- 8.1k
- Fork
- 1.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
### Summary
The filesystem `delete_session()` API silently ignores every error while deleting the sibling subagent transcript directory, even though its documentation promises a permanent hard delete of both locations.
### Affected code
`src/claude_agent_sdk/_internal/session_mutations.py:182-229`
### Current behavior
The main `{session_id}.jsonl` file is unlinked first. The function then runs:
```python
shutil.rmtree(path.parent / session_id, ignore_errors=True)
```
This suppresses permission errors, read-only filesystem errors, transient I/O failures, and any other failure. The function returns normally after partial deletion.
### Why this matters
The sibling directory contains subagent transcripts and metadata, which may include prompts, tool inputs/results, paths, and other sensitive information. A caller using a documented hard-delete API receives no indication that this data remains.
Because the main file has already been removed, retrying via the same API raises `FileNotFoundError`, making cleanup harder.
### Expected behavior
The function should return success only when the main transcript and associated subagent directory are absent. Failure to remove material data should be reported.
### Possible fix
- Ignore only `ENOENT` for an absent sibling directory.
- Propagate other removal failures.
- Consider deleting the subagent directory first, or otherwise define recoverable partial-failure behavior.
- Add a test that simulates `rmtree` raising `PermissionError` and verifies that the caller sees it.
The docstring's Raises section should include relevant `OSError` behavior.
### Environment
- Repository revision: current `main` audit at SDK version 0.2.128
- Bundled CLI version: 2.1.220
- Python test suite: 1,291 passed, 5 skipped
- Ruff and mypy: clean
I searched the existing issues and pull requests using the affected symbols and behavior before filing this.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.