Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
serve: Codex's thread-title turn can be answered without the engine, opt-in (#923)
moebear2db8ae14afd2
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex 0b4c6d21c..867419088 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -990,6 +990,7 @@ are refused with an error that says so.| `reasoning.effort` | `none`/`minimal`, `low`, `medium`, `high`/`xhigh`; without it the model's default (high) || `max_output_tokens` | The output cap (thinking included). Running out ends the response `incomplete` (`max_output_tokens`) || `text.format` | `json_schema` and `json_object` use the [JSON response formats](#json-response-formats) (checked, not constrained) |+| `thread_source` `thread_title` in `client_metadata["x-codex-turn-metadata"]` | Codex's thread-title request (opt-in: `"codex_thread_titles": true` in `strata-<model>.json`, off by default), sent beside each user turn from another session with `tools: []`: answered without the engine as `{"title": "<the user's line, cut to 36 characters>"}`, so the conversation keeps the prompt cache. The title is the user's line, not one the model wrote || `temperature`, `top_p`, `reasoning_budget_tokens`, ... | As on the chat path |The model's thinking comes back as a `reasoning` output item with `reasoning_text` content (streamed asdiff --git a/serve/responses.py b/serve/responses.pyindex 616111eec..7e3d80019 100644--- a/serve/responses.py+++ b/serve/responses.py@@ -293,6 +293,71 @@ def request_tools(req: dict):return tools or None, names, skipped+def _turn_body(req: dict):+ meta = req.get("client_metadata")+ raw = meta.get("x-codex-turn-metadata") if isinstance(meta, dict) else None+ try:+ turn = json.loads(raw) if isinstance(raw, str) else None+ except ValueError:+ return None+ return turn if isinstance(turn, dict) else None+++def _title_text(req: dict) -> str:+ """The user line Codex asked to name, cut to the schema's 36 characters."""+ parts = []+ items = req.get("input")+ if isinstance(items, str):+ items = [{"role": "user", "content": items}]+ if isinstance(items, list):+ for item in items:+ if not isinstance(item, dict) or item.get("role") != "user":+ continue+ content = item.get("content")+ if isinstance(content, str):+ parts.append(content)+ elif isinstance(content, list):+ for piece in content:+ if isinstance(piece, dict) and isinstance(piece.get("text"), str):+ parts.append(piece["text"])+ text = "\n".join(parts)+ if "User prompt:" in text:+ text = text.split("User prompt:", 1)[1]+ line = next((x.strip() for x in text.splitlines() if x.strip()), "Untitled")+ line = line.strip(" \"'`")+ while line and line[-1] in ".。!!??,,;;::":+ line = line[:-1].rstrip()+ return line[:36].rstrip() or "Untitled"+++def thread_title_events(req: dict, model: str):+ """Codex's thread-title turn, answered here. None when this request is not one.++ Codex 0.160 sends this beside the user turn: another session, no tools, the full instructions. Running it on the+ one prefix cache replaces the conversation.+ """+ if (_turn_body(req) or {}).get("thread_source") != "thread_title":+ return None+ check_request(req)+ text = json.dumps({"title": _title_text(req)}, ensure_ascii=False)+ asm = Assembler(req, model, 0, {}, False, json_mode=False)+ events = asm.start()+ events += asm._open({"id": new_id("msg"), "type": "message", "status": "in_progress", "role": "assistant",+ "content": []})+ asm.item["content"][0]["text"] = text+ events.append(asm.event("response.output_text.delta", item_id=asm.item["id"], output_index=asm.index,+ content_index=0, delta=text, logprobs=[]))+ events += asm.close()+ asm.response["usage"] = {+ "input_tokens": 0, "input_tokens_details": {"cached_tokens": 0},+ "output_tokens": 0, "output_tokens_details": {"reasoning_tokens": 0},+ "total_tokens": 0}+ asm.response["status"] = "completed"+ asm.response["completed_at"] = int(time.time())+ events.append(asm.event("response.completed", response=asm.snapshot()))+ return events++def text_format(req: dict):"""`text.format` -> the chat path's response_format (None: plain text)."""text = req.get("text")diff --git a/serve/server.py b/serve/server.pyindex dd568df34..876aab3f1 100644--- a/serve/server.py+++ b/serve/server.py@@ -2206,6 +2206,7 @@ class Service:self.literals = literal_tags(getattr(tokenizer, "control_tokens", ())) # texts that stay text inside a messageself.fit_max_tokens = fit_max_tokens # --fit-max-tokens: clamp the output cap instead of 400self.aliases: list[str] = [] # #297: other names of the model (the config's `aliases`)+ self.codex_thread_titles = False # #923 (opt-in): answer Codex's thread-title turns without the engineself.sampling_defaults = dict(sampling_defaults or {}) # the run config's `sampling` blockself.shared = {} # the web app's Chat settings for every client (POST /settings)self.shared_path = None # where they are kept between starts (next to the config)@@ -4450,9 +4451,29 @@ def make_handler(svc: Service):self._note(error=err["error"])self.wfile.write(b"data: " + json.dumps(err).encode() + b"\n\ndata: [DONE]\n\n")+ def _responses_ready(self, req, events):+ """Send a finished Responses result that did not run on the engine."""+ if not req.get("stream"):+ return self._json(200, responses_api.collect(events))+ self._sse()+ try:+ for e in events:+ self.wfile.write(f"event: {e['type']}\n".encode() + b"data: " ++ json.dumps(e, ensure_ascii=False).encode() + b"\n\n")+ self.wfile.flush()+ except OSError:+ self._note(outcome="disconnected")+def _responses(self, req):"""#451: POST /v1/responses - OpenAI's Responses API, stateless (serve/responses.py), on the chat path.Errors use the Responses format; once the stream has started they arrive as a response.failed event."""+ try:+ title = (responses_api.thread_title_events(req, svc.model_for(req))+ if svc.codex_thread_titles else None)+ except ResponsesError as e:+ return self._json(e.status, e.body())+ if title is not None:+ return self._responses_ready(req, title)try:ids, thinking, tools, max_new, asm, validator, req = self._responses_prepare(req)except ResponsesError as e:@@ -5099,6 +5120,7 @@ def main() -> int:model_name=cfg.get("model_name", "qwen3.8-flash-next"), vision=vision,sampling_defaults=sampling_defaults,fit_max_tokens=a.fit_max_tokens or cfg.get("fit_max_tokens") is True)+ svc.codex_thread_titles = cfg.get("codex_thread_titles") is True # #923: opt-in, off by defaulttry:svc.set_aliases(cfg.get("aliases")) # #297: other names the model answers toexcept ValueError as e:diff --git a/serve/test_responses.py b/serve/test_responses.pyindex 939d4e117..0fafc9648 100644--- a/serve/test_responses.py+++ b/serve/test_responses.py@@ -15,8 +15,8 @@ from pathlib import Pathsys.path.insert(0, str(Path(__file__).resolve().parents[1]))from serve.frontend import ChatTemplate # noqa: E402-from serve.responses import (ENCRYPTED_PREFIX, ResponsesError, input_messages, request_tools, # noqa: E402- template_kwargs, text_format)+from serve.responses import (ENCRYPTED_PREFIX, ResponsesError, collect, input_messages, request_tools, # noqa: E402+ template_kwargs, text_format, thread_title_events)from serve.server import ByteTokenizer, MockEngine, Service, serve # noqa: E402ROOT = Path(__file__).resolve().parents[1]@@ -405,5 +405,39 @@ class ToolRoundTrip(Server):["multi_agent_v1.spawn_agent", "apply_patch"])+class ThreadTitle(Server):+ def test_a_thread_title_is_answered_without_the_engine(self):+ self.svc.codex_thread_titles = True # opt-in: "codex_thread_titles": true in the config+ user = {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "what is in a.txt?"}]}+ code, r = self.post({"model": "m", "instructions": "You are a coding agent.", "input": [user], "tools": TOOLS})+ self.assertEqual(code, 200, r)+ seen = list(self.engine.last_prompt)+ self.assertTrue(seen)+ meta = {"session_id": "019a-title", "thread_id": "019a-title", "request_kind": "turn",+ "thread_source": "thread_title"}+ code, r = self.post({+ "model": "m", "instructions": "You are Codex", "tools": [],+ "client_metadata": {"x-codex-turn-metadata": json.dumps(meta)},+ "input": [{"type": "message", "role": "user", "content": [+ {"type": "input_text", "text": "Generate a concise title.\n\nUser prompt:\n只回四個字然後停:傾印測試"}]}]})+ self.assertEqual(code, 200, r)+ self.assertEqual(self.engine.last_prompt, seen)+ self.assertEqual(json.loads(r["output"][0]["content"][0]["text"]), {"title": "只回四個字然後停:傾印測試"})+ long = {"model": "m", "instructions": "You are Codex", "tools": [],+ "client_metadata": {"x-codex-turn-metadata": json.dumps(meta)},+ "input": "User prompt:\n" + ("甲" * 40) + "。"}+ self.assertEqual(json.loads(collect(thread_title_events(long, "m"))["output"][0]["content"][0]["text"]),+ {"title": "甲" * 36})++ def test_off_by_default_the_engine_answers(self):+ meta = {"thread_source": "thread_title"}+ code, r = self.post({"model": "m", "instructions": "You are Codex", "tools": [],+ "client_metadata": {"x-codex-turn-metadata": json.dumps(meta)},+ "input": "User prompt:" + chr(10) + "hello"})+ self.assertEqual(code, 200, r)+ self.assertTrue(self.engine.last_prompt) # it ran on the engine+ self.assertNotIn('"title"', json.dumps(r["output"]))++if __name__ == "__main__":unittest.main()