Skip to content

Architecture: deepen local runtime seams #44

Closed

Description

@ElbertePlinio

Goal

Concentrate repeated local runtime policy into a few deep modules so future browser, storage, and provisioning work changes one implementation rather than lockstep CLI/MCP or command paths.

Why

Current source duplicates local session lifecycle composition across CLI and MCP, splits local teardown between explicit destroy and reaping, divides run verification among readers, and leaves provisioning privilege metadata outside execution policy. This increases change cost and makes the important interface test surface hard to exercise once.

Top priority

PR 1 — Centralize local session lifecycle composition. It removes source-confirmed duplicate transaction policy with high confidence and medium risk, while preserving browser ownership, viewer behavior, evidence wrapping, and control-state separation.

Architecture constraints

Scope / acceptance checklist

  • One local lifecycle implementation owns recipe expansion, rollback, typed destroy dispatch, and canonical status aggregation; CLI/MCP output behavior remains unchanged.
  • Reaper and explicit destroy use one typed runtime teardown owner; retry and durable finalization semantics remain characterized.
  • One verified run catalog owns root precedence, directory/manifest binding, ordering, and verified reads before Store run artifacts outside project repositories by default #34 storage modes land.
  • One provisioning implementation owns consent, dry-run, privilege routing, cancellation, and partial results; no credential material is captured or persisted.
  • Focused characterization tests cover the retained invariants before each migration.
  • Typecheck and build pass for every PR; full validation follows normal repository policy.

Dependency-ordered PR plan

PR 1 — Centralize local session lifecycle composition

  • Depends on: none
  • Touches: CLI/MCP session adapters, MCP session resources, shared local lifecycle implementation, focused lifecycle tests
  • Prove: desktop+Android rollback, abort behavior, browser status, destroy-all partial failures, and adapter-specific viewer/evidence behavior remain unchanged
  • Validation: bun run test packages/cli/test/commands.test.ts packages/mcp-server/test/tools.test.ts packages/mcp-server/test/browser.test.ts; bun run typecheck; bun run build
  • Link: pending

PR 2 — Route reaper teardown through typed runtime ownership

  • Depends on: PR 1 preferred; coordinate with Harden pre-identity browser daemon cleanup #29
  • Touches: core reaper, desktop/Android/browser teardown adapters, reaper/destroy characterization tests
  • Prove: explicit destroy and reaping share typed stop outcomes; failed cleanup retains retryable state; durable finalization remains correct
  • Validation: focused core session/reaper plus desktop, Android, and browser destroy tests; bun run typecheck
  • Link: pending

PR 3 — Establish verified run catalog and land #34 storage resolver

  • Depends on: none
  • Touches: core run/evidence/path/config logic, CLI artifacts, MCP resources, storage compatibility tests
  • Prove: verified reads bind manifest identity to its directory; legacy runs remain readable; new writes follow configured storage mode with no automatic migration
  • Validation: bun run test packages/core/test/run.test.ts packages/core/test/evidence.test.ts packages/mcp-server/test/resources.test.ts; focused Store run artifacts outside project repositories by default #34 config/path tests; bun run typecheck; bun run build
  • Link: pending

PR 4 — Deepen provisioning execution policy

  • Depends on: none; Support secure graphical sudo prompts for agent commands #27 follows through this implementation
  • Touches: provisioning executor, setup-lab-user, setup-android, doctor, init, planner/executor tests
  • Prove: consent, dry-run, privileged routing, cancellation, and partial failures are consistent across commands without changing command wording
  • Validation: bun run test packages/cli/test/executor.test.ts packages/cli/test/planner.test.ts packages/cli/test/cli.test.ts; bun run typecheck; bun run build
  • Link: pending

Existing issue coordination

Non-goals

  • No generic session plugin registry.
  • No merge of CLI and MCP adapters.
  • No provider-neutral cloud abstraction before a proven provider implementation.
  • No broad evidence-journal split.
  • No automatic storage migration.
  • No new runtime command for Standardize isolated Flutter component previews #43.

No-feature-flag decision

No feature flag. Each PR is an internal refactor or backward-compatible storage rollout with preserved current defaults and independently reviewable behavior.

Audit commit snapshot

de467fbd14d00d4afa4946f610d05d724a6fa777 on main.

Current status

Planned.

Next action

Open PR 1 with characterization tests and migrate only local lifecycle composition; do not combine teardown, storage, or privilege execution changes.

Activity

  1. added
    enhancement
    on Jul 15, 2026
  2. ElbertePlinio commented on Jul 19, 2026

    @ElbertePlinio
    MemberAuthor

    CAND-1 landed in #49: createLocalSessions/destroyLocalSessions/status aggregation now live in packages/core/src/session-lifecycle.ts; CLI and MCP adapters route through it with unchanged output. CAND-2 (reaper teardown routing) now has its preferred placement available.

  3. ElbertePlinio commented on Jul 19, 2026

    @ElbertePlinio
    MemberAuthor

    CAND-2 started on refactor/reaper-typed-teardown from current origin/main (including #47 and #49). Scope is limited to routing opportunistic reaping through typed runtime teardown ownership while preserving core retry/finalization policy; coordinating with #29 by preserving browser PID-reuse refusal and retryable cleanup semantics.

  4. ElbertePlinio commented on Jul 19, 2026

    @ElbertePlinio
    MemberAuthor

    CAND-2 is implemented in #50. Reaping now composes the desktop, Android, and browser typed teardown owners; core retains registry/liveness/retry/evidence policy, and the duplicate stopRecordedPids path is removed.

    Validation: core + all runtime suites + CLI/MCP session tests (644 passed, 2 skipped), focused post-review fix tests (47 passed), typecheck, and build. Local serious-backend review found one Android reused-serial ownership issue; it was fixed and targeted verification is clean.

  5. ElbertePlinio commented on Jul 19, 2026

    @ElbertePlinio
    MemberAuthor

    CAND-3 is implemented in #52. One verified run catalog now owns current-root discovery/precedence, directory-manifest identity binding, corrupt-entry handling, deterministic ordering, duplicate IDs, and verified root-file reads. Core listRuns, evidence retention, CLI artifacts, MCP artifact tools, and MCP resources now use the catalog.

    The seam is ready for #34 to plug in storage-mode roots later; this PR intentionally adds no new storage modes, migration, or write-location changes.

    Validation: core run/catalog/evidence (93 passed), MCP resources/tools (58 passed), CLI commands (43 passed), typecheck, and build. Serious-backend local review and targeted fix verification are clean.

  6. ElbertePlinio commented on Jul 19, 2026

    @ElbertePlinio
    MemberAuthor

    All four candidates landed: #49 (central session lifecycle), #50 (typed reaper teardown), #52 (verified run catalog — ready for #34 storage modes), #51 (provisioning executor policy). Main CI green.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions