feat: support postgres autonomy runtime
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const os = require('os');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { enqueueJob, leaseNextJob, completeJob, failJob } = require('../src/autonomy/jobs');
|
||||
|
||||
@@ -104,8 +104,8 @@ function reconcileLiveBatch(archiveDb, intelligenceDb, batchSize = 250) {
|
||||
}
|
||||
|
||||
async function runAutonomyWorker({ archivePath, intelligencePath, workerId = `autonomy-${os.hostname()}-${process.pid}`, pollMs = 1000 } = {}) {
|
||||
const archiveDb = new Database(archivePath, { readonly: true });
|
||||
const intelligenceDb = new Database(intelligencePath);
|
||||
const archiveDb = openRuntimeDb(archivePath, { schema: 'archive', readonly: true });
|
||||
const intelligenceDb = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
intelligenceDb.pragma('journal_mode = WAL');
|
||||
intelligenceDb.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(intelligenceDb);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const os = require('os');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { calibrateOutcomes, cohortKey } = require('../src/autonomy/calibration');
|
||||
const { decide } = require('../src/autonomy/policy');
|
||||
@@ -144,7 +144,7 @@ function refreshReplayEvaluations(db) {
|
||||
}
|
||||
|
||||
async function runCalibrationWorker({ intelligencePath, pollMs = 60000, workerId = `calibration-${os.hostname()}-${process.pid}` } = {}) {
|
||||
const db = new Database(intelligencePath);
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(db);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { leaseNextJob, completeJob, failJob } = require('../src/autonomy/jobs');
|
||||
const { callCoordinator } = require('../src/autonomy/llm');
|
||||
@@ -31,8 +31,8 @@ function buildPrompt(event, articles) {
|
||||
}
|
||||
|
||||
async function runCoordinatorWorker({ archivePath, intelligencePath, workerId = `coordinator-${os.hostname()}-${process.pid}`, pollMs = 1000 } = {}) {
|
||||
const archiveDb = new Database(archivePath, { readonly: true });
|
||||
const intelligenceDb = new Database(intelligencePath);
|
||||
const archiveDb = openRuntimeDb(archivePath, { schema: 'archive', readonly: true });
|
||||
const intelligenceDb = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
intelligenceDb.pragma('journal_mode = WAL');
|
||||
intelligenceDb.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(intelligenceDb);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const os = require('os');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { createOrderIntent } = require('../src/autonomy/orderIntents');
|
||||
const { createAlpacaPaperClient } = require('../src/brokers/alpacaPaper');
|
||||
@@ -8,7 +8,7 @@ function sleep(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }
|
||||
|
||||
async function runExecutionWorker({ intelligencePath, pollMs = 10000, mode = 'shadow', notional = 100, workerId = `execution-${os.hostname()}-${process.pid}` } = {}) {
|
||||
if (!['shadow', 'paper'].includes(mode)) throw new Error(`unsupported execution mode: ${mode}`);
|
||||
const db = new Database(intelligencePath);
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(db);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const os = require('os');
|
||||
const https = require('https');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { calculateOutcome } = require('../src/autonomy/outcomes');
|
||||
|
||||
@@ -33,7 +33,7 @@ async function history(symbol) {
|
||||
}
|
||||
|
||||
async function resolveAutonomyOutcomes({ intelligencePath, workerId = `outcome-${os.hostname()}-${process.pid}`, pollMs = 60000 } = {}) {
|
||||
const db = new Database(intelligencePath);
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(db);
|
||||
@@ -56,9 +56,18 @@ async function resolveAutonomyOutcomes({ intelligencePath, workerId = `outcome-$
|
||||
continue;
|
||||
}
|
||||
db.prepare(`
|
||||
INSERT OR REPLACE INTO autonomy_outcomes
|
||||
INSERT INTO autonomy_outcomes
|
||||
(prediction_id, price_0, price_horizon, benchmark_0, benchmark_horizon, excess_return, direction_correct, error_type)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(prediction_id) DO UPDATE SET
|
||||
price_0=excluded.price_0,
|
||||
price_horizon=excluded.price_horizon,
|
||||
benchmark_0=excluded.benchmark_0,
|
||||
benchmark_horizon=excluded.benchmark_horizon,
|
||||
excess_return=excluded.excess_return,
|
||||
direction_correct=excluded.direction_correct,
|
||||
error_type=excluded.error_type,
|
||||
evaluated_at=datetime('now')
|
||||
`).run(prediction.id, result.price0, result.priceHorizon, result.benchmark0, result.benchmarkHorizon,
|
||||
result.excessReturn, result.directionCorrect, result.directionCorrect ? null : 'direction_error');
|
||||
db.prepare("UPDATE autonomy_predictions SET status = 'resolved' WHERE id = ?").run(prediction.id);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const os = require('os');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb } = require('../src/db/runtime');
|
||||
const { initAutonomySchema } = require('../src/autonomy/schema');
|
||||
const { enqueueJob, leaseNextJob, completeJob, failJob } = require('../src/autonomy/jobs');
|
||||
const { callCoordinator } = require('../src/autonomy/llm');
|
||||
@@ -94,8 +94,8 @@ function scheduleNext(db, archiveDb, run) {
|
||||
}
|
||||
|
||||
async function runReplayWorker({ archivePath, intelligencePath, workerId = `replay-${os.hostname()}-${process.pid}`, pollMs = 15000 } = {}) {
|
||||
const archiveDb = new Database(archivePath, { readonly: true });
|
||||
const db = new Database(intelligencePath);
|
||||
const archiveDb = openRuntimeDb(archivePath, { schema: 'archive', readonly: true });
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence' });
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('busy_timeout = 5000');
|
||||
initAutonomySchema(db);
|
||||
|
||||
Reference in New Issue
Block a user