New Strategy Entity, Chat CRUD, and Schema Sync
Summary
Blank bot creation now creates a real versioned strategy entity named New Strategy instead of leaving the bot with no active bot_strategies row. The AI chat can now create, inspect, update, and reset strategy entities, and every strategy code save path synchronizes code-used parameters into params and parameter_schema.properties.
This fixes the backtest failure for newly created blank bots:
Unsupported strategy: . Provide strategyId/strategySnapshotId or codeText, or select a different strategy.
Root Cause
createBot only inserted a bot_strategies snapshot when bot.strategy.trim() was non-empty. A bot created with an empty strategy therefore had no strategy entity, no snapshot id, and no code/snapshot fallback for backtests.
The chat layer also detected code/schema drift but mostly reported it back to the model instead of repairing the stored defaults and schema. That allowed strategy code to reference parameters that did not exist in the saved schema or default parameter payload.
Changes
Strategy lifecycle
insertBotStrategyVersionnow normalizes blank names toNew Strategyat the repository boundary.createBotalways seeds an initialbot_strategiesrow, even when the requested strategy is empty.- Legacy blank bots are repaired lazily through the chat resolver and receive a
New Strategysnapshot. - Bot creation greeting text now describes the blank
New Strategyentity instead of implying there is no strategy.
AI chat strategy tools
- Added
create_strategyfor creating or replacing the active strategy entity. - Added
delete_strategyas a non-destructive reset to a blankNew Strategysnapshot. - Existing
get_strategy, metadata, schema, and code-write tools now use normalized strategy display names. - Strategy mutation tools respect shared-bot permissions through the existing read/write tool filtering.
Parameter schema synchronization
Code-used parameters are now inferred and merged into saved strategy state whenever code is persisted through:
commit_strategy_fileswrite_strategy_codeupdate_strategy_codefile-scoped editsupdate_strategy_codesurgical editsupdate_strategy_codefull generated rewrites
The sync adds missing keys to both params and parameter_schema.properties. It preserves existing user-specified values and does not delete existing fields.
Backtest fallback repair
- Chat backtest tools now merge missing defaults from the active strategy snapshot before running.
- Backtest requests carry the active strategy snapshot id and code when available.
- Strategy labels are normalized so blank legacy labels do not flow into the runner.
- The runner can now pair explicit
strategyCodeTextwith a requested snapshot's savedparamsandparameter_schema, so explicit-code backtests still get the synced schema/default metadata.
Parameter mutation fix
parseBotParameters now clones object and parsed JSON values before use. This prevents shared object mutation between tool calls and removed hidden state leakage in tests and runtime paths.
Files Changed
services/backend/src/routes/bots/bot-strategies-repository.tsservices/backend/src/routes/bots/bots-service.tsservices/backend/src/routes/bots/bots-chat-handlers.tsservices/backend/src/lib/backtest-engine/runner.tsservices/backend/tests/bot-chat-tools.test.ts
Validation
Executed successfully:
cd projects/quantago/services/backend && pnpm test:tools
cd projects/quantago/services/backend && pnpm typecheck
cd projects/quantago/services/backend && pnpm lint
cd projects/quantago && pnpm typecheck
cd projects/quantago && pnpm lint
cd /Users/adam/github/saas-stack && pnpm typecheck
cd /Users/adam/github/saas-stack && pnpm lint
Results:
- Bot chat tool suite: 89/89 passing.
- Backend typecheck: clean.
- Backend lint: clean.
- Quantago project typecheck: clean.
- Quantago project lint: clean.
- Root typecheck: clean.
- Root lint: passed with one non-fatal Biome schema-version info for
templates/base/biome.json.
Notes
The delete_strategy chat tool intentionally resets the active strategy to a new blank snapshot instead of deleting historical rows. That keeps version history intact while giving the user the expected fresh New Strategy state.