Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(sessions): map codex function_call events to the assistant kind (#2652)

Aman6ab357656ea1
diff --git a/packages/core/src/repowise/core/sessions/adapters/codex.py b/packages/core/src/repowise/core/sessions/adapters/codex.py
index e41f2ce39..385c8eb8e 100644
--- a/packages/core/src/repowise/core/sessions/adapters/codex.py
+++ b/packages/core/src/repowise/core/sessions/adapters/codex.py
@@ -480,9 +480,12 @@ def _event_kind(entry_kind: str | None, payload_kind: str | None, payload: dict[
return "assistant"
if role == "developer":
return "system"
- if payload_kind == "custom_tool_call":
- return "assistant"
- if payload_kind == "custom_tool_call_output":
+ if payload_kind in (
+ "custom_tool_call",
+ "custom_tool_call_output",
+ "function_call",
+ "function_call_output",
+ ):
return "assistant"
return payload_kind or "assistant"
if entry_kind == "event_msg":
diff --git a/tests/unit/sessions/test_codex_adapter.py b/tests/unit/sessions/test_codex_adapter.py
index d22294613..2f03ddee7 100644
--- a/tests/unit/sessions/test_codex_adapter.py
+++ b/tests/unit/sessions/test_codex_adapter.py
@@ -194,17 +194,84 @@ def test_normalize_handles_mcp_function_call_and_output(adapter: CodexAdapter) -
output_event = adapter.normalize(tool_output)
assert call_event is not None
+ assert call_event.kind == "assistant"
assert call_event.tool_uses[0].id == "call_mcp_1"
assert call_event.tool_uses[0].name == "search_codebase"
assert call_event.tool_uses[0].input["query"] == "signup"
assert call_event.tool_uses[0].input["path"] == "app.py"
assert output_event is not None
+ assert output_event.kind == "assistant"
assert output_event.tool_results[0].tool_use_id == "call_mcp_1"
# The output should bind the returned file to the original tool call.
assert call_event.tool_uses[0].input["path"] == "app.py"
+def test_function_call_decision_gets_file_attribution(adapter: CodexAdapter) -> None:
+ """A `function_call` tool use must reach the decision miner like `custom_tool_call` does.
+
+ Regression for #2622: the adapter used to label `function_call` /
+ `function_call_output` events with the raw payload type instead of
+ `"assistant"`, so the decision miner's `kind == "assistant"` gate skipped
+ them outright and a decision right after the call got no file context.
+ """
+ session_meta = json.dumps(
+ {
+ "timestamp": "2026-07-17T16:46:00.000Z",
+ "type": "session_meta",
+ "payload": {"id": "s1", "session_id": "s1", "cwd": r"C:\work\repo"},
+ }
+ )
+ tool_call = json.dumps(
+ {
+ "timestamp": "2026-07-17T16:46:01.000Z",
+ "type": "response_item",
+ "payload": {
+ "type": "function_call",
+ "name": "get_context",
+ "call_id": "c1",
+ "arguments": json.dumps({"path": "app.py"}),
+ },
+ }
+ )
+ tool_output = json.dumps(
+ {
+ "timestamp": "2026-07-17T16:46:02.000Z",
+ "type": "response_item",
+ "payload": {"type": "function_call_output", "call_id": "c1", "output": "ok"},
+ }
+ )
+ choice = json.dumps(
+ {
+ "timestamp": "2026-07-17T16:46:03.000Z",
+ "type": "response_item",
+ "payload": {
+ "type": "message",
+ "role": "assistant",
+ "content": [
+ {
+ "type": "output_text",
+ "text": (
+ "We chose Flask because it is lightweight and keeps "
+ "SQLite integration straightforward."
+ ),
+ }
+ ],
+ },
+ }
+ )
+
+ events = [adapter.normalize(line) for line in (session_meta, tool_call, tool_output, choice)]
+
+ assert [e.kind for e in events] == ["session_meta", "assistant", "assistant", "assistant"]
+
+ decisions = mine_events(events, r"c:\work\repo")
+
+ assert len(decisions) == 1
+ assert decisions[0].kind == "explicit_choice"
+ assert decisions[0].files == ["app.py"]
+
+
def _search_then_output(output: object) -> str:
"""An rg search whose result is *output*, as one raw transcript line."""
return json.dumps(