Repository navigation
feat: reseed a resumed chat after its server session expired (E1.6) - #696
Conversation
…E1.6)
POST /{community}/chat takes optional prior_turns (24 turns, 4,000 chars each) and mode.
A session the request just created is started from one fenced message built by
reseeded_message; a live session ignores both. Tested against the real app and graph.
Skipped here, no ANTHROPIC_API_KEY; not run.
… session (E1.6) Newest 12 turns, text only, each cut from the middle at 2,000 chars; sent on the first request of a page load, after opening a chat from History or the resume card, and after a day without a server answer. New test-widget-reseed.js (54 checks) wired into CI; the other widget suites still pass.
Preview Deployment
This preview will be updated automatically when you push new commits. |
…ip, drop whole oldest turns (tested)
…test widget limits against the server's (tested)
…ction (not run: no API key)
…t the rule (actionlint clean)
… budget and api-structure fields; changelog
Review round 1: outcomesFix commits are on this branch (dadf332, 1dedc9f, 8c58489, cee3461, a1b8548).
Tests run
|
…sted (bun test-widget-reseed.js)
Review round 2: outcomes
Tested: |
Merge verdict: not merged yetEverything is in place except one criterion.
To unblock: someone with a key runs |
# Conflicts: # CHANGELOG.md # frontend/osa-chat-widget.js # src/api/routers/community.py
Summary
A conversation that resumes after its server session is gone (24 hour idle lifetime, a restart, or LRU eviction) used to be answered with no context: the widget kept the old session id and the server made a fresh, empty session under it. Now the widget sends a compact transcript on the requests where the server might not have the session, and the server uses it only when the request just created the session.
Server (
src/api/routers/community.py,src/agents/model_routing.py):POST /{community}/chataccepts optionalprior_turns(at most 24{role: user|assistant, text}turns, 4,000 characters each, extra fields forbidden, blank text refused, all 422) andmode(quick|analysis).HumanMessagebuilt by the newreseeded_message(transcript, reader_message): the transcript (reusinghistory_transcript, kept to whole turns withinSUMMARY_INPUT_MAX_CHARS, the oldest dropped behind an[earlier turns omitted]marker) as fenced background, then the reader's message, so there are never two consecutive user messages. Its own fence is stripped from the text (repeatedly, so a fence rebuilt by removing another is removed too). A session that already has messages ignores both fields.routing_applies,modesetssession.modebefore the turn, sohanding_overis false and the turn runs on the stored tier with no handover events and no summarizer call. Elsewheremodeis ignored. The keyword check (wants_analysis) reads the reader's own words, not the transcript, so a keyword in an old turn does not flip a quick chat to analysis./chat/resumeis unchanged.Widget (
frontend/osa-chat-widget.js):// BEGIN reseedblock: newest 12 turns, user and assistant text only, each cut from the middle at 2,000 characters with an ellipsis (never splitting a surrogate pair), the greeting is not a turn,modefrom the newest reply that stored one.serverConfirmedAtis set on asessionordoneevent (and a non-streaming reply) and is not persisted. It is reset on page load, on opening a conversation from History or the resume card, on a new, deleted or cleared chat, and, by the rule inreseedFields, when more thanSESSION_TTL_MShas passed since the last server answer. Nothing is sent for a new empty chat, a chat with no assistant reply, or a session the server confirmed in this page load.conversation_id: #694 has since merged. A reseeded session is created under the session id the widget stored, so its usage rows keep that id as their conversation id; after a handover the stored id is the analysis session's, so a reseeded analysis chat starts a new conversation in the cost report, as the metrics docs from #694 say.Refs #659 (it closes after a real-model check of reseeding on develop-demo, since
test_reseed_llm.pyhas not been run with a key)Tests
tests/test_api/test_reseed.py(new, 47 tests): real app, realcreate_community_assistant, real graph, real session store. The stand-in model answers from what its input contains (the dataset id, or "no context"), not from a script. Covers: a first request withprior_turnsabouton002718and "which dataset were we discussing" answers with the id; the same request without them does not; exactly one user message reaches the model; stored history alternates; a live session ignoresprior_turnsandmode; 422 for 25 turns, a long turn, bad roles, blank text, extra fields, wrong types and an unknown mode; the limits themselves are accepted; the seed is trimmed to the newest text; a fence in a turn cannot close its section; a storedanalysismode keeps the analysis tier with no handover events and no quick-model call; mode is ignored when not routed (noexecute_code, a chosen model, a community that does not route); the non-streaming path seeds too.tests/test_frontend/test_reseed_limits.py(new): keeps the widget's reseed bounds equal to the server's limits.tests/test_integration/test_reseed_llm.py(new,llmandintegration): real NEMAR community and real models (quick, analysis, and the no-turns control, usingxx099904). SKIPPED here: this environment has noANTHROPIC_API_KEY, so it has not been run.frontend/test-widget-reseed.js(new, 63 checks, wired intofrontend-testsin.github/workflows/tests.yml): asserts the captured request bodies for a restored conversation, a reload, a new empty chat, a conversation with no assistant reply, a conversation opened from History, the idle rule at one hour either side ofSESSION_TTL_HOURS, a request the server never answered, the 12 turn and 2,000 character bounds, and text-only; plus the extracted pure block.Commands run
gh pr view 694 --json state,mergedAt:OPEN, not mergeduv run pytest tests/test_api/test_reseed.py tests/test_api/test_model_routing.py tests/test_api/test_session_lifecycle.py tests/test_agents/test_model_routing.py tests/test_frontend -q:tests/test_api1664 passeduv run pytest tests/test_integration/test_reseed_llm.py -m llm -q: 3 skipped (noANTHROPIC_API_KEYin this environment)bun frontend/test-widget-reseed.js: 63 passed, 0 failedbun frontend/test-widget-fresh-return.js(59 passed),test-widget-history-store.js(212 passed),test-widget-handover-events.js(14 passed)frontend/test-widget-*.jssuite: exit 0uv run ruff check .anduv run ruff format --check .: clean