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
strategyIdsupport to theprepare_backtest_datatool 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 Strategywith snapshot/code fallback metadata.
Validation
pnpm test:toolsfromservices/backend: 89/89 passing.pnpm typecheckfromservices/backend: passing.pnpm lintfromservices/backend: passing.pnpm typecheck && pnpm lintfrom Quantago root: passing.pnpm typecheckfrom SaaS Stack root: passing.pnpm lintfrom SaaS Stack root: passing with one existing Biome schema-version info intemplates/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/healthreturned200 {"ok":true}.https://api.quantago.co/api/healthreturned200 {"ok":true}.