anthropics / anthropics/claude-agent-sdk-typescript

SDK writes assistant entries with parentUuid referencing UUIDs not present in the transcript file

Aperta
#287 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug claude-code-assisted
Lingua principale
Shell
Stelle
1.8k
Fork
226
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Description

The Claude Agent SDK writes some assistant entries to the session JSONL where `parentUuid` references a UUID that does **not appear as any entry's `uuid` in the file**. These are "parent-only" references — the claimed parent was never persisted.

Related to #244 but a distinct failure mode (parent-chain integrity vs. content-block validity).

## Observed

Working in a project that kills the SDK container on a config change (model switch) and relies on `resume: sessionId` to restore the conversation, we saw every post-switch resume return only the last assistant turn — user messages preceding it were not reconstructed.

Verified on a reproduction transcript (a fresh linear conversation, no compaction involved):

```
$ for UUID in 77efb846 ef05a531 490328da 85bedef9 dbfad746; do
AS_UUID=$(grep -c "\"uuid\":\"$UUID" session.jsonl)
AS_PARENT=$(grep -c "\"parentUuid\":\"$UUID" session.jsonl)
echo "$UUID: as_uuid=$AS_UUID as_parentUuid=$AS_PARENT"
done
77efb846: as_uuid=0 as_parentUuid=1
ef05a531: as_uuid=0 as_parentUuid=1
490328da: as_uuid=0 as_parentUuid=1
85bedef9: as_uuid=0 as_parentUuid=1
dbfad746: as_uuid=0 as_parentUuid=1
```

Each of these UUIDs appears exactly once, only as a `parentUuid`, never as an entry's own `uuid`. Assistant text entries pointing at these dangling parents sit in between correctly-chained user entries, so the conversation tree looks like: `user0 → asst0 → user1 → asst2(parent=GHOST) → user2 → asst3(parent=GHOST2) → ...`.

All entries in this reproduction have `isSidechain: false` — not subagent transcripts.

## Impact

When the SDK resumes from disk, walking the parent chain from the latest entry backwards stops at the first dangling parent. Reconstructed history collapses to whatever tail remains reachable. For our use case (model switch triggering a container restart), this presents as "entire session context gone after switch" — the resumed session starts as if the user's messages never existed.

In-memory runs don't expose this because the SDK maintains state outside the file. It only shows up on cold-resume.

## Workaround

We rewrite `parentUuid` into a linear `user ↔ assistant` chain during our pre-resume transcript sanitiser (the same pass that already strips cross-model thinking signatures). Works, but relies on knowing the conversation is linear and non-branching.

## Expected

The SDK should either (a) not write `parentUuid` references to UUIDs it isn't going to persist, or (b) tolerate dangling parents on resume and fall back to chronological ordering.

## Environment

- SDK version: `@anthropic-ai/claude-agent-sdk` (version from CLI bundle; please point me to the canonical release channel if needed)
- Node.js v24
- Provider: mixed (Anthropic + MiniMax via proxy). The orphan `parentUuid`s were observed in MiniMax-produced turns in this reproduction, but the pattern is worth checking across providers.

---

This issue was written by Claude Code.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.