[PR #5751] [MERGED] fix(mari): make an approval question binding for the rest of the run #6917

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

📋 Pull Request Information

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

Base: staging ← Head: fix/5748-mari-ask-latch


📝 Commits (4)

  • f869c27 fix(mari): make an approval question binding for the rest of the run (#5748)
  • 2c63e11 fix(mari): harden the ask latch per adversarial review (#5748)
  • 5771349 fix(mari): survive navigation with a held proposal; sharpen the ask detector (#5748)
  • 9e5130b fix(mari): defer a same-frame ask the strict detector recognizes (#5748)

📊 Changes

5 files changed (+369 additions, -19 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/client/src/components/chat/HomeProfessorMariChat.tsx (+28 -7)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+88 -12)
📝 packages/shared/src/types/professor-mari-workspace.ts (+12 -0)
➕ scripts/regressions/mari-ask-latch.regression.ts (+240 -0)

📄 Description

Linked issue

Closes #5748.

Why this change

A maintainer playtest of the understood-request tool (#5740) surfaced this live: "propose your edits" ended with Mari asking "Let me know if you want me to apply these changes!" — and then applying anyway one round later, with no user reply in between ("Ah, my bad! To properly show you the Keep/Restore review card I need to actually submit"). The five-agent investigation on the issue verified the chain end to end: the approval detector fired on her question, but the deferral requires a mutating command in the same frame, and her attached apply:false preview is classified non-mutating — so the engine had nothing to hold, granted the next round, and its own dry-run result text ("Use apply:true only if the user asked you to make the change") coached the pivot. Empirical counterfactual from the investigation: her identical prose with apply:true would have been held. The preview boolean alone defeated the hold.

What changed

Engine — the floor. A run-scoped ask latch: any round that asks the user for apply-permission arms a run-LOCAL flag, regardless of that round's commands — precisely the conjunct that failed. Two precision decisions came out of the adversarial review below and matter for reviewing this:

  • The latch arms off a new strict detector (visibleTextAsksApplyPermission, anchored on interrogative forms: do you want me to / should I / shall I / let me know if you want) plus the explicit awaitingAuthorization field. The existing loose detector (whose bare "want me to" also matches Mari's routine restatements like "Got it — you want me to update…") stays untouched for the same-frame deferral, where a false positive is inert unless that frame also stages a mutation. Arming the latch off the loose detector would have forced an Accept on plainly requested edits — #5721's double-generation again.
  • Arming happens where the text actually streams to the user (lexically adjacent to the visible-text append), so a discarded protocol-repair round — prose the user never saw — can never bind the run.

Once armed:

  • a later described mutating round defers behind the existing Accept action (the latch joins the shouldDeferMutations disjunction — same hold, same chip, same next-run apply);
  • a later silent mutating frame is refused at the executor with guidance, mirroring the Manual silent floor. Manual itself is carved out (its own floor plus manualApprovalArmed govern the post-Accept silent re-send, which must keep working); Bypass never holds; Plan's floor already refuses everything.

A user reply or Accept starts a new run with a fresh latch, so the approval path itself is never blocked.

Prompt + result coaching — the efficiency.

  • The dry-run result now states, truthfully, that the user cannot see previews (apply:false renders no card or diff) — replacing the old text that re-posed the apply decision to Mari every round. It is deliberately conditional: "if the user already asked for this change, proceed per your Permissions Mode; if instead you asked them whether to apply, wait for their answer." A blanket later-round ban (the first draft) would have broken the prompt's own sanctioned inspect-then-apply flows — validating a risky requested change, and the lorebook raw-db-delete dry-run-first rule.
  • "Propose your edits" / "present a proposal" / "draft a change" now maps to ONE described-and-held proposal: before/after in say, the real apply:true commands in the same frame, awaitingAuthorization: true. One generation, one Accept, no preview-then-regenerate double work (the reported run generated the full patch twice). The hold claims are scoped "outside Plan and Bypass" — Plan refuses mutations and Bypass never holds, so an unconditional promise would have been false in both.
  • New rule stating the ask is binding for the rest of the run, so the prompt and the engine floor agree.
  • The home-widget template — the one place the prompt itself modeled preview-then-confirm-then-reapply — now uses the same held-proposal shape.

Regression — new mari-ask-latch lane. Functional: the reported ask-phrasing and genuine questions arm the strict detector; Mari's restatements do not (the #5721 anti-regression tests); the declarative self-answer matches neither detector (why the latch, not phrasing, is the guard); the loose detector's restatement match is pinned as documentation of why it must never arm the latch. Structural pins run against a whitespace-flattened copy (Prettier-proof) and bind the properties the fix rests on: declaration-before-the-round-loop ordering, exact write counts (initialized once, armed once, never reset mid-run), arming lexically adjacent to the streamed-text append, the deferral disjunct, the silent floor with its Manual/Bypass carve-outs, the conditional dry-run text (with doesNotMatch guards on both rejected drafts), and the mode-scoped hold claims. Differentially verified: removing the latch from the deferral, and the two scope-destroying reverts the adversarial review proved slipped past the first-draft pins (declaration into the loop body was killed by the ordering pin's design; a mid-run reset was replayed and fails the write-count pin). Both detectors are exported for the lane.

Durable Accept affordance (from the maintainer's live playtest of this branch: "the Accept button disappeared when I returned to the chat"). The chips store is a single app-wide ephemeral slot: a regular chat starting a generation clears it (use-generate.ts), the suggestions-disabled mount sweeps clear it without the authorization-accept exemption the delivery path has, and a reload never restores it. Since this PR makes held proposals the standard flow, that fragility would orphan them. The deferral itself is already persisted (mariDeferredMutations on the assistant message's extra — the exact flag the server arms the next run from), so the client now re-derives the Accept chip from that persisted truth whenever the deferral is still the chat's last word — making the affordance precisely as durable as the deferral it answers, and self-dismissing the moment the user replies. The chip object moves to a shared constant (MARI_AUTHORIZATION_ACCEPT_CHIP) used by both the server event and the client derivation, so they can never drift.

Deliberately not in this PR: a user-visible preview card for apply:false dry-runs (the issue's largest direction — needs a design call on a "shown but NOT saved" vocabulary distinct from the Keep/Restore card), and honoring stop after a command batch (blast radius across every legitimate multi-step sequence). Both remain open options on #5748's list. Nothing here touches #5740's understood-request record (hard constraint: diagnostic only) — a latch-held round records outcome held, accurately.

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

  • pnpm lint, the full pnpm build (shared/server/client), and pnpm check:e2e-types are green locally; format:check fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly).
  • Lanes: new mari-ask-latch (differentially verified — removing the latch from the deferral disjunction fails the lane), plus mari-permissions-mode, mari-understood-request, mari-edit-flow-revert, prompt.regression, and open-issues all pass.
  • A two-lens adversarial review (latch mechanics + mode matrix; prompt coherence + regression teeth — 18 agents, every finding refuted or confirmed by a dedicated verifier) ran over the first commit: 8 findings confirmed, 8 refuted. All 8 confirmed findings are fixed in the second commit, and the two worst were exactly the kind worth catching before review: the original latch trigger would have re-introduced #5721's forced-Accept-on-requested-edits via Mari's restatement phrasing, and the original dry-run coaching banned the prompt's own sanctioned inspect-then-apply flows. The second commit's summary walks all 8.
  • Please verify manually (the reported scenarios): in a fresh Auto-mode Mari chat, ask her to "propose your edits" for a character change. Expected: one reply describing the change with an Accept chip and no applied edit; accepting applies it with the Keep/Restore card. Then, with a proposal held: open the Chats popover, switch away and back (or reload the page) — the Accept chip should still be there, and should disappear once you reply. Also worth trying: interrupt her mid-proposal with an unrelated question — her answer should not resurrect or apply the held change unprompted.

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)

CHANGELOG updated under [Unreleased] → Fixed. No user-facing docs under docs/ touched (docs-i18n debt stays batched per the standing call).

UI evidence (if applicable)

No new UI. The visible behavior change: a proposal round now ends with the existing Accept chip instead of a self-answered apply, and a post-ask hidden edit surfaces as a refused command in the workspace trace.

Summary by CodeRabbit

  • Bug Fixes
    • Professor Mari now consistently honors approval questions throughout a run.
    • Changes proposed after an approval request remain held until the user selects Accept.
    • Unapproved background edits are blocked and accompanied by guidance.
    • The Accept option remains available when a pending change is saved in the conversation.
    • Dry-run previews now clearly indicate that they are not visible in the interface.
    • “Propose your edits” requests now present one held proposal instead of requiring a second generation.

🔄 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/5751 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/2/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5748-mari-ask-latch` --- ### 📝 Commits (4) - [`f869c27`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f869c27c69990ee675f7e8aca4ff7af039488ad3) fix(mari): make an approval question binding for the rest of the run (#5748) - [`2c63e11`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2c63e11c41d483665b5c9a9c8a1a0d1a4ab6ff37) fix(mari): harden the ask latch per adversarial review (#5748) - [`5771349`](https://github.com/Pasta-Devs/Marinara-Engine/commit/577134952cda149c8c112c333bbfd329b7cfdc92) fix(mari): survive navigation with a held proposal; sharpen the ask detector (#5748) - [`9e5130b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9e5130b98f0bb251aac631da448f210c87886bd8) fix(mari): defer a same-frame ask the strict detector recognizes (#5748) ### 📊 Changes **5 files changed** (+369 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/client/src/components/chat/HomeProfessorMariChat.tsx` (+28 -7) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+88 -12) 📝 `packages/shared/src/types/professor-mari-workspace.ts` (+12 -0) ➕ `scripts/regressions/mari-ask-latch.regression.ts` (+240 -0) </details> ### 📄 Description ## Linked issue Closes #5748. ## Why this change A maintainer playtest of the understood-request tool (#5740) surfaced this live: "propose your edits" ended with Mari asking *"Let me know if you want me to apply these changes!"* — and then applying anyway one round later, with no user reply in between (*"Ah, my bad! To properly show you the Keep/Restore review card I need to actually submit"*). The five-agent investigation on the issue verified the chain end to end: the approval detector **fired** on her question, but the deferral requires a mutating command in the same frame, and her attached `apply:false` preview is classified non-mutating — so the engine had nothing to hold, granted the next round, and its own dry-run result text ("Use apply:true only if the user asked you to make the change") coached the pivot. Empirical counterfactual from the investigation: her identical prose with `apply:true` would have been held. The preview boolean alone defeated the hold. ## What changed **Engine — the floor.** A run-scoped ask latch: any round that asks the user for apply-permission arms a run-LOCAL flag, *regardless of that round's commands* — precisely the conjunct that failed. Two precision decisions came out of the adversarial review below and matter for reviewing this: - The latch arms off a **new strict detector** (`visibleTextAsksApplyPermission`, anchored on interrogative forms: *do you want me to / should I / shall I / let me know if you want*) plus the explicit `awaitingAuthorization` field. The existing loose detector (whose bare "want me to" also matches Mari's routine *restatements* like "Got it — you want me to update…") stays untouched for the same-frame deferral, where a false positive is inert unless that frame also stages a mutation. Arming the latch off the loose detector would have forced an Accept on plainly requested edits — #5721's double-generation again. - Arming happens **where the text actually streams to the user** (lexically adjacent to the visible-text append), so a discarded protocol-repair round — prose the user never saw — can never bind the run. Once armed: - a later **described** mutating round defers behind the existing Accept action (the latch joins the `shouldDeferMutations` disjunction — same hold, same chip, same next-run apply); - a later **silent** mutating frame is refused at the executor with guidance, mirroring the Manual silent floor. Manual itself is carved out (its own floor plus `manualApprovalArmed` govern the post-Accept silent re-send, which must keep working); Bypass never holds; Plan's floor already refuses everything. A user reply or Accept starts a new run with a fresh latch, so the approval path itself is never blocked. **Prompt + result coaching — the efficiency.** - The dry-run result now states, truthfully, that the user cannot see previews (`apply:false` renders no card or diff) — replacing the old text that re-posed the apply decision to Mari every round. It is deliberately **conditional**: "if the user already asked for this change, proceed per your Permissions Mode; if instead you asked them whether to apply, wait for their answer." A blanket later-round ban (the first draft) would have broken the prompt's own sanctioned inspect-then-apply flows — validating a risky requested change, and the lorebook raw-db-delete dry-run-first rule. - "Propose your edits" / "present a proposal" / "draft a change" now maps to ONE described-and-held proposal: before/after in `say`, the real `apply:true` commands in the same frame, `awaitingAuthorization: true`. One generation, one Accept, no preview-then-regenerate double work (the reported run generated the full patch twice). The hold claims are scoped "outside Plan and Bypass" — Plan refuses mutations and Bypass never holds, so an unconditional promise would have been false in both. - New rule stating the ask is binding for the rest of the run, so the prompt and the engine floor agree. - The home-widget template — the one place the prompt itself modeled preview-then-confirm-then-reapply — now uses the same held-proposal shape. **Regression** — new `mari-ask-latch` lane. Functional: the reported ask-phrasing and genuine questions arm the strict detector; Mari's restatements do *not* (the #5721 anti-regression tests); the declarative self-answer matches neither detector (why the latch, not phrasing, is the guard); the loose detector's restatement match is pinned as documentation of why it must never arm the latch. Structural pins run against a whitespace-flattened copy (Prettier-proof) and bind the properties the fix rests on: declaration-before-the-round-loop ordering, exact write counts (initialized once, armed once, **never reset mid-run**), arming lexically adjacent to the streamed-text append, the deferral disjunct, the silent floor with its Manual/Bypass carve-outs, the conditional dry-run text (with `doesNotMatch` guards on both rejected drafts), and the mode-scoped hold claims. Differentially verified: removing the latch from the deferral, and the two scope-destroying reverts the adversarial review proved slipped past the first-draft pins (declaration into the loop body was killed by the ordering pin's design; a mid-run reset was replayed and fails the write-count pin). Both detectors are exported for the lane. **Durable Accept affordance** (from the maintainer's live playtest of this branch: *"the Accept button disappeared when I returned to the chat"*). The chips store is a single app-wide ephemeral slot: a regular chat starting a generation clears it (`use-generate.ts`), the suggestions-disabled mount sweeps clear it without the `authorization-accept` exemption the delivery path has, and a reload never restores it. Since this PR makes held proposals the standard flow, that fragility would orphan them. The deferral itself is already persisted (`mariDeferredMutations` on the assistant message's extra — the exact flag the server arms the next run from), so the client now **re-derives the Accept chip from that persisted truth** whenever the deferral is still the chat's last word — making the affordance precisely as durable as the deferral it answers, and self-dismissing the moment the user replies. The chip object moves to a shared constant (`MARI_AUTHORIZATION_ACCEPT_CHIP`) used by both the server event and the client derivation, so they can never drift. Deliberately **not** in this PR: a user-visible preview card for `apply:false` dry-runs (the issue's largest direction — needs a design call on a "shown but NOT saved" vocabulary distinct from the Keep/Restore card), and honoring `stop` after a command batch (blast radius across every legitimate multi-step sequence). Both remain open options on #5748's list. Nothing here touches #5740's understood-request record (hard constraint: diagnostic only) — a latch-held round records outcome `held`, accurately. ## 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 - `pnpm lint`, the full `pnpm build` (shared/server/client), and `pnpm check:e2e-types` are green locally; `format:check` fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly). - Lanes: new `mari-ask-latch` (differentially verified — removing the latch from the deferral disjunction fails the lane), plus `mari-permissions-mode`, `mari-understood-request`, `mari-edit-flow-revert`, `prompt.regression`, and `open-issues` all pass. - A two-lens adversarial review (latch mechanics + mode matrix; prompt coherence + regression teeth — 18 agents, every finding refuted or confirmed by a dedicated verifier) ran over the first commit: 8 findings confirmed, 8 refuted. All 8 confirmed findings are fixed in the second commit, and the two worst were exactly the kind worth catching before review: the original latch trigger would have re-introduced #5721's forced-Accept-on-requested-edits via Mari's restatement phrasing, and the original dry-run coaching banned the prompt's own sanctioned inspect-then-apply flows. The second commit's summary walks all 8. - **Please verify manually (the reported scenarios):** in a fresh Auto-mode Mari chat, ask her to "propose your edits" for a character change. Expected: one reply describing the change with an **Accept** chip and no applied edit; accepting applies it with the Keep/Restore card. Then, with a proposal held: open the Chats popover, switch away and back (or reload the page) — the Accept chip should still be there, and should disappear once you reply. Also worth trying: interrupt her mid-proposal with an unrelated question — her answer should not resurrect or apply the held change unprompted. ## 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) CHANGELOG updated under **[Unreleased] → Fixed**. No user-facing docs under `docs/` touched (docs-i18n debt stays batched per the standing call). ## UI evidence (if applicable) No new UI. The visible behavior change: a proposal round now ends with the existing Accept chip instead of a self-answered apply, and a post-ask hidden edit surfaces as a refused command in the workspace trace. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Professor Mari now consistently honors approval questions throughout a run. * Changes proposed after an approval request remain held until the user selects **Accept**. * Unapproved background edits are blocked and accompanied by guidance. * The **Accept** option remains available when a pending change is saved in the conversation. * Dry-run previews now clearly indicate that they are not visible in the interface. * “Propose your edits” requests now present one held proposal instead of requiring a second generation. <!-- 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:14:53 +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#6917
No description provided.