chore(scheduler): skip agents whose data sources aren't granted (#128)
Check getEligibleAgentIds per user in runCycle before calling computeAndStore — agents without consented data sources, silenced by active context, or disabled via preference are skipped rather than computed unconditionally. Eligibility check failure skips the whole user (fail-closed). Skipped count added to cycle-complete log line. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import { gt, lt } from 'drizzle-orm';
|
||||
import { logger } from '../logger.js';
|
||||
import { config } from '../config.js';
|
||||
import { computeAndStore } from '../routes/agent-outputs.js';
|
||||
import { getEligibleAgentIds } from '../profile/eligibility.js';
|
||||
|
||||
const FALLBACK_AGENT_IDS = [
|
||||
'overdue-task',
|
||||
@@ -67,8 +68,22 @@ async function runCycle(agentIds: string[]): Promise<void> {
|
||||
let ok = 0;
|
||||
let failed = 0;
|
||||
|
||||
let skipped = 0;
|
||||
for (const userId of userIds) {
|
||||
let eligible: Set<string>;
|
||||
try {
|
||||
eligible = await getEligibleAgentIds(userId);
|
||||
} catch (err: any) {
|
||||
logger.error({ err, userId }, 'agent-scheduler: eligibility check failed, skipping user');
|
||||
skipped += agentIds.length;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const agentId of agentIds) {
|
||||
if (!eligible.has(agentId)) {
|
||||
skipped++;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await computeAndStore(userId, agentId);
|
||||
ok++;
|
||||
@@ -86,7 +101,7 @@ async function runCycle(agentIds: string[]): Promise<void> {
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{ ok, failed, users: userIds.length, agents: agentIds.length },
|
||||
{ ok, failed, skipped, users: userIds.length, agents: agentIds.length },
|
||||
'agent-scheduler: cycle complete',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user