anthropics / anthropics/claude-agent-sdk-python

delete_session can report success while leaving subagent transcripts behind

Aberta
#1,164 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
8.1k
Forks
1.3k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.