Repository navigation
fix: send lowercase session keys so prompt caching survives - #46
Open
Mattheinrichs wants to merge 1 commit into
Open
Mattheinrichs wants to merge 1 commit into
Mattheinrichs wants to merge 1 commit into
Conversation
Home Assistant hands out conversation ids as uppercase ULIDs. OpenClaw session keys are canonically lowercase, so an uppercase key is refused on the session write and rewritten into the request envelope on the next turn. That makes the history non-append-only, which invalidates the provider prompt cache and forces a full prefill of the agent prompt every turn. Normalise the base id and the agent prefix in scope_agent_session_id, and cover the uppercase base id and already-scoped uppercase key with tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Home Assistant hands out
conversation_idvalues as uppercase ULIDs._resolve_conversation_id()passes that value toscope_agent_session_id(), so the session key sent to OpenClaw looks likeagent:voice:01M7KF8J84WTQTZWH6FCDSP4GN.OpenClaw session keys are canonically lowercase. The gateway refuses the write:
and the envelope is rewritten on the following turn:
Because the history is no longer append-only, the provider prefix cache is invalidated and the full agent prompt is re-prefilled every turn. On a ~24k-token voice agent that is ~9-14 s per turn instead of ~2 s.
Fix
Normalise the key in
scope_agent_session_id(): lowercase the base id and the agent prefix, and keep the idempotency guard for already-scoped keys. One function, no call-site changes.Tests
Two regression tests added: an uppercase HA ULID and an already-scoped uppercase key.
python3 -m unittest discover -s tests -p 'test_*.py'-> 11 tests, OK.Notes
assist_session_idstill bypasses this helper and is sent verbatim; left unchanged here.