refactor(api) [Patch 2/9]: extract system routes to src/api/system_routes.py#378
Merged
Merged
Conversation
7 tasks
This was referenced Jul 2, 2026
Move 5 system routes (health, correlation, shutdown, skills, api-info) and the _terminate_current_process helper from api_server.py into a self-contained route module following the PR HKUDS#375 pattern. - system_routes.py defines HealthResponse locally (no shared modules) - register_system_routes() resolves _security and _require_shutdown_authorization via sys.modules fallback - Re-exports _terminate_current_process for test monkeypatch compat - api_server.py: -92 lines (3552 → 3471) Co-Authored-By: OpenCode <noreply@opencode.ai> AI-Model: idealab/Qwen3.7-Max-DogFooding Co-Authored-By: opencode <noreply@ai-tool.com> Co-Authored-By: Claude Code <noreply@anthropic.com> AI-Contributed/Feature: 270/270 AI-Contributed/UT: 0/0
ed51b90 to
7c00d5d
Compare
Collaborator
|
Thanks @shadowinlife, merged this via normal merge so the original commit authorship and co-author credits are preserved. Local verification before merge:
Nice clean extraction for patch 2/9. |
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.
Summary
agent/api_server.pyintoagent/src/api/system_routes.pysystem_routes.pyis self-contained — definesHealthResponselocally, resolves_securityand_require_shutdown_authorizationfrom hostapi_serverviasys.modulesfallback_terminate_current_processback toapi_serverto preserve existing test monkeypatch compatibilityWhy
Part of the API modularisation roadmap (#331). Follows the self-contained route-module pattern established by #375. Each route module is independently extractable, has no shared scaffolding, and gives an immediate measurable reduction in the monolithic
api_server.py.Refs #331
Refs #375
Changes
agent/src/api/system_routes.py: 5 routes (health, correlation, shutdown, skills, api-info) +_terminate_current_processhelperapi_server.py: remove the 5 route definitions, add registration call + re-exportdeps.py,models.py,helpers.py)Security(_security)DI pattern preserved exactly for/system/shutdownapi_server.pyshrinks from 3,552 to 3,471 linesTest Plan
PYTHONPATH=agent pytest agent/tests/test_security_auth_api.py agent/tests/test_spa_deep_link.py -q # 65 passed python -m compileall -q agent/api_server.py agent/src/api/system_routes.py git diff --checkChecklist
src/agent/,src/session/,src/providers/) without prior discussionOverall Project Plan
This PR is Patch 2 of 9 in the API modularisation series (issue #331). The goal is to decompose the 3,552-line
api_server.pyinto 9 self-contained route modules undersrc/api/, leaving only app factory, Pydantic models, auth dependencies, and shared helpers (~1,200 lines).Each patch follows the #375 pattern: self-contained route module,
sys.modulesfallback for auth, route-level constants/models, re-exports for test monkeypatch compat, zero behaviour change, zero test modifications.