fix(gateway): stop /refine cold-cache false emptiness - #83872
fangliquanflq wants to merge 4 commits into
Conversation
Consult the persisted transcript when the messaging agent cache is cold, ask to resume when durable turns exist, and keep transcript read failures distinct from empty.
fix(gateway): stop /refine cold-cache false emptiness
|
|
Thanks for the detailed review. I investigated each point and pushed the actionable fixes in
While validating the read path, I also found that the production Validation:
|
Thanks for the pass — the lock-held |
|
Thanks for confirming. The current head keeps the lock-held read-only session lookup, reports the persisted user/assistant count precisely, and preserves the canonical replay shape returned by |
What does this PR do?
On messaging platforms,
/refineno longer treats a cold_agent_cacheas an empty conversation. When the live agent is missing, the handler loads the persisted transcript off the event loop and reports that durable turns exist so the user can resume first. When the agent is cached but_session_messagesis empty, it falls back to that transcript and starts the review. Transcript read failures return a distinct error instead of looking like emptiness.Symptom
/refineon Telegram/Discord/etc. can returnNothing to refine yet - send a message first.after completed turns once the idle agent has left_agent_cache.Impact
Messaging users cannot refine an existing conversation, or get a false empty-conversation claim, even though the session store still has usable turns.
Bug Cause
Trigger:
gateway/slash_commands.py::_handle_refine_commandwith a cold_agent_cacheCausal chain:
/refinelooks up the session agent only in_agent_cache.session_store.load_transcript, so durable turns are ignored.Why it is wrong: Cache absence is not emptiness. The Desktop/TUI path already fixed the sibling false claim in #83520; messaging still had the cold-cache branch.
Working sibling / contrast: #83520 loads persisted history and runs refine for Desktop/TUI. This PR covers the messaging gateway path called out as complementary on #83455.
Ruled out: A truly empty transcript still returns the original empty-conversation messages.
Fix
Resolve the session entry, load the transcript via
async_session_store(already offloaded withasyncio.to_thread), countuser/assistantrows, and:_session_messages+ durable turns -> run review against the persisted snapshotRelated Issue
Fixes #83871
Related: #83455, #83520
Type of Change
Changes Made
gateway/slash_commands.py- consult persisted transcript for cold-cache and empty in-memory/refinepathstests/gateway/test_refine_command.py- cover resume prompt, true empty, read failure, and persisted-snapshot reviewHow to Test
Results: 5 passed on Windows with the project venv.
Checklist
Code
Documentation & Housekeeping