Files
cleveragents-core/tools
drew defea003a4 feat(auto-agents): llm_activity.prompt_hash for duplicate-prompt measurement
Adds a SHA-256 hash of each session's first user message to every
``llm_activity`` row so we can answer the question "would response
caching for repeat prompts pay back?" with data instead of
hypothesis.

Schema (v7):
- ``llm_activity`` grows a ``prompt_hash`` column (nullable, indexed,
  NOT unique — duplicates are the measurement signal)
- Idempotent ALTER-gated migration; chains cleanly from v5/v6
- Migration test pinned for the v5→v6→v7 walk end-to-end

Scraper:
- ``_first_user_prompt_hash`` hashes the concatenated text parts of
  the session's first user message; that hash is applied to every
  assistant turn from the same session, so ``GROUP BY prompt_hash``
  measures cross-session duplication, not within-session multi-turn

Real-archive smoke (449 archives / 3740 turns):
- 448 distinct sessions → 436 distinct prompt_hashes
- 12 sessions share a prompt with another session (2.7% redundancy)
- Confirms the hypothesis: workers have per-cycle entropy in their
  prompts; generic response caching wouldn't pay back. The estimator's
  existing ``(pr_number, head_sha)`` cache covers the only place
  exact-prompt repeats happen by design.

Takes effect on the next pipeline run — existing rows stay NULL.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 16:43:39 -04:00
..