Repository navigation
Studio: keep compacted turns searchable when the archive embedder fails - #16718
Conversation
When the embedding model behind the conversation archive could not run (a failed load, a missing llama-server, a download still pending), compaction still dropped the old turns but archived nothing. The chat then never had an archive, so search_conversation was never offered and the automatic recall found nothing. Those turns are now stored for keyword search instead, with a marker that matches no embedder, so the next request with a working embedder re-embeds them in place. A store failure still archives nothing, so it is retried as before. Fixes unslothai#16706
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 33216e3409
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if store.documents_by_hash(conn, scope, digest): | ||
| continue |
There was a problem hiding this comment.
Preserve each evicted occurrence of a repeated turn
When the embedder is unavailable and identical turns occur at different positions, this unconditional hash check discards every occurrence after the first. For example, archiving set X to 1, set X to 2, then set X to 1 with identical assistant replies writes only two documents; recall consequently presents the intermediate value 2 as the latest update. The dense path explicitly preserves these occurrences using _write_budget and separate ordinals. Apply the same occurrence-aware, live-prompt-aware budget in both lexical duplicate checks rather than treating any existing copy as sufficient.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ec32fba: the keyword fallback now writes one copy per evicted occurrence (_write_budget, live-prompt aware) at each occurrence's seat, as the dense path does; test_keyword_copies_keep_every_evicted_occurrence_of_a_repeated_turn.
| if dense_failed and not (cancel_check is not None and cancel_check()): | ||
| # Without any copy there is no archive, so search_conversation is never offered (#16706). | ||
| # degraded() stays set: dense recall is still down. | ||
| written += _archive_turns_lexically(thread_id, scope, groups, positions) |
There was a problem hiding this comment.
Poll cancellation while writing the lexical fallback
When the embedder fails on a long compacted history, a Chat Stop received after this call starts is ignored until every group has been chunked and committed: the helper receives no cancel_check and processes all groups without the dense path's cap. In an isolated check, setting cancellation after the first lexical write still allowed all 3,000 turns to be written. Because _archive_and_recall calls this synchronously, cancellation cannot interrupt the archival pass. Pass the callback through and poll it between groups.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ec32fba: cancel_check is passed through and polled before each turn (a 3000-turn fallback took 7.8 s here without it); test_chat_stop_interrupts_the_keyword_fallback.
…hat Stop [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec32fba863
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if len(store.documents_by_hash(conn, scope, digest)) >= budget: | ||
| continue |
There was a problem hiding this comment.
Retire surplus keyword copies after a rewind
With the embedder still unavailable, archive X=1, X=2, X=1, rewind to the first two turns, and compact again. Both lexical duplicate checks simply skip existing copies, leaving archive ordinals [0, 1, 2] instead of [0, 1]. _document_on_live_branch accepts the removed repeat because its text matches the surviving first occurrence, so recall presents X=1 as the latest update, overriding the actual latest value X=2. Apply the dense path's surplus-copy and ordinal reconciliation before skipping retained keyword copies.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bfa6aef: a keyword copy that already meets its budget now goes through the dense pre-check's _restamp (re-seats, retires surplus copies after a rewind); test_a_rewind_retires_the_copy_the_conversation_no_longer_holds now also runs with the embedder failing.
| if len(store.documents_by_hash(conn, scope, digest)) >= budget: | ||
| continue |
There was a problem hiding this comment.
Widen the transcript span of existing keyword copies
When the embedder is unavailable and a previously archived tool exchange is re-evicted with an additional retrieval-result message, stripping retrieval leaves the same content hash. These duplicate checks skip the copy without calling _widen_span, so a copy saved with archive_messages=3 remains at 3 even when the new transcript span is 4. Reproducing the existing longer-span regression case with the embedder disabled makes _document_matches_one_run reject the otherwise matching turn, and branch-filtered recall returns nothing. Preserve the dense path's span widening on both lexical duplicate-skip paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bfa6aef: the same skip path calls _widen_span; test_the_same_text_over_a_longer_span_widens_the_stored_window now also runs with the embedder failing.
…ike dense copies [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fixes #16706 (also the cause behind #16187 and #16602).
What was wrong
search_conversationis only offered once something has been archived for the chat (has_archive), and archiving needs the embedding model. When that model could not run (a failed load, no llama-server for the embedding fallback, a download still pending),archive_turnsloggedconversation_archive.ingest_failedand wrote nothing, while the compaction fit had already dropped the turns. The chat then never got an archive, so:search_conversationwas never added to the tool list, on GGUF and API models alike;What this changes
conversation_archive._archive_turns: when the embedder fails (an exception before any vectors came back, the embedder's own error after a partial pass, orEmbeddingModelDownloadRequiredError), the evicted turns that have no copy yet are stored for keyword search only (_archive_turns_lexically). They get the same document row, archive position and FTS5 rows as a normal copy, but no vectors.vectors-dropped:none(the existingrag_db.VECTORS_DROPPEDmarker), so they match no embedder. Once the embedder works, the next eviction sees them as stale and re-embeds them in place, keeping their position. Dense search never returns them in the meantime.store.add_lexical_chunkswriteschunks+chunks_ftswithout achunks_vecrow.add_chunksfailing) does not fall back, so it still archives nothing and is retried as before.degraded()keeps its meaning (the dense write failed), so recall room and checkpoint resets behave as before.Tests
New in
tests/test_conversation_archive.py:test_turns_evicted_while_the_embedder_fails_stay_searchable: with the embedder failing, the thread gets an archive,search_conversationfinds both turns, and a later working embedder re-embeds them at the same positions. Fails on main (archive_turnsreturns 0).test_a_failing_store_does_not_fall_back_to_keyword_copies.Updated for the new behaviour: the pending-download, degraded and partial-batch tests now expect the keyword copies (and the pending-download test also recalls the turn evicted while the download was pending).
Run on Windows 11 (Ryzen 5 5600H, RTX 3050 4 GB), Python 3.12, with and without the change:
test_conversation_archive.py,test_external_conversation_archive.py,test_conversation_recall_injection.py,test_conversation_recall_session.py,test_rag_store.py,test_rag_reembed.py,test_rag_retrieval.py,test_rag_vec_cache.py,test_rag_embedding_identity.py,test_checkpoint_compaction.py,test_llama_cpp_tool_loop.py,test_openai_auto_switch.pyand the other suites that touch the archive (27 files). Same results on both apart from the two new tests; the few failures/errors there (test_checkpoint_compaction.py, one each intest_llama_cpp_tool_loop.pyandtest_view_image_tool.py) fail identically on clean main on this machine.End to end: a real Studio server (
run.py --api-only) with an OpenAI-compatible stub provider (vLLM type, 4k window), driving a 6-turn chat, two edits of the last message, a follow-up, and a turn where the model callssearch_conversation:search_conversationoffered after the first compactionRAG_EMBED_BACKEND=llama-server, no binary)Not tested here: a real llama.cpp chat (no llama-server on this machine) and macOS.