fix(memory): wire MAGE soft-escalation gate and fix community.rs newline injection#6135
Merged
Merged
Conversation
…ine injection Wire TrajectoryRiskAccumulator's should_escalate()/record_escalation() soft-warning tier into the tool-dispatch loop: risk in [escalation_threshold, risk_threshold) now requests a batch-level human confirmation before dispatch, then falls through to the unmodified tier execution loop so per-call check_trust/PermissionPolicy and shadow-probe gates still apply. Previously only the hard-block tier fired, leaving the graduated warn-before-block design inert. Also add config-load validation rejecting an inverted or collapsed escalation_threshold/risk_threshold band. Replace whitespace-preserving strip_format_chars with strip_control_chars for entity_names/intra_facts in classify_communities, closing a newline/tab prompt-injection vector reintroduced by the #6091 sanitization consolidation.
bug-ops
enabled auto-merge (squash)
July 12, 2026 14:08
bug-ops
force-pushed
the
fix/5956-mage-escalation-injection
branch
from
July 12, 2026 14:08
217c759 to
303cde8
Compare
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.
Summary
TrajectoryRiskAccumulator::should_escalate()/record_escalation()(spec 004-16 FR-006, MAGE shadow-memory soft-warning tier) into the tool-dispatch loop. Previously only the hard-block tier (is_blocked()) gated tool execution — the graduated warn-before-block design was inert. When cumulative trajectory risk lands in[escalation_threshold, risk_threshold), the agent now requires a single batch-level human confirmation, then dispatches through the unmodified tier execution loop socheck_trust/PermissionPolicyand the shadow-probe safety gate still apply per call exactly as without escalation.escalation_threshold/risk_thresholdband.strip_format_charswithstrip_control_charsforentity_names/intra_factsinclassify_communities, closing a newline/tab prompt-injection vector reintroduced by the fix(security): consolidate duplicated sanitization and redaction logic #6091 sanitization consolidation.Closes #5956
Closes #6093
Review history
This PR went through the full team-develop bug-fix chain (developer → tester → adversarial critic → developer → critic re-verify → code reviewer):
ToolError::ConfirmationRequiredper call and dispatched approved calls throughexecute_tool_call_confirmed_erased, which intentionally bypassescheck_trustfor already-approved calls. That would have let a policy-Denytool execute under MAGE escalation — including unattended under auto-approve/-y/--bare/non-TTY CLI modes — precisely when accumulated risk signals made that the worst possible moment to drop the gate. Caught by adversarial review before merge; fixed by gating on one up-front batch confirmation and falling through to the unmodified, fully-gated tier execution loop. Independently re-verified closed by both the critic and the code reviewer.escalation_threshold/risk_threshold, a tightened hard-block-vs-escalation precedence test, and 3 regression tests using a realTrustGateExecutor+PermissionPolicystack (not a permissive mock) proving a policy-Denytool never executes on approval, including under auto-approve.Test plan
cargo +nightly fmt --checkcargo clippy --profile ci --workspace --all-targets --features "desktop,ide,server,chat,pdf,scheduler,testing" -- -D warningscargo nextest run --config-file .github/nextest.toml --workspace --features "desktop,ide,server,chat,pdf,scheduler" --lib --bins(13021 passed, 0 failed)RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps --workspace --features "desktop,ide,server,chat,pdf,scheduler")zeph-memory/src/shadow/mod.rs, 7 in newzeph-core/.../tests/mage_escalation_tests.rs, 1 inzeph-memory/src/graph/community.rs, 3 config-validation tests inzeph-config/src/loader.rs, plus 5 more spread across the above per the review history.local/testing/playbooks/memory.mdandmemory-graph.mdupdated with new scenarios.local/testing/coverage-status.mdupdated in place