`fork_session` hangs forever on a cyclic `parentUuid` chain (no cycle guard in `_build_fork_lines`)
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
src/claude_agent_sdk/_internal/session_mutations.py の _build_fork_lines(411〜418行目付近)にある parentUuid の走査から始め、src/claude_agent_sdk/_internal/sessions.py の _build_conversation_chain にある walk_seen ガードと比較してください。タイムアウトを設定したうえで再現手順を実行し、その後、親IDが繰り返されたらループを抜けるよう既読セットを追加します。循環する progress のケースがフォークされたトランスクリプトを返し、非循環のベースラインでも葉の parentUuid が引き続き再マッピングされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Python
- スター
- 8.5k
- フォーク
- 1.4k
- 平均マージ
- 3日 10時間
- マージ済み PR(30日)
- 13
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
anthropics/claude-agent-sdk-python のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
anthropics/claude-agent-sdk-python#1509 ·
メンテナーはふだん 2 日以内に返信
-
`parse_message` raises raw `TypeError` instead of `MessageParseError` on non-dict nested payloadsオープンbug good first issue
難易度 2/5 半日 初心者へのやさしさ 76/100
anthropics/claude-agent-sdk-python#1508 ·
メンテナーはふだん 2 日以内に返信
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
anthropics/claude-agent-sdk-python#1507 ·
メンテナーはふだん 2 日以内に返信
-
ClaudeSDKClient.connect() with an async iterable closes stdin, so follow-up query() fails対応中かも @m4xkushnir が 19 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
anthropics/claude-agent-sdk-python#1443 ·
メンテナーはふだん 2 日以内に返信
-
fork_session drops transcript entries containing U+2028/U+2029/U+0085 (str.splitlines), breaking the parentUuid chain対応中かも @mangeshraut712 が 19 日前に担当しました。 オープンbug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
anthropics/claude-agent-sdk-python#1441 ·
メンテナーはふだん 2 日以内に返信
anthropics/claude-agent-sdk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dbt-labs/spark-utils#51 ·
-
bug pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pydantic/pydantic-ai#13444 ·
メンテナーはふだん 1 日以内に返信
-
good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
good first issue help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
changelog investigate
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
ramnes/notion-sdk-py#502 ·