stock-bot/docs/development/backlog/tasks/P04.md

3.8 KiB

P04 — Schedule deterministic batches across a bounded worker pool

Parent epic: E7. Priority/severity: P2 / Medium. Relative complexity: M. Recommended specialization: Performance/infrastructure engineering.

Scheduling source of truth: manifest entry P04. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Use existing isolated one-shot workers and durable claims to run independent trials concurrently at a configurable1/2/4 process limit. Resident dataset reuse is optional P03, not a dependency. Each trial gets deterministic seed/identity and separate mutable state; admission/backpressure honors cancellation/leases. No parallel event processing inside one portfolio.

Exclusions

No speculative distributed infrastructure or weakened correctness gates.

Likely files and ownership

  • apps/stock/orchestrator/src/backtest/NativeBacktestWorker.ts
  • apps/stock/orchestrator/src/backtest/BacktestRunner.ts
  • apps/stock/web-api/src/services/BacktestDispatcher.ts

Write locks: worker-pool, web-backtest-dispatch. One agent owns this change. Lock names do not override actual overlapping files.

Dependencies and blockers

Implementation requires F07, R06, C06, P01 integrated.

Architecture decisions: ADR-008. Agents may not independently amend their policies.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • Concurrency1/2/4 produces identical per-trial economic hashes and completion-independent ranking.
  • A worker crash retries only affected durable attempts; batch cancellation drains or kills workers with no stale result commit.
  • Pool concurrency is configurable; no assumption that all available CPUs improve throughput.

Mandatory tests

  • parallel_hash_parity, worker_crash_retry, cancellation_under_load, lease_fencing_pool.
  • P01 trials/s, efficiency T1/(p*Tp), tail latency and RSS at1/2/4 workers.

Apply the relevant quality gates; submit exact commands, outcomes and skipped checks. Named cases above are required regression scenarios, not claims that those tests already exist.

Regression risks and rollback

Performance measurements can hide semantic changes; require economic hash equivalence. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

Handoff

Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.