Skip to content

[Engineering]: Decompose oversized core runtime modules by ownership boundary #675

Description

@Fangjj0621

Is there an existing issue for the same feature?

  • I have checked the existing issues.

Is your feature request related to a problem?

As a contributor trying to understand or modify the runtime, several core modules are too large to review safely and make ownership boundaries difficult to see.

On current main (374320e), examples include approximately:

  • crates/services/src/runs.rs: 37k lines;
  • crates/runtime/src/server/server_loop_host.rs: 31k lines;
  • crates/runtime/src/server/run/lifecycle/mod.rs: 22k lines;
  • crates/runtime/src/turn/agentic_loop/execution_phase.rs: 20k lines;
  • crates/astra-cli/src/tui/event_loop.rs: 15k lines.

The repository correctly emphasizes one canonical source of truth, but very large canonical modules create a different failure mode: unrelated state transitions, persistence code, protocol adaptation, policy checks, and test helpers accumulate in the same compilation unit. This raises review cost, increases merge conflicts, and makes it hard for a new contributor to prove that a change preserves cross-surface semantics.

Describe the feature you'd like

Introduce an incremental decomposition plan for oversized runtime modules based on ownership, not arbitrary file length. Candidate boundaries include:

  • durable state transitions versus SQL persistence;
  • admission/lease/fencing versus status projection;
  • model-loop orchestration versus provider transport;
  • event persistence versus streaming projection;
  • production implementation versus test fixtures/builders.

Add lightweight architecture checks that prevent already-large modules from growing without an explicit exemption. The goal should not be a blanket line-count rule; it should be reviewable ownership with one canonical implementation per behavior.

Acceptance criteria

  • Document the intended ownership boundaries for the five largest core modules.
  • Extract at least one high-churn responsibility from each selected module behind an internal typed interface.
  • Preserve existing offline and Matrix E2E behavior during decomposition.
  • Add a CI report or ratchet that flags growth in designated oversized modules.
  • Do not introduce duplicate lifecycle/provider decision paths as part of the split.

Implementation / design notes

A useful first step could be dependency-direction tests or module-level architecture tests before moving code. That would make the refactor measurable and reduce the chance of replacing one large file with circular internal packages.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions