Skip to content

fix(public-chat): an anonymous session finds its own history after a reload (#3443) - #3477

Merged
vybe merged 2 commits into
devfrom
feature/3443-public-chat-history-lookup
Oct 9, 2026
Merged

vybe merged 2 commits into
devfrom
feature/3443-public-chat-history-lookup

Conversation

@trinity-ability

Copy link
Copy Markdown
Contributor

Description

get_session_by_identifier lowercased its argument unconditionally, while get_or_create_session stores an anonymous token verbatim, so a mixed-case anonymous id never matched its own row — history never restored and New conversation cleared nothing. The lookup now matches the exact string first and falls back to the lowercased form only against rows with identifier_type = 'email', so email lookups stay case-insensitive.

Part of the UI sweep epic #3471.

Related Issue

Fixes #3443

Journey Impact

Journey Impact: none: bug fix to existing behaviour found by the UI sweep; no journey promise is added or changed

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Testing

  • I have tested this locally
  • New tests added (if applicable)
  • All existing tests pass
  • Every new test executes the changed path

Mutation: tests/unit/test_3443_public_chat_history_lookup.py — 3 red with the fix stashed (test_mixed_case_anonymous_token_finds_its_own_session, test_anonymous_tokens_differing_only_in_case_stay_separate, test_anonymous_lookup_is_not_case_insensitive); restored byte-identical. SQLite leg only; the PostgreSQL leg of the harness was not run locally.

UI verification: on an isolated stack built from this change with a seeded link, a mixed-case anonymous session and two stored messages (user + assistant): GET /api/public/history/<token>?session_id=<mixed-case id> returns both messages and the page renders them; the lowercased id gives an empty conversation. The seeded agent had no container, so the page's availability gate was bypassed in the browser to reach the history call — a full reload against a running agent with a real reply was not exercised.

Checklist

  • My code follows the project's style guidelines
  • I have updated the documentation (if applicable)
  • I have not committed any sensitive data (API keys, credentials, etc.)

🤖 Generated with Claude Code

…n, so history survives a reload (#3443)

get_or_create_session stores an identifier verbatim unless it is an email,
but get_session_by_identifier lowercased its argument unconditionally. An
anonymous identifier is a mixed-case secrets.token_urlsafe(16) token, so the
lookup behind GET /api/public/history/{token} and DELETE
/api/public/session/{token} never matched the row the chat turn had just
written: history came back empty after every reload, and "New conversation"
cleared nothing. Where two tokens differed only in case, the mixed-case
visitor was handed the lowercase visitor's session.

The lookup now matches the exact string first and reaches a row through its
lowercased form only when that row is identifier_type = 'email', which keeps
email lookups case-insensitive. One SQLAlchemy Core implementation serves
both SQLite and PostgreSQL; both route callers already pass the anonymous
token unmodified, so no caller changes.

Tests: tests/unit/test_3443_public_chat_history_lookup.py. With the fix
reverted, three go red:
test_mixed_case_anonymous_token_finds_its_own_session,
test_anonymous_tokens_differing_only_in_case_stay_separate and
test_anonymous_lookup_is_not_case_insensitive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	tests/registry.json
@vybe

vybe commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

merge-train (2026-10-10): merged origin/dev into this branch to clear the tests/registry.json append collision with #3479 (stage-based union, no new duplicates). Mechanical, no source change.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20261009-2324-b (#3504)

@vybe
vybe merged commit 471e4c4 into dev Oct 9, 2026
24 checks passed
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