feat(research): retry failed experiment trials with retained history

This commit is contained in:
Boki 2026-10-24 10:56:58 -04:00
parent 6f64ef62ba
commit b373410320
32 changed files with 3336 additions and 61 deletions

View file

@ -294,6 +294,7 @@ export async function fixture(browser: Browser, native = false) {
'20-research-workspace.sql',
'21-run-reproduction.sql',
'22-experiments.sql',
'23-experiment-retries.sql',
]) {
await pool.query(
readFileSync(new URL(`../../database/postgres/init/${name}`, import.meta.url), 'utf8')
@ -345,6 +346,17 @@ export async function fixture(browser: Browser, native = false) {
const engine = native
? new RustBacktestAdapter({ logger, storage: runStorage }, { timeoutMs: 15000 })
: controlled;
const canonicalFailures: string[] = [];
if (engine instanceof RustBacktestAdapter) {
const executeCanonical = engine.runCanonical.bind(engine);
engine.runCanonical = async (...args) => {
const failure = canonicalFailures.shift();
if (failure) {
throw new Error(failure);
}
return executeCanonical(...args);
};
}
const runner = new BacktestRunner({
engine,
engineName: 'native',
@ -570,6 +582,12 @@ export async function fixture(browser: Browser, native = false) {
frames,
delayResponse,
controlled,
failNextCanonical: (message: string) => {
if (!native) {
throw new Error('A native fixture is required for canonical failure injection');
}
canonicalFailures.push(message);
},
dispatcher,
request,
login,