Skip to content

fix(contextpilot): stop spurious WARNING on single-prompt completion optimize (#146 Bug 3) - #149

Open
drunkcoding wants to merge 3 commits into
devfrom
fix/contextpilot-completion-empty-context
Open

fix(contextpilot): stop spurious WARNING on single-prompt completion optimize (#146 Bug 3)#149
drunkcoding wants to merge 3 commits into
devfrom
fix/contextpilot-completion-empty-context

Conversation

@drunkcoding

Copy link
Copy Markdown
Contributor

Summary

Fixes #146 Bug 3: every single-prompt /v1/completions request logged a
spurious WARNING —

ContextPilot completion optimize failed: list index out of range

— even though the request proceeds fine via fallback.

process_completion_request calls ContextPilot.optimize([], prompt) (a bare
completion prompt has no separate contexts), and ContextPilot raises
IndexError: list index out of range on that empty context set. The completion
path only caught TypeError, so the IndexError fell through to the broad
except Exceptionlogger.warning(...).

Change

  • Catch (ValueError, IndexError) in process_completion_request and preserve
    the prompt with a DEBUG log — exactly how the chat path
    (_reorder_messages) already guards the same ContextPilot edge case. Requests
    still proceed (unchanged); only the noisy WARNING goes away.
  • Regression test test_process_completion_request_survives_optimize_index_error:
    injects a ContextPilot whose optimize raises IndexError, and asserts the
    prompt is returned and no "completion optimize failed" WARNING is
    emitted (non-vacuous — it fails against the pre-fix code, which warns).

Verification

returned: 'the capital of france is'
WARNING 'failed' present: False
DEBUG  'preserving' present: True
  • tests/python/contextpilot76 passed, 1 skipped (was 75; +1 new test).
  • ruff format / ruff check clean; LSP clean.

Relationship to #147 / #148

Independent of #147 (Bug 1, multi-GPU device hang) and #148 (Bug 2, surface
failed init as unhealthy). All three target dev and reference #146. With this,
the three concrete blockers from #146 are addressed.

Refs: #146

drunkcoding added 3 commits August 11, 2026 16:36
process_completion_request calls ContextPilot.optimize([], prompt) -- a
bare completion prompt carries no separate contexts -- and ContextPilot
raises IndexError ("list index out of range") on that empty set. The
completion path only caught TypeError, so the IndexError hit the broad
`except Exception` and logged a WARNING ("ContextPilot completion
optimize failed: ...") on every single-prompt completion, even though the
request still proceeds via fallback (issue #146 Bug 3).

Guard the same way the chat path (_reorder_messages) already does: catch
(ValueError, IndexError), log at DEBUG, and preserve the prompt. Adds a
regression test asserting no WARNING is emitted and the prompt is
returned unchanged.

Refs: #146
…to_experts

transformers 5.15 removed GlmMoeDsaMoE.route_tokens_to_experts, which
glm_moe_dsa.py and test_glm_routing.py rely on. CI installs the latest
5.x (requirements pin transformers>=5.3.0,<6), so unit-tests (3.10)/(3.12)
fail on dev (and every open PR) with
"AttributeError: type object 'GlmMoeDsaMoE' has no attribute
route_tokens_to_experts".

Skip the GLM routing module when the method is absent (mirrors the
existing importorskip guard), and resolve it via getattr so the block
raises a clear, actionable error at routing time instead of a cryptic
AttributeError at construction.

Refs: #146
_initialize_model passes speculative_draft to ContinuousBatchingEngine
(since the DFlash integration), but the watchdog test's _FakeRuntimeEngine
mock never accepted it. On transformers 5.15, once the earlier GLM
failure stops masking it (pytest runs fail-fast), test_watchdog_integration
fails with "unexpected keyword argument 'speculative_draft'". Match the
real ContinuousBatchingEngine signature (same fix already in #148).

Refs: #146
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.

1 participant