fix(cli): quantify what a memory approval destroys in the pending list #136996
Opened as a draft: this account cannot clear that flag itself — REST PATCH {"draft": false} returns 200 with the flag unchanged, and GraphQL markPullRequestReadyForReview returns FORBIDDEN — so the PR stays invisible to CI and to reviewers until someone marks it ready for review. Requesting that here.
Head efad6c50e2bd0f6dba0d8f2f3d5fb1fae60c3bd4, 1 commit, 2 files, +89/−3, Fixes #136738. python scripts/check --commit HEAD --base HEAD^1 → 12 checks, ok (code health: 2 files vs 8a7a5a905f: 0 blocking, 0 advisory); the 5 new cases fail against the unpatched handler and pass with it; 110 + 672 neighbouring tests pass, 0 failures.
It is a reporting change only — the pending list gains the per-proposal char delta and the destructive flag. The approve all gate this report also asks for is deliberately left out, since that belongs to the replace-semantics discussion in #124582.
Head moved to dc2cbc383b (2 commits): the repro now ships inside the PR as evals/memory_pending_delta_136738.py, runnable against any tree —
python evals/memory_pending_delta_136738.py [source_tree]
It stages a destructive whole-entry replace plus a remove through the background review's own staging path, prints both approval surfaces verbatim, and exits non-zero when the pending view quantifies nothing. PASS: 5/5 checks (exit 0) on this branch; FAIL: 1/5 checks (exit 1) against main at 8a7a5a905f — the one check that passes there is the full-pinned-entry one, which #133736 already landed.
The readiness ask above still stands, with one more file: 3 files, +~200/−3, python scripts/check --commit HEAD --base 8a7a5a905f → 12 checks, ok (code health: 3 files … 0 blocking, 0 advisory). The tests, the neighbour sweep and the pending-list output are unchanged by this commit.
[Bug] (blocking) This leaves a new eval-136738-* directory behind every time the eval runs because mkdtemp() is never cleaned up. I confirmed that the directory and its Hermes state remain after a successful 5/5 run. Repeated runs will keep accumulating scratch state. Please remove the temporary home when main() finishes.
Review conclusion
Request changes on head dc2cbc383bb6ebef3a8b0227a2c5b7efa4fe8f16. GitHub would not accept a formal REQUEST_CHANGES event from this account, so I am recording the conclusion here.
Motivation
This addresses a real approval risk. Before this change, a staged replace from 235 characters to 47 characters showed the full pinned entry but did not state the loss. After this change, /memory pending shows 235 -> 47 chars, -188 (-80%) and calls out the destructive shape before the operator approves it.
Approach
_entry_delta() derives the before and after sizes from the pinned staged payload. _matched_entries() adds that result without changing the existing full-entry display or the unpinned legacy guard. The tests cover single and batch removes plus shrinking, same-size, and growing replacements through the real background-review staging path.
Changed surfaces
The production change is limited to hermes_cli/write_approval_commands.py. tests/tools/test_write_approval.py adds focused regression coverage. The new eval drives both /memory pending and /memory approve all and confirms the observable output.
Risk and findings
The formatter path itself looks sound. It reads fields that staging already validates and pins. The positive and negative paths both behaved as expected in the focused run.
[Design] (blocking) The PR says /memory approve all still applies destructive staged writes, but Fixes #136738 would close an issue whose title and body explicitly include that bulk path. #124582 tracks the broader replace semantics. It does not make this approval-path behavior resolved. Please use Refs #136738, or get an explicit maintainer decision that the remaining bulk guard has been split out before this PR closes the P1.
[Bug] (blocking) The new eval leaves its scratch Hermes home behind after a successful run. I published the exact-line finding here: https://github.com/NousResearch/hermes-agent/pull/136996#discussion_r4245074533
[Suggestion] (non-blocking) The earlier approval-surface fix is PR #117988 at merge commit 05b9bacbf8, not #133736. #133736 is an unrelated cursor-provider update. Please correct that link so the history is traceable.
Overall
The user-facing formatter and regression tests are solid, but the issue closure and scratch-directory leak should be fixed before this is ready.
Validation: scripts/run_tests.sh tests/tools/test_write_approval.py -q passed 28 tests. The eval passed 5/5 checks. scripts/check passed all 12 checks. git diff --check passed. GitHub reports no hosted checks for this draft head.
Fixed in d8ff303d11. You were right at line 36: HERMES_HOME was a bare tempfile.mkdtemp() and nothing removed it, so each run accumulated an eval-136738- tree — our own earlier verification runs had already left four of them behind.
main() now owns the home as a TemporaryDirectory (what the rest of evals/ uses — 15 files against 6), drives the checks through _drive(), and prints whether the tree survived, returning 1 if it did, so this cannot come back silently.
Verified on a clean checkout of the head:
PASS: 5/5 checks (exit 0), and eval-136738-4ctafgfe is left in $TMPDIR;PASS: 5/5 checks (exit 0), scratch HERMES_HOME removed: .../eval-136738-zn6r0mp8, and no eval-136738- anywhere;FAIL: 1/5 checks, exit 1) also leaves none.Review conclusion answered — head d8ff303d11
Thanks for the line-level catch on the leak and for the provenance correction; both were real, and the wrong citation in particular was ours to have checked before repeating it. Head moved to d8ff303d119903779d8c53a70b38d7cc73f81b74 (3 commits, still draft). All three findings, in order.
[Design] blocking — accepted, Fixes → Refs. You are right: this PR leaves the bulk path exactly as it was, so a closing keyword would close #136738 with its first-named behaviour still standing. The Related Issue section now says Refs #136738 and states the split (per-proposal quantification here; the approve all gate belongs to #124582 and is not pre-empted).
One thing you should know rather than find at merge time: the keyword also sits in the first commit's message (efad6c50, "Fixes #136738"), and GitHub reads closing keywords from commit messages as well as from the PR body. Removing it from the head means rewriting a commit that the reviewed SHA dc2cbc383b contains — which orphans your review anchor — and this sandbox refuses an unattended force-push (--force-with-lease was blocked here when the head was re-cut earlier, which is also why the PR is opened draft). So the head's history still carries that trailer; the body and the new tip say Refs, and the new commit's message records the correction. If you would rather have the branch clean of the keyword, say so and I will re-cut it as a fresh branch and PR — that is your call, not something I should take by rewriting under an open review.
[Bug] blocking — confirmed and fixed in d8ff303d11. Line 36 was exactly the leak: HERMES_HOME was a bare tempfile.mkdtemp() and nothing removed it. main() now owns the home as a TemporaryDirectory (the pattern 15 files in evals/ already use, against 6 with mkdtemp), drives the checks through _drive(), prints whether the tree survived and returns 1 if it did, so a leak can no longer pass as a clean run. The docstring's "nothing is written outside the scratch HERMES_HOME" now also says what happens to that home.
Reproduced before fixing, then re-run on a clean checkout of the head:
PASS: 5/5 checks (exit 0), and eval-136738-4ctafgfe is left in $TMPDIR — same as you saw; four more eval-136738- trees sat in /tmp from our earlier verification runs at 05:47Z;PASS: 5/5 checks (exit 0), scratch HERMES_HOME removed: …/eval-136738-zn6r0mp8, and no eval-136738- anywhere;FAIL: 1/5 checks, exit 1) also leaves none.[Suggestion] non-blocking — you are right and the citation was ours. #133736 is a two-line plugin-catalog/cursor-provider.yaml bump. The two surfaces actually came from:
/memory pending's full pinned matched_entry: #121275, merged 2026-09-24 (merge commit 88dee3e866; commits b96e88b245, 3da1c59377, 5c3afeee45);Overwrote entire entry): #117988, merged 2026-09-21 (merge commit 05b9bacbf8, "fix(memory): surface the overwritten entry on the /memory approve surface too").Verified in-tree with git merge-base --is-ancestor: both are ancestors of the v0.21.5 release commit f97608f1 (2026-09-24T10:08:47Z, 23 seconds after #121275 merged), so both surfaces are in the build the report was filed against. The PR body names both now, the tip commit's message records the correction, and I posted the same correction on #136738 (6119552905) — the wrong citation appears twice there (the maintainer note and our own verification comment).
Re-ran for the new head: scripts/run_tests.sh tests/tools/test_write_approval.py → === Summary: 1 files, 28 tests passed, 0 failed (100% complete) in 120.3s (4 workers) ===; python evals/memory_pending_delta_136738.py . → PASS: 5/5 checks, exit 0; against the base tree → FAIL: 1/5 checks, exit 1; python scripts/check --commit HEAD --base 590af66a58 → 12 checks, ok (code health: 15 files vs 590af66a58c2: 0 blocking, 0 advisory).
Please un-draft when you are satisfied: the account that opened this PR has no way to clear the flag, so merging stays gated on someone else doing it.
[Bug] (blocking) A small shrink can be reported with a positive percentage. round() turns any change smaller than 0.5% into integer zero, and the signed formatter then renders it as +0%. I reproduced this through /memory pending with a 1,000-character entry replaced by 999 characters. The result is -1 (+0%), shrinks it, which gives opposite direction signals on the approval screen. Please keep the percentage direction consistent when the rounded value is zero, and cover a near-zero shrink in the regression tests.
Request changes conclusion
GitHub would not accept a formal REQUEST_CHANGES event from this account, so I am recording the same hold verdict on exact head d8ff303d119903779d8c53a70b38d7cc73f81b74.
Motivation
The problem is real. A staged whole-entry replacement can look like a small clause edit even when it removes most of a memory entry. This PR puts the size and direction of that change in /memory pending, before the operator approves it. The separate bulk-approval gate remains under #124582, and the maintainer has accepted that ownership split.
Approach
The staging path already pins the full matched_entry. _fmt_pending_list() sends that payload through _matched_entries(), and the new _entry_delta() compares the pinned entry with the replacement content or zero for a removal. The shared handler serves the CLI, gateway, TUI, and Desktop paths, so the change stays in one owner. It does not add state, change approval semantics, or alter the default path when no destructive write is pending.
Concrete changes
The production change is 25 added lines and 3 removed lines in hermes_cli/write_approval_commands.py. The tests add shrinking, same-size, growing, single-remove, and batch-remove cases through the real background-review staging path. The eval drives both approval surfaces inside a TemporaryDirectory. The earlier scratch-home leak is fixed, and the full pinned entry plus the legacy unpinned warning remain intact.
Risk to main
The patch applies cleanly to current main at 3569e8461ea721623fa16e6f01fb636157989fe6. The focused lane passes 28 tests on the exact head and again on current-main composition. The eval passes 5 of 5 checks on both patched trees, while current main reproduces the old 1 of 5 result. scripts/check passes all 12 checks. GitHub has no hosted checks for this draft.
One output bug remains. A small shrink rounds to integer zero, then the signed formatter prints a positive zero. Through the real pending path, replacing a 1,000-character entry with 999 characters produces -1 (+0%), shrinks it. That line contradicts itself on the approval screen this PR is meant to make trustworthy.
Overall assessment
The placement, scope, tests, and cleanup fix are sound. Please correct the rounded-zero direction and add a near-zero shrink regression before this is ready. I found no other blocking issue in the exact-head diff.
Accepted — replacement PR #137340, head 97064a56f4.
You were right: round() of 1000→999 is integer 0, and {0:+d} prints +0, so the pending line read -1 (+0%), shrinks it. Integers have no signed zero, so the percentage now takes its sign from the char delta. Through the same pending path, 1000→999 is now -1 (-0%), shrinks it.
The near-zero shrink is a regression in tests/tools/test_write_approval.py. On d8ff303d11 it failed with the line you quoted; on this head it passes.
#136996 cannot be reopened (The repository that submitted this pull request has been deleted.). The follow-up is #137340.
Review 5488991117 answered on replacement #137340, head 97064a56f4
This PR cannot be reopened (state cannot be changed. The repository that submitted this pull request has been deleted.). The remaining hold — a sub-0.5% shrink printing (+0%) next to a negative char delta — is fixed on #137340.
[Bug] blocking (inline r4246602717) — accepted. round(100 * -1 / 1000) is integer 0, and the signed formatter then printed +0. The percentage now takes its sign from the char delta, so 1000→999 through the real pending path is -1 (-0%), shrinks it. The new regression failed on d8ff303d11 with the line you quoted and passes here.
HERMES_PYTHON=/tmp/hermes-venv/bin/python scripts/run_tests.sh tests/tools/test_write_approval.py → === Summary: 1 files, 29 tests passed, 0 failed ===tests/tools/test_skill_pending_diff_batch.py → === Summary: 1 files, 8 tests passed, 0 failed ===python evals/memory_pending_delta_136738.py → PASS: 5/5 checkspython scripts/check --commit HEAD --base HEAD^1 → 12 checks, ok (code health: 2 files vs d8ff303d1199: 0 blocking, 0 advisory)
ehz0ah
PRELVAS94
What does this PR do?
/memory pendingshowed a staged memory replace/remove with the full entry it is pinned to, but nothing about what the payload does to that entry. Memory's whole-entry contract means a payload that rewrites one clause of a multi-fact entry silently deletes every sibling fact it did not re-mention, while the record's own summary line shows only theold_textsearch string. So the size of the loss was invisible in the list the approver reads, and only appeared after approving, in the overwritten-entry echo.Each staged entry now carries its own delta, ahead of the entry text:
"Below half" is the shape of the incident — a partial-edit payload whose fragment replaced the entry — and that is what the flag reports. A replace that keeps or grows the entry is labelled as such (
leaves it the same size/grows the entry) rather than crying wolf, so the flag keeps its meaning.This is a reporting change only.
approve allstill applies every staged record: the reporter's second remedy (refuse, or require--force, when a staged proposal guts an entry) is a gate on the bulk path and belongs to the replace-semantics discussion, so it is deliberately not in this PR.Related Issue
Refs #136738 — deliberately not
Fixes. The report names two problems and this PR resolves oneof them:
destructive flag).
approve allapplies destructive proposals wholesale → still true after this PR. That gatebelongs to the replace-semantics discussion in #124582, and adding it here would pre-empt a
decision that is not ours. Closing #136738 on merge would close the P1 while its first-named
behaviour stands.
For the record, the visibility half the maintainer note describes as already fixed on
mainis realand was driven here, but the attribution in that note is wrong: it is not #133736, which is a
two-line
plugin-catalog/cursor-provider.yamlbump./memory pendingprinting the full pinnedmatched_entry: #121275 (merged 2026-09-24, mergecommit
88dee3e866, commitsb96e88b245/3da1c59377/5c3afeee45).Overwrote entire entry): #117988 (merged2026-09-21, merge commit
05b9bacbf8, "fix(memory): surface the overwritten entry on the/memory approve surface too").
Both are ancestors of the
v0.21.5release commitf97608f1(2026-09-24T10:08:47Z — 23 secondsafter #121275 merged), verified with
git merge-base --is-ancestor, so both surfaces are already inthe build the report was filed against. The same correction is posted on #136738.
Type of Change
Changes Made
hermes_cli/write_approval_commands.py— new_entry_delta(op)renders a staged replace/remove asbefore -> after chars, ±delta (±pct%), <verdict>;_matched_entriesprefixes each pinned entry with it. Verdicts:deletes the entry(no content left),grows the entry,leaves it the same size,shrinks it below half,shrinks it. The fullmatched_entryand the unpinned-legacy-target message are unchanged.tests/tools/test_write_approval.py—test_pending_view_quantifies_what_a_replace_does_to_the_entry(3 payload shapes: gutting, same-size, growing) andtest_pending_view_quantifies_a_remove_as_a_whole_entry_loss(single and batch record shapes), both staging through the review fork's own path (memory_toolunder the unattended-review provenance) so the pinned entry and the delta are asserted together.evals/memory_pending_delta_136738.py— the runnable repro:python evals/memory_pending_delta_136738.py [source_tree]stages a destructive replace plus a remove through the review fork, prints both approval surfaces verbatim, and exits 1 when the pending view quantifies nothing. 5/5 checks and exit 0 on this branch; 1/5 and exit 1 onmainat8a7a5a905f. Its scratchHERMES_HOMEis aTemporaryDirectoryowned bymain(), so a run leaves nothing behind — the run states whether the tree is gone and returns 1 if it is not.How to Test
1.
scripts/run_tests.sh tests/tools/test_write_approval.py— 28 passed.2. Pre-fix proof: the 5 new cases fail against the unpatched handler (
assert '235 -> 47 chars, -188' in out→ the pending list shows the entry with no numbers at all), and pass against the fix.3.
python evals/memory_pending_delta_136738.py .→PASS: 5/5 checks(exit 0);python evals/memory_pending_delta_136738.py <checkout-of-main>→FAIL: 1/5 checks(exit 1). Both runs state whether their scratchHERMES_HOMEis gone; a surviving tree fails the run.4. Neighbour sweep, all green:
tests/tools/test_memory_tool.py,tests/tools/test_skill_pending_diff_batch.py,tests/tools/test_skill_manage_batch.py(110 tests), andtests/gateway/test_slash_dispatch_routed_scope.py+tests/tui_gateway/test_tui_gateway_server.py+tests/hermes_cli/test_slash_dispatch_table.py(672 tests) — the only consumers of this formatter.5. Driven end-to-end, single-profile gateway, staging a 4-op batch through the background review (the reporter's scenario) and reading both surfaces: the pending list now reports
235 -> 47 chars, -188 (-80%), shrinks it below halfand42 -> 0 chars, -42 (-100%), deletes the entry; the approve reply is unchanged and still echoes the full overwritten and removed entries.Checklist
Code
char delta/destructivein the write-approval pending view → 0 hits; the issue itself has no linked PR and no assignee)python scripts/check --commit HEAD --base 590af66a58c2b3eb3c5edd1dcfefa09c625ae18apasses — 12 checks, ok;code health: 15 files vs 590af66a58c2: 0 blocking, 0 advisoryDocumentation & Housekeeping
cli-config.yaml.example— N/A (no config keys)CONTRIBUTING.mdorAGENTS.md— N/Amemorytool's schema is unchanged; this is the CLI approval surface)Screenshots / Logs
Before (base
8a7a5a905f) — the pending list names the entries but quantifies nothing:After — the same two records, with the loss stated up front: