Skip to main content

Prepare Backtest Data Strategy Fallback

Summary​

Fixed a production failure where prepare_backtest_data could still call the backtest resolver with a blank strategy label and trigger:

Unsupported strategy: . Provide strategyId/strategySnapshotId or codeText, or select a different strategy.

The staging tool now mirrors the important fallback behavior used by run_backtest: it resolves the active strategy snapshot, normalizes blank strategy names to New Strategy, passes both strategyId and strategySnapshotId, includes strategy code text for the active snapshot, and injects the user's Pepperstone credential when cTrader/Pepperstone data is needed.

Reasoning​

New bots can legitimately start from an empty strategy name while still having a durable bot_strategies row. The backtest resolver can run those strategies if it receives snapshot or code fallback metadata, but prepare_backtest_data is the first tool the chat calls before queuing a backtest. If staging misses that metadata, the user sees the unsupported blank-strategy error before run_backtest gets a chance to use its fallback path.

Key Changes​

const requestedStrategyId = typeof args.strategyId === 'string' ? args.strategyId.trim() : '';
if (requestedStrategyId) {
botParams.strategyId = requestedStrategyId;
botParams.strategySnapshotId = requestedStrategyId;
} else if (activeStrategy.id) {
botParams.strategySnapshotId = activeStrategy.id;
botParams.strategyId = activeStrategy.id;
}
  • Added optional strategyId support to the prepare_backtest_data tool schema.
  • Added Pepperstone/cTrader credential auto-injection to prepare_backtest_data.
  • Added regression coverage for a blank bot strategy and blank active strategy name resolving as New Strategy with snapshot/code fallback metadata.

Validation​

  • pnpm test:tools from services/backend: 89/89 passing.
  • pnpm typecheck from services/backend: passing.
  • pnpm lint from services/backend: passing.
  • pnpm typecheck && pnpm lint from Quantago root: passing.
  • pnpm typecheck from SaaS Stack root: passing.
  • pnpm lint from SaaS Stack root: passing with one existing Biome schema-version info in templates/base/biome.json.

Deployment​

  • Dev backend deployed as Worker version eb86eec9-61a8-4aea-ab8f-904e38cfd5af.
  • Production backend deployed as Worker version f286ee57-7844-455c-9416-f92c7ab72571.
  • https://dev-api.quantago.co/api/health returned 200 {"ok":true}.
  • https://api.quantago.co/api/health returned 200 {"ok":true}.