Skip to content

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

Merged
kaizhou-lab merged 2 commits into
iOfficeAI:mainfrom
mabobsa:fix/cron-assistant-rules
Jul 2, 2026
Merged

fix(cron): apply custom assistant rules in scheduled runs#495
kaizhou-lab merged 2 commits into
iOfficeAI:mainfrom
mabobsa:fix/cron-assistant-rules

Conversation

@mabobsa

@mabobsa mabobsa commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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).

DragonMinNHN and others added 2 commits June 19, 2026 15:26
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.
# Conflicts:
#	crates/aionui-assistant/src/service.rs
@kaizhou-lab kaizhou-lab enabled auto-merge (squash) July 2, 2026 07:21
@kaizhou-lab kaizhou-lab merged commit 3840b77 into iOfficeAI:main Jul 2, 2026
6 checks passed
piorpua pushed a commit that referenced this pull request Jul 2, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.41](v0.1.40...v0.1.41)
(2026-07-02)


### Bug Fixes

* **assistant:** normalize avatar storage and identity
([#558](#558))
([155c278](155c278))
* **conversation:** derive assistant runtime type from metadata
([#555](#555))
([236217d](236217d))
* **conversation:** partition temp workspaces and logs by date
([#560](#560))
([9bb1f33](9bb1f33))
* **cron:** apply custom assistant rules in scheduled runs
([#495](#495))
([3840b77](3840b77))
* **cron:** lock team cron execution mode
([#562](#562))
([56f3873](56f3873))
* **cron:** route skill scheduling through helper
([#553](#553))
([c57970f](c57970f))
* **database:** require explicit corrupted database recovery
([#563](#563))
([203bd1b](203bd1b))
* resolve ACP backends from metadata
([#559](#559))
([6c15bb7](6c15bb7))
* **runtime:** harden managed Node command resolution
([#565](#565))
([e69b83a](e69b83a))
* **runtime:** protect active ACP tasks from idle cleanup
([#561](#561))
([1fa7a54](1fa7a54))
* **skill:** raise import size limits
([#564](#564))
([50d9aff](50d9aff))
* **skills:** correct AionUi Butler skill drift against current backend
([#557](#557))
([41c2c94](41c2c94))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

3 participants