Repository navigation
SCAL-352370: store the analytical session with each chat-history answer - #78
Open
mouryabalabhadra wants to merge 5 commits into
Open
mouryabalabhadra wants to merge 5 commits into
mouryabalabhadra wants to merge 5 commits into
Conversation
A ThoughtSpot analytical session belongs to the Org it was created in. After an Org switch the old session rejects new messages, so the agent opens a new one and later charts live there. The chat history kept one session id per chat, so on reopen those charts were looked up in the first session and came back wrong or not at all. - Tag every answer and Show work query with the session it was polled from, and let a newer create_analysis_session replace the stored one. - Store the session on each reply and each answer placeholder, plus how many questions the reply sent (ts_message_count). Number answers within their own session on reopen, so a session another Org cannot read keeps its placeholders and the SDK shows its notice instead of the app dropping them. - Pair replies with ThoughtSpot messages by that count instead of assuming one message per reply, which dropped charts when the agent retried within a reply. - Load Show work answers from the reply's session; reject sessions the chat never used. - Additive migration: new turns columns, older replies pinned once to the chat's session. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Security review follow-up. The session id in a get_session_updates call comes from the model's tool arguments, so a prompt could point it at any session and have that id stored with the chat's answers. - Track the sessions create_analysis_session returned per conversation (seeded from storage on reload) and tag charts only with those. - Accept only URL-safe session ids, and quote them in ThoughtSpot REST paths. - Reject a malformed session_id on the work-answers endpoint as well as one the chat never used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deleting a conversation cleared its message cache and current session but left its trusted-session set behind. Clear all three together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite "How chat history works" in plainer terms: a short glossary, what to save and why, and a step-by-step example of one chat that spans two sessions after an Org switch - what the agent does, what is saved, how the charts are numbered on reopen, the replay links, and what a viewer in each Org sees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent review follow-ups. - Count the questions ThoughtSpot accepted as they happen (a new session_message SSE event from call_tool) instead of reading the finished Claude history. A turn that fails or is cancelled after asking now still records its questions, and a greeting before any session records none, so later replies are no longer shifted. - Store the counts per session (ts_message_counts JSON) and number each chart within its own stored session, so a reply that spans two sessions keeps both charts. - Store a reply even when all it did was ask ThoughtSpot a question. - Distinguish "ThoughtSpot will not return this session" (4xx: keep the placeholders, the SDK shows its notice) from "ThoughtSpot is unavailable" (5xx/timeout: retry once, then 503) so a transient failure never numbers charts onto the wrong answer. - Run the migration's ALTERs and backfill in one transaction; carry over counts written by the pre-release ts_message_count column. - README: correct the worked example (accepted vs rejected questions, the old-behaviour counterfactual), document session_message and ts_message_counts, and list the limits for chats saved before this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
A ThoughtSpot analytical session belongs to the Org it was created in. After an Org switch mid-chat, the old session rejects new questions (HTTP 400) and reading it returns 422 "Invalid org id", so the agent opens a new session. The chat-history example stored one session id per chat, numbered charts across the whole chat, and assumed one ThoughtSpot message per reply. On reopen, charts from the second session were looked up in the first one: they came back as the wrong chart or were silently dropped. The one-message-per-reply assumption also dropped charts whenever the agent retried inside a reply.
Change (
mcp/python-react-agent-simple-ui)answer/ Show work query event carries the session it was polled from; reply rows and answer placeholders store it. Charts are numbered within their own session on reopen.session_messageSSE event (ignored by the UI) fires each time ThoughtSpot accepts asend_session_message. Replies storets_message_counts({session: n}), so failed/cancelled turns, greetings (0) and retries (2+) pair correctly with ThoughtSpot's messages.create_analysis_sessionreplaces the chat's current session, so follow-ups go straight to it.turns.analytical_session_id,turns.ts_message_counts), in one transaction; older replies are pinned once to the chat's session and count as one question.SDK side (doc-only): thoughtspot/visual-embed-sdk#748.
Testing
/api/rest/2.0/ai/agent/conversations/{id}/messages) and the SDK's (/conversation/v2/{id}/public) return the same final answers in the same order.tsc --noEmitpasses.Known limit: chats saved before this change that already spanned two sessions, or had retries, cannot be repaired (nothing recorded which reply used which session).
🤖 Generated with Claude Code