Skip to content

Commit 30046fe

Browse files
theo-learnerclaude
andcommitted
feat: trigger Goal Manager tick on seed injection for organic queue updates
After injecting a scenario (stable/rising/spike), immediately call tickGoalManager() so Goal Queue reflects new signals without waiting for the next Agent Loop cycle (30s). Response includes goalsQueued count; UI feedback shows "· N goals queued" when goals are created. Goal Manager disabled (default) → no-op, zero overhead. Goal Manager enabled → signal snapshot → candidates → queue. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 22af5f2 commit 30046fe

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/app/api/metrics/seed/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { pushMetric, clearMetrics, getRecentMetrics, getMetricsCount } from '@/l
99
import { resetPredictionState } from '@/lib/predictive-scaler';
1010
import { initVcpuProfile, clearVcpuProfile, getVcpuValuesForScenario } from '@/lib/seed-vcpu-manager';
1111
import { getStore } from '@/lib/redis-store';
12+
import { tickGoalManager } from '@/lib/goal-manager';
1213
import { MetricDataPoint } from '@/types/prediction';
1314
import logger from '@/lib/logger';
1415

@@ -227,10 +228,23 @@ export async function POST(request: NextRequest) {
227228

228229
logger.info(`[Seed API] Scheduled automatic cleanup in ${SEED_TTL_SECONDS}s`);
229230

231+
// Trigger Goal Manager tick so the queue reflects the injected scenario immediately
232+
let goalsQueued = 0;
233+
try {
234+
const tickResult = await tickGoalManager();
235+
goalsQueued = tickResult.queuedCount;
236+
if (tickResult.enabled) {
237+
logger.info(`[Seed API] Goal Manager tick: ${goalsQueued} goals queued for scenario=${scenario}`);
238+
}
239+
} catch {
240+
// Goal Manager errors must not affect seed response
241+
}
242+
230243
return NextResponse.json({
231244
success: true,
232245
scenario,
233246
injectedCount: dataPoints.length,
247+
goalsQueued,
234248
ttlSeconds: SEED_TTL_SECONDS,
235249
ttlExpiry: new Date(Date.now() + SEED_TTL_SECONDS * 1000).toISOString(),
236250
timeRange: {

src/app/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,13 @@ export default function Dashboard() {
709709
throw new Error(message);
710710
}
711711
const injectedCount = typeof body.injectedCount === 'number' ? body.injectedCount : null;
712+
const goalsQueued = typeof body.goalsQueued === 'number' ? body.goalsQueued : 0;
713+
const goalsSuffix = goalsQueued > 0 ? ` · ${goalsQueued} goals queued` : '';
712714
setAutonomyActionFeedback({
713715
type: 'success',
714716
message: injectedCount !== null
715-
? `Scenario ${scenario} injected (${injectedCount} data points)`
716-
: `Scenario ${scenario} injected`,
717+
? `Scenario ${scenario} injected (${injectedCount} data points)${goalsSuffix}`
718+
: `Scenario ${scenario} injected${goalsSuffix}`,
717719
});
718720
} else if (action === 'goal-tick') {
719721
const res = await fetch(`${BASE_PATH}/api/goal-manager/tick`, {

0 commit comments

Comments
 (0)