anthropics / anthropics/anthropic-sdk-python

`setup_skills` re-downloads and `rmtree`s skills on every session, racing when workers share a workdir

Đang mở
#1,871 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
3.9k
Fork
853
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
11

Mô tả

### Summary

Self-hosted workers that serve multiple sessions concurrently from one `workdir` (`max_concurrent_sessions > 1`) hit two problems:

1. `download_session_skills` unconditionally `rmtree`s and re-extracts each skill directory even when the resolved `version_id` is unchanged, so every new session re-downloads the same archives.
2. `AgentToolContext._cleanup_skills` removes those directories when any one session ends.

Together these mean a session in flight can have its skill files deleted or replaced underneath it by another session starting or finishing. The window is small but real, and the redundant downloads are pure overhead on a long-running worker.

### Version

`anthropic==1.0.0`, Python 3.12.

### Repro

1. Run one `EnvironmentWorker` process serving two sessions concurrently with the same `workdir` (both agents attach the same skill).
2. Session B starts while session A is running: the skill directory A is using is `rmtree`'d and re-extracted.
3. Session A ends while B is running: `_cleanup_skills` removes the directory B is using.

### Workaround in use

We monkey-patch `AgentToolContext.setup_skills` with a process-wide cache (a `skill_id -> version_id` map behind an `asyncio.Lock`, downloading only when the resolved version differs) and neutralise the teardown by leaving `_skill_dirs` empty. This works but pins us to internals (`_skills._resolve_skill_version`, `_skills._download_and_extract`).

### Request

Either of these would let us drop the patch:

- Skip the download when the resolved `version_id` matches what is already on disk (an idempotent `setup_skills`), and
- an opt-out for the teardown `rmtree` — e.g. `AgentToolContext(keep_skills=True)` — so a shared skills tree can be treated as a process-wide cache owned by the worker rather than by an individual session.

Happy to open a PR if you have a preference on the shape.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.