Skip to content

fix(cron): apply custom assistant rules in scheduled runs#495

Open
mabobsa wants to merge 1 commit into
iOfficeAI:mainfrom
mabobsa:fix/cron-assistant-rules
Open

fix(cron): apply custom assistant rules in scheduled runs#495
mabobsa wants to merge 1 commit into
iOfficeAI:mainfrom
mabobsa:fix/cron-assistant-rules

Conversation

@mabobsa

@mabobsa mabobsa commented Jun 19, 2026

Copy link
Copy Markdown

Problem

Running a custom assistant via a scheduled task (cron) does not apply the assistant's rules (its system prompt). The agent receives only the bare task text, so it goes off-task and narrates in English instead of following the configured persona/language. Interactive runs are unaffected (the frontend supplies preset_context).

Root cause

Two independent gaps, both on the cron path:

  1. Rule dispatcher not wired. build_cron_state constructs its own ConversationService and wires every assistant repo except the rule dispatcher — it never calls with_assistant_dispatcher. So resolve_assistant_snapshot finds assistant_dispatcher() == None, never calls read_rule, and rules_content stays empty. (The interactive build_conversation_state does wire it.)

  2. Locale lost → rule file missed. Cron creates the conversation with assistant: None, so no locale reaches read_rule(id, None). That looks up {id}.md, but user rules are stored locale-suffixed as {id}.{locale}.md, so the file is never found even once the dispatcher is present.

Both must be fixed: without (1) read_rule is never called; with (1) but without (2) it returns empty for locale-less callers.

Fix

  • Wire the assistant rule dispatcher into the cron ConversationService at the assembly site (build_module_states), mirroring the interactive path. build_cron_state's signature is left unchanged.
  • read_rule falls back to any saved {id}.*.md rule file when the locale-specific file is absent, so locale-less callers (cron) still resolve rules.
  • Adds a regression test (read_rule_user_falls_back_to_saved_locale_when_locale_missing).

Verification

  • cargo test -p aionui-assistant — read_rule tests pass.
  • End-to-end: a scheduled custom-assistant run now resolves non-empty rules, and the agent's [Assistant Rules] block contains the configured rules (confirmed via runtime logs and the stored conversation snapshot).

Scheduled (cron) runs of a custom assistant never applied the assistant's
rules (its system prompt), so the agent worked from the bare task text only,
went off-task, and narrated in English instead of following the configured
persona/language. Interactive runs are unaffected (the frontend supplies
preset_context).

Two independent gaps, both on the cron path:

- build_cron_state constructs its own ConversationService and wires every
  assistant repo except the rule dispatcher (no with_assistant_dispatcher), so
  resolve_assistant_snapshot sees a None dispatcher, never calls read_rule, and
  rules_content stays empty. The interactive build_conversation_state wires it.
- Cron creates the conversation with `assistant: None`, so no locale reaches
  read_rule(id, None). That looks up `{id}.md`, but user rules are stored
  locale-suffixed as `{id}.{locale}.md`, so the file is missed even once the
  dispatcher is present.

Fix:
- Wire the assistant rule dispatcher into the cron ConversationService at the
  assembly site, mirroring build_conversation_state. build_cron_state's
  signature is left unchanged.
- read_rule falls back to any saved `{id}.*.md` file when the locale-specific
  file is absent, so locale-less callers (cron) still resolve rules. Adds a
  regression test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants