From b2c4f1f376167e7e34a88c3dbd544e1fdc848c14 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:26:23 +0530 Subject: [PATCH] refactor(api): reuse _COMPACTION_INTERNAL_FIELDS from compaction_display The 7-key internal-fields tuple was inlined twice (agent/compaction_display.py and _project_client_message); a drift between the copies would silently leak one internal field class through the API projection. Surfaced during review of PR #85442. --- gateway/platforms/api_server.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.py index 143aae20c7..53e9ad7a70 100644 --- a/gateway/platforms/api_server.py +++ b/gateway/platforms/api_server.py @@ -441,20 +441,15 @@ def _project_client_message(message: Dict[str, Any]) -> Dict[str, Any]: summary delimiter. Tool calls are dropped from both shapes because a carrier's inherited calls are historical context, not live client output. """ - from agent.compaction_display import project_compaction_message_for_display + from agent.compaction_display import ( + _COMPACTION_INTERNAL_FIELDS, + project_compaction_message_for_display, + ) projected = project_compaction_message_for_display(message) if projected is None: projected = message.copy() - for internal_key in ( - "tool_calls", - "finish_reason", - "reasoning", - "reasoning_content", - "reasoning_details", - "codex_reasoning_items", - "codex_message_items", - ): + for internal_key in _COMPACTION_INTERNAL_FIELDS: projected.pop(internal_key, None) projected["content"] = "" projected["display_kind"] = "hidden"