anthropics / anthropics/claude-agent-sdk-python

delete_session can report success while leaving subagent transcripts behind

Abierto
#1,164 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
8.1k
Forks
1.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.