Repository navigation
make server.py capabale to run codex - #132
Conversation
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="dflash/scripts/server.py">
<violation number="1" location="dflash/scripts/server.py:413">
P1: Responses API `tool_choice` is typed as `str | None`, so valid object-style tool_choice payloads will be rejected with 422 before mapping logic runs.</violation>
<violation number="2" location="dflash/scripts/server.py:1525">
P2: Responses non-stream parsing drops `started_in_thinking`, so prefixed `<think>` generations can be misclassified as normal content instead of reasoning.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@howard0su we have been working on the same problem, mine was Openclaw/Hermes. @davide221 pointed me to this PR. I have rebased my branch to yours, most of your stuff addresses this issue, what was only left on my branch was just some improvements in handling tool calls. If you can test my PR that will be appreciated. #145 |
|
There is still some issues in my code. I am hitting empty_response after several rounds of tools call. |
yes I am hitting this as well. Debugging. I will let you know if we solve it. |
add the missing feature, integrate tools call support for server.py
- Rewrite test_server.py with 36 comprehensive tests (was 10):
- TestParseReasoning: 8 tests covering tags, headless, disabled, started_in_thinking
- TestParseToolCalls: 6 tests for single/multi/params/text preservation
- TestStopHelpers: 7 tests for normalize_stop and first_stop_match
- Endpoint tests: health, CORS, models (OpenAI+Codex), chat completions
(non-streaming, streaming, tool calls), Responses API (non-streaming,
string input, instructions, streaming, tools, function_call_output,
developer role mapping)
- Fix UnboundLocalError for started_in_thinking in streaming closures
by adding nonlocal declarations in chat and anthropic SSE generators
- Add DEVELOPER.md with environment, setup, build, and test documentation
Co-authored-by: Copilot <[email protected]>
Change tool_choice type from 'str | None' to 'Any | None' in
ResponsesCreateRequest so object-style payloads like
{"type": "function", "name": "..."} pass Pydantic validation
and reach the mapping logic. Matches ChatRequest which already uses Any.
Add test_responses_object_tool_choice to cover this case.
Co-authored-by: Copilot <[email protected]>
Pass started_in_thinking through to _responses_non_stream and forward it to parse_reasoning so prefixed <think> generations are correctly classified as reasoning instead of leaking into output content. Also reset started_in_thinking=False on cache hits (consistent with chat completions path). Add test_responses_non_streaming_started_in_thinking regression test. Co-authored-by: Copilot <[email protected]>
Qwen's chat template requires the system message at position 0 and rejects multiple system messages. Codex sends both 'instructions' and developer-role input items, which _map_responses_input was converting into separate system messages, causing 'System message must be at the beginning' errors. Fix: collect all system/developer content and merge into a single system message prepended to the message list. Also add name='DFlash' to the Codex config docs (required by v0.130.0) and remove temporary debug try/except wrapper. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Log each incoming request with: response_id, stream mode, message count by role, tool count, prompt token count, max output tokens, max_ctx, and model name. Log completion with output types and token counts. Add WARNING-level logs when prompt exceeds max_ctx (the silent response.failed that was causing Codex to disconnect). Co-authored-by: Copilot <[email protected]>
Report elapsed time and tok/s in DONE log lines for both chat completions and responses endpoints (stream + non-stream). Example output: responses DONE resp_abc in=4096 out=512 3.2s 160.0 tok/s output=['message'] text_len=2048 Co-authored-by: Copilot <[email protected]>
When enabled, the ~3.3 GB decode draft model is parked (freed from VRAM) at startup and between requests. It is automatically unparked before each generate command and parked again after tokens are consumed. This frees VRAM for longer KV cache context (e.g. +247K tokens with TQ3_0 KV type) at the cost of ~200-500ms per-request overhead for the GPU reload. Implementation: - Park draft in _startup() after daemon ready - Unpark draft in _write_cmd() before sending generate command - Park draft via _park_draft_if_lazy() after token consumption in all 7 generate paths (3 endpoints × stream/non-stream + early stop return) - DEBUG-level logging for park/unpark events Co-authored-by: Copilot <[email protected]>
Break down elapsed time into phases: compress, unpark, prefill, decode,
park. Prefill is measured as time-to-first-token after command sent.
Decode shows wall time and tok/s for tokens 2..N (excluding TTFT).
Example log output:
responses DONE resp_xxx in=15451 out=102 55.8s 1.8 tok/s ...
compress=45.2s unpark=0.3s prefill=7.1s decode=2.9s(34.8tok/s) park=0.0s
Implementation: thread a timing dict through _write_cmd, _park_draft_if_lazy,
_astream_tokens, _collect_tokens_sync, and _token_stream. The _timing_summary
helper formats the breakdown for log lines.
Co-authored-by: Copilot <[email protected]>
When the daemon returns 0 tokens (e.g. 'empty prompt' from missing/empty .bin file), confirm_inline_snap/confirm_full_snap was registering cache entries for snapshots that were never actually taken. Future requests hitting those entries would RESTORE from corrupt/stale KV data. Changes: - Add _confirm_or_abort_snap() helper: confirms snap only when n_tokens>0, otherwise calls abort_inline_snap/abort_full_snap to release reservation - Replace all 6 raw confirm_inline_snap/confirm_full_snap call sites with the new helper (chat/anthropic/responses × stream/non-stream) - Add .bin file validation in _write_cmd: warns if file is missing or 0 bytes before sending the generate command to the daemon Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@howard0su ok I think I have fixed the empty reply issues. While I was also debugging this other issues was also uncovered. This now works well with OpenClaw and Hermes. The last 2 commits on my PR are the fixes. #145 Please kindly test my branch, I have rebased this your recent push above. |
I checked your PR. I suggest you to split the focused fix as a separate PR (I believe your last commit). We need it ASAP. |
make server.py capabale to run codex
No description provided.