[PR #5775] [MERGED] fix(mari): staged sensitive changes no longer satisfy the verification guard #6927

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

📋 Pull Request Information

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

Base: staging ← Head: fix/5756-staged-mutation-guard


📝 Commits (6)

  • aededb0 fix(server): distinguish staged workspace changes
  • 8dd31b9 fix(mari): harden the staged-change gate against marker forgery (#5756)
  • 3531d0f fix(mari): close the staged-round gaps the adversarial review confirmed (#5756)
  • a562c38 fix(mari): harden approval dedupe against case and mid-approve races (CodeRabbit)
  • bd473fd fix(regression): update the #5740 outcome pin for the staged "held" mapping
  • 3852418 fix(mari): staged results leave completed verification standing (CodeRabbit)

📊 Changes

6 files changed (+145 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+42 -6)
📝 packages/server/src/services/professor-mari/workspace-change-review.service.ts (+24 -2)
📝 packages/shared/src/types/professor-mari-workspace.ts (+5 -3)
📝 scripts/regressions/mari-understood-request.regression.ts (+4 -1)
📝 scripts/regressions/prompt.regression.ts (+69 -0)

📄 Description

Linked issue

Closes #5756

Why this change

  • Sensitive write/edit commands can succeed while only staging the change behind a user approval, but the workspace verification guard counted every successful non-app_data mutation as applied. A follow-up read of the (unchanged) file then satisfied the guard, so Mari could claim a change was done while the approval was still pending — exactly the silent-persistent-failure class the guard exists to prevent.
  • This adopts @mikemikimike's fix from #5757 (thank you!). That PR is authored by an outside contributor, so its required "Owner approval for outside contributors" check can only be satisfied by SpicyMarinara, who is away for two weeks. Rather than leave the bug live, this PR re-homes the fix under a member account with the original commit's authorship preserved, and hardens it.

What changed

  • First commit (author @mikemikimike, cherry-picked unchanged from #5757): isAppliedWorkspaceMutation no longer counts a sensitive write/edit result whose output is the engine's staging response as an applied mutation, so staged changes create no verification state and a read of the unchanged file can't "verify" them. Regression cases cover staged write, staged edit, and an ordinary applied write.
  • Hardening on top: the original gate matched the staging marker with a multiline-anchored regex, i.e. at any line start of the output. An applied write/edit echoes the model-chosen path (which on Linux may legally contain newlines), so an applied mutation could pose as staged and skip verification debt — weakening the guard. The staging marker is engine-authored at position zero of the output and compactOutput() only truncates tails, so the gate now uses startsWith against a shared STAGED_SENSITIVE_CHANGE_PREFIX constant that both staging emitters reference (emitters and detector can no longer drift). New regression cases pin the forgery scenario (marker on a later line still counts as applied) and staged/applied mixed rounds in both orders.
  • Second hardening round, from a multi-agent adversarial review of the adopted diff (three confirmed regressions it would have introduced):
    • [applied → read → staged] rounds lost interception: the staged result became inert in the resolver, so the round read "verified" and a completion claim covering the staged file shipped unchallenged — while its approval card silently expires after 10 minutes. Staged results now reset the verifying-read flag without counting as a mutation, and the resolver gains a dedicated "staged" state, so the claim is still intercepted with accurate coaching.
    • Wrong repair coaching for staged rounds: the "none" branch told Mari "no mutating command succeeded… perform the mutation", which re-staged duplicate approval cards. Staged rounds now get their own repair message ("report it as awaiting the user's approval"), and stageSensitiveFileChange is idempotent for an identical path/before/after change.
    • Diagnostics contradiction: the #5740 understood-request record upgraded staged-only rounds to outcome "applied" — corroborating exactly the claim the guard refuses. Staged rounds now record as "held" (existing outcome value; doc comment extended).
  • CHANGELOG entry under [Unreleased] → Fixed, crediting the original fix.

Pre-existing sibling gaps the review also confirmed (same bug class, not introduced by this PR — filed as follow-up issues rather than ballooning an adopted fix): bash mari CLI dry-runs counting as applied mutations, sandbox-denied sensitive writes in error-tolerant compound bash commands counting as applied, and write/edit through a workspace symlink bypassing sensitive-file staging.

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

  • Commands run locally (all passing): node ./scripts/run-regressions.mjs --filter prompt (5/5, includes the new staged/forgery/mixed cases), pnpm --filter @marinara-engine/server lint, pnpm build.
  • Server-side guard logic only — no UI surface. Manual browser verification that would still be valuable: in a Mari chat, ask her to edit a supply-chain-sensitive file (e.g. package.json), and confirm she reports the change as pending your approval rather than applied.

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)

UI evidence (if applicable)

Not applicable — server-side guard behavior only.

Summary by CodeRabbit

  • Bug Fixes
    • Sensitive file changes awaiting approval are now reported as held rather than completed.
    • Duplicate approval requests are prevented for identical pending changes.
    • Verification diagnostics distinguish staged changes from applied changes.
    • Staged changes no longer incorrectly satisfy mutation verification.
    • Pending approval states remain accurate after subsequent workspace reads.
    • Completion messaging now reflects whether a change was applied or held.

🔄 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/5775 **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/5756-staged-mutation-guard` --- ### 📝 Commits (6) - [`aededb0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/aededb0e450845edcacabe082a0e563c9fbf309e) fix(server): distinguish staged workspace changes - [`8dd31b9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8dd31b97342a3e4510a0a7b3ff9f7c153bdf8954) fix(mari): harden the staged-change gate against marker forgery (#5756) - [`3531d0f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3531d0f6f8bfc2b10bdadf727cbbddb852465d75) fix(mari): close the staged-round gaps the adversarial review confirmed (#5756) - [`a562c38`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a562c38b21ac3672530d124a62bd258544a5a7e8) fix(mari): harden approval dedupe against case and mid-approve races (CodeRabbit) - [`bd473fd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bd473fdf9119cdcd529cd07dcab66dffb291d0e2) fix(regression): update the #5740 outcome pin for the staged "held" mapping - [`3852418`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3852418d78257047d0454e7e5e4f1e96ce98c2f2) fix(mari): staged results leave completed verification standing (CodeRabbit) ### 📊 Changes **6 files changed** (+145 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+42 -6) 📝 `packages/server/src/services/professor-mari/workspace-change-review.service.ts` (+24 -2) 📝 `packages/shared/src/types/professor-mari-workspace.ts` (+5 -3) 📝 `scripts/regressions/mari-understood-request.regression.ts` (+4 -1) 📝 `scripts/regressions/prompt.regression.ts` (+69 -0) </details> ### 📄 Description ## Linked issue Closes #5756 ## Why this change - Sensitive `write`/`edit` commands can succeed while only **staging** the change behind a user approval, but the workspace verification guard counted every successful non-`app_data` mutation as *applied*. A follow-up read of the (unchanged) file then satisfied the guard, so Mari could claim a change was done while the approval was still pending — exactly the silent-persistent-failure class the guard exists to prevent. - This adopts @mikemikimike's fix from #5757 (thank you!). That PR is authored by an outside contributor, so its required "Owner approval for outside contributors" check can only be satisfied by SpicyMarinara, who is away for two weeks. Rather than leave the bug live, this PR re-homes the fix under a member account with the original commit's authorship preserved, and hardens it. ## What changed - First commit (author @mikemikimike, cherry-picked unchanged from #5757): `isAppliedWorkspaceMutation` no longer counts a sensitive `write`/`edit` result whose output is the engine's staging response as an applied mutation, so staged changes create no verification state and a read of the unchanged file can't "verify" them. Regression cases cover staged write, staged edit, and an ordinary applied write. - Hardening on top: the original gate matched the staging marker with a multiline-anchored regex, i.e. at **any** line start of the output. An applied `write`/`edit` echoes the model-chosen path (which on Linux may legally contain newlines), so an applied mutation could pose as staged and skip verification debt — weakening the guard. The staging marker is engine-authored at position zero of the output and `compactOutput()` only truncates tails, so the gate now uses `startsWith` against a shared `STAGED_SENSITIVE_CHANGE_PREFIX` constant that both staging emitters reference (emitters and detector can no longer drift). New regression cases pin the forgery scenario (marker on a later line still counts as applied) and staged/applied mixed rounds in both orders. - Second hardening round, from a multi-agent adversarial review of the adopted diff (three confirmed regressions it would have introduced): - **`[applied → read → staged]` rounds lost interception**: the staged result became inert in the resolver, so the round read "verified" and a completion claim covering the staged file shipped unchallenged — while its approval card silently expires after 10 minutes. Staged results now reset the verifying-read flag without counting as a mutation, and the resolver gains a dedicated `"staged"` state, so the claim is still intercepted with accurate coaching. - **Wrong repair coaching for staged rounds**: the "none" branch told Mari "no mutating command succeeded… perform the mutation", which re-staged duplicate approval cards. Staged rounds now get their own repair message ("report it as awaiting the user's approval"), and `stageSensitiveFileChange` is idempotent for an identical path/before/after change. - **Diagnostics contradiction**: the #5740 understood-request record upgraded staged-only rounds to outcome "applied" — corroborating exactly the claim the guard refuses. Staged rounds now record as "held" (existing outcome value; doc comment extended). - CHANGELOG entry under [Unreleased] → Fixed, crediting the original fix. Pre-existing sibling gaps the review also confirmed (same bug class, **not** introduced by this PR — filed as follow-up issues rather than ballooning an adopted fix): bash `mari` CLI dry-runs counting as applied mutations, sandbox-denied sensitive writes in error-tolerant compound bash commands counting as applied, and write/edit through a workspace symlink bypassing sensitive-file staging. ## 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 - Commands run locally (all passing): `node ./scripts/run-regressions.mjs --filter prompt` (5/5, includes the new staged/forgery/mixed cases), `pnpm --filter @marinara-engine/server lint`, `pnpm build`. - Server-side guard logic only — no UI surface. Manual browser verification that would still be valuable: in a Mari chat, ask her to edit a supply-chain-sensitive file (e.g. `package.json`), and confirm she reports the change as pending your approval rather than applied. ## Docs and release impact - [ ] No docs changes needed - [x] 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) ## UI evidence (if applicable) Not applicable — server-side guard behavior only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Sensitive file changes awaiting approval are now reported as held rather than completed. * Duplicate approval requests are prevented for identical pending changes. * Verification diagnostics distinguish staged changes from applied changes. * Staged changes no longer incorrectly satisfy mutation verification. * Pending approval states remain accurate after subsequent workspace reads. * Completion messaging now reflects whether a change was applied or held. <!-- 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:58 +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#6927
No description provided.