Skip to content

fix(agent): rebuild resume transcripts from ACP top-level tool fields#3084

Merged
tatoalo merged 2 commits into
mainfrom
posthog-code/fix-resume-hydration-tool-calls
Jul 2, 2026
Merged

fix(agent): rebuild resume transcripts from ACP top-level tool fields#3084
tatoalo merged 2 commits into
mainfrom
posthog-code/fix-resume-hydration-tool-calls

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Problem

When a cloud run resumes into a successor run, the agent server rebuilds the prior Claude session JSONL from the run's S3 event log (hydrateSessionJsonl). The rebuild read toolCallId/toolInput/toolResponse from _meta.claudeCode, but in the logs agent-server actually persists, ACP puts toolCallId, rawInput, and rawOutput on the update object itself. _meta.claudeCode only reliably carries toolName.

Result: every tool call was silently dropped from the rebuilt transcript. A real 30-minute run with 7,522 log entries and 97 tool calls hydrated to a 4-line transcript (the prompt plus ~2KB of assistant prose), so the resumed agent greeted the user, found a clean tree, and re-implemented the whole task from scratch.

Changes

  • rebuildConversation now reads toolCallId from the update (falling back to meta for older logs), takes input from rawInput (skipping the empty {} the opening tool_call ships so it can't clobber streamed input), and results from rawOutput or meta.toolResponse
  • individual tool payloads are capped at 10k chars so one giant Write input or test dump can't dominate the resume budget
  • selectRecentTurns gets a fallback for the shape every single-prompt run produces (one user turn plus one giant assistant turn): when the final turn alone exceeds the token budget it now sheds the oldest tool calls until it fits, instead of selecting zero turns and writing an empty transcript

Session JSONL hydration read toolCallId/toolInput/toolResponse from
_meta.claudeCode, but ACP puts toolCallId, rawInput, and rawOutput on
the update object itself (meta only reliably carries toolName). Every
tool call was dropped, so a 30-minute run resumed as a 4-line
transcript and the agent re-derived everything from scratch.

Also cap individual tool payloads at 10k chars and make
selectRecentTurns degrade an over-budget final turn by shedding its
oldest tool calls instead of returning an empty selection.

Generated-By: PostHog Code
Task-Id: 9111837d-6522-400e-8495-ea6f1cfd6e17
@tatoalo tatoalo self-assigned this Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 57ffb69.

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): rebuild resume transcripts f..." | Re-trigger Greptile

Comment thread packages/agent/src/adapters/claude/session/jsonl-hydration.ts
…ipts

Review follow-up: capToolPayload replaced oversized object inputs with a
truncated string, but tool_use.input must stay an object per the Claude
API schema. Wrap truncated non-string payloads in
{ _truncated, preview, originalSize } instead.

Generated-By: PostHog Code
Task-Id: 9111837d-6522-400e-8495-ea6f1cfd6e17
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 2, 2026
@tatoalo tatoalo marked this pull request as ready for review July 2, 2026 13:22

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix correctly extends the SessionUpdate interface to read ACP top-level fields and adds a robust fallback for oversized single-turn transcripts. The greptile bot's object-truncation concern was genuinely addressed, and the new tests cover both the ACP shape and the truncation/fallback behaviors.

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "fix(agent): keep truncated tool inputs a..." | Re-trigger Greptile

@tatoalo tatoalo merged commit 84bfe68 into main Jul 2, 2026
30 checks passed
@tatoalo tatoalo deleted the posthog-code/fix-resume-hydration-tool-calls branch July 2, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant