Skip to content

PR #568: Add /admin/walkforward endpoint#437

Merged
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-568-walkforward-endpoint
May 15, 2026
Merged

PR #568: Add /admin/walkforward endpoint#437
jaayslaughter-cpu merged 1 commit into
mainfrom
pr-568-walkforward-endpoint

Conversation

@jaayslaughter-cpu
Copy link
Copy Markdown
Owner

@jaayslaughter-cpu jaayslaughter-cpu commented May 15, 2026

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.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a254d2e-7447-4833-ba64-618c97ac2a7b

📥 Commits

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented May 15, 2026

DeepSource Code Review

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.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Docker May 15, 2026 3:13a.m. Review ↗
JavaScript May 15, 2026 3:13a.m. Review ↗
Python May 15, 2026 3:13a.m. Review ↗
SQL May 15, 2026 3:13a.m. Review ↗
Secrets May 15, 2026 3:13a.m. Review ↗

Important

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.

@jaayslaughter-cpu jaayslaughter-cpu merged commit 06815d1 into main May 15, 2026
5 of 9 checks passed
@codacy-production
Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 4 high

Alerts:
⚠ 4 issues (≤ 0 issues of at least minor severity)

Results:
4 new issues

Category Results
ErrorProne 4 high

View in Codacy

🟢 Metrics 8 complexity

Metric Results
Complexity 8

View in Codacy

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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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.

Comment thread orchestrator.py
Comment on lines +1287 to +1288
async def _run_walkforward():
try:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Suggested change
async def _run_walkforward():
try:
async def _run_walkforward():
import importlib.util
try:

Comment thread orchestrator.py
wf_mod = importlib.import_module("wire_walkforward_backtest")
bt_mod = importlib.import_module("propiq_walkforward_backtest")
await loop.run_in_executor(None, wf_mod.export_from_db)
await loop.run_in_executor(None, bt_mod.run, folds)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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.

Comment thread orchestrator.py

@app.get("/admin/walkforward")
@app.post("/admin/walkforward")
async def admin_walkforward(folds: int = 3):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread orchestrator.py
saves results to data/walkforward_results.json.
Usage: POST /admin/walkforward or GET /admin/walkforward?folds=5
"""
async def _run_walkforward():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Micro-Learning Topic: Resource exhaustion (Detected by phrase)

Matched on "resource exhaustion"

What is this? (2min video)

Allocating objects or timers with user-controlled sizes or durations can cause resource exhaustion.

Try a challenge in Secure Code Warrior

Comment thread orchestrator.py
return JSONResponse({
"status": "started",
"message": f"Walk-forward backtest running in background (~3-5 min, {folds} folds). "
"Results written to data/walkforward_results.json when complete.",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.",

Comment thread orchestrator.py
async def _run_walkforward():
try:
loop = asyncio.get_event_loop()
spec_wf = importlib.util.find_spec("wire_walkforward_backtest")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread orchestrator.py
try:
loop = asyncio.get_event_loop()
spec_wf = importlib.util.find_spec("wire_walkforward_backtest")
spec_bt = importlib.util.find_spec("propiq_walkforward_backtest")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread orchestrator.py
if spec_wf is None or spec_bt is None:
logger.warning("[walkforward] Required scripts not found — skipping")
return
wf_mod = importlib.import_module("wire_walkforward_backtest")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Comment thread orchestrator.py
logger.warning("[walkforward] Required scripts not found — skipping")
return
wf_mod = importlib.import_module("wire_walkforward_backtest")
bt_mod = importlib.import_module("propiq_walkforward_backtest")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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.

Comment thread orchestrator.py
except Exception as exc:
logger.error("[walkforward] Failed: %s", exc, exc_info=True)

asyncio.create_task(_run_walkforward())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant