anthropics / anthropics/claude-agent-sdk-python

delete_session can report success while leaving subagent transcripts behind

未关闭
#1,164 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
8.1k
派生
1.3k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。