Files
CyberGril/spike/hel857/audit864.py
T
zonggongandmultica-agent c65de003a1 HEL-864: full-grammar whole-answer parsing for S6 affirmative verification - per manager independent review of 7aa9280: (1) affirms_promise_claim/affirms_promise_state rewritten as bounded-grammar full-parse (parse_supported_answer): the entire answer must be declarative (no question marks, no sentence-final 吗/呢/吧/嘛/呗) and EVERY clause must be fully consumed (fullmatch) as exactly one of P promise clause (subject? -> promise verb -> aspect 过/了? -> 周五(晚)? -> tell action -> receiver pronoun? -> correct object 面试结果, nothing further) / C closed-state clause / O open-state clause; whole answer needs >=1 P clause, state affirmation needs >=1 clause of required polarity and 0 of the opposite; (2) manager seven wrong-answer groups all now judged fail through the same real s6_result: foreign object without 结果 suffix (体检报告现在已经告诉我了), post-state object (现在已经告诉我了体检情况), bare-noun clause in earlier position (体检结果,现在已经告诉我了), whole-answer conflicting tail (但面试结果仍待告知), question mood (……吗?), conditional (如果你答应……), suffix denial (已经告诉我了是假的) - plus the same seven mirrored on the unresolved side; (3) EN equally verified with the same clause structure (old code failed even the EN positive with 'the interview result'; now 3 EN positives pass, 6 EN negatives fail); substring-assembly judges (clause_affirms_promise/clause_affirms_state/clause_foreign_object/_prefix_negated) removed - no per-sentence blacklists, no 报告/吗/假 forbidden words, no new model, no generic semantic engine
Co-authored-by: multica-agent <github@multica.ai>
2026-10-26 02:29:18 +08:00

360 lines
16 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""HEL-864 负例复现脚本:总管独立复核《HEL-863-独立复核.md》七组反例+未结侧镜像。
零真实模型、零网络(socket 硬拒绝 + HF 离线)、零本地嵌入:S6 判据为纯函数
代入(真实 s6_result 构造器同一入口);既有判据不回归部分直接复用 audit861
的两组纯函数节(S6 全套正负例 + S2/S3 总判据)、audit862 的四组复核用例与
audit863 的三组复核用例(后两组在起点 7aa9280 已判失败,预期极性固定为不
回归)。同一脚本在修复前(7aa9280)与修复后代码上均可运行:
修复前(--phase prefix,在 7aa9280 工作树上运行)→ 七组反例与七组未结侧
镜像全部 pass=true(复现),其余用例维持既有预期极性;英文为本轮新声明
支持,prefix 期仅记录实际值、不参与退出码
修复后(默认 postfix)→ 同一真实 s6_result 七组+镜像全部判失败;正确
正例(含 audit860/rework 形态)、HEL-862 四组、HEL-863 三组、audit861
既有正负例与 S2/S3 总判据维持预期;英文同等验证(正例过、反例败)
补正口径(固定合成语料领域内的有界语法全量匹配,预声明受支持结构与语气):
整个回答必须为陈述语气且每个小句被且仅被三类结构完整消费——P 承诺小句
(主语?→承诺动词→体标记?→周五(晚)?→告知动作→接收者?→正确对象,到此为止)、
C 已结状态小句、O 未结状态小句;整篇 ≥1 个 P;状态肯定另要求 ≥1 对应极性
C/O 且 0 个反向极性小句。外来对象(含无"结果"后缀,如体检报告/体检情况)、
状态后置对象、裸名词小句(体检结果)、全段冲突尾句(但面试结果仍待告知)、
条件句(如果你答应)、疑问语气(……吗?)、状态短语后否认(已经告诉我了是
假的)一律保守判失败;已结侧与未结侧镜像输入同判。不加七句黑名单、不补
"报告/吗/假"禁词、不新增模型、不做通用语义引擎;中英文同等结构验证。
退出码真实依赖正负例:除全部用例满足预期外,还对每个用例做翻转自检
(flip 任一用例的实际结果,用例总判必翻转);任一翻转不改变结论则退出 1。
用法:python -m spike.hel857.audit864 [--phase prefix|postfix] [输出json路径]
退出码:prefix=0 当且仅当七组反例与七组镜像全部复现(pass=true)且其余用例
维持预期;postfix=0 当且仅当七组+镜像全部判失败、正例保留、英文同等验证、
既有判据不回归、权威账与既有证据只读未动、翻转自检全部通过。权威嵌入账
只读快照核对(不补种不回退不双扣)。
"""
from __future__ import annotations
import hashlib
import json
import os
import socket
import sqlite3
import subprocess
import sys
from pathlib import Path
REPO = Path(__file__).resolve().parents[2]
LEDGER = Path("/home/xiaomo/multica_workspaces/hello-af23464d222e/"
"hel-859-1f079e50f551/workdir/audit-data/embed_ledger.sqlite3")
os.environ["HEL857_EMBED_LEDGER"] = str(LEDGER)
os.environ.setdefault("HF_HUB_OFFLINE", "1")
os.environ.setdefault("TRANSFORMERS_OFFLINE", "1")
def deny_network(*a, **k):
raise RuntimeError("audit864 blocks network")
socket.socket.connect = deny_network
socket.socket.connect_ex = deny_network
from . import ab_scenarios as A
from .audit861 import section_s2_s3_no_regression, section_s6_affirmative
from .audit862 import (HELD_S2S3_EXPECT, HELD_S6_EXPECT, ORCH6,
REVIEW_CASES, REVIEW_NEGATIVE_NAMES)
from .audit863 import ADDITIONAL_CASES
OUT = {"real_network_allowed": False, "real_model_requests": 0,
"local_embeddings": 0}
PHASE = "postfix"
def ledger_snapshot():
with sqlite3.connect(f"file:{LEDGER}?mode=ro", uri=True) as c:
return {"counts": dict(c.execute("select kind,sum(items) from embed_ops "
"group by kind")),
"rows": c.execute("select count(*) from embed_ops").fetchone()[0]}
PRESERVED_EVIDENCE = [
"ab_scenarios_run1.json", "ab_scenarios.json", "rework858_offline.json",
"rework859_offline.json", "rework860_offline.json", "audit859_prefix.json",
"audit859_postfix.json", "audit859_reuse860.json", "audit860_prefix.json",
"audit860_postfix.json", "audit861_prefix.json", "audit861_postfix.json",
"audit861_reuse862.json", "audit862_prefix.json", "audit862_postfix.json",
"audit861_reuse863.json", "audit863_prefix.json", "audit863_postfix.json"]
def evidence_hashes():
res = {}
for name in PRESERVED_EVIDENCE:
p = REPO / "spike/hel857/results" / name
res[name] = (hashlib.sha256(p.read_bytes()).hexdigest()
if p.exists() else "missing")
return res
# ---------------------------------------------------------------------------
# 总管《HEL-863-独立复核.md》七组反例(已结侧原文逐字)+ 未结侧镜像(同一缺口
# 在 unresolved 侧的形态)。两侧均经同一真实 s6_result 入口,对侧用正确答案。
def s6_answer(s):
return {"answer": s, "ok": True}
GOOD_CLOSED = "你答应周五晚告诉我面试结果,现在已经告诉我了。"
GOOD_OPEN = "你答应周五晚告诉我面试结果,还没有告诉我。"
P = "你答应周五晚告诉我面试结果,"
SEVEN_CLOSED = {
"foreign_object_without_result_suffix":
P + "体检报告现在已经告诉我了。",
"foreign_object_after_state":
P + "现在已经告诉我了体检情况。",
"foreign_object_in_previous_clause":
P + "体检结果,现在已经告诉我了。",
"conflicting_target_state":
P + "现在已经告诉我了,但面试结果仍待告知。",
"question_not_assertion":
P + "现在已经告诉我了吗?",
"conditional_not_promise":
"如果你答应周五晚告诉我面试结果,现在已经告诉我了。",
"suffix_denies_state":
P + "已经告诉我了是假的。",
}
SEVEN_OPEN_MIRROR = {
"open_foreign_object_without_result_suffix":
P + "体检报告还没有告诉我。",
"open_foreign_object_after_state":
P + "还没有告诉我体检情况。",
"open_foreign_object_in_previous_clause":
P + "体检结果,还没有告诉我。",
"open_conflicting_target_state":
P + "还没有告诉我,但面试结果仍待告知。",
"open_question_not_assertion":
P + "还没有告诉我吗?",
"open_conditional_not_promise":
"如果你答应周五晚告诉我面试结果,还没有告诉我。",
"open_suffix_denies_state":
P + "还没有告诉我是假的。",
}
SEVEN_NAMES = tuple(SEVEN_CLOSED.keys())
MIRROR_NAMES = tuple(SEVEN_OPEN_MIRROR.keys())
# 英文同等验证(本轮声明支持即同等结构核验:正例必须过、反例必须败)。
# 值为 (已结侧回答, 未结侧回答)。
EN_POSITIVE = {
"en_positive_resolved": (
"You promised to tell me the interview result, "
"and you have already told me.", GOOD_OPEN),
"en_positive_open": (
GOOD_CLOSED, "You promised to tell me the interview result, "
"but you haven't told me yet."),
"en_positive_open_not_received": (
GOOD_CLOSED, "You promised to tell me the interview result, "
"you haven't received it yet."),
}
EN_NEGATIVE = {
"en_conditional_not_promise": (
"If you promised to tell me the interview result, "
"you have already told me.", GOOD_OPEN),
"en_question_not_assertion": (
"You promised to tell me the interview result, "
"have you already told me?", GOOD_OPEN),
"en_foreign_object_suffix": (
"You promised to tell me the interview result, and you have "
"already told me the medical check result.", GOOD_OPEN),
"en_negated_promise": (
"You never promised to tell me the interview result, "
"and you have already told me.", GOOD_OPEN),
"en_open_mirror_question": (
GOOD_CLOSED, "You promised to tell me the interview result, "
"haven't you told me yet?"),
"en_open_mirror_conditional": (
GOOD_CLOSED, "If you promised to tell me the interview result, "
"you haven't told me yet."),
}
def _record(name: str, resolved: str, unresolved: str, expected: bool) -> dict:
result = A.s6_result(ORCH6, s6_answer(resolved), s6_answer(unresolved))
mu = result["layers"]["model_use"]
return {
"resolved_input": resolved, "unresolved_input": unresolved,
"expected_pass": expected, "actual_pass": result["pass"],
"layers": {
"resolved_states_promise": mu["resolved_states_promise"],
"resolved_affirms_closed": mu["resolved_affirms_closed"],
"unresolved_states_promise": mu["unresolved_states_promise"],
"unresolved_affirms_open": mu["unresolved_affirms_open"]},
"result": result,
}
def section_seven_and_mirror() -> dict:
"""七组反例+未结侧镜像:prefix 期预期 pass=true(复现),postfix 判失败。"""
out = {}
for name, closed in SEVEN_CLOSED.items():
out[name] = _record(name, closed, GOOD_OPEN, PHASE == "prefix")
for name, opened in SEVEN_OPEN_MIRROR.items():
out[name] = _record(name, GOOD_CLOSED, opened, PHASE == "prefix")
return out
def section_held_previous() -> dict:
"""HEL-862 四组与 HEL-863 三组:起点 7aa9280 已按预期判失败,极性固定。"""
out = {}
for name, (closed, opened) in REVIEW_CASES.items():
out[f"review.{name}"] = _record(
name, closed, opened, name not in REVIEW_NEGATIVE_NAMES)
for name, closed in ADDITIONAL_CASES.items():
out[f"additional.{name}"] = _record(name, closed,
"你答应周五晚告诉我面试结果,还没有告诉我。", False)
return out
def section_english_cases() -> dict:
"""英文同等验证:postfix 期参与退出码(正例过、反例败),prefix 期仅记录。"""
out = {}
for name, (resolved, unresolved) in EN_POSITIVE.items():
out[name] = _record(name, resolved, unresolved, True)
for name, (resolved, unresolved) in EN_NEGATIVE.items():
out[name] = _record(name, resolved, unresolved, False)
return out
def _case_table(seven_mirror: dict, english: dict, held_prev: dict,
held_s6: dict, held_s2s3: dict) -> dict:
"""全部用例的实际 pass 与预期极性(退出码公式输入;英文仅 postfix 参与)。"""
table: dict[str, bool] = {}
expect: dict[str, bool] = {}
for name, c in seven_mirror.items():
key = f"seven_mirror.{name}"
table[key] = bool(c["actual_pass"])
expect[key] = bool(c["expected_pass"])
if PHASE == "postfix":
for name, c in english.items():
key = f"english.{name}"
table[key] = bool(c["actual_pass"])
expect[key] = bool(c["expected_pass"])
for name, c in held_prev.items():
table[name] = bool(c["actual_pass"])
expect[name] = bool(c["expected_pass"])
for name, res in held_s6.items():
key = f"held_s6.{name}"
table[key] = bool(res["pass"])
expect[key] = HELD_S6_EXPECT[name]
for name, res in held_s2s3.items():
key = f"held_s2s3.{name}"
table[key] = bool(res["pass"])
expect[key] = HELD_S2S3_EXPECT[name]
return table, expect
def _all_cases_match(table: dict, expect: dict) -> bool:
return all(table[k] == expect[k] for k in expect)
def _flip_dependence(table: dict, expect: dict) -> dict:
"""翻转自检:任一用例实际值翻转必须改变用例总判(退出码真实依赖正负例)。"""
base = _all_cases_match(table, expect)
flips = {}
for k in expect:
flipped = dict(table)
flipped[k] = not flipped[k]
flips[k] = _all_cases_match(flipped, expect) != base
return {"base_all_match": base, "every_flip_changes_verdict": all(
flips.values()), "per_case": flips}
# ---------------------------------------------------------------------------
def main(argv: list[str]) -> dict:
global PHASE
argv = list(argv)
rest: list[str] = []
PHASE = "postfix"
it = iter(argv[1:])
for tok in it:
if tok == "--phase":
PHASE = next(it, "postfix")
elif tok.startswith("--phase="):
PHASE = tok.split("=", 1)[1]
elif not tok.startswith("--"):
rest.append(tok)
args = rest
OUT["phase"] = PHASE
commit = subprocess.run(["git", "rev-parse", "--short", "HEAD"],
capture_output=True, text=True,
cwd=str(REPO)).stdout.strip()
OUT["commit"] = commit
OUT["ledger_before"] = ledger_snapshot()
OUT["preserved_evidence_before"] = evidence_hashes()
OUT["seven_and_mirror"] = section_seven_and_mirror()
OUT["english_cases"] = section_english_cases()
OUT["held_previous_rounds"] = section_held_previous()
held_s6 = section_s6_affirmative()
held_s2s3 = section_s2_s3_no_regression()
OUT["held_s6_affirmative"] = held_s6
OUT["held_s2_s3_no_regression"] = held_s2s3
table, expect = _case_table(OUT["seven_and_mirror"], OUT["english_cases"],
OUT["held_previous_rounds"], held_s6, held_s2s3)
OUT["case_expect"] = {k: bool(v) for k, v in expect.items()}
OUT["case_actual"] = {k: bool(v) for k, v in table.items()}
OUT["all_cases_match_expectation"] = _all_cases_match(table, expect)
OUT["flip_dependence"] = _flip_dependence(table, expect)
OUT["ledger_after"] = ledger_snapshot()
OUT["ledger_unchanged"] = OUT["ledger_before"] == OUT["ledger_after"]
OUT["preserved_evidence_after"] = evidence_hashes()
OUT["preserved_evidence_unchanged"] = (
OUT["preserved_evidence_before"] == OUT["preserved_evidence_after"])
sm = OUT["seven_and_mirror"]
# ---- prefix:七组反例与七组镜像全部复现(pass=true)----
fourteen_reproduced = (all(sm[n]["actual_pass"] for n in SEVEN_NAMES)
and all(sm[n]["actual_pass"] for n in MIRROR_NAMES))
# ---- postfix:七组+镜像全部判失败 ----
fourteen_rejected = (not any(sm[n]["actual_pass"] for n in SEVEN_NAMES)
and not any(sm[n]["actual_pass"] for n in MIRROR_NAMES))
# ---- postfix:英文同等验证(正例过、反例败)----
english_ok = all(c["actual_pass"] == c["expected_pass"]
for c in OUT["english_cases"].values())
OUT["summary"] = {
"phase": PHASE,
"fourteen_reproduced": fourteen_reproduced,
"fourteen_rejected": fourteen_rejected,
"english_equal_verification_pass": english_ok if PHASE == "postfix"
else None,
"all_cases_match_expectation": OUT["all_cases_match_expectation"],
"flip_dependence_holds": OUT["flip_dependence"][
"every_flip_changes_verdict"],
"ledger_unchanged": OUT["ledger_unchanged"],
"preserved_evidence_unchanged": OUT["preserved_evidence_unchanged"],
"pass": (fourteen_reproduced and PHASE == "prefix"
and OUT["all_cases_match_expectation"]
and OUT["flip_dependence"]["every_flip_changes_verdict"]
and OUT["ledger_unchanged"]
and OUT["preserved_evidence_unchanged"])
or (fourteen_rejected and PHASE == "postfix"
and english_ok
and OUT["all_cases_match_expectation"]
and OUT["flip_dependence"]["every_flip_changes_verdict"]
and OUT["ledger_unchanged"]
and OUT["preserved_evidence_unchanged"]),
}
out_path = Path(args[0]) if args else (
REPO / "spike/hel857/results/"
f"audit864_{'prefix' if PHASE == 'prefix' else 'postfix'}.json")
out_path.parent.mkdir(parents=True, exist_ok=True)
out_path.write_text(json.dumps(OUT, ensure_ascii=False, indent=2),
encoding="utf-8")
print(json.dumps(OUT["summary"] | {"out": str(out_path)},
ensure_ascii=False))
return OUT
if __name__ == "__main__":
raise SystemExit(0 if main(sys.argv)["summary"]["pass"] else 1)