sessions: replace per-step LLM request bodies with hash-deduped prompt envelopes - #484
Merged
Conversation
…t envelopes The per-step LLM request log stored the full provider payload on every model-call step — the entire growing conversation re-serialized per step, O(turns squared) bytes — and it dominates database growth on any active deployment; the message arrays it duplicates are already durable exactly once on the session tape. Replace the stored request body with a compact prompt envelope: system/tools/config captured once and deduplicated by content hash, with the message window reconstructed from the tape on read. Observability views reassemble the original request for inspection, so debugging fidelity is unchanged while storage per step drops from the full conversation to a constant-size record.
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.
The per-step LLM request log stored the full provider payload on every model-call step — the entire growing conversation re-serialized per step, O(turns squared) bytes — and it dominates database growth on any active deployment; the message arrays it duplicates are already durable exactly once on the session tape. Replace the stored request body with a compact prompt envelope: system/tools/config captured once and deduplicated by content hash, with the message window reconstructed from the tape on read. Observability views reassemble the original request for inspection, so debugging fidelity is unchanged while storage per step drops from the full conversation to a constant-size record.
Deployment notes
llm_prompt_envelopesto exclusions.ALTER session_llm_requests ALTER COLUMN request DROP NOT NULL,ADD COLUMN IF NOT EXISTS prompt_hash,CREATE TABLE IF NOT EXISTS llm_prompt_envelopes. No table rewrite; pre-migration request bodies are frozen in place and detail reads fall back to them — old rows keep serving.request = NULL+prompt_hash. Old code'srowToLlmRequestand the admin viewer expectrequest NOT NULLsemantics — during a blue-green overlap or after rollback, old instances read NULL-request rows and render blank context for those steps. The ALTER already dropped the constraint, so writes do not fail; this is a read-quality gap, forensics-only, not user-facing.session_llm_requestsmust also excludellm_prompt_envelopes.Screenshots of the admin viewer were omitted from this PR; the viewer change reassembles the same request view as before, with a blank-context fallback for NULL-request rows.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.