Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(gateway): classify Codex requests by request_kind, not keywords in the turn metadata (#6334)
t0sakia8bd02bac7d6
diff --git a/openviking_gateway/protocols.py b/openviking_gateway/protocols.pyindex f652427d2..ddccea160 100644--- a/openviking_gateway/protocols.py+++ b/openviking_gateway/protocols.py@@ -380,11 +380,18 @@ def classify(body: dict, headers: dict, messages: list[dict]) -> tuple[str, int]"x-claude-code-request-type","x-claude-code-request-kind","x-claude-code-agent-type",- "x-codex-turn-metadata",))if re.search(r"compact|summar|title|classif|heartbeat|suggest|permission", hints, re.I):return "auxiliary", anchor+ # Codex sends the whole turn metadata (workspace paths, remotes, tool names) on every+ # request; only its request_kind says what the request is.+ try:+ turn = orjson.loads(headers.get("x-codex-turn-metadata") or "null")+ except orjson.JSONDecodeError:+ turn = None+ if isinstance(turn, dict) and turn.get("request_kind") in ("compaction", "memory"):+ return "auxiliary", anchor# Each part on its own and as plain text, so a pattern's anchors and line breaks hold.parts = [text_content({"content": body.get(key, "")}) for key in ("system", "instructions")]if anchor >= 0:diff --git a/tests/gateway/test_kernel.py b/tests/gateway/test_kernel.pyindex 0ee8a5418..103f532fe 100644--- a/tests/gateway/test_kernel.py+++ b/tests/gateway/test_kernel.py@@ -1,5 +1,6 @@import asyncioimport copy+import jsonimport reimport sysimport time@@ -577,10 +578,22 @@ def test_classification_and_plugin_namespaces():assert classify({}, {}, [user, tool])[0] == "continuation"assert classify({}, {"x-claude-code-request-class": "compaction"}, [user])[0] == "auxiliary"assert classify({}, {"x-claude-code-request-class": "auxiliary"}, [user])[0] == "auxiliary"- assert (- classify({}, {"x-codex-turn-metadata": '{"request_kind":"compact"}'}, [user])[0]- == "auxiliary"- )+ for kind in ("compaction", "memory"):+ metadata = json.dumps({"request_kind": kind})+ assert classify({}, {"x-codex-turn-metadata": metadata}, [user])[0] == "auxiliary"+ # Workspace paths, remotes and tool names in Codex's metadata are not request hints.+ turn = {+ "request_kind": "turn",+ "workspaces": {+ "/home/u/subtitle-tool": {+ "associated_remote_urls": {"origin": "[email protected]:acme/summary-bot.git"}+ }+ },+ "tool_namespaces_info": [{"tools": ["mcp__notes__summarize_page", "permission_check"]}],+ }+ malformed = ('{"request_kind":"compaction"', '{"request_kind":[]}', "compaction", "[]")+ for metadata in (json.dumps(turn), *malformed):+ assert classify({}, {"x-codex-turn-metadata": metadata}, [user])[0] == "user"assert classify({}, {"x-claude-code-agent-id": "child"}, [user])[0] == "subagent"# OpenViking tools alone, as from an MCP connection, are not a plugin.namespaces = {