fix(gateway): add parentId to non-agent-run transcript messages#11033
fix(gateway): add parentId to non-agent-run transcript messages#11033openperf wants to merge 1 commit intoopenclaw:mainfrom
Conversation
src/gateway/server-methods/chat.append-transcript-parentId.test.ts
Outdated
Show resolved
Hide resolved
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/gateway/server-methods/chat.ts
Line: 639:641
Comment:
**Still writes orphan**
`chat.inject` still appends a `type: "message"` transcript entry without a `parentId`, which recreates the same transcript-tree breakage described in this PR (any inject that isn’t part of an agent run will start a new root). This should use the same `readTranscriptLeafId()`/parentId logic as `appendAssistantTranscriptMessage` (or call that helper) so injected messages remain on the existing branch.
How can I resolve this? If you propose a fix, please make it concise. |
50c7624 to
0317e98
Compare
|
Hi! This PR is ready for review. |
|
Heads up: the lint failure ( git fetch origin main && git rebase origin/main && git push --force-with-lease |
|
Update: the lint failure has been resolved by #11093 (merged), which excluded git fetch origin main && git rebase origin/main && git push --force-with-lease |
0317e98 to
2179c9f
Compare
|
Closing this PR — the underlying bug has been fixed in #12283, which introduced SessionManager.appendMessage() to automatically maintain the parentId chain. My manual readTranscriptLeafId approach is no longer needed. |
Summary
This fixes an issue where commands that don't trigger an agent run (like
/status) would append a reply to the transcript without aparentId. This created an orphaned root node in the transcript tree, causing subsequent messages to lose the conversation history.This addresses the same category of transcript tree breakage described in #10821. A related but separate issue (missing
parentIdafter gateway restart) is tracked in #10018 / PR #10060.Fixes #10821
Repro Steps
/status)./statuscommand.Root Cause
The
appendAssistantTranscriptMessagefunction insrc/gateway/server-methods/chat.tswas called for non-agent-run replies. This function created a new transcript entry with a newmessageIdbut without aparentId, effectively starting a new branch in the transcript tree.The original issue suggested two possible fixes: either not writing these replies to the transcript, or adding a
parentId. We chose to add theparentIdbecause it is a more localized and safer change that preserves the metadata of the command reply in the transcript, which could be useful for debugging, without altering the broader logic of what gets written to the transcript.Behavior Changes
readTranscriptLeafIdhas been added tochat.tsto read the last message ID from a transcript file.appendAssistantTranscriptMessagenow uses this helper to get theparentIdof the last message and includes it in the new transcript entry./statusare correctly appended to the existing conversation branch, preserving context.Codebase and GitHub Search
appendAssistantTranscriptMessageto identify call sites.parentIdin a similar context.Tests
src/gateway/server-methods/chat.append-transcript-parentId.test.ts.readTranscriptLeafIdhelper function, covering cases like non-existent files, empty files, and files with various entry types.Validation
npx vitest run src/gateway/server-methods/chat.append-transcript-parentId.test.ts
npx vitest run src/gateway/chat-sanitize.test.ts src/gateway/chat-attachments.test.ts
npx tsc --noEmit
Greptile Overview
Greptile Summary
readTranscriptLeafId()to find the last message id in a session transcript JSONL.appendAssistantTranscriptMessage()so non-agent-run command replies are appended with aparentIdinstead of creating a new root./status.Confidence Score: 2/5
appendAssistantTranscriptMessagelooks correct, butchat.injectstill appends transcript messages withoutparentId, reintroducing the same class of breakage. Additionally, the new test reimplements the helper rather than asserting behavior of the production code, so it won’t reliably prevent regressions.Context used:
dashboard- CLAUDE.md (source)dashboard- AGENTS.md (source)