refactor(gateway): deepen ACP event normalization into event_encoder module - #155
Merged
Conversation
…module Applies the improve-codebase-architecture skill's top deepening recommendation. The pure ACP-update -> SSE normalization (the highest-churn encoding surface — it shifts with every agent/model update) was buried in the 3179-line session_manager god module, interleaved with the stateful session lifecycle, relay, permission and provisioning machinery. Move the stateless dict->dict encoding rules into a new sibling module app/services/agents/event_encoder.py behind a small interface: normalize_session_update, normalize_sdk_task_message, parse_sdk_compaction, parse_elicitation_fields (+ the SDK_TASK_MESSAGE_FILTERS list and COMPACTION_SUMMARY_PREAMBLE marker the session meta/replay builders still use). The 8 leading-underscore helpers + regex/phase constants become private internals of the module. Pure relocation — byte-identical behaviour. session_manager imports the public entry points; it shrinks 3179 -> 2595 lines. Per "the interface is the test surface" / "replace, don't layer", the existing tests (test_agent_normalize, test_agent_questions, test_agent_usage_gateway) re-point to the real seam (event_encoder) rather than session_manager re-exporting. Wins — locality: encoding rules concentrate in one named module; leverage: reusable by any transport without touching session state; navigability: a maintainer reasons about encoding without scrolling a 3k-line file. fastapi 362 passed, ruff clean. Behaviour unchanged (no callsite logic touched).
This was referenced Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applies the improve-codebase-architecture skill's top deepening recommendation (chosen from 30 surfaced candidates).
What
The pure ACP-update→SSE normalization — the highest-churn encoding surface (it shifts with every agent/model update) — was buried in the 3179-line
session_manager.pygod module, interleaved with the stateful session lifecycle, relay, permission, and provisioning machinery. This moves the statelessdict→dictencoding rules into a new sibling moduleapp/services/agents/event_encoder.pybehind a small interface:normalize_session_update,normalize_sdk_task_message,parse_sdk_compaction,parse_elicitation_fields(+ theSDK_TASK_MESSAGE_FILTERSlist andCOMPACTION_SUMMARY_PREAMBLEmarker the session meta/replay builders still reference).session_manager.pyshrinks 3179 → 2595 lines and imports the public entry points.Why
event_encoderwould scatter the rules back across the session module.Pure relocation — behaviour-preserving
No callsite logic changed. Per "the interface is the test surface" / "replace, don't layer", the existing tests (
test_agent_normalize,test_agent_questions,test_agent_usage_gateway) re-point to the real seam (event_encoder) rather than session_manager re-exporting.Verified: a 5-agent adversarial pass confirmed the moved code is byte-identical (
diffexit 0), no circular import, callsites unchanged, no test weakened — and an xhigh code-review returned 0 findings.fastapi 362 passed, ruff clean.No user-facing change → no CHANGELOG entry.