#1856

Architecture cleanup: finish extracting legacy route/UI/store behavior into domain services

OpenGit-on-my-levelopened 5mo ago

Theme

Recent PRs have been moving Codex Autorunner toward a cleaner architecture: backend-owned state, typed read models, unified automation jobs, thin route/UI surfaces, and clean terminology migrations without long-lived compatibility shims. There are still several high-ROI follow-up refactors that fit that same direction.

Relevant recent PRs

  • #1855 - Add unified automation plane
  • #1853 - Rename lifecycle archive actions to retire
  • #1848 - Improve chat transcript efficiency
  • #1846 - Add chat architecture goal function
  • #1843 - Make PMA chat genesis explicit
  • #1842 - Extract PMA chat architecture goal
  • #1830 - Move Web Chat toward turn-structured detail projection
  • #1827 - Chat archive lifecycle authority + newt surface semantics

Highest-ROI cleanup areas

  1. Split src/codex_autorunner/core/pma_automation_store.py into PMA compatibility persistence, domain translation/reducer glue, unified automation mirror/backfill, and a thin facade. This is the largest remaining pre-unified-plane boundary leak.
  2. Move chat transcript/queue/optimistic reconciliation ownership out of src/codex_autorunner/web_frontend/src/routes/chats/[[chatId]]/+page.svelte and into read-model/application modules, keeping the Svelte page as a binding layer.
  3. Retire or isolate legacy PMA transcript file-path fallbacks in src/codex_autorunner/core/pma_transcripts.py once mirror coverage is explicit.
  4. Extract PMA managed-thread route helper/application logic out of route modules and remove reverse dependencies from web services into routes.
  5. Consolidate repeated Web read-model page scaffolding and small duplicated loaders after the main state-ownership cuts are done.

Target architecture

  • Core/domain modules own state transitions, compatibility migration, and durable writes.
  • Web routes expose typed read models and dispatch commands; they do not become business-logic owners.
  • Frontend pages subscribe to screen-shaped read models and delegate normalization/reconciliation to application/view-model modules.
  • Compatibility paths are either removed after migration coverage or isolated behind explicit one-time migration/backfill code.

Suggested CAR ticket flow

Create tickets for the first three high-ROI cuts now: PMA automation store split, chat detail read-model ownership, and PMA transcript legacy retirement. Follow with managed-thread route/service dependency cleanup if the first three land cleanly.

Activity

1
Git-on-my-level5mo ago

Progress report from mini CAR review sweep:

The implementation work for this cleanup is materially real, not just planning artifacts. The completed queue currently has:

  • TICKET-001 done: PMA automation store split and transcript legacy fallback review.
  • TICKET-002 done: chat detail display/read-model ownership moved further into application modules.
  • TICKET-003 done: managed-thread route business logic moved into PMA service modules.
  • TICKET-004 open: remaining read-model scaffolding and hotspot overage cleanup.

Follow-up review fixes made during the sweep:

  • Removed the unused src/codex_autorunner/surfaces/web/routes/pma_routes/managed_thread_route_helpers.py compatibility shim after confirming no production/test imports remained.
  • Removed the broad empty-model fallback in src/codex_autorunner/surfaces/web/services/pma/managed_thread_automation.py; automation store failures should now surface instead of masquerading as valid empty state.
  • Added a regression test covering that failure behavior.
  • Updated CAR contextspace and opened TICKET-004 so the remaining quality bar is durable for the next run.

Validation from the review:

car tickets lint --repo /Users/dazheng/car-workspace/worktrees/chat-app-managed/discord/discord-3
# OK: 4 ticket(s) linted

.venv/bin/python -m pytest -q tests/surfaces/web/routes/pma_routes/test_managed_thread_route_helpers.py
# 38 passed, 1 warning

.venv/bin/python -m pytest -q tests/test_managed_threads_routes.py::test_list_subscription_unified_model_does_not_hide_store_failures tests/test_managed_threads_routes.py::test_create_subscription_auto_resolves_lane_from_bound_thread
# 2 passed, 1 warning

Closure judgment: I would not close this issue yet under the stricter maintainability bar. tests/test_hotspot_budgets.py::test_hotspot_file_budgets still fails on issue-relevant read-model/page files:

  • src/codex_autorunner/surfaces/web/services/pma/managed_thread_read_models.py
  • src/codex_autorunner/surfaces/web/services/chat_read_models.py
  • src/codex_autorunner/web_frontend/src/lib/application/pmaChatArchitecture.ts
  • src/codex_autorunner/web_frontend/src/routes/chats/[[chatId]]/+page.svelte

The remaining close bar is: complete TICKET-004 by consolidating real duplicated read-model/page scaffolding and reducing those hotspot overages without just raising caps to bless the current shape. After that passes, this issue should be close-ready unless the final review finds another material boundary leak or unrealistic fallback path.