stock-bot/docs/development/orchestrator-engine-cleanup.md

7 KiB
Raw Blame History

Orchestrator and engine cleanup

Baseline: 700ee09c, inspected 2026-10-26. Owner authorized backlog creation, a planning commit, implementation, and one focused commit per completed task. The manifest is the sole scheduling source; CL14–CL21 task files define scope and acceptance.

Direction

Keep Rust authoritative for finance and replay, TypeScript for strategies and supervision, existing durable custody, and reviewed algorithms. Simplify supported interfaces and remove abandoned scaffolding. Do not reopen performance work, change economic policies, activate paper/live accounts, or replace existing services. Earlier CL01–CL13 independent-review status remains unchanged.

Sequence and ownership

  1. CL14 narrows canonical runner contracts and removes unused constructor requirements. CL15 independently removes verified unused Rust scaffolding after a calculation/caller inventory.
  2. CL16 gives application startup/shutdown an explicit resource owner. Serialize its container.ts edits after CL14; no financial contract changes.
  3. CL17 historical readers and CL20 typed worker results follow CL14. CL18 shared native parser/view follows CL15. CL19 pure strategy bookkeeping may proceed independently with exclusive paper/helper ownership.
  4. CL21 private replay preparation extraction is deferred until an actual scheduler/calendar edit warrants it and the owner activates it. It is not required to finish this cleanup wave.

Use isolated worktrees with local workspace links/build outputs. Start at most two implementation agents and reserve a slot for independent review. Root owns manifest integration and commits; each agent supplies a scoped patch and exact check evidence. A task commit contains its acceptance evidence; its SHA is recorded in the next bookkeeping update rather than embedded in itself. No commits/pushes/PRs by agents unless specifically delegated.

Gates

Run scoped tests and typechecks per story; native changes rebuild this checkout's addon and preserve existing economic fixtures. Use disposable PostgreSQL/Redis for custody boundaries. Independent review precedes completion and each task commit. Root runs combined bun run check; no benchmark or browser gate is needed for unchanged performance/UI behavior. Missing/skipped checks are explicit, never reported as passing.

Read-only audit baseline passed 17 architecture tests, 29 focused integration tests and 150 Rust tests (4 ignored). These are baseline evidence, not acceptance of future changes.

Execution evidence

Implementation records will be appended here as tasks pass review and validation.

CL15 — accepted

Removed 24 unused adapter/alternate-architecture files; moved two uncompiled reporting prototypes byte-for-byte into engine/reference/legacy-reporting/ with explicit limitations. MIGRATION.md records every removal/preservation and current boundaries. Only compiled-code change removes the unused adapter module; canonical finance, legacy algorithms and native exports are unchanged.

Implemented by /root/implement_cl15; independently reviewed/integrated by /root. Both preserved files were compared against baseline bytes. Root rebuilt the addon and ran bun test scripts/test/native-bindings.test.ts test/integration/native-terminal-equity.test.ts test/integration/native-market-data.test.ts scripts/test/architecture.test.ts: 75 passed. cargo test -p engine --lib --offline: 150 passed, 4 ignored. git diff --check passed. The sandbox initially prevented NAPI from spawning /bin/sh; the authorized rebuild succeeded. No performance claim or stored-artifact migration.

CL14 — accepted

The durable runner now requires canonical engine/repository capabilities. Legacy playback uses an explicit separate interface; concrete compatibility methods and historical formats remain. Removed unused adapter storage and runner engineName. Existing pause/resume/speed routes keep their production rejection behavior without SQL control writes. Negative type fixtures reject missing canonical capabilities.

Implemented by /root/implement_cl14; independently reviewed/integrated by /root. Root rebuilt the orchestrator and passed application typecheck/contract tests. Focused runner/workflow/worker/pool/isolation/architecture suite: 91 passed, 6,888 assertions. Disposable PostgreSQL canonical and retained durable-run suites: 33 passed, 181 assertions. No SQL/native/economic policy changes. Worker tests required execution outside the sandbox; two transient worktree Bun dependency-reading failures passed on separate reruns and root integration. Legacy-only provider-spy assertions were removed with the unused injection, not replaced with fabricated coverage. Full combined repository gate follows CL16 integration.

CL15 implementation commit: bc2b8a89.

CL16 — accepted

ServiceContainerBuilder.buildOwned() adds an explicit shared-resource lifetime while preserving build() for existing callers. Orchestrator composition returns {services, shutdown}; registration rollback and normal shutdown share idempotent application cleanup. Startup route/bind failures release the runtime. Shutdown finishes accepted HTTP requests and durable work before closing queue/database/cache adapters. The obsolete ModeManager closer and unowned delayed self-test timer are removed from the canonical entrypoint.

Implemented by /root; independently reviewed by /root/review_cl16 with no blocking findings. Focused lifecycle/composition tests: 39 passed, 166 assertions. Independent architecture rerun: 17 passed. Native worker lifecycle outside sandbox: 10 passed, 33 assertions. The new test was explicitly typechecked and linted because the default application tsconfig excludes tests; controlled fixture adapters have an explicit test-only container widening. Tests cover registration/resolution/bind failure, original-error retention, repeated stop, continued cleanup and a delayed terminal write before PostgreSQL closes.

Combined CARGO_BUILD_JOBS=2 bun run check passed on CL14+CL15+CL16: 132 tooling, 43 utility, 44 calculation, 1,231 integration and 150 Rust tests. Fourteen existing integration conditional skips and four Rust ignored tests remain. Builds, application/contract typechecks, lint and secret audit passed. Scoped disposable PostgreSQL gate remains the CL14 33-case result; no UI or financial schema/transition changed, so browser/full database suites were not rerun. Logs are under /tmp/stock-bot-engine-cleanup-20261026/ (combined-check.log, cl14-root-postgres.log, cl16-worker-accepted.log). No performance profiling or activation was performed.

CL14 implementation commit: 21666242. First wave completes CL14, CL15 and CL16; CL17–CL20 are the next ready tasks and CL21 remains conditional. Prior 68 task records retain their pre-wave state.

CL16 implementation commit: 8546fce4. Disposable test containers were stopped/removed after validation. Main checkout is the integrated source; isolated worktrees and logs are retained for inspection.