Commit graph

5 commits

Author SHA1 Message Date
Garm
084678df7c fix(proxy): strip cache_control before hashing turn_id
compute_turn_id hashed the raw message dicts, which meant the same
user-text message produced a different hash on each call of one agent
loop because clients (notably Claude Code) move the cache_control
breakpoint to the newest message per call. The user-text block carries
cache_control on call 1 and not on call 2, so the serialized prefix
differs and the turn_id rolls over. Effect downstream: every API call
becomes its own "turn" and any prompt-level aggregation (e.g. the
Headroom desktop app's prompt all-time record) collapses to the
largest single call, not the sum across the prompt.

Add a small recursive normalization pass that strips cache_control from
the hashed prefix and from list-shaped system prompts before hashing.
Two new tests cover cache_control moving between calls on both the
messages array and the system prompt.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 16:04:57 +02:00
Garm
58282bbc5e test(proxy): cover turn_id branches flagged by codecov
Patch coverage on helpers.py was 87% — 5 lines of compute_turn_id
were untested. Add cases for: non-dict / non-user messages in the
reverse scan, empty-string user content (should keep scanning),
mixed text+tool_result content (agent-loop continuation, not a
turn boundary), and system=None (hashes without the system segment).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 23:34:41 +02:00
Garm
e8835affb8 docs(changelog): record turn_id feature; fix import order in new test
Follow-up to b2536e6: add the Unreleased changelog entry describing the
prompt-turn identifier, and pick up the ruff-fixed import layout in the
new test file (ruff --fix of I001).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 23:16:38 +02:00
Garm
c4464c066f feat(proxy): emit turn_id linking agent-loop API calls from one user prompt
Adds compute_turn_id() helper that hashes (model, system, messages prefix
up to the last user text message). An agent loop sends the same user-text
prefix across every iteration plus a growing tool chain, so this id is
stable across the turn but rolls over when the user sends a new prompt.

Stamps the id onto RequestLog at all three call sites (anthropic handler
bedrock + direct branches, and the streaming handler) and surfaces it as
turn_id in /transformations/feed so downstream consumers can aggregate
savings per user prompt rather than per API call.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 23:15:55 +02:00
JerrettDavis
0aae886f77 feat: add live transformations feed to dashboard
- New /transformations/feed endpoint returning message diffs
- Alpine.js drawer UI with virtual scrolling and auto-stream pause
- Live Feed button hidden when log_full_messages=false
- Added --log-messages CLI flag to enable full message logging
- Backend stores request/response messages when enabled

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-20 23:47:43 -05:00