[PR #6600] [MERGED] feat(decision): priority and every-N-turns timing on decision statements #7247

Closed
opened 2026-10-23 04:17:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6600
Author: @kolacheee
Created: 9/24/2026
Status: ✅ Merged
Merged: 9/24/2026
Merged by: @kolacheee

Base: staging ← Head: feat/decision-priority-timing


📝 Commits (2)

  • 6f21af0 feat(decision): priority and every-N-turns timing on decision statements
  • 6423787 fix(decision): count every: from the last check with the current number

📊 Changes

12 files changed (+449 additions, -50 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/connections/decision-models.md (+1 -1)
📝 docs/prompts/conditional-prompts.md (+35 -1)
📝 docs/prompts/macros.md (+1 -1)
📝 packages/server/src/routes/chats.routes.ts (+2 -2)
📝 packages/server/src/routes/generate.routes.ts (+4 -2)
📝 packages/server/src/routes/generate/dry-run-route.ts (+2 -2)
📝 packages/server/src/services/decision/decision-timers.ts (+54 -6)
📝 packages/server/src/services/decision/prompt-decisions.ts (+64 -24)
📝 packages/shared/src/utils/macro-engine.ts (+29 -10)
➕ scripts/regressions/decision-priority-timing.regression.ts (+254 -0)
📝 scripts/regressions/decision-reachable-statements.regression.ts (+1 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6599

Why this change

  • Busy presets go over Decision statements per turn, and authors know which statements matter. Until now the limit dropped whatever came last in the prompt, with no way to say that one statement matters more than another.
  • Many statements do not need asking every turn. Scene-level instructions and agent gates often only need an occasional check, but each one still cost a slot, and on a hosted connection a billed question, every turn.

What changed

  • priority:high and priority:low, written after a statement like sticky: and cooldown: (#6582). When a turn has more statements than its limit, high ones are asked first and low ones dropped first; a statement with no priority is medium. Within a priority, source order still decides. A statement written in several places uses the highest priority given anywhere.
    • The planner now collects every statement first (merging options and modifiers across occurrences), works out which are held, then fills the slots by priority. This also fixes a small leak where a Choice statement with no options took a slot before being discarded.
    • The prompt's statements are planned first; statements in lorebook entries' text are planned once the scan knows which entries activate, with the slots left. So a lorebook statement never displaces the prompt's, whatever its priority, and the docs say so.
  • every:N asks a statement only every N turns. It is asked the first turn it is reached, then N turns later; between checks it reads as no, is not asked, and takes no slot. Turns count the same way as sticky and cooldown, so a regeneration reads the same answer. The next check is kept per chat beside the sticky and cooldown timers, only after a real answer, so a timed-out question is asked again next turn. A statement written in several places uses the smallest every:.
  • Docs: Conditional Prompts gains "Checking every few turns" and "Priority" sections, the limits note and the Decision Models guide mention priority, and the macro reference lists both modifiers. CHANGELOG entry included.
  • Not covered: a lorebook entry's Decision field takes no modifiers; its own Sticky and Cooldown already cover timing.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Run by the agent:

  • pnpm check, pnpm localization:check and pnpm regression:node (367 of 367, on staging 9a737a137).
  • New scripts/regressions/decision-priority-timing.regression.ts:
    • Parsing: priority:high, every:3 and sticky:2 together; priority:medium stored as the default; an unknown priority and every:0 ignored.
    • Priority: with limits 1, 2 and 3, high is asked first and low dropped first; merging keeps the highest priority (an occurrence without one counts as medium) and the smallest every:.
    • Timing: asked, then no for two turns, then asked again with every:3; a check that comes due is dropped; every:1 keeps nothing; the planner passes each statement's every: to the timers, and a statement between checks takes no slot.
    • Real turns against a fake System One server, two slots per turn: turn 1 asks the high and the medium statements and drops the low one; turn 2 the every:2 statement is between checks, so it reads as no and the low one gets its slot; a regeneration asks nothing; turn 3 the timed statement is due again.
    • Each wiring point was mutation-checked: reverting it makes the regression fail. The mutation checks also caught a real bug before commit, where a lone priority:low merged into medium.
  • Local CodeRabbit review: no findings.

Please verify manually:

  • In a preset, write three decision blocks with priority:high, no priority and priority:low, set Decision statements per turn to 1, send {{prompt}}, and confirm Peek Prompt lists the medium and low ones as dropped.
  • Write a block with every:2, send a few messages with a Decision model set, and confirm it is asked every other turn (debug log: [decision] Prompt statement).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Changed user docs for the batched [docs-i18n] follow-up (#6532, updated to list them): docs/prompts/conditional-prompts.md (two new sections and one sentence), docs/prompts/macros.md (one sentence), docs/connections/decision-models.md (one sentence).

UI evidence (if applicable)

No UI changes.

Summary by CodeRabbit

  • New Features
    • Decision statements support every:N to ask a statement at set intervals. Between checks, it reads as “no” and doesn’t use a statement slot.
    • Use priority:high or priority:low to control which statements are asked first when the per-turn limit is exceeded. Unspecified priority is treated as medium, and lower-priority statements are dropped first.
    • When a statement appears more than once, the smallest every: interval and highest priority apply.
  • Documentation
    • Updated guides to explain the new modifiers and how statement limits are applied.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6600 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/24/2026 **Status:** ✅ Merged **Merged:** 9/24/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/decision-priority-timing` --- ### 📝 Commits (2) - [`6f21af0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6f21af00881243fd62f065c4beada57d48d03aa2) feat(decision): priority and every-N-turns timing on decision statements - [`6423787`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6423787ed4c139e857b1c87bc69b1e1a32fedaef) fix(decision): count every: from the last check with the current number ### 📊 Changes **12 files changed** (+449 additions, -50 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/connections/decision-models.md` (+1 -1) 📝 `docs/prompts/conditional-prompts.md` (+35 -1) 📝 `docs/prompts/macros.md` (+1 -1) 📝 `packages/server/src/routes/chats.routes.ts` (+2 -2) 📝 `packages/server/src/routes/generate.routes.ts` (+4 -2) 📝 `packages/server/src/routes/generate/dry-run-route.ts` (+2 -2) 📝 `packages/server/src/services/decision/decision-timers.ts` (+54 -6) 📝 `packages/server/src/services/decision/prompt-decisions.ts` (+64 -24) 📝 `packages/shared/src/utils/macro-engine.ts` (+29 -10) ➕ `scripts/regressions/decision-priority-timing.regression.ts` (+254 -0) 📝 `scripts/regressions/decision-reachable-statements.regression.ts` (+1 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #6599 ## Why this change - **Busy presets go over Decision statements per turn, and authors know which statements matter.** Until now the limit dropped whatever came last in the prompt, with no way to say that one statement matters more than another. - **Many statements do not need asking every turn.** Scene-level instructions and agent gates often only need an occasional check, but each one still cost a slot, and on a hosted connection a billed question, every turn. ## What changed - **`priority:high` and `priority:low`,** written after a statement like `sticky:` and `cooldown:` (#6582). When a turn has more statements than its limit, high ones are asked first and low ones dropped first; a statement with no priority is medium. Within a priority, source order still decides. A statement written in several places uses the highest priority given anywhere. - The planner now collects every statement first (merging options and modifiers across occurrences), works out which are held, then fills the slots by priority. This also fixes a small leak where a Choice statement with no options took a slot before being discarded. - The prompt's statements are planned first; statements in lorebook entries' text are planned once the scan knows which entries activate, with the slots left. So a lorebook statement never displaces the prompt's, whatever its priority, and the docs say so. - **`every:N`** asks a statement only every N turns. It is asked the first turn it is reached, then N turns later; between checks it reads as no, is not asked, and takes no slot. Turns count the same way as sticky and cooldown, so a regeneration reads the same answer. The next check is kept per chat beside the sticky and cooldown timers, only after a real answer, so a timed-out question is asked again next turn. A statement written in several places uses the smallest `every:`. - **Docs:** Conditional Prompts gains "Checking every few turns" and "Priority" sections, the limits note and the Decision Models guide mention priority, and the macro reference lists both modifiers. CHANGELOG entry included. - **Not covered:** a lorebook entry's **Decision** field takes no modifiers; its own Sticky and Cooldown already cover timing. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Run by the agent: - `pnpm check`, `pnpm localization:check` and `pnpm regression:node` (367 of 367, on staging `9a737a137`). - New `scripts/regressions/decision-priority-timing.regression.ts`: - **Parsing:** `priority:high`, `every:3` and `sticky:2` together; `priority:medium` stored as the default; an unknown priority and `every:0` ignored. - **Priority:** with limits 1, 2 and 3, high is asked first and low dropped first; merging keeps the highest priority (an occurrence without one counts as medium) and the smallest `every:`. - **Timing:** asked, then no for two turns, then asked again with `every:3`; a check that comes due is dropped; `every:1` keeps nothing; the planner passes each statement's `every:` to the timers, and a statement between checks takes no slot. - **Real turns** against a fake System One server, two slots per turn: turn 1 asks the high and the medium statements and drops the low one; turn 2 the `every:2` statement is between checks, so it reads as no and the low one gets its slot; a regeneration asks nothing; turn 3 the timed statement is due again. - Each wiring point was mutation-checked: reverting it makes the regression fail. The mutation checks also caught a real bug before commit, where a lone `priority:low` merged into medium. - Local CodeRabbit review: no findings. Please verify manually: - In a preset, write three decision blocks with `priority:high`, no priority and `priority:low`, set **Decision statements per turn** to 1, send `{{prompt}}`, and confirm Peek Prompt lists the medium and low ones as dropped. - Write a block with `every:2`, send a few messages with a Decision model set, and confirm it is asked every other turn (debug log: `[decision] Prompt statement`). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Changed user docs for the batched `[docs-i18n]` follow-up (#6532, updated to list them): `docs/prompts/conditional-prompts.md` (two new sections and one sentence), `docs/prompts/macros.md` (one sentence), `docs/connections/decision-models.md` (one sentence). ## UI evidence (if applicable) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Decision statements support `every:N` to ask a statement at set intervals. Between checks, it reads as “no” and doesn’t use a statement slot. * Use `priority:high` or `priority:low` to control which statements are asked first when the per-turn limit is exceeded. Unspecified priority is treated as medium, and lower-priority statements are dropped first. * When a statement appears more than once, the smallest `every:` interval and highest priority apply. * **Documentation** * Updated guides to explain the new modifiers and how statement limits are applied. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:17:54 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7247
No description provided.