← Back to Pull requests

fix(cli): quantify what a memory approval destroys in the pending list #136996

Closed
PRELVAS94 closed this pull request without merging on Oct 12, 2026 18:16 UTC
View on GitHub
PRELVAS94 PRELVAS94 commented on Oct 12, 2026 05:44 UTC
Author

What does this PR do?

/memory pending showed 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 the old_text search 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:

      replaces entry: 235 -> 47 chars, -188 (-80%), shrinks it below half: laptop drop-off = DELIBERATE KDE AC auto-suspend 1h (not a fault), no WoL; wifi = WPA3 only on 5GHz, ...
      removes entry: 42 -> 0 chars, -42 (-100%), deletes the entry: tailnet = 100.64.0.0/10, exit node = nas-2

"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 all still 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 one
of them:

  • the pending view quantifies nothing about the loss → fixed here (per-proposal char delta plus a

  • destructive flag).
  • approve all applies destructive proposals wholesale → still true after this PR. That gate

  • belongs 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 main is real
    and was driven here, but the attribution in that note is wrong: it is not #133736, which is a
    two-line plugin-catalog/cursor-provider.yaml bump.

  • /memory pending printing the full pinned matched_entry: #121275 (merged 2026-09-24, merge

  • commit 88dee3e866, commits b96e88b245 / 3da1c59377 / 5c3afeee45).
  • The approve reply's overwritten-entry echo (Overwrote entire entry): #117988 (merged

  • 2026-09-21, merge commit 05b9bacbf8, "fix(memory): surface the overwritten entry on the
    /memory approve surface too").

    Both are ancestors of the v0.21.5 release commit f97608f1 (2026-09-24T10:08:47Z — 23 seconds
    after #121275 merged), verified with git merge-base --is-ancestor, so both surfaces are already in
    the build the report was filed against. The same correction is posted on #136738.

    Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

  • ✨ New feature (non-breaking change that adds functionality)

  • 🔒 Security fix

  • 📝 Documentation update

  • ✅ Tests (adding or improving test coverage)

  • ♻️ Refactor (no behavior change)

  • 🎯 New skill (bundled or hub)
  • Changes Made

  • hermes_cli/write_approval_commands.py — new _entry_delta(op) renders a staged replace/remove as before -> after chars, ±delta (±pct%), <verdict>; _matched_entries prefixes 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 full matched_entry and 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) and test_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_tool under 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 on main at 8a7a5a905f. Its scratch HERMES_HOME is a TemporaryDirectory owned by main(), 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 scratch HERMES_HOME is 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), and tests/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 half and 42 -> 0 chars, -42 (-100%), deletes the entry; the approve reply is unchanged and still echoes the full overwritten and removed entries.

    Checklist

    Code

  • I've read the Contributing Guide

  • My commit messages follow Conventional Commits

  • I searched for existing PRs to make sure this isn't a duplicate (char delta / destructive in the write-approval pending view → 0 hits; the issue itself has no linked PR and no assignee)

  • My PR contains only changes related to this fix/feature (3 files: the formatter, its tests, the eval repro)

  • I've run the affected test lanes and they pass (see How to Test — the full suite is not run here, the change is confined to one formatter and its tests)

  • python scripts/check --commit HEAD --base 590af66a58c2b3eb3c5edd1dcfefa09c625ae18a passes — 12 checks, ok; code health: 15 files vs 590af66a58c2: 0 blocking, 0 advisory

  • I've added tests for my changes

  • I've tested on my platform: Linux 6.12, Python 3.14.7
  • Documentation & Housekeeping

  • I've updated relevant documentation — N/A (docstring on the new helper carries the rationale)

  • I've updated cli-config.yaml.example — N/A (no config keys)

  • I've updated CONTRIBUTING.md or AGENTS.md — N/A

  • I've considered cross-platform impact — N/A (pure string formatting, no paths or shell)

  • I've updated tool descriptions/schemas — N/A (the memory tool's schema is unchanged; this is the CLI approval surface)
  • Screenshots / Logs

    Before (base 8a7a5a905f) — the pending list names the entries but quantifies nothing:

          replaces entry: laptop drop-off = DELIBERATE KDE AC auto-suspend 1h (not a fault), no WoL; wifi = WPA3 only on 5GHz, 2.4GHz band disabled at the AP; backup = nightly restic to nas-2 at 03:30, retention 14d; printer = cups queue hp-m428, duplex default
          removes entry: tailnet = 100.64.0.0/10, exit node = nas-2
    

    After — the same two records, with the loss stated up front:

          replaces entry: 235 -> 47 chars, -188 (-80%), shrinks it below half: laptop drop-off = DELIBERATE KDE AC auto-suspend 1h (not a fault), no WoL; wifi = WPA3 only on 5GHz, 2.4GHz band disabled at the AP; backup = nightly restic to nas-2 at 03:30, retention 14d; printer = cups queue hp-m428, duplex default
          removes entry: 42 -> 0 chars, -42 (-100%), deletes the entry: tailnet = 100.64.0.0/10, exit node = nas-2
    

    Diff: 192 lines (+189 / -3) across 3 files Reviewer: ehz0ah Review duration: 752m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.37) × (1 − Review Confidence (0.82)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 192 lines diff across 3 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.77 · 5 substantive comment(s)
    0.77
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    82%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.315
    Real PR Conversation Timeline
    11 items
    PRELVAS94 PRELVAS94 commented on Oct 12, 2026 05:44 UTC
    Author

    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.

    PRELVAS94 PRELVAS94 commented on Oct 12, 2026 05:49 UTC
    Author

    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.

    ehz0ah ehz0ah commented on code on Oct 12, 2026 06:02 UTC
    Code Review
    evals/memory_pending_delta_136738.py:1
    @@ -0,0 +1,88 @@
    +"""Drive issue #136738's approval surfaces against a source tree and report what they say.
    +
    +    python evals/memory_pending_delta_136738.py [source_tree]     # default: this checkout
    +
    +The issue: `/memory pending` names the entry a staged replace/remove is pinned to, but says
    +nothing about what the payload does to it — while memory's whole-entry contract means a
    +clause-level payload deletes every sibling fact it did not re-mention. So a destructive
    +proposal reads like a small edit in the list a human is approving, and the size of the loss
    +only shows up afterwards, as a smaller MEMORY.md.
    +
    +This stages a destructive whole-entry replace plus a remove through the background review's own
    +staging path (unattended review stages instead of applying), then prints both surfaces verbatim:
    +`/memory pending` and `/memory approve all`. Exit 0 when the pending view states the char delta
    +of each staged entry, 1 when it does not (the state before the fix). Nothing is written outside
    +the scratch HERMES_HOME this script creates.
    +"""
    +import json
    +import os
    +import sys
    +import tempfile
    +from pathlib import Path
    +
    +# One entry packing several unrelated facts — the shape the issue's incident ran into, where the
    +# payload rewrites the first clause and drops the rest.
    +ENTRY = ("laptop drop-off = DELIBERATE KDE AC auto-suspend 1h (not a fault), no WoL; "
    +         "wifi = WPA3 only on 5GHz, 2.4GHz band disabled at the AP; "
    +         "backup = nightly restic to nas-2 at 03:30, retention 14d; "
    +         "printer = cups queue hp-m428, duplex default")
    +NEW_CLAUSE = "drop-off = deliberate KDE AC suspend 1h, no WoL"
    +TAILNET = "tailnet = 100.64.0.0/10, exit node = nas-2"
    +
    +
    +def main(argv):
    +    tree = Path(argv[1]).resolve() if len(argv) > 1 else Path(__file__).resolve().parents[1]
    +    sys.path.insert(0, str(tree))
    +    os.environ["HERMES_HOME"] = tempfile.mkdtemp(prefix="eval-136738-")

    [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.

    ehz0ah ehz0ah commented on Oct 12, 2026 06:02 UTC
    Contributor

    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.

    PRELVAS94 PRELVAS94 commented on code on Oct 12, 2026 07:14 UTC
    Code Review
    evals/memory_pending_delta_136738.py:1
    @@ -0,0 +1,88 @@
    +"""Drive issue #136738's approval surfaces against a source tree and report what they say.
    +
    +    python evals/memory_pending_delta_136738.py [source_tree]     # default: this checkout
    +
    +The issue: `/memory pending` names the entry a staged replace/remove is pinned to, but says
    +nothing about what the payload does to it — while memory's whole-entry contract means a
    +clause-level payload deletes every sibling fact it did not re-mention. So a destructive
    +proposal reads like a small edit in the list a human is approving, and the size of the loss
    +only shows up afterwards, as a smaller MEMORY.md.
    +
    +This stages a destructive whole-entry replace plus a remove through the background review's own
    +staging path (unattended review stages instead of applying), then prints both surfaces verbatim:
    +`/memory pending` and `/memory approve all`. Exit 0 when the pending view states the char delta
    +of each staged entry, 1 when it does not (the state before the fix). Nothing is written outside
    +the scratch HERMES_HOME this script creates.
    +"""
    +import json
    +import os
    +import sys
    +import tempfile
    +from pathlib import Path
    +
    +# One entry packing several unrelated facts — the shape the issue's incident ran into, where the
    +# payload rewrites the first clause and drops the rest.
    +ENTRY = ("laptop drop-off = DELIBERATE KDE AC auto-suspend 1h (not a fault), no WoL; "
    +         "wifi = WPA3 only on 5GHz, 2.4GHz band disabled at the AP; "
    +         "backup = nightly restic to nas-2 at 03:30, retention 14d; "
    +         "printer = cups queue hp-m428, duplex default")
    +NEW_CLAUSE = "drop-off = deliberate KDE AC suspend 1h, no WoL"
    +TAILNET = "tailnet = 100.64.0.0/10, exit node = nas-2"
    +
    +
    +def main(argv):
    +    tree = Path(argv[1]).resolve() if len(argv) > 1 else Path(__file__).resolve().parents[1]
    +    sys.path.insert(0, str(tree))
    +    os.environ["HERMES_HOME"] = tempfile.mkdtemp(prefix="eval-136738-")

    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:

  • pre-fix: PASS: 5/5 checks (exit 0), and eval-136738-4ctafgfe is left in $TMPDIR;

  • post-fix: PASS: 5/5 checks (exit 0), scratch HERMES_HOME removed: .../eval-136738-zn6r0mp8, and no eval-136738- anywhere;

  • the failing path against the base tree (FAIL: 1/5 checks, exit 1) also leaves none.
  • PRELVAS94 PRELVAS94 commented on Oct 12, 2026 07:22 UTC
    Author

    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:

  • pre-fix: 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;

  • post-fix: PASS: 5/5 checks (exit 0), scratch HERMES_HOME removed: …/eval-136738-zn6r0mp8, and no eval-136738- anywhere;

  • the failing path against the base tree (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);

  • the approve reply's overwritten-entry echo (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.

    ehz0ah ehz0ah commented on code on Oct 12, 2026 09:41 UTC
    Code Review
    hermes_cli/write_approval_commands.py:1
    @@ -110,11 +110,33 @@ def _changed_entries(result: dict, kind: str) -> list[str]:
         return ([single] if single else []) + [batch[k] for k in sorted(batch, key=int)]
     
     
    +def _entry_delta(op) -> str:
    +    """``'235 -> 47 chars, -188 (-80%), shrinks it below half'`` for a staged replace/remove.
    +
    +    Memory's whole-entry contract means a payload that edits one clause of a multi-fact entry
    +    deletes the rest (#124582); the payload alone reads like a small edit, and the summary line
    +    shows only the old_text search, never the size of the loss. The char delta is the one number
    +    that makes a destructive proposal visible in the list an approver is already reading."""
    +    before = len(op["matched_entry"])
    +    after = len(op.get("content") or op.get("new_text") or "") if op["action"] == "replace" else 0
    +    delta = after - before
    +    pct = round(100 * delta / before) if before else 0

    [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.

    ehz0ah ehz0ah commented on Oct 12, 2026 09:41 UTC
    Reviewer

    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.

    PRELVAS94 PRELVAS94 commented on code on Oct 12, 2026 18:52 UTC
    Code Review
    hermes_cli/write_approval_commands.py:1
    @@ -110,11 +110,33 @@ def _changed_entries(result: dict, kind: str) -> list[str]:
         return ([single] if single else []) + [batch[k] for k in sorted(batch, key=int)]
     
     
    +def _entry_delta(op) -> str:
    +    """``'235 -> 47 chars, -188 (-80%), shrinks it below half'`` for a staged replace/remove.
    +
    +    Memory's whole-entry contract means a payload that edits one clause of a multi-fact entry
    +    deletes the rest (#124582); the payload alone reads like a small edit, and the summary line
    +    shows only the old_text search, never the size of the loss. The char delta is the one number
    +    that makes a destructive proposal visible in the list an approver is already reading."""
    +    before = len(op["matched_entry"])
    +    after = len(op.get("content") or op.get("new_text") or "") if op["action"] == "replace" else 0
    +    delta = after - before
    +    pct = round(100 * delta / before) if before else 0

    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.

    PRELVAS94 PRELVAS94 commented on Oct 12, 2026 18:52 UTC
    Author

    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 ===

  • neighbour 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 checks

  • python scripts/check --commit HEAD --base HEAD^1 → 12 checks, ok (code health: 2 files vs d8ff303d1199: 0 blocking, 0 advisory)
  • Reviewers
    Assignees
    PRELVAS94 PRELVAS94
    Labels
    risk: low confidence: 82.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 37.4% (MEDIUM) · Higher = larger blast radius
    37.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 82.1% · Lower = rushed or shallow review
    82.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.7% · Safe to merge
    6.7%