Skip to content

feat: add debug traces and failure events to message history - #238

Open
HardeepAsrani wants to merge 1 commit into
developmentfrom
feat/message-history-debug
Open

feat: add debug traces and failure events to message history#238
HardeepAsrani wants to merge 1 commit into
developmentfrom
feat/message-history-debug

Conversation

@HardeepAsrani

@HardeepAsrani HardeepAsrani commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

Closes Codeinwp/hyve#300
Pro PR: https://github.com/Codeinwp/hyve/pull/301

Until now, the Messages screen only showed what the visitor and the bot said, with no way to tell why a reply came out the way it did. This PR records a debug trace with every bot reply and surfaces it in the conversation view.

Each bot reply now shows a summary line (answered or not, number of sources used) with a Show trace toggle that expands a detail panel:

  • Answered by: self-hosted or Hyve Connect, poll or stream
  • Model, latency and token usage for the turn
  • Sources: which knowledge base entries matched, with similarity score bars, the threshold marker, and entries that matched but were dropped because the context was full
  • Page: the page the visitor chatted from, and whether its content was used as context
  • Skills used during the turn and what they returned (Pro)
  • Follow-ups suggested to the visitor
  • Model reply & retrieval query: the raw reply (when a reply wasn't shown to the visitor) and the query used to search the knowledge base

Failed turns are no longer lost: messages flagged by moderation, rate-limited visitors and API errors now appear as event markers in the conversation. The visitor's message is kept, and the failure is never recorded as a bot reply. Repeated rate-limit hits collapse into a single event so abuse can't grow the database.

Also fixed along the way:

  • A temporary moderation API outage was reported to the visitor as "your message was flagged". It now returns a proper "try again" error.
  • A failed first message used to fork the conversation into two threads.

Works across all four reply paths: self-hosted and Hyve Connect, polling and streaming. Older conversations without traces render exactly as before.

Screenshots

Screenshot 2026-08-17 at 3 18 47 PM Screenshot 2026-08-17 at 1 26 31 PM

QA instructions

  1. With self-hosted mode and a populated knowledge base, ask the chatbot a few questions on the frontend (some it can answer, some it can't).
  2. Go to Hyve → Messages and open the conversation. Each bot reply should show a line like "Answered · 3 sources · Show trace".
  3. Click Show trace and check the panel shows the model, latency, tokens, threshold and the source list with score bars. Hover the small ? icons to see the help text. Click Hide trace to collapse it.
  4. Ask a question the bot can't answer. The trace should say Not answered and include the raw model reply.
  5. Ask a question from a regular page (not the homepage). The trace's Page row should link to that page.
  6. Send an abusive/offensive message. The conversation should show a "flagged by moderation" event divider instead of a bot reply, and the visitor's message should still be recorded.
  7. Send messages rapidly until rate-limited. A single "rate limit" event should appear, without duplicates for repeated attempts.
  8. Switch to Hyve Connect mode and repeat a couple of questions. Traces should show "Hyve Connect" with latency, tokens and sources (no threshold or score bars, that data stays on the platform).
  9. Open an old conversation created before this update. It should look unchanged.

…istory

Every bot reply now stores a debug trace with the conversation entry: the
answered flag, mode/transport, model, latency, token usage, similarity
threshold, the exact retrieval query, every matched KB chunk with its score
and token count (including chunks dropped for the context budget), the
visitor's page URL, follow-ups offered, and skills executed. The Messages
screen renders it as a collapsed line under each reply ("12:31 pm · Not
answered · 9 sources · Show trace") expanding into a label/value ledger
with score bars and a threshold tick.

Failed turns are no longer invisible: moderation-flagged, rate-limited and
errored turns record the visitor's message plus an event divider (never a
bot bubble). Rate-limit events only land on existing threads and collapse
consecutively, so blocked traffic cannot grow the database.

Also fixes two bugs found along the way: a moderation API failure was
reported to the visitor as "flagged by moderation", and a failed first
turn forked the conversation into a second thread instead of adopting the
real conversation id on the next successful turn.

Ref Codeinwp/hyve#300

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pirate-bot

Copy link
Copy Markdown
Contributor

🌍 i18n String Review Report

📊 Summary

Category Count
➕ Added 39
➖ Removed 0
🔄 Changed 0
Total 39
➕ Added Strings (39) - Click to expand
String Location Words Suggested Match
Message was flagged by moderation — no reply wa... src/backend/screens/Message... 10 This message was flagged by OpenAI moderation and was not answered.
Visitor hit the rate limit — the message was no... src/backend/screens/Message... 11 You are sending messages too quickly. Please wait a moment and try again.
%d source src/backend/screens/Message... 4 %d message
The minimum similarity score a knowledge base c... src/backend/screens/Message... 22 Similarity threshold
Follow-up questions suggested to the visitor a... src/backend/screens/Message... 9 Follow-up questions
The reply failed with an error src/backend/screens/Message... 6 No close match
Self-hosted src/backend/screens/Message... 1 No close match
Not answered src/backend/screens/Message... 2 No close match
Hide trace src/backend/screens/Message... 2 No close match
Show trace src/backend/screens/Message... 2 No close match
Answered by src/backend/screens/Message... 2 No close match
Where the reply was generated: on this site (s... src/backend/screens/Message... 22 No close match
The AI model that generated this reply. src/backend/screens/Message... 7 No close match
Latency src/backend/screens/Message... 1 No close match
Time from the visitor sending the message to th... src/backend/screens/Message... 12 No close match
Tokens src/backend/screens/Message... 1 No close match
OpenAI tokens spent on this reply: prompt (in... src/backend/screens/Message... 16 No close match
%1$s in · %2$s out src/backend/screens/Message... 5 No close match
Threshold src/backend/screens/Message... 1 No close match
Skills the assistant ran while composing this r... src/backend/screens/Message... 26 No close match
Yes src/backend/screens/Message... 1 No close match
%d round trip src/backend/screens/Message... 6 No close match
aborted src/backend/screens/Message... 1 No close match
Page src/backend/screens/Message... 1 No close match
The page the visitor was on when they sent this... src/backend/screens/Message... 11 No close match
content included as context src/backend/screens/Message... 4 No close match
Page context src/backend/screens/Message... 2 No close match
The content of the page the visitor was on was ... src/backend/screens/Message... 17 No close match
Included src/backend/screens/Message... 1 No close match
Follow-ups src/backend/screens/Message... 1 No close match
Knowledge base content sent to the model as con... src/backend/screens/Message... 39 No close match
%d tokens src/backend/screens/Message... 2 No close match
marks the similarity threshold (%s) src/backend/screens/Message... 6
Dimmed sources matched but were left out: the c... src/backend/screens/Message... 12 No close match
None matched src/backend/screens/Message... 2 No close match
Model reply src/backend/screens/Message... 2 No close match
What the model actually returned for this turn... src/backend/screens/Message... 15 No close match
Query src/backend/screens/Message... 1 No close match
The exact text used to search the knowledge bas... src/backend/screens/Message... 23 No close match
Total 309

@github-actions

Copy link
Copy Markdown

Plugin build for 09f2247 is ready 🛎️!

@HardeepAsrani
HardeepAsrani changed the base branch from main to development August 17, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants