Skip to content

Refactor managed-agent runtime into cohesive modules#2974

Merged
wesbillman merged 1 commit into
mainfrom
kennylopez-fix-desktop-runtime-file-size
Jul 26, 2026
Merged

Refactor managed-agent runtime into cohesive modules#2974
wesbillman merged 1 commit into
mainfrom
kennylopez-fix-desktop-runtime-file-size

Conversation

@klopez4212

@klopez4212 klopez4212 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • split the managed-agent runtime warehouse into cohesive modules for process ownership/termination, orphan sweeping, dead-instance reaping, lifecycle synchronization, and runtime metadata
  • preserve the existing runtime API through narrow re-exports; helper bodies and platform cfg branches are unchanged apart from module-qualified visibility
  • reduce runtime.rs from 2,220 lines on main to 908 lines and remove its temporary file-size override, restoring the standard 1,000-line ceiling

Why

main failed after stale successful PR checks allowed independent growth to combine above runtime.rs's 2,216-line override. The earlier fix in #2974 extracted only 55 lines and left the monolith on a special ratchet. This replacement includes that extraction but establishes responsibility boundaries and removes the exception entirely.

Module boundaries

  • process.rs — process identity, ownership markers, receipt validation, and termination primitives
  • orphan_sweep.rs — same-instance orphan discovery and cleanup
  • instance_reaper.rs — foreign/dead desktop instance detection and agent reaping
  • lifecycle.rs — tracked runtime synchronization and stale record cleanup
  • metadata.rs — model/provider metadata resolution
  • runtime.rs — summary/config/spawn orchestration and composition

Validation

At a824fda31eff6ecc0d39ca1b8ea5602a108897e6:

  • pre-push desktop-check
  • pre-push desktop-test
  • pre-push full desktop-tauri-test: 1,637 passed, 0 failed, 14 ignored; integration + doc tests passed
  • cargo check --manifest-path desktop/src-tauri/Cargo.toml --lib
  • cargo fmt --manifest-path desktop/src-tauri/Cargo.toml --all -- --check
  • node desktop/scripts/check-file-sizes.mjs

Supersedes #2974 and #2930.

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff and traced both moved helpers and their visibility/call sites. This is a behavior-preserving module extraction: the helper bodies are byte-for-byte unchanged, the parent re-exports retain the existing pub(crate) API, and CI is green across Desktop Core, Rust lint, macOS/Windows builds, smoke, relay, and integration jobs. This reduces runtime.rs from 2,220 to 2,167 lines, restoring 49 lines of headroom under the existing 2,216 ratchet. Recommend this over #2930, which only leaves 3 lines of headroom.

@wesbillman
wesbillman marked this pull request as ready for review July 26, 2026 14:39
@wesbillman
wesbillman requested a review from a team as a code owner July 26, 2026 14:39
@wesbillman
wesbillman force-pushed the kennylopez-fix-desktop-runtime-file-size branch from 8314549 to a824fda Compare July 26, 2026 14:47
@wesbillman wesbillman changed the title Fix desktop runtime file-size check Refactor managed-agent runtime into cohesive modules Jul 26, 2026
@wesbillman
wesbillman force-pushed the kennylopez-fix-desktop-runtime-file-size branch from a824fda to b47ccf9 Compare July 26, 2026 14:57
@wesbillman
wesbillman enabled auto-merge (squash) July 26, 2026 14:59
Split process ownership, orphan sweeping, dead-instance reaping, lifecycle
synchronization, and runtime metadata into cohesive runtime submodules. Keep
the existing runtime API through narrow re-exports and remove the temporary
runtime.rs file-size override now that the composition root is below the
standard 1000-line ceiling.

Co-authored-by: Princess Donut <68157ebd23b3897c1991015c3038658ea916200c67d3a54620b0754d1b92f6e0@buzz.block.builderlab.xyz>
Co-authored-by: Kenny Lopez <klopez4212@gmail.com>
Signed-off-by: Wes <wesbillman@users.noreply.github.com>
@wesbillman
wesbillman force-pushed the kennylopez-fix-desktop-runtime-file-size branch from b47ccf9 to 2fffc3e Compare July 26, 2026 15:22
@wesbillman
wesbillman merged commit 74b63e1 into main Jul 26, 2026
25 checks passed
@wesbillman
wesbillman deleted the kennylopez-fix-desktop-runtime-file-size branch July 26, 2026 15:34
tlongwell-block pushed a commit that referenced this pull request Jul 26, 2026
Main's #2974 modularized managed_agents/runtime.rs (process / orphan_sweep /
instance_reaper / lifecycle / metadata) from pre-PR content, conflicting with
this PR's runtime.rs changes. Resolution re-applies the PR's semantics into
the new module layout, changing nothing else:

- process.rs: valid_agent_runtime_receipt delegates to injectable
  valid_agent_runtime_receipt_with; marker-only ownership (name gate dropped).
- orphan_sweep.rs: sweep ownership rule comment block; marker-only gates in
  sweep_orphaned/sweep_system/collect_same_instance_orphans (macOS + Linux).
- instance_reaper.rs: name pre-gate removed on both platforms (marker is the
  authoritative proof).
- lifecycle.rs: kill_stale_tracked_processes delegates to injectable
  kill_stale_tracked_processes_with.
- runtime.rs: build_managed_agent_summary/spawn_agent_child keep the PR's
  descriptor resolver, global_config param, MissingBinary requirement, and
  descriptor.env write-back (main refactor did not touch these hunks);
  cfg(test) re-exports added for the injectable seams.
- check-file-sizes.mjs: took main's side (runtime.rs override removed by
  #2974; post-merge runtime.rs is 944 lines, under the 1000 ceiling).
  runtime/tests.rs keeps the PR's 1320 ratchet.

Verified at merge tree: cargo test --lib 1705/0 (14 ignored), clippy -D
warnings, fmt, file-size gate all clean.

Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants