fix(hyperagent): sticky thread for agentic tool loops (Claude Code) - #8470
Conversation
Follow-up to diegosouzapw#7994. When a reverse-conversion proxy rewrites assistant text between turns (Intent+JSON -> native tool_calls -> re-serialized tool text), conversationFingerprint(prefix) no longer matches the key stored after turn 1, so HyperAgent created a new thread and multi-turn tool results appeared as a cold start. - Key sticky sessions by root user task (normalize pin wrappers) - Flatten Anthropic tool_use / tool_result for lastUserText + fingerprints - Regression tests for mutated-assistant tool loops Tests: tests/unit/executor-hyperagent.test.ts (19/19)
|
Thanks for the detailed follow-up to #7994 — this is a well-documented fix and the reproduction of the reverse-conversion tool-loop cold-start problem makes sense. We ran your test suite as-is ( One thing we want to work through before merging: the new We'd like to land your fix, but with the root-key fallback made a bit more specific (e.g. requiring some corroborating signal beyond just the first user line, or moving it strictly after the existing last-assistant fallback rather than before it) plus a regression test for the "two different conversations, same opening line" case. Happy to help pair on the exact shape if useful — otherwise feel free to push the update to this branch and we'll re-run the suite. |
…agent sticky thread) open-sse/executors/hyperagent.ts grows 937->1026 lines and gains one new cognitive/cyclomatic-complexity violation (extractMessageText, from the new Anthropic tool_use/tool_result flattening branches) on top of inherited base-tip drift already present on origin/release/v3.8.49 (file-size was already at cap; cognitive-complexity 951->956 and cyclomatic-complexity 2130->2169 drift predates this PR). Rebaselined file-size to 1026, cognitiveComplexity to 957, complexity count to 2170, matching measured values on the merged tree. Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
# Conflicts: # config/quality/file-size-baseline.json
…iegosouzapw#8470) * fix(hyperagent): sticky thread for agentic tool loops (Claude Code) Follow-up to diegosouzapw#7994. When a reverse-conversion proxy rewrites assistant text between turns (Intent+JSON -> native tool_calls -> re-serialized tool text), conversationFingerprint(prefix) no longer matches the key stored after turn 1, so HyperAgent created a new thread and multi-turn tool results appeared as a cold start. - Key sticky sessions by root user task (normalize pin wrappers) - Flatten Anthropic tool_use / tool_result for lastUserText + fingerprints - Regression tests for mutated-assistant tool loops Tests: tests/unit/executor-hyperagent.test.ts (19/19) * chore(quality): rebaseline for PR diegosouzapw#8470 own-growth (hyperagent sticky thread) open-sse/executors/hyperagent.ts grows 937->1026 lines and gains one new cognitive/cyclomatic-complexity violation (extractMessageText, from the new Anthropic tool_use/tool_result flattening branches) on top of inherited base-tip drift already present on origin/release/v3.8.49 (file-size was already at cap; cognitive-complexity 951->956 and cyclomatic-complexity 2130->2169 drift predates this PR). Rebaselined file-size to 1026, cognitiveComplexity to 957, complexity count to 2170, matching measured values on the merged tree. Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com> --------- Co-authored-by: ikelvingo <im.kelvinwong@gmail.com> Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com> Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
…iegosouzapw#8470) * fix(hyperagent): sticky thread for agentic tool loops (Claude Code) Follow-up to diegosouzapw#7994. When a reverse-conversion proxy rewrites assistant text between turns (Intent+JSON -> native tool_calls -> re-serialized tool text), conversationFingerprint(prefix) no longer matches the key stored after turn 1, so HyperAgent created a new thread and multi-turn tool results appeared as a cold start. - Key sticky sessions by root user task (normalize pin wrappers) - Flatten Anthropic tool_use / tool_result for lastUserText + fingerprints - Regression tests for mutated-assistant tool loops Tests: tests/unit/executor-hyperagent.test.ts (19/19) * chore(quality): rebaseline for PR diegosouzapw#8470 own-growth (hyperagent sticky thread) open-sse/executors/hyperagent.ts grows 937->1026 lines and gains one new cognitive/cyclomatic-complexity violation (extractMessageText, from the new Anthropic tool_use/tool_result flattening branches) on top of inherited base-tip drift already present on origin/release/v3.8.49 (file-size was already at cap; cognitive-complexity 951->956 and cyclomatic-complexity 2130->2169 drift predates this PR). Rebaselined file-size to 1026, cognitiveComplexity to 957, complexity count to 2170, matching measured values on the merged tree. Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com> --------- Co-authored-by: ikelvingo <im.kelvinwong@gmail.com> Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com> Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Summary
Follow-up to #7994.
When a reverse-conversion proxy (e.g. tools→text Intent+JSON for web models, then text→native
tool_callsfor Claude Code) rewrites the assistant message between turns,conversationFingerprint(prefix)no longer matches the key stored after turn 1. HyperAgent then created a new thread, so multi-turn tool results looked like a cold start (model re-states protocol instead of continuing).Changes
rootUserFingerprint) after normalizing common agentic user-pin wrappers (My current task:, etc.)tool_use/tool_resultcontent blocks inextractMessageTextso Claude Code histories contribute to fingerprints +lastUserTextTests
19/19 PASS
Risk
Low — only HyperAgent thread cache keying; chat body / SSE protocol unchanged. Cookie isolation preserved (
projectKeystill gates lookups).