fix(cron): apply custom assistant rules in scheduled runs#495
Open
mabobsa wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
Rule dispatcher not wired.
build_cron_stateconstructs its ownConversationServiceand wires every assistant repo except the rule dispatcher — it never callswith_assistant_dispatcher. Soresolve_assistant_snapshotfindsassistant_dispatcher() == None, never callsread_rule, andrules_contentstays empty. (The interactivebuild_conversation_statedoes wire it.)Locale lost → rule file missed. Cron creates the conversation with
assistant: None, so nolocalereachesread_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_ruleis never called; with (1) but without (2) it returns empty for locale-less callers.Fix
ConversationServiceat the assembly site (build_module_states), mirroring the interactive path.build_cron_state's signature is left unchanged.read_rulefalls back to any saved{id}.*.mdrule file when the locale-specific file is absent, so locale-less callers (cron) still resolve rules.read_rule_user_falls_back_to_saved_locale_when_locale_missing).Verification
cargo test -p aionui-assistant— read_rule tests pass.[Assistant Rules]block contains the configured rules (confirmed via runtime logs and the stored conversation snapshot).