🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(bot-wake): judge a message against the bot's duties while its owner is around (#21739)
Arvin Xu2cd4dd87f498
diff --git a/apps/server/src/services/agentSignal/scenarios/botWake/policies/duty.ts b/apps/server/src/services/agentSignal/scenarios/botWake/policies/duty.tsindex aedb19afe80..e1669446871 100644--- a/apps/server/src/services/agentSignal/scenarios/botWake/policies/duty.ts+++ b/apps/server/src/services/agentSignal/scenarios/botWake/policies/duty.ts@@ -63,8 +63,9 @@ const degraded = (reason: string): WakePolicyResult => ({** Use when:* - Nothing else woke the bot: it was not named, not @-mentioned, outside the follow-up window,- * and no rule denied the message. The recorder's `initiate` runs it last; it is not part of the- * policy set the other paths evaluate.+ * and no rule denied the message but owner presence, which keeps the bot out of chatter, not+ * off its duties. The recorder's `initiate` runs it last; it is not part of the policy set the+ * other paths evaluate.** Expects:* - `rules.duties.text` is set; without duties the recorder does not build this policydiff --git a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.duty.test.ts b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.duty.test.tsindex 4dda21692fe..2a8f433c398 100644--- a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.duty.test.ts+++ b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.duty.test.ts@@ -212,6 +212,31 @@ describe('bot-wake recorder: a message within the bot duties', () => {expect(judge).not.toHaveBeenCalled();});+ // The owner chatting in the channel kept every feature request in it from being logged.+ it('still steps in on its duties while the owner is around, and nowhere else', async () => {+ const ownerAround = () => fakeState({ ownerLastSpokeAt: Date.now() - 10_000 });+ const judge = dutyJudge(0.9);++ await expect(+ make(DUTIES(), ownerAround(), { dutyJudge: judge }).initiate(request()),+ ).resolves.toMatchObject({ reason: 'in-duty' });+ expect(judge).toHaveBeenCalledOnce();++ // Without duties, owner presence still keeps the bot out of the chatter.+ await expect(+ make({ mode: 'enforce' }, ownerAround()).initiate(request()),+ ).resolves.toBeUndefined();+ // A deny before presence (the budget) still wins over the duties.+ await expect(+ make(+ DUTIES('enforce', { rules: { maxSilentWakes: 2 } }),+ fakeState({ ownerLastSpokeAt: Date.now() - 10_000, silentWakes: 2 }),+ { dutyJudge: judge },+ ).initiate(request()),+ ).resolves.toBeUndefined();+ expect(judge).toHaveBeenCalledOnce();+ });+it('leaves its name and a confirmed follow-up to their own paths', async () => {const judge = dutyJudge(1);const named = make(DUTIES(), fakeState(), { dutyJudge: judge });diff --git a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.tsindex da8e4fe3483..dbbfb858919 100644--- a/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts+++ b/apps/server/src/services/bot/BotMessageRouter/wakeDecision.ts@@ -35,6 +35,7 @@ import {createDutyPolicy,createWakePolicySet,DUTY_POLICY_ID,+ OWNER_RULES_POLICY_ID,} from '@/server/services/agentSignal/scenarios/botWake/policies';import { createBotWakeRolloutProbe } from '@/server/services/agentSignal/scenarios/botWake/rollout';import type {@@ -846,10 +847,20 @@ export const createBotWakeRecorder = (options: BotWakeRecorderOptions): BotWakeRif (!rulesEnforce || ruleDecision.verdict !== 'allow' || ruleDecision.fastPath) {// Nothing addressed the bot and no rule allowed it: not named, outside the follow-up// window. Only when no rule had an opinion either way, whatever the rules' mode: a deny- // (a channel list, the silent-wake budget) still keeps the bot out.+ // (a channel list, the silent-wake budget) still keeps the bot out. Owner presence is+ // the exception: it keeps the bot out of chatter the owner can answer, not off its+ // duties. Logging a feature request does not wait for the owner to go quiet.+ const onlyOwnerPresent =+ ruleDecision.verdict === 'deny' &&+ ruleDecision.decidedBy === OWNER_RULES_POLICY_ID &&+ ruleDecision.reason === 'owner-present' &&+ ruleDecision.records.every(+ (record) => record.policyId === OWNER_RULES_POLICY_ID || record.verdict === 'abstain',+ );const undecided =!ruleDecision.fastPath &&- ruleDecision.records.every((record) => record.verdict === 'abstain');+ (onlyOwnerPresent ||+ ruleDecision.records.every((record) => record.verdict === 'abstain'));if (!undecided || !dutyPolicy) {// An enforcing deny is what kept the bot quiet: keep its verdicts, so the row names the// rule that stopped the wake instead of replaying every policy as if it only watched.