Skip to content

Split provider.rs (3,978 lines) and core lib.rs (2,402 lines) — documented merge-hazard hot files #159

Description

@haasonsaas

Problem

Three files have grown large enough to be both hard to navigate and, per AGENTS.md, an active merge hazard:

  • crates/sandboxwich-worker/src/provider.rs — 3,978 lines (tests were already extracted into provider/tests.rs in a prior pass, so this is all implementation).
  • crates/sandboxwich-core/src/lib.rs — 2,402 lines of shared typed contracts.
  • crates/sandboxwich-worker/src/main.rs — 2,110 lines.

AGENTS.md's "Landing PRs" section already names crates/sandboxwich-worker/src/provider.rs as one of the shared hot files that produced semantic merge conflicts during the 2026-07-09 audit wave (three incidents: #96×#98, #97×#99, #97/#99×#100) and instructs auditing all call sites after merging anything that touches it. The file's size is a direct contributor to why merges collide there.

Evidence

  • crates/sandboxwich-worker/src/provider.rs: 3,978 lines (wc -l), named explicitly in AGENTS.md under "Landing PRs" as a shared hot file requiring post-merge call-site audits.
  • crates/sandboxwich-core/src/lib.rs: 2,402 lines (wc -l).
  • crates/sandboxwich-worker/src/main.rs: 2,110 lines (wc -l).
  • Precedent: crates/sandboxwich-api/src/main.rs was already split this way in Split sandboxwich-api main.rs and http_contract.rs into modules #110 into handlers/ by resource family, db.rs, auth.rs, scheduler.rs, cleanup.rs, etc., per AGENTS.md's "Layout" section.

Suggested approach

Apply the same #110-style split used for the API crate:

  • provider.rs: separate by concern, e.g. Kubernetes manifest construction (Pod/PVC/Service/NetworkPolicy/VolumeSnapshot builders), the dry-run vs apply-mode branching, reconciliation, and the kubectl-invocation plumbing (run_kubectl_command_with_stdin and friends) into their own modules under provider/.
  • crates/sandboxwich-core/src/lib.rs: split typed request/response/event contracts by resource family (sandboxes, jobs/leases, snapshots, workers, runtime resources) into submodules, re-exported from lib.rs.
  • crates/sandboxwich-worker/src/main.rs: separate the CLI arg parsing/entrypoint from the work loop (work_loop, handle_lease, claim, heartbeat/registration/drain helpers), mirroring the "thin entrypoint, logic in modules" convention AGENTS.md already establishes for the API crate.

Smaller, concern-scoped modules reduce the odds of two PRs touching the same lines and reduce the blast radius AGENTS.md asks reviewers to audit after every merge.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions