Refactor application orchestration and runtime bootstrap#179
Merged
michaelchu merged 9 commits intomainfrom Apr 6, 2026
Merged
Refactor application orchestration and runtime bootstrap#179michaelchu merged 9 commits intomainfrom
michaelchu merged 9 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors backtest/sweep/pipeline orchestration into a new src/application/ layer and centralizes runtime bootstrap wiring into AppServices, reducing cross-importing between REST handlers, queued tasks, and MCP tool handlers.
Changes:
- Added
src/application/modules (backtests,sweeps,pipeline,tasks) and rewired MCP/REST/task flows to call into these shared services. - Introduced
AppServicesbootstrap bundle (src/bootstrap.rs) and refactoredmain.rsto use transport-specific runners (run_http/run_stdio). - Replaced raw price endpoint
eprintln!logging with structuredtracing::debug!.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tools/raw_prices.rs | Switches raw price request logging from eprintln! to tracing. |
| src/tools/backtest.rs | Routes single backtests, sweeps, and pipeline mode through the new application services. |
| src/server/handlers/tasks.rs | Simplifies queued task execution via shared application::tasks orchestration and app-layer backtest/sweep/pipeline executors. |
| src/server/handlers/sweeps.rs | Removes duplicated sweep logic and delegates sweep execution/persistence to application::sweeps. |
| src/server/handlers/run_script.rs | Converts handler into compatibility wrappers around application::backtests. |
| src/server/handlers/pipeline.rs | Delegates pipeline execution to application::pipeline instead of the MCP backtest tool. |
| src/server/handlers/backtests.rs | Delegates backtest persistence to application::backtests helpers. |
| src/main.rs | Refactors startup into run_http/run_stdio and uses AppServices for validated wiring. |
| src/lib.rs | Exposes new application and bootstrap modules. |
| src/bootstrap.rs | Adds AppServices to centralize DB/store/task-manager construction from env. |
| src/application/mod.rs | Defines the application-layer module surface. |
| src/application/tasks.rs | Introduces shared queued-task lifecycle helpers (permit, cancel, mark running/completed/failed). |
| src/application/sweeps.rs | Adds shared sweep execution + persistence orchestration (grid/bayesian + permutation gate). |
| src/application/pipeline.rs | Adds shared pipeline orchestration built on persisted sweep + existing pipeline stages. |
| src/application/backtests.rs | Adds shared script execution + persistence helpers (symbol/capital resolution, trade stripping, DB insertion). |
Comments suppressed due to low confidence (1)
src/server/handlers/backtests.rs:124
backtests::persist_backtestcan return errors unrelated to database insertion (e.g., missing/resolution ofsymbol). Emitting these as"DB insert failed: ..."in the SSE stream is misleading; please surface the actual error (and optionally differentiate validation vs persistence failures).
match backtests::persist_backtest(
&*state.run_store,
&strategy_key,
&req.params,
&response,
"manual",
None,
) {
Ok((id, _)) => {
if let Ok(Some(detail)) = state.run_store.get_run(&id) {
let json = serde_json::to_string(&detail).unwrap_or_default();
let _ = tx.send(Event::default().event("result").data(json)).await;
}
}
Err((_status, msg)) => {
let _ = tx
.send(
Event::default()
.event("error")
.data(format!("DB insert failed: {msg}")),
)
.await;
}
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
src/server/handlers/backtests.rs:109
backtests::persist_backtestcan return non-storage errors (e.g., symbol resolution -> BAD_REQUEST). This handler’s error path later prefixes allpersist_backtestfailures with "DB insert failed", which can be misleading. Consider branching on the returnedStatusCode(only prefix INTERNAL_SERVER_ERROR) or emitting the raw message for validation/other failures.
match backtests::persist_backtest(
&*state.run_store,
&strategy_key,
&req.params,
&response,
"manual",
None,
) {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/application/tracingTesting