You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds GET/POST /admin/walkforward to orchestrator.py. Triggers wire_walkforward_backtest.export_from_db() then propiq_walkforward_backtest.run(folds) in background. Results → data/walkforward_results.json. All three data-level jobs now have HTTP triggers.
Summary by cubic
Adds a new /admin/walkforward endpoint to run walk-forward backtests in the background and write results to data/walkforward_results.json. This completes HTTP triggers for all data-level jobs.
New Features
Adds /admin/walkforward (GET/POST) to export graded legs and run fold analysis.
Calls wire_walkforward_backtest.export_from_db then propiq_walkforward_backtest.run(folds); default folds=3.
Runs asynchronously and returns JSON { status: "started" }; allow ?folds=5 or POST body to set folds.
Skips if required modules are missing and logs warnings/errors.
Written for commit 7dd8e98. Summary will update on new commits.
Summary by CodeRabbit
New Features
Added new admin endpoint for initiating and managing walk-forward analysis workflows. Supports configurable fold parameters (default: 3) allowing customization of analysis granularity. Workflows execute asynchronously in the background. The endpoint immediately returns a JSON response containing operational status, estimated time to completion, and applied configuration details to the caller.
Reviewing files that changed from the base of the PR and between 54c0281 and 7dd8e98.
📒 Files selected for processing (1)
orchestrator.py
📝 Walkthrough
Walkthrough
A new FastAPI admin endpoint /admin/walkforward is added to orchestrator.py that accepts a folds count, dynamically discovers and imports walk-forward backtest modules, executes export and analysis tasks in a background threadpool, logs results, and immediately returns a JSON status response with ETA and fold configuration.
Changes
Admin Walk-Forward Endpoint
Layer / File(s)
Summary
Walk-forward admin endpoint with dynamic module loading and background execution orchestrator.py
New admin_walkforward route handler accepts folds parameter (default 3), dynamically discovers wire_walkforward_backtest and propiq_walkforward_backtest via importlib, runs export and analysis tasks via threadpool executor, logs outcome, and returns non-blocking {status: "started"} JSON response with ETA and fold count.
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
A new pathway appears, walkforward they say,
With folds gathered up, the backtest holds sway,
Dynamic modules dance in the background so free,
While JSON responds with swift certainty! 🐰✨
✨ Finishing Touches📝 Generate docstrings
Create stacked PR
Commit on current branch
🧪 Generate unit tests (beta)
Create PR with unit tests
Commit unit tests in branch pr-568-walkforward-endpoint
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
We reviewed changes in 54c0281...7dd8e98 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer TIP This summary will be updated as you push new changes.
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new /admin/walkforward endpoint to trigger background backtest tasks. Several critical issues were identified: the importlib module is not imported, the called function bt_mod.run does not exist in the target module, and the folds parameter lacks validation against zero or negative values. Additionally, the feedback suggests implementing concurrency control to prevent multiple simultaneous backtests and correcting the output file path in the response message to match the actual script configuration.
The reason will be displayed to describe this comment to others. Learn more.
The 'importlib' module is not defined in this scope, which will cause a 'NameError' when calling 'importlib.util.find_spec'. Additionally, 'importlib.util' must be explicitly imported to access the 'util' submodule and the base 'importlib' package.
The reason will be displayed to describe this comment to others. Learn more.
The 'propiq_walkforward_backtest' module does not contain a 'run' function. Calling 'bt_mod.run(folds)' will raise an 'AttributeError'. Based on the module's content, you likely intended to call 'run_walkforward_backtest', but that function requires 'pitching_df' and 'prop_lines_df' DataFrames as input. Ensure the intended function is defined or use a wrapper that handles data loading.
The reason will be displayed to describe this comment to others. Learn more.
The 'folds' parameter should be validated to ensure it is a positive integer. If 'folds=0' is passed, it will cause a 'ZeroDivisionError' in 'propiq_walkforward_backtest.py' at line 562 during the fold size calculation.
The reason will be displayed to describe this comment to others. Learn more.
This background task lacks concurrency control. Multiple requests to this endpoint will trigger multiple backtests simultaneously, potentially leading to resource exhaustion or file write conflicts in the output directory. Consider implementing a guard (e.g., a global boolean flag or an 'asyncio.Lock') to prevent concurrent executions.
The reason will be displayed to describe this comment to others. Learn more.
There is a discrepancy between the response message and the actual script output. The message points to 'data/walkforward_results.json', but 'propiq_walkforward_backtest.py' is configured to write its summary to 'backtest_results/walkforward_summary.json' (line 699).
Suggested change
"Results written to data/walkforward_results.json when complete.",
"Results written to backtest_results/walkforward_summary.json when complete.",
The reason will be displayed to describe this comment to others. Learn more.
Undefined variable 'importlib'
The variable name is not defined where it is used.
This will lead to an error during the runtime.
Make sure there is no typo. If the name was supposed to be imported, verify that you've actually imported the name.
The reason will be displayed to describe this comment to others. Learn more.
Undefined variable 'importlib'
The variable name is not defined where it is used.
This will lead to an error during the runtime.
Make sure there is no typo. If the name was supposed to be imported, verify that you've actually imported the name.
The reason will be displayed to describe this comment to others. Learn more.
Undefined variable 'importlib'
The variable name is not defined where it is used.
This will lead to an error during the runtime.
Make sure there is no typo. If the name was supposed to be imported, verify that you've actually imported the name.
The reason will be displayed to describe this comment to others. Learn more.
Undefined variable 'importlib'
The variable name is not defined where it is used.
This will lead to an error during the runtime.
Make sure there is no typo. If the name was supposed to be imported, verify that you've actually imported the name.
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="orchestrator.py">
<violation number="1" location="orchestrator.py:1303">
P1: Prevent concurrent `/admin/walkforward` runs; overlapping background tasks can race and overwrite shared walkforward output.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
The reason will be displayed to describe this comment to others. Learn more.
P1: Prevent concurrent /admin/walkforward runs; overlapping background tasks can race and overwrite shared walkforward output.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At orchestrator.py, line 1303:
<comment>Prevent concurrent `/admin/walkforward` runs; overlapping background tasks can race and overwrite shared walkforward output.</comment>
<file context>
@@ -1274,6 +1274,40 @@ async def admin_bp2vec_train():
+ except Exception as exc:
+ logger.error("[walkforward] Failed: %s", exc, exc_info=True)
+
+ asyncio.create_task(_run_walkforward())
+ return JSONResponse({
+ "status": "started",
</file context>
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
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.
Adds GET/POST /admin/walkforward to orchestrator.py. Triggers wire_walkforward_backtest.export_from_db() then propiq_walkforward_backtest.run(folds) in background. Results → data/walkforward_results.json. All three data-level jobs now have HTTP triggers.
Summary by cubic
Adds a new
/admin/walkforwardendpoint to run walk-forward backtests in the background and write results todata/walkforward_results.json. This completes HTTP triggers for all data-level jobs./admin/walkforward(GET/POST) to export graded legs and run fold analysis.wire_walkforward_backtest.export_from_dbthenpropiq_walkforward_backtest.run(folds); defaultfolds=3.{ status: "started" }; allow?folds=5or POST body to set folds.Written for commit 7dd8e98. Summary will update on new commits.
Summary by CodeRabbit