`fork_session` hangs forever on a cyclic `parentUuid` chain (no cycle guard in `_build_fork_lines`)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu với bước duyệt parentUuid trong _build_fork_lines ở src/claude_agent_sdk/_internal/session_mutations.py (khoảng dòng 411-418), rồi so sánh với chốt bảo vệ walk_seen trong _build_conversation_chain ở src/claude_agent_sdk/_internal/sessions.py. Chạy bản tái hiện với thời gian chờ giới hạn, sau đó thêm một tập hợp các id đã thấy để vòng lặp dừng khi gặp lại một id cha. Hoàn thành khi trường hợp có vòng lặp progress trả về một bản ghi hội thoại đã rẽ nhánh và đường cơ sở không có vòng lặp vẫn ánh xạ lại parentUuid của nút lá.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
_build_fork_lines walks the parentUuid chain with no seen-set or iteration bound. If a session transcript contains a cycle of progress entries (or a single self-parenting progress entry), fork_session / fork_session_via_store loop forever, hanging the calling thread with no timeout or error.
This is a correctness/robustness bug, not a security vulnerability: triggering it requires a transcript file the caller already controls.
Version
- Repo:
anthropics/claude-agent-sdk-python - Package:
claude-agent-sdk0.2.181 - Commit:
22b8eb9c19adfa78759b79e22bd664a57843bb06(main, 2026-11-12)
Location
src/claude_agent_sdk/_internal/session_mutations.py:411-418 (_build_fork_lines):
while parent_id:
parent = by_uuid.get(parent_id)
if not parent:
break
if parent.get("type") != "progress":
new_parent_uuid = uuid_mapping.get(parent_id)
break
parent_id = parent.get("parentUuid")
by_uuid includes progress entries (:396-398), and neither _parse_fork_transcript (:601-613) nor the fork_session_via_store partition (:937-946) validates parentUuid shape — they check only type and uuid — so a cyclic graph reaches the walk unchecked.
Note the sibling walk in _build_conversation_chain guards the same traversal with a walk_seen set (src/claude_agent_sdk/_internal/sessions.py:969-975), which shows cycles are treated as possible input elsewhere in the codebase.
Minimal repro
Transcript with two progress entries pointing at each other, plus a user entry parented to one of them (single-entry variant: one progress entry whose parentUuid is its own uuid, parented-to by a user entry):
from claude_agent_sdk._internal import session_mutations
entries = [
{"uuid": "A", "parentUuid": "B", "type": "progress", "timestamp": "2026-01-01T00:00:00Z"},
{"uuid": "B", "parentUuid": "A", "type": "progress", "timestamp": "2026-01-01T00:00:00Z"},
{"uuid": "U", "parentUuid": "A", "type": "user", "timestamp": "2026-01-01T00:00:00Z",
"message": {"role": "user", "content": "hi"}},
]
# WARNING: this call does not return on the affected version.
session_mutations._build_fork_lines(entries, [], "sess", None, None, lambda: None)
(The same input reaches this walk through the public fork_session(session_id) / fork_session_via_store paths; the hang was demonstrated by driving _build_fork_lines directly, with the walk run in a bounded child process.)
Observed: the walk alternates A → B → A forever; the child process was still running at a 3s timeout (vs a <1ms acyclic baseline) and had to be terminated. Same result for the self-parenting variant.
Expected: the walk terminates — e.g. it breaks on a repeated parent id (mirroring walk_seen), returning a forked transcript instead of hanging.
Impact
A malformed or corrupted transcript (cyclic parentUuid links between progress entries) makes any fork of that session hang indefinitely with no error, blocking the calling thread. The fork operation has no timeout, so the caller cannot recover except by killing the thread/process. Local correctness/robustness impact only.
Suggested fix
Add a seen-set (or iteration bound) to the parentUuid walk in _build_fork_lines, breaking on a repeated parent id, mirroring the walk_seen guard in _build_conversation_chain.
Environment
- Python 3.12.3, Linux
- Verified against the pinned commit above; the acyclic baseline (user → progress → user) finishes in <1s with the leaf's
parentUuidcorrectly remapped.
- Ngôn ngữ chính
- Python
- Star
- 8.5k
- Fork
- 1.4k
- Merge trung bình
- 3 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 13
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của anthropics/claude-agent-sdk-python
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
anthropics/claude-agent-sdk-python#1509 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`parse_message` raises raw `TypeError` instead of `MessageParseError` on non-dict nested payloadsĐang mởbug good first issue
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 76/100
anthropics/claude-agent-sdk-python#1508 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anthropics/claude-agent-sdk-python#1507 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ClaudeSDKClient.connect() with an async iterable closes stdin, so follow-up query() failsCó thể đã có người làm @m4xkushnir đã nhận 19 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
anthropics/claude-agent-sdk-python#1443 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
fork_session drops transcript entries containing U+2028/U+2029/U+0085 (str.splitlines), breaking the parentUuid chainCó thể đã có người làm @mangeshraut712 đã nhận 19 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
anthropics/claude-agent-sdk-python#1441 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của anthropics/claude-agent-sdk-python
Issue tương tự
-
Contributing instructionsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dbt-labs/spark-utils#51 ·
-
bug pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pydantic/pydantic-ai#13444 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
good first issue help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
changelog investigate
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 68/100
ramnes/notion-sdk-py#502 ·