The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): sanitized deferral evidence for ledgered manual serve blockers
liuhao102446ac31e84c69
diff --git a/apps/desktop/electron/venv-blocker-scan.test.ts b/apps/desktop/electron/venv-blocker-scan.test.tsindex 1b9c07a61c5..c90bd98f10b 100644--- a/apps/desktop/electron/venv-blocker-scan.test.ts+++ b/apps/desktop/electron/venv-blocker-scan.test.ts@@ -106,6 +106,45 @@ describe('parseVenvBlockerScanOutput', () => {assert.equal(o.kind, 'blocked')})+ // Contract fixture (#98336/#98350): the scanner reports exemption+ // diagnostics (counts + sanitized evidence) alongside the authoritative+ // blocked/processes fields. The consumer must tolerate those fields today+ // and must keep enforcing blocked/processes consistency — a future parser+ // change that either chokes on the diagnostics or silently reinterprets+ // an exemption as a blocker breaks this fixture.+ it('tolerates exemption diagnostics while enforcing blocked/processes consistency', () => {+ const clear = parseVenvBlockerScanOutput(+ ok({+ pausable_gateways: 2,+ deferred_backends: 1,+ deferred_backend_evidence: [{ pid: 78, purpose: 'serve', port: 9119 }]+ })+ )++ assert.equal(clear.kind, 'clear')++ const blocked = parseVenvBlockerScanOutput(+ ok({+ blocked: true,+ processes: [{ pid: 79, name: 'python.exe', cmdline: 'c' }],+ pausable_gateways: 1,+ deferred_backends: 1,+ deferred_backend_evidence: [{ pid: 78, purpose: 'serve', port: 9119 }]+ })+ )++ assert.equal(blocked.kind, 'blocked')++ if (blocked.kind !== 'blocked') {+ return+ }++ assert.deepEqual(+ blocked.result.processes.map((p) => p.pid),+ [79]+ )+ })+it('classifies Python http.server blockers as safe local previews with a human label', () => {const o = parseVenvBlockerScanOutput(ok({diff --git a/hermes_cli/_scan_venv_blockers.py b/hermes_cli/_scan_venv_blockers.pyindex 5e050c2bfe7..ca8ceab6d84 100644--- a/hermes_cli/_scan_venv_blockers.py+++ b/hermes_cli/_scan_venv_blockers.py@@ -265,14 +265,25 @@ def _is_updater_owned_backend(pid: int, cmdline: str) -> bool:that supervisor would respawn whatever the updater kills. Anythingunprovable → not exempt (fail closed, pre-exemption behavior)."""+ return _updater_owned_backend_entry(pid, cmdline) is not None+++def _updater_owned_backend_entry(pid: int, cmdline: str) -> dict | None:+ """Ledger entry for a deferred backend, or ``None`` when it must block.++ Same decision logic as ``_is_updater_owned_backend`` (which delegates+ here); returning the matched ledger entry lets ``main()`` emit sanitized+ decision evidence — structured identity fields only, never argv, which+ can carry tokens or private endpoints (#98350).+ """try:from hermes_cli.update_cmd import _hermes_holder_subcommand # noqa: PLC0415purpose = _hermes_holder_subcommand(cmdline)except Exception:- return False+ return Noneif purpose not in ("serve", "dashboard"):- return False+ return Nonetry:from hermes_cli.process_identity import ( # noqa: PLC0415ledger_entries,@@ -281,19 +292,40 @@ def _is_updater_owned_backend(pid: int, cmdline: str) -> bool:entries = ledger_entries()except Exception:- return False+ return Nonefor entry in entries:if entry.get("pid") != pid:continueif entry.get("purpose") not in ("serve", "dashboard"):- return False+ return Nonedead = spawner_is_dead(entry)if dead is not False:# Spawner dead, unrecorded, or unprovable-but-registered: the# updater's ledger rungs own this holder (reap or stop+relaunch).- return True- return _spawner_is_this_handoff_desktop(entry)- return False+ return entry+ if _spawner_is_this_handoff_desktop(entry):+ return entry+ return None+ return None+++def _deferred_backend_evidence(entries: list[dict]) -> list[dict]:+ """Sanitized decision evidence for deferred serve/dashboard backends.++ Structured ledger fields only — pid, purpose, recorded port — never the+ command line, which can carry tokens or private endpoints. Lets the+ scan result explain *why* a holder disappeared from ``processes``+ without echoing argv (#98350).+ """+ evidence = []+ for entry in entries:+ pid = entry.get("pid")+ if not isinstance(pid, int):+ continue+ evidence.append(+ {"pid": pid, "purpose": entry.get("purpose"), "port": entry.get("port")}+ )+ return evidencedef _spawner_is_this_handoff_desktop(entry: dict) -> bool:@@ -337,16 +369,17 @@ def main() -> None:processes = []exempted_gateways = 0- deferred_backends = 0+ deferred_entries: list[dict] = []for pid, name, cmdline in matches:if _is_pausable_gateway(cmdline):exempted_gateways += 1continue- if _is_updater_owned_backend(pid, cmdline):+ deferred_entry = _updater_owned_backend_entry(pid, cmdline)+ if deferred_entry is not None:# Ledger-verified serve/dashboard backend the CLI updater's own# rungs stop (and relaunch) downstream — reporting it here would# dead-end the hand-off before that machinery can run (#98336).- deferred_backends += 1+ deferred_entries.append(deferred_entry)continueprocess = {"pid": pid,@@ -368,7 +401,10 @@ def main() -> None:"pausable_gateways": exempted_gateways,# Diagnostic only: ledger-verified serve/dashboard backends deferred# to the updater's stop/relaunch rungs (#98336).- "deferred_backends": deferred_backends,+ "deferred_backends": len(deferred_entries),+ # Diagnostic only: sanitized evidence (structured ledger identity,+ # never argv) explaining which holders the deferral consumed (#98350).+ "deferred_backend_evidence": _deferred_backend_evidence(deferred_entries),}print(json.dumps(data))sys.exit(0)diff --git a/tests/hermes_cli/test_scan_venv_blockers.py b/tests/hermes_cli/test_scan_venv_blockers.pyindex ac81ca82127..2af75159c7a 100644--- a/tests/hermes_cli/test_scan_venv_blockers.py+++ b/tests/hermes_cli/test_scan_venv_blockers.py@@ -363,13 +363,21 @@ def test_updater_owned_backend_dead_spawner_is_deferred(monkeypatch, capsys):orphan `_ledger_reapable_backend_pids` reaps — the scan must defer itinstead of dead-ending the hand-off (#98336)."""_patch_ledger(- monkeypatch, [{"pid": 78, "purpose": "serve", "spawner_pid": 4242}], dead=True+ monkeypatch,+ [{"pid": 78, "purpose": "serve", "spawner_pid": 4242, "port": 9119}],+ dead=True,)code, data = _run_main_with_detector(monkeypatch, capsys, [(78, "python.exe", _SERVE_CMD)])assert code == 0assert data["blocked"] is Falseassert data["processes"] == []assert data["deferred_backends"] == 1+ # Sanitized decision evidence (#98350): structured ledger identity only —+ # the deferral must explain itself without echoing the command line.+ assert data["deferred_backend_evidence"] == [+ {"pid": 78, "purpose": "serve", "port": 9119}+ ]+ assert "--host" not in json.dumps(data["deferred_backend_evidence"])def test_updater_owned_backend_unrecorded_spawner_is_deferred(monkeypatch, capsys):