fix(webui): reconcile running turns on reconnect (#6715)

* fix(webui): reconcile running turns on reconnect

* test(webui): verify only the current turn-sync policy
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 16:08:20 +08:00
1 parent b453de9cf6
commit 094bac0dc3
25 files changed
+455 -226

No files matched your search

+30 -38
View File
@@ -1,24 +1,20 @@
#!/usr/bin/env python3
"""Check bounded current-policy models without writing generated files into the checkout."""
"""Check bounded turn-sync models without writing generated files into the checkout."""
from __future__ import annotations
import argparse
import hashlib
import json
from pathlib import Path
import re
import shutil
import subprocess
import tempfile
import time
from pathlib import Path
SOURCE = Path(__file__).resolve().parent
EXPECTED_LIMITS = {
"lifecycle-failed-read-limit": (13, "Temporal properties were violated"),
"lifecycle-fragment-id-limit": (13, "Temporal properties were violated"),
}
ATTACH_CASE = "attach-reconciliation"
REVISED_CASES = (
"revised-mounted", "revised-unmounted",
"revised-mounted-fragments", "revised-unmounted-fragments",
@@ -30,16 +26,16 @@ USAGE_CASES = (
)
# Larger products are reproducible explicitly, not claimed exhausted by defaults.
OPTIONAL_CASES = ("requests-two", "lifecycle-fullpage-two-chats")
LIMIT_CASES = tuple(EXPECTED_LIMITS)
CASES = REVISED_CASES + USAGE_CASES + OPTIONAL_CASES + LIMIT_CASES
DEFAULT_CASES = REVISED_CASES + USAGE_CASES + (ATTACH_CASE,)
CASES = DEFAULT_CASES + OPTIONAL_CASES
MODULES = {
**{case: "RevisedTurnSync.tla" for case in REVISED_CASES},
**{case: "SharedRequests.tla" for case in ("requests-one", "requests-two-no-invalidations", "requests-two")},
"authority": "CompletionAuthority.tla",
**{case: "CacheHandoff.tla" for case in ("handoff-fullpage-active", "handoff-fullpage-idle")},
**{case: "UsageLifecycle.tla" for case in (
"lifecycle-fullpage-dynamic", "lifecycle-fullpage-two-chats", *LIMIT_CASES,
)},
"lifecycle-fullpage-dynamic": "UsageLifecycle.tla",
"lifecycle-fullpage-two-chats": "UsageLifecycle.tla",
ATTACH_CASE: "AttachReconciliation.tla",
}
COUNTS = re.compile(
r"([\d,]+) states generated, ([\d,]+) distinct states found, ([\d,]+) states left on queue"
@@ -49,7 +45,10 @@ IMPLEMENTATION_FILES = (
"webui/src/lib/client-run-ledger.ts", "webui/src/lib/nanobot-client.ts",
"webui/src/lib/canonical-run-snapshot.ts", "webui/src/lib/latest-thread-request.ts",
"webui/src/lib/thread-transcript.ts", "webui/src/lib/webui-thread-cache.ts",
"webui/src/components/thread/ThreadShell.tsx",
"webui/src/components/thread/ThreadShell.tsx", "webui/src/lib/types.ts",
"nanobot/session/webui_turns.py", "nanobot/webui/inbound_commands.py",
"nanobot/webui/session_projection.py", "nanobot/webui/outbound_delivery.py",
"nanobot/webui/ws_http.py", "nanobot/channels/websocket/runtime.py",
)
@@ -61,10 +60,8 @@ def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--jar", required=True, type=Path, help="External official tla2tools.jar; never copied")
parser.add_argument("--output-root", type=Path, help="New task-owned directory outside this checkout")
parser.add_argument("--implementation-root", type=Path, help="Optional read-only TypeScript provenance; not mechanical verification")
selection = parser.add_mutually_exclusive_group()
selection.add_argument("--case", action="append", choices=CASES, dest="cases", help="Repeat to select cases")
selection.add_argument("--limits", action="store_true", help="Run ONLY current-policy missing-evidence counterexamples, not positive checks")
parser.add_argument("--implementation-root", type=Path, help="Optional read-only implementation provenance; not mechanical verification")
parser.add_argument("--case", action="append", choices=CASES, dest="cases", help="Repeat to select cases")
parser.add_argument("--java", default="java")
parser.add_argument("--workers", type=int, default=2)
parser.add_argument("--heap-mb", type=int, default=1536)
@@ -83,7 +80,7 @@ def main() -> int:
output.mkdir(parents=True, exist_ok=False)
inputs = sorted((*SOURCE.glob("*.tla"), *SOURCE.glob("*.cfg")))
manifest = {
"scope": "finite fixed-mount, dynamic lifecycle, shared-request and completion partitions; not a checked TypeScript/compositional/all-system proof",
"scope": "finite history, request, completion and attach partitions; not a checked implementation/compositional proof",
"jar": {"path": str(jar), "sha256": sha256(jar)},
"source_sha256": {path.name: sha256(path) for path in inputs},
"results": [],
@@ -93,11 +90,11 @@ def main() -> int:
manifest["implementation_snapshot"] = {
"root": str(implementation),
"sha256": {name: sha256(implementation / name) for name in IMPLEMENTATION_FILES},
"note": "Read-only provenance, not a checked refinement of TypeScript",
"note": "Read-only provenance, not a checked refinement of implementation code",
}
print(f"Evidence: {output}", flush=True)
unexpected = 0
selected = args.cases or (LIMIT_CASES if args.limits else REVISED_CASES + USAGE_CASES)
failed = 0
selected = args.cases or DEFAULT_CASES
for case in selected:
case_dir = output / case
case_dir.mkdir()
@@ -113,7 +110,6 @@ def main() -> int:
"tlc2.TLC", "-workers", str(args.workers), "-config", f"{case}.cfg",
"-metadir", str(case_dir / "states"), module,
]
expected_exit, required_error = EXPECTED_LIMITS.get(case, (0, None))
started = time.monotonic()
timed_out = False
try:
@@ -133,19 +129,16 @@ def main() -> int:
(case_dir / "tlc.log").write_text(text, encoding="utf-8")
matches = list(COUNTS.finditer(text))
counts = tuple(int(value.replace(",", "")) for value in matches[-1].groups()) if matches else None
matched = not timed_out and actual_exit == expected_exit
if required_error:
matched = matched and required_error in text
else:
matched = (matched and "Model checking completed. No error has been found." in text
and counts is not None and counts[2] == 0)
status = ("LIMITATION_COUNTEREXAMPLE" if required_error else "EXHAUSTED_NO_COUNTEREXAMPLE") if matched else "UNEXPECTED_RESULT"
unexpected += not matched
exhausted = (
actual_exit == 0 and "Model checking completed. No error has been found." in text
and counts is not None and counts[2] == 0
)
status = "EXHAUSTED_NO_COUNTEREXAMPLE" if exhausted else "UNEXPECTED_RESULT"
result = {
"case": case, "status": status,
"category": ("missing-evidence-limit" if case in LIMIT_CASES else
"category": ("attach-model" if case == ATTACH_CASE else
"expanded-usage-model" if case in USAGE_CASES + OPTIONAL_CASES else "fixed-mount-model"),
"expected_exit": expected_exit, "actual_exit": actual_exit, "required_error": required_error,
"actual_exit": actual_exit,
"timed_out": timed_out, "seconds": round(time.monotonic() - started, 3),
"generated": counts[0] if counts else None, "distinct": counts[1] if counts else None,
"left_on_queue": counts[2] if counts else None,
@@ -153,13 +146,12 @@ def main() -> int:
}
manifest["results"].append(result)
(output / "manifest.json").write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8")
print(f"{case}: {status}; exit={actual_exit}, expected={expected_exit}; distinct={result['distinct']}", flush=True)
if not matched:
print(f"{case}: {status}; exit={actual_exit}; distinct={result['distinct']}", flush=True)
if not exhausted:
failed += 1
print(text[-5000:], flush=True)
positive_count = sum(result["status"] == "EXHAUSTED_NO_COUNTEREXAMPLE" for result in manifest["results"])
limit_count = sum(result["status"] == "LIMITATION_COUNTEREXAMPLE" for result in manifest["results"])
print(f"Positive exhausted checks: {positive_count}; missing-evidence counterexamples: {limit_count}; unexpected: {unexpected}")
return 1 if unexpected else 0
print(f"Exhausted checks: {len(selected) - failed}; failed: {failed}")
return 1 if failed else 0
if __name__ == "__main__":