跳到正文
DEV Community· John·· 3 小時前AI 評分39

AI 智能體審查規則補上兩個漏洞:撤回核准須使用專屬旗標

Readers Found Two Gaps in My AI Agent's Review Rules. Undoing an Approval Now Needs Its Own Flag.

AI 導讀

研究工具作者修補 AI 智能體審查規則的兩個漏洞,要求撤回已核准主張時使用專屬旗標。程式庫加入 undo_approval,CLI 加入 --undo-approval 和不同的確認字串;衝突資料亦會保留相異值或對應主張及來源網址。單元測試由 1124 項增至 1135 項,並以唯讀方式重播既有資料,確認儲存數據指紋不變。

正文

Originally published on hexisteme notes.

Two readers left comments on my earlier note about letting an AI agent withdraw evidence claims but not approve them. In my replies I admitted two gaps in my research tool. One was that the agent could still remove something I had approved, through the same path it used for withdrawals. The other was that a datum flagged as contradicted kept the flag but lost the value it was contradicted by. On November 18 I decided to fix both. This note covers what changed, how I checked it against the real store, and the gap the comments pointed at that I left open.

Where the earlier rule stopped

The earlier note set up a split for a batch of pending claims. The agent was delegated withdrawals. Passing a claim, which adopts it as evidence, stayed with me. Nothing in that rule said the delegation was limited to pending claims. That split covers two acts: approving and withdrawing.

One reader asked about reversibility and about who is on the hook for each decision. Answering that made me look at the transition table again, and it allowed passed → withdrawn. In my reply I wrote that an agent withdrawing a passed claim removes something I approved and stops it propagating, which is the expensive direction. The only code gate was the terminal check, and it treated every decision the same. A line in an agent-written review script that reversed one of my passes would be recorded with the same call and the same 8-character confirmation as a routine verdict on a pending claim.

So there was a third act the split had not named: undoing an approval. It needed its own door.

The first gap: undoing a pass

The transition table has exactly two transitions that leave passed: passed → failed and passed → withdrawn. Both count as undoing an approval, so both got the same treatment.

In the library, record_assessment_review now takes an explicit undo_approval argument. Recording failed or withdrawn on a passed claim without undo_approval=True returns TRANSITION_INVALID. With the flag, it is recorded. Passing the flag on a pending claim is refused too, because there is no approval to undo there. Transitions out of pending behave as before.

In the CLI, assess review on a passed claim without --undo-approval is refused before the confirmation prompt appears. With the flag, it first shows the approval being undone: who recorded it, when, and the reason. Then it accepts only the string undo- followed by the first 8 characters of the claim's id. Typing the 8 characters alone, which is what a normal review asks for, cancels. The flag on a pending claim is refused.

A script built to answer the routine prompt cannot reverse a pass by accident, because the routine answer cancels. Existing tests that reversed a pass were allowed one edit, adding undo_approval=True at the call site; their expected codes and states stayed the same.

The second gap: the counterpart was thrown away

The other reader described a listing where three pages on one vendor's domain said free, free, and freemium. In my reply I explained that my tool would count those as one source, and that for conflicting values it does less than you might expect. The pipeline already flagged some data as contradicted, and a review note surfaced that flag with fixed wording saying the contradiction in meaning was unconfirmed. It never picked a value.

Then I admitted the gap: the flag survived in the frozen input, and the value on the other side of the conflict did not. I could later show that a value was disputed, but not what it was disputed against.

The fix adds a conflicts field to the datum:

  • For a value conflict, it keeps the values that differ from the representative one, each with its source URL.
  • For a conflict between claims, it keeps the counterpart group's sentence with its source URL.
  • When the counterpart came through the path that withholds excerpts, its title is kept in place of the sentence.

When the frozen premise of a claim carries conflicts, the PREMISE_CONTRADICTED review note now names the counterpart and drops the wording that says the counterpart was not preserved. Claims frozen before this change have no conflicts, so their note keeps the old wording.

What the fix does not touch is the decision of what counts as contradicted. The detection conditions, distinct_values and cross_conflict, were explicitly off limits. The change records the counterpart and nothing else.

Why the empty case writes no key

The awkward detail was a hash. Each frozen claim premise refers to its datum by datum_ref, and datum_ref is a hash of the whole stored datum dict. If every datum got a conflicts key, even an empty one, every new report would produce different refs from the same data.

So the renderer writes conflicts only when it is non-empty. A datum that is not contradicted stores exactly the same dict as before, and its ref does not move. This follows a pattern already in the code: candidate fields such as basis and derivations are also left out when they hold default values, to keep existing ids stable. One of the new tests, test_no_conflicts_key_when_not_contradicted, pins this.

Checking it against the real store

Unit tests went from 1124 to 1135 passing. The new tests include test_undo_approval_cli_needs_distinct_confirmation for the cancel-on-routine-answer case and test_claim_conflicts_do_not_store_withheld_excerpt for the path that withholds excerpts.

Then I replayed the change over the existing data, read-only. The replay was not allowed to write to the stored data or record a real review. The log:

K 119 loaded, load errors 0
review history REVIEW_INVALID 0
PREMISE_CONTRADICTED 5 — same as the 11-08 list: True, old wording kept: True
stored reports 317, reports with a conflicts key 0
claim↔report binding: report found 66, not found 53, premise datum_ref mismatch 0
stored data fingerprint unchanged (read-only): True
1.0s

K is what my tool calls a claim. All 119 loaded without errors. The same 5 claims as in the November 8 replay got the contradiction note, with the old wording, which is what should happen when none of them carries conflicts yet. None of the 317 stored reports has the new key, because none was produced after the change.

The 53 "not found" needed a second look. For those claims the stored report's digest did not match, so the replay could not pair them with a report file. The datum_ref re-check inside load_inputs passed for all 119. I did not trace why those 53 digests differ; the replay only shows that it is not a datum_ref mismatch.

One more line went into the counsel module's docs. Counsel results are not frozen yet. Once they are, withdrawing a pending claim will break any counsel that cited it, and the delegation rule for withdrawals has to be decided again at that point.

What the comments did not fix

Two things stayed out of scope on purpose.

The first is retroactive enrichment. The 5 claims that already carry the contradiction note were frozen without their counterparts, and they still do not have them. Only reports produced after the change will name what a datum was contradicted by.

The second is the one I care more about. In my reply on revision binding, I wrote that claim files are immutable and the id is a hash of the content, so a review already attaches to one revision, and that the reviewer field is only the OS login name, so the "who" half is the weaker one. This change did not touch that. Undoing a pass now needs a flag and a distinct confirmation string, and the CLI shows whose approval is being undone. But the name it shows is whatever OS login ran the command. An agent running under my login would record reviews under my name, approvals and undo records alike. Reviewer authentication and signing were listed as anti-goals for this change, to keep it small.

So the separate flag guards against a mistake. A script that answers the routine prompt can no longer reverse a pass by answering it. It does not tell me who reversed a pass when the reversal was deliberate. Next I want to decide whether the reviewer field should carry anything an agent session cannot produce, or whether the terminal refusal from the earlier note is the only line I can actually defend.

Email list for these notes: hexisteme.beehiiv.com — no issue has gone out yet, so you would be on it before the first one. No welcome sequence, no course, no upsell.

More notes at hexisteme.github.io/notes.

來源:DEV Community · dev.to