Repository navigation
Studio: cancel + bound conversation-archive embeddings before inference (#14519) - #14546
danielhanchen merged 33 commits into
Conversation
…ation path Long chats spent minutes in a single SentenceTransformer.encode inside archive_turns before llama.cpp saw the request, and Chat Stop could not interrupt it (unslothai#14519). Batch embeds with cooperative cancel_check, cap chunks per call, and keep already-written groups.
…to current upstream main
… cap test A timeout late in a long archive pass discarded every batch already embedded, so the next request redid them all. Write the groups those batches fully cover, then report the failure as before. The cap test assumed one follow-up drains the backlog; loop until it does and check every call stays under the cap. [skip ci]
[skip ci]
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. |
…g at the cap [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: f31c2cd399
ℹ️ 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".
| ) | ||
| _widen_span(conn, scope, digest, span) | ||
| continue | ||
| if collected >= max_chunks: |
There was a problem hiding this comment.
Bound the crossing group before chunking it
When collected is below the cap but the next evicted turn expands beyond the remaining budget (for example, 255 chunks followed by a large pasted turn), this newly added guard still lets chunk_pages tokenize and materialize the entire turn before the later kept pass discards it. Since cancellation is only polled around whole groups, Stop cannot interrupt that work, and the discarded turn is processed again on the next compaction, so a single large group can still recreate the pre-inference stall this cap is meant to prevent; make chunk production honor the remaining budget or defer the group without fully chunking it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as is: the wasted step is tokenizing one oversized turn, not embedding it. Measured, a 191k-token turn chunks in 2.9 s against roughly 40 s to embed its 439 chunks, and that turn is embedded on the next request once it is first in line.
|
Codex Review: Didn't find any major issues. Nice work! 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". |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
[skip ci]
… vector rows [skip ci]
…ech-to-text loads
|
Codex Review: Didn't find any major issues. Keep them coming! 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". |
# Conflicts: # studio/backend/core/inference/diffusion.py [skip ci]
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
Two more backend checks fail on `main` (60c7715). Both reproduce on a clean `main` worktree, and in both the test needed to change, not the product. | Check | Introduced by | Fix | |---|---|---| | `studio/backend/tests/test_inference_dispatcher_resilience.py::test_route_llama_streaming_async_clients_disable_proxy_env` (`assert 0 == 5`) | #14546 | That PR builds the five local llama-server clients in `routes/inference.py` through `gated_async_client`. It wraps `httpx.AsyncClient` so that conversation-archive embedding pauses for the request. The AST walk only matched `httpx.AsyncClient(...)`, so it found none. It now counts both spellings and still requires `trust_env=False` on each of the five. It also pins that `gated_async_client` passes its `**kwargs` to the `httpx.AsyncClient` it builds, which is the step that keeps a proxy setting from reaching the local server. | | `tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding[6]` | #14868 | `test_diffusion_zimage_cfg_split.py` read `diffusion.py` with `read_text()`. That read now passes `encoding = "utf-8"`. | The product side checks out: all five `gated_async_client(...)` calls pass `trust_env = False`, and the wrapper forwards it. ## Verification - `test_inference_dispatcher_resilience.py` and `test_diffusion_zimage_cfg_split.py`: 38 passed. - `tests/test_source_read_encoding.py`: 16 passed. - Sabotage checks, each fails the guard: - removing `trust_env = False` from one of the five calls; - making `gated_async_client` drop its `**kwargs`; - restoring the bare `read_text()`.
`studio/backend/tests/test_gguf_load_cache_reuse.py::TestLoadHubDownloadExclusion::test_load_marker_precedes_hub_guard_which_precedes_the_gpu_handoff` fails on `main`, for example in Backend CI `(Python 3.13, a-k)` on #15000 and #15001. ## Cause The test's last assertion is a literal source match: `"@_with_gguf_load_marker\n def load_model("`. #14546 added `@holds_inference` between that decorator and `def load_model`, so the string no longer appears. The load marker still wraps `LlamaCppBackend.load_model`, so the product is fine and the test was out of date. ## Fix The check now parses `llama_cpp.py`, finds `LlamaCppBackend.load_model`, and asserts that `_with_gguf_load_marker` is in its decorator list, in any position. The rest of the test, including the ordering in `routes/inference.py`, is unchanged. ## Verification - `studio/backend/tests/test_gguf_load_cache_reuse.py`: 75 passed. On `main` this test failed when run alone. - Sabotage check: removing `@_with_gguf_load_marker` from `load_model` fails the test.
Summary
archive_turnsblocked the generation worker in a single synchronousSentenceTransformer.encodeof every pending chunk, and Chat Stop did not interrupt it (distinct from the string-matcher fix in fix(rag): avoid long CPU stalls when archiving tool calls #14098)._ARCHIVE_EMBED_BATCH = 64) and poll an optionalcancel_checkbetween batches;_archive_and_recallforwardscancel_eventfrom the chat Stop path.archive_turnscall (default 256, overrideRAG_ARCHIVE_EMBED_MAX_CHUNKS); deferred groups stay unindexed and are picked up on a later request (idempotent by digest). Already-written groups are kept; incomplete groups are not written.@danielhanchen - this matches the reporter’s py-spy stack (
_archive_and_recall→archive_turns→encode_with_identity). Happy to adjust batch/cap defaults if you prefer different numbers.Test plan
pytest studio/backend/tests/test_conversation_archive.py::test_a_first_compaction_embeds_its_turns_in_one_passpytest studio/backend/tests/test_conversation_archive.py::test_archive_embed_honors_cancel_between_batchespytest studio/backend/tests/test_conversation_archive.py::test_archive_embed_caps_chunks_per_callRAG_CONVERSATION_ARCHIVE=1, send a short follow-up, press Stop during the pre-inference CPU spike - embed work should stop between batches and inference path should not stay pegged at ~17 coresFollow-up changes
Fixes #14519