feat: prepare zero-mutation Telegram Leo chain proof

This commit is contained in:
twentyOne2x 2026-07-15 03:37:39 +02:00
parent 15c30f1fbe
commit dfa6be6ba0
14 changed files with 2576 additions and 0 deletions

View file

@ -0,0 +1,135 @@
{
"authorization_gate_status": "ready_to_request_exact_authorization",
"checks": {
"authenticated_chrome_is_only_send_transport": true,
"exact_prompts_imported_from_handler_verifier": true,
"exact_three_turn_sequence": true,
"first_prompt_supplies_no_row_id": true,
"handler_checks_all_pass": true,
"handler_outcomes_all_pass": true,
"handler_prompt_ids_exact": true,
"handler_proved_no_telegram_post": true,
"handler_proved_read_only_tool_traces": true,
"handler_proved_unchanged_fingerprint": true,
"handler_receipt_passed": true,
"handler_receipt_schema_supported": true,
"handler_safety_gate_passed": true,
"handler_tier_remains_below_telegram_visible": true,
"packet_does_not_mutate_database": true,
"packet_does_not_send": true
},
"claim_ceiling": {
"current_tier": "T0_spec_plus_prior_T2_handler_evidence",
"not_proven": [
"Telegram-visible delivery of these three messages",
"Telegram-visible replies from Leo",
"post-send canonical fingerprint equality"
],
"proven": "The exact three-turn Chrome send packet is bound to a passing no-send handler receipt.",
"required_tier": "T3_live_readonly"
},
"clear_CTA": "Reply with the exact authorization sentence in this packet. That sentence names the destination, transport, complete message bodies, ordering, evidence, and no-mutation boundary.",
"exact_messages": [
{
"dimension": "independent_weak_claim_selection",
"message": "Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet.",
"message_sha256": "c63838b98448f4f4599e4cf2b004c6b36f602ad0d25c92e442a6f866cd2740fc",
"prompt_id": "OOS-CHAIN-01",
"sequence": 1,
"wait_for_visible_reply_before_next": true
},
{
"dimension": "challenge_body_evidence_and_candidates",
"message": "That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge.",
"message_sha256": "73346a98db4d7f74b49e1a5741b323d4216fd21f8346f6c4a4a69b1a6dd07946",
"prompt_id": "OOS-CHAIN-02",
"sequence": 2,
"wait_for_visible_reply_before_next": true
},
{
"dimension": "user_objection_revision_and_apply_boundary",
"message": "I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo.",
"message_sha256": "5f6b32b2c8c51cc594242ed9bdac849c744156ca2395efb7e8593c83c86286d4",
"prompt_id": "OOS-CHAIN-03",
"sequence": 3,
"wait_for_visible_reply_before_next": true
}
],
"expected_proof_paths_after_authorized_run": {
"capture_json": "outputs/telegram-visible-unseen-chain-20260715/capture.json",
"capture_receipt_json": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-capture-receipt-current.json",
"final_accessibility": "outputs/telegram-visible-unseen-chain-20260715/final-accessibility.txt",
"final_screenshot": "outputs/telegram-visible-unseen-chain-20260715/final.png",
"postflight_json": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-postflight-current.json",
"preflight_json": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-preflight-current.json",
"turn_accessibility": [
"outputs/telegram-visible-unseen-chain-20260715/turn-1-accessibility.txt",
"outputs/telegram-visible-unseen-chain-20260715/turn-2-accessibility.txt",
"outputs/telegram-visible-unseen-chain-20260715/turn-3-accessibility.txt"
],
"turn_screenshots": [
"outputs/telegram-visible-unseen-chain-20260715/turn-1.png",
"outputs/telegram-visible-unseen-chain-20260715/turn-2.png",
"outputs/telegram-visible-unseen-chain-20260715/turn-3.png"
]
},
"explicit_operator_authorization_text": "I authorize Codex to use the already-authenticated Chrome Telegram UI to send exactly these three messages, in order and with no additional messages, to the Telegram group Leo (chat ID -5146042086), waiting for Leo's visible reply after each turn: [OOS-CHAIN-01] \"Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet.\" [OOS-CHAIN-02] \"That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge.\" [OOS-CHAIN-03] \"I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo.\" Capture the visible replies, message IDs, timestamps, screenshot and accessibility evidence; perform only read-only DB/service readbacks; do not use the Bot API; do not stage, approve, apply, or otherwise mutate knowledge.",
"generated_at_utc": "2026-07-15T01:32:53.837725+00:00",
"handler_receipt_binding": {
"deployed_git_head": "b3aa184dd4c721f6c40dc813dcefd5930f8ed417",
"fingerprint_sha256": "32a1f2c18f4b4c623443cbd4d9520982e9f291ec74ca63855cef51c88ac56f24",
"path": "docs/reports/leo-working-state-20260709/leo-unseen-reasoning-chain-canary-current.json",
"proof_tier": "live_vps_gatewayrunner_temp_profile_no_telegram_post_no_apply",
"remote_run_id": "d5702cafbb0b",
"schema": "livingip.leoUnseenReasoningChainReceipt.v2",
"sha256": "f4fcf0207484e5322074c7838f3a345d421c1664e5dc8d73b9199c4475b4cee8"
},
"mode": "telegram_visible_unseen_chain_exact_packet_not_sent",
"mutates_db": false,
"next_non_user_action_after_authorization": [
"Re-run the zero-mutation preflight and confirm its packet file hash is current.",
"Use authenticated Chrome only and verify the Leo chat ID before typing anything.",
"Send one exact message, wait for Leo's visible reply, then continue to the next exact message.",
"Capture message IDs, timestamps, screenshot, and accessibility text without copying handler output.",
"Extract the selected DB object reference and run the read-only postflight with that reference.",
"Run the Telegram-visible verifier and accept T3 only if every visible and state check passes."
],
"packet_generation_git_sha": "a47415b60ef059ecc55e067ae556f49d818dc68d",
"production_apply_executed": false,
"protocol_sha256": "c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da",
"ready_to_request_action_time_authorization": true,
"schema": "livingip.telegramVisibleUnseenChainPacket.v1",
"target": {
"allowed_transport": "authenticated_chrome_telegram_ui",
"chat_id": "-5146042086",
"chat_label": "Leo",
"expected_prompt_ids": [
"OOS-CHAIN-01",
"OOS-CHAIN-02",
"OOS-CHAIN-03"
],
"forbidden_transports": [
"telegram_bot_api",
"copied_transcript",
"handler_substitution"
],
"message_count": 3,
"platform": "telegram"
},
"telegram_visible_message_authorization_present": false,
"telegram_visible_messages_sent": false,
"tooling_binding": {
"capture_verifier": {
"path": "scripts/verify_telegram_visible_unseen_chain.py",
"sha256": "4eb3eb8799282d07689a39d21a608cfbb90568db56f3d0c9c8b3430e0c3024e9"
},
"packet_builder": {
"path": "scripts/build_telegram_visible_unseen_chain_packet.py",
"sha256": "623452bbd577f3576b38412f3578cbe341d4c310b6e9657b1b9874588e38e4a0"
},
"state_collector": {
"path": "scripts/collect_telegram_visible_unseen_chain_state.py",
"sha256": "4fa5174e79ec8f5224e42c4e3d01f5df019a17073275d51e32e1a57a06be481d"
}
}
}

View file

@ -0,0 +1,64 @@
# Telegram-Visible Unseen Chain Authorization Packet
Generated UTC: `2026-07-15T01:32:53.837725+00:00`
Protocol SHA256: `c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da`
Ready to request action-time authorization: `True`
Telegram-visible messages sent: `False`
Mutates DB: `False`
## Exact Destination
- Chat: `Leo` (`-5146042086`)
- Transport: `authenticated_chrome_telegram_ui`
## Exact Messages
### 1. OOS-CHAIN-01
Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet.
SHA256: `c63838b98448f4f4599e4cf2b004c6b36f602ad0d25c92e442a6f866cd2740fc`
### 2. OOS-CHAIN-02
That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge.
SHA256: `73346a98db4d7f74b49e1a5741b323d4216fd21f8346f6c4a4a69b1a6dd07946`
### 3. OOS-CHAIN-03
I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo.
SHA256: `5f6b32b2c8c51cc594242ed9bdac849c744156ca2395efb7e8593c83c86286d4`
## Checks
- `authenticated_chrome_is_only_send_transport`: `True`
- `exact_prompts_imported_from_handler_verifier`: `True`
- `exact_three_turn_sequence`: `True`
- `first_prompt_supplies_no_row_id`: `True`
- `handler_checks_all_pass`: `True`
- `handler_outcomes_all_pass`: `True`
- `handler_prompt_ids_exact`: `True`
- `handler_proved_no_telegram_post`: `True`
- `handler_proved_read_only_tool_traces`: `True`
- `handler_proved_unchanged_fingerprint`: `True`
- `handler_receipt_passed`: `True`
- `handler_receipt_schema_supported`: `True`
- `handler_safety_gate_passed`: `True`
- `handler_tier_remains_below_telegram_visible`: `True`
- `packet_does_not_mutate_database`: `True`
- `packet_does_not_send`: `True`
## Exact Action-Time Authorization
I authorize Codex to use the already-authenticated Chrome Telegram UI to send exactly these three messages, in order and with no additional messages, to the Telegram group Leo (chat ID -5146042086), waiting for Leo's visible reply after each turn: [OOS-CHAIN-01] "Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet." [OOS-CHAIN-02] "That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge." [OOS-CHAIN-03] "I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo." Capture the visible replies, message IDs, timestamps, screenshot and accessibility evidence; perform only read-only DB/service readbacks; do not use the Bot API; do not stage, approve, apply, or otherwise mutate knowledge.
## Clear CTA
Reply with the exact authorization sentence in this packet. That sentence names the destination, transport, complete message bodies, ordering, evidence, and no-mutation boundary.
## Claim Ceiling
Current tier: `T0_spec_plus_prior_T2_handler_evidence`
Required tier: `T3_live_readonly`

View file

@ -0,0 +1,84 @@
{
"capture_template": {
"capture_source": {
"captured_at_utc": "",
"captured_by": "",
"chat_id": "-5146042086",
"chat_label": "Leo",
"final_accessibility": "",
"final_screenshot": "",
"platform": "telegram",
"transport": "authenticated_chrome_telegram_ui"
},
"extra_messages_sent": 0,
"messages": [
{
"prompt_id": "OOS-CHAIN-01",
"reply": "",
"reply_at_utc": "",
"reply_message_id": "",
"sent_at_utc": "",
"sent_text": "Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet.",
"sequence": 1,
"telegram_message_id": "",
"turn_accessibility": "",
"turn_screenshot": ""
},
{
"prompt_id": "OOS-CHAIN-02",
"reply": "",
"reply_at_utc": "",
"reply_message_id": "",
"sent_at_utc": "",
"sent_text": "That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge.",
"sequence": 2,
"telegram_message_id": "",
"turn_accessibility": "",
"turn_screenshot": ""
},
{
"prompt_id": "OOS-CHAIN-03",
"reply": "",
"reply_at_utc": "",
"reply_message_id": "",
"sent_at_utc": "",
"sent_text": "I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo.",
"sequence": 3,
"telegram_message_id": "",
"turn_accessibility": "",
"turn_screenshot": ""
}
],
"operator_authorization_captured_at_utc": "",
"operator_authorization_text": "I authorize Codex to use the already-authenticated Chrome Telegram UI to send exactly these three messages, in order and with no additional messages, to the Telegram group Leo (chat ID -5146042086), waiting for Leo's visible reply after each turn: [OOS-CHAIN-01] \"Looking at what Leo currently believes about collective intelligence or coordination, pick one claim that would matter to a founder making a product decision but seems more confident than its support. Do not ask me for an ID. Show what the database actually says and what supports it, then tell me the first narrower claim you would test. Do not change anything yet.\" [OOS-CHAIN-02] \"That still feels like you are polishing the same idea. Inspect the exact body and evidence you just chose: what is assumption versus observed support, what would falsify it, and which replacement claim or claims would you put into review? Keep them as proposals, not live knowledge.\" [OOS-CHAIN-03] \"I disagree with your first replacement because it jumps from a mechanism to a business outcome. Revise it with that objection, tell me what source would resolve the disagreement, and show the approval and apply boundary before it could become part of Leo.\" Capture the visible replies, message IDs, timestamps, screenshot and accessibility evidence; perform only read-only DB/service readbacks; do not use the Bot API; do not stage, approve, apply, or otherwise mutate knowledge.",
"preflight_state_token_sha256": "a0af7235b62f88a009184f8f51b6de4b9aec008f6d93ebfa1458f9b77fc208ec",
"protocol_sha256": "c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da"
},
"checks": {
"action_time_authorization_present": false,
"capture_present": false,
"packet_ready": true,
"postflight_present": false,
"preflight_passed": true
},
"claim_ceiling": {
"not_proven": [
"Telegram-visible message delivery",
"Telegram-visible Leo replies",
"post-send fingerprint equality"
],
"proven": "The exact packet and live zero-mutation preflight are ready."
},
"current_tier": "T0_packet_plus_T3_preflight",
"generated_at_utc": "2026-07-15T01:33:10.948040+00:00",
"mode": "telegram_visible_unseen_chain_capture_verifier",
"mutates_db": false,
"packet_path": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-authorization-packet-current.json",
"postflight_path": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-postflight-current.json",
"preflight_path": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-preflight-current.json",
"receipt_ready": false,
"required_tier": "T3_live_readonly",
"schema": "livingip.telegramVisibleUnseenChainReceipt.v1",
"status": "awaiting_action_time_authorization",
"telegram_visible_messages_sent": false
}

View file

@ -0,0 +1,25 @@
# Telegram-Visible Unseen Chain Capture Receipt
Generated UTC: `2026-07-15T01:33:10.948040+00:00`
Status: `awaiting_action_time_authorization`
Receipt ready: `False`
Current tier: `T0_packet_plus_T3_preflight`
Required tier: `T3_live_readonly`
Telegram-visible messages sent: `False`
Mutates DB: `False`
## Checks
- `action_time_authorization_present`: `False`
- `capture_present`: `False`
- `packet_ready`: `True`
- `postflight_present`: `False`
- `preflight_passed`: `True`
## Awaiting Authorized Capture
The packet and preflight are ready. No Telegram message has been sent by this verifier.
## Claim Ceiling
The exact packet and live zero-mutation preflight are ready.

View file

@ -0,0 +1,21 @@
{
"fallback_goal_path": "goal.md",
"generated_at_utc": "2026-07-15T01:26:37Z",
"platform_goal_after": {
"objective": "Complete and verify the Telegram-visible unseen challenge-to-revision canary defined in this goal file while proving zero database mutation.",
"status": "active",
"thread_id": "019f6350-3350-7040-b223-c5c22673fece"
},
"platform_goal_before": null,
"platform_goal_current": {
"objective": "Complete and verify the Telegram-visible unseen challenge-to-revision canary defined in this goal file while proving zero database mutation.",
"status": "active",
"thread_id": "019f6350-3350-7040-b223-c5c22673fece",
"time_used_seconds_at_readback": 1116,
"tokens_used_at_readback": 211127
},
"platform_goal_repair_action": "create_goal",
"platform_goal_replaced": false,
"schema": "livingip.telegramVisibleUnseenChainGoalReadback.v1",
"why_not_replaced": "No active platform Goal existed, so the canonical Goal was created rather than replaced."
}

View file

@ -0,0 +1,62 @@
{
"cleanup_readback": {
"collector_or_verifier_processes_remaining": [],
"status": "clean"
},
"generated_at_utc": "2026-07-15T01:37:18Z",
"live_preflight": {
"canonical_fingerprint_sha256": "32a1f2c18f4b4c623443cbd4d9520982e9f291ec74ca63855cef51c88ac56f24",
"canonical_fingerprint_unchanged_across_two_snapshots": true,
"deployed_git_stamp": "15c30f1fbe30c8f2295ddc33e293a45788a95706",
"gateway_main_pid": "347406",
"gateway_restarts": "0",
"mutates_db": false,
"path": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-preflight-current.json",
"packet_file_sha256": "fb0ab4af0396b2064efce1ead44aacc0465ee0e3eacf9b4a7c07abae044d217a",
"protocol_sha256": "c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da",
"readback_attempts": {
"deploy": 1,
"fingerprint_after": 1,
"fingerprint_before": 1,
"service_after": 1,
"service_before": 1
},
"state_token_sha256": "a0af7235b62f88a009184f8f51b6de4b9aec008f6d93ebfa1458f9b77fc208ec",
"tooling_hashes_match_current_sources": true,
"status": "pass",
"table_count": 39,
"total_rows": 52167
},
"not_tested": [
"Telegram message delivery",
"Telegram-visible Leo replies",
"post-send selected-object readback",
"post-send canonical fingerprint equality"
],
"proof_paths": [
"docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-authorization-packet-current.json",
"docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-preflight-current.json",
"docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-capture-receipt-current.json",
"docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-goal-readback-current.json"
],
"schema": "livingip.telegramVisibleUnseenChainNonsendProof.v1",
"send_boundary": {
"action_time_authorization_present": false,
"authenticated_chrome_used": false,
"telegram_visible_messages_sent": false
},
"tests": [
{
"command": "/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/work/teleo-infra-main/.venv/bin/pytest -q tests/test_verify_leo_unseen_reasoning_chain.py tests/test_build_telegram_visible_unseen_chain_packet.py tests/test_collect_telegram_visible_unseen_chain_state.py tests/test_verify_telegram_visible_unseen_chain.py",
"result": "24 passed in 0.16s"
},
{
"command": "/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/work/teleo-infra-main/.venv/bin/pytest -q",
"result": "1293 passed in 102.03s"
},
{
"command": "/Users/user/Documents/Codex/2026-07-09/019f34eb-d297-72d0-b7e2-b222d5515ab9-load/work/teleo-infra-main/.venv/bin/ruff check <new scripts and tests>",
"result": "All checks passed"
}
]
}

View file

@ -0,0 +1,115 @@
{
"baseline_checks": {},
"baseline_path": "",
"blocker_readback": {
"attempted_routes": [
"local exact packet validation",
"SSH deploy stamp and gateway service readback",
"two canonical repeatable-read read-only Postgres parity manifests"
],
"clear_CTA": "Use the packet's exact authorization sentence only when ready to cross the send boundary.",
"current_canary": "Read-only pre-send readiness for the exact three-turn unseen Leo chain in Telegram",
"exact_gate": "",
"next_non_user_action": "Run the authenticated-Chrome three-turn flow only after exact authorization, then collect postflight."
},
"claim_ceiling": {
"current_tier": "T3_live_readonly",
"not_proven": [
"Telegram-visible delivery or reply behavior",
"authorization to send Telegram messages",
"canonical mutation"
],
"proven": "Two canonical read-only snapshots and the gateway process were unchanged during this probe."
},
"generated_at_utc": "2026-07-15T01:33:10.551000+00:00",
"mode": "telegram_visible_unseen_chain_zero_mutation_state_readback",
"mutates_db": false,
"packet_checks": {
"packet_does_not_mutate_db": true,
"packet_has_no_authorization_recorded": true,
"packet_messages_exact": true,
"packet_not_sent": true,
"packet_prompt_ids_exact": true,
"packet_protocol_sha256_present": true,
"packet_ready_for_authorization_request": true,
"packet_requires_authenticated_chrome": true,
"packet_schema_supported": true,
"packet_targets_exact_leo_chat": true,
"packet_tooling_hashes_match_current_sources": true
},
"packet_file_sha256": "fb0ab4af0396b2064efce1ead44aacc0465ee0e3eacf9b4a7c07abae044d217a",
"packet_path": "docs/reports/leo-working-state-20260709/telegram-visible-unseen-chain-authorization-packet-current.json",
"phase": "preflight",
"production_apply_executed": false,
"protocol_sha256": "c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da",
"ready_for_action_time_authorization": true,
"ready_for_visible_capture_verification": false,
"remote": {
"deploy_head": "15c30f1fbe30c8f2295ddc33e293a45788a95706",
"deploy_stamp_ancestor": true,
"fingerprint_after": {
"fingerprint_sha256": "32a1f2c18f4b4c623443cbd4d9520982e9f291ec74ca63855cef51c88ac56f24",
"schema": "livingip.teleoCanonicalDatabaseFingerprint.v1",
"status": "ok",
"structure_sha256": "61bf482330a652ebdb419de3fb78196f2c7d25d1a482b100f385e8102c8e8d52",
"table_count": 39,
"table_rows_sha256": "f50d86fc3ce699f602bdc0029485bd901fd98bd8114eecd5dcc4346a0f52112a",
"total_rows": 52167,
"transaction_read_only": "on"
},
"fingerprint_before": {
"fingerprint_sha256": "32a1f2c18f4b4c623443cbd4d9520982e9f291ec74ca63855cef51c88ac56f24",
"schema": "livingip.teleoCanonicalDatabaseFingerprint.v1",
"status": "ok",
"structure_sha256": "61bf482330a652ebdb419de3fb78196f2c7d25d1a482b100f385e8102c8e8d52",
"table_count": 39,
"table_rows_sha256": "f50d86fc3ce699f602bdc0029485bd901fd98bd8114eecd5dcc4346a0f52112a",
"total_rows": 52167,
"transaction_read_only": "on"
},
"last_deploy_sha": "15c30f1fbe30c8f2295ddc33e293a45788a95706",
"readback_attempts": {
"deploy": 1,
"fingerprint_after": 1,
"fingerprint_before": 1,
"service_after": 1,
"service_before": 1
},
"service_after": {
"ActiveState": "active",
"ExecMainStartTimestamp": "Tue 2026-07-14 22:59:43 UTC",
"MainPID": "347406",
"NRestarts": "0",
"SubState": "running"
},
"service_before": {
"ActiveState": "active",
"ExecMainStartTimestamp": "Tue 2026-07-14 22:59:43 UTC",
"MainPID": "347406",
"NRestarts": "0",
"SubState": "running"
},
"subject_readback": null,
"workspace_head_matches_deployed_stamp": true
},
"remote_checks": {
"canonical_fingerprint_unchanged_during_probe": true,
"deployed_stamp_is_ancestor_of_workspace_head": true,
"deployed_stamp_is_sha": true,
"fingerprints_are_read_only": true,
"first_fingerprint_complete": true,
"second_fingerprint_complete": true,
"service_active_before_and_after": true,
"service_identity_complete": true,
"service_process_unchanged_during_probe": true,
"ssh_readbacks_succeeded": true,
"workspace_head_is_sha": true
},
"remote_returncode": 0,
"remote_stderr": "",
"schema": "livingip.telegramVisibleUnseenChainState.v1",
"state_token_sha256": "a0af7235b62f88a009184f8f51b6de4b9aec008f6d93ebfa1458f9b77fc208ec",
"status": "pass",
"subject_ref": "",
"telegram_visible_messages_sent_by_collector": false
}

View file

@ -0,0 +1,49 @@
# Telegram-Visible Unseen Chain Preflight
Generated UTC: `2026-07-15T01:33:10.551000+00:00`
Status: `pass`
Protocol SHA256: `c815dad151d640335eecbddd2ca7bb651c43f6c1d4e53642e12c8a35157ac2da`
Packet file SHA256: `fb0ab4af0396b2064efce1ead44aacc0465ee0e3eacf9b4a7c07abae044d217a`
State token SHA256: `a0af7235b62f88a009184f8f51b6de4b9aec008f6d93ebfa1458f9b77fc208ec`
Messages sent by collector: `False`
Mutates DB: `False`
## Checks
- `packet_does_not_mutate_db`: `True`
- `packet_has_no_authorization_recorded`: `True`
- `packet_messages_exact`: `True`
- `packet_not_sent`: `True`
- `packet_prompt_ids_exact`: `True`
- `packet_protocol_sha256_present`: `True`
- `packet_ready_for_authorization_request`: `True`
- `packet_requires_authenticated_chrome`: `True`
- `packet_schema_supported`: `True`
- `packet_targets_exact_leo_chat`: `True`
- `packet_tooling_hashes_match_current_sources`: `True`
- `canonical_fingerprint_unchanged_during_probe`: `True`
- `deployed_stamp_is_ancestor_of_workspace_head`: `True`
- `deployed_stamp_is_sha`: `True`
- `fingerprints_are_read_only`: `True`
- `first_fingerprint_complete`: `True`
- `second_fingerprint_complete`: `True`
- `service_active_before_and_after`: `True`
- `service_identity_complete`: `True`
- `service_process_unchanged_during_probe`: `True`
- `ssh_readbacks_succeeded`: `True`
- `workspace_head_is_sha`: `True`
## Live Readback
- Deploy head: `15c30f1fbe30c8f2295ddc33e293a45788a95706`
- Deploy stamp: `15c30f1fbe30c8f2295ddc33e293a45788a95706`
- Gateway MainPID: `347406`
- Gateway NRestarts: `0`
- Canonical fingerprint: `32a1f2c18f4b4c623443cbd4d9520982e9f291ec74ca63855cef51c88ac56f24`
- Canonical tables: `39`
- Canonical rows: `52167`
- Selected object ref: ``
## Claim Ceiling
Two canonical read-only snapshots and the gateway process were unchanged during this probe.

View file

@ -0,0 +1,326 @@
#!/usr/bin/env python3
"""Build the exact no-send packet for Leo's unseen Telegram reasoning chain."""
from __future__ import annotations
import argparse
import hashlib
import json
import subprocess
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
try:
import verify_leo_unseen_reasoning_chain as unseen
except ImportError: # pragma: no cover - imported as scripts.* in tests
from scripts import verify_leo_unseen_reasoning_chain as unseen
SCHEMA = "livingip.telegramVisibleUnseenChainPacket.v1"
REPORT_DIR = Path("docs/reports/leo-working-state-20260709")
DEFAULT_HANDLER_RECEIPT = REPORT_DIR / "leo-unseen-reasoning-chain-canary-current.json"
DEFAULT_OUT = REPORT_DIR / "telegram-visible-unseen-chain-authorization-packet-current.json"
DEFAULT_MARKDOWN_OUT = REPORT_DIR / "telegram-visible-unseen-chain-authorization-packet-current.md"
DEFAULT_CAPTURE_RECEIPT = REPORT_DIR / "telegram-visible-unseen-chain-capture-receipt-current.json"
DEFAULT_PREFLIGHT = REPORT_DIR / "telegram-visible-unseen-chain-preflight-current.json"
DEFAULT_POSTFLIGHT = REPORT_DIR / "telegram-visible-unseen-chain-postflight-current.json"
DEFAULT_CHAT_ID = "-5146042086"
DEFAULT_CHAT_LABEL = "Leo"
DEFAULT_PROOF_DIR = "outputs/telegram-visible-unseen-chain-20260715"
TOOLING_PATHS = {
"packet_builder": Path("scripts/build_telegram_visible_unseen_chain_packet.py"),
"state_collector": Path("scripts/collect_telegram_visible_unseen_chain_state.py"),
"capture_verifier": Path("scripts/verify_telegram_visible_unseen_chain.py"),
}
def _load_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text(encoding="utf-8"))
def _sha256_bytes(value: bytes) -> str:
return hashlib.sha256(value).hexdigest()
def _sha256_file(path: Path) -> str:
return _sha256_bytes(path.read_bytes())
def _canonical_sha256(value: Any) -> str:
encoded = json.dumps(value, sort_keys=True, separators=(",", ":")).encode("utf-8")
return _sha256_bytes(encoded)
def current_git_sha(repo_root: Path = Path(".")) -> str:
proc = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=repo_root,
text=True,
capture_output=True,
check=False,
)
return proc.stdout.strip() if proc.returncode == 0 else ""
def exact_messages() -> list[dict[str, Any]]:
messages = []
for sequence, prompt in enumerate(unseen.PROMPTS, start=1):
message = str(prompt["message"])
messages.append(
{
"sequence": sequence,
"prompt_id": prompt["id"],
"dimension": prompt["dimension"],
"message": message,
"message_sha256": _sha256_bytes(message.encode("utf-8")),
"wait_for_visible_reply_before_next": True,
}
)
return messages
def tooling_binding(repo_root: Path = Path(".")) -> dict[str, dict[str, Any]]:
return {name: {"path": str(path), "sha256": _sha256_file(repo_root / path)} for name, path in TOOLING_PATHS.items()}
def _handler_checks(receipt: dict[str, Any]) -> dict[str, bool]:
safety = receipt.get("safety_gate") if isinstance(receipt.get("safety_gate"), dict) else {}
safety_checks = safety.get("checks") if isinstance(safety.get("checks"), dict) else {}
database = receipt.get("database") if isinstance(receipt.get("database"), dict) else {}
prompt_ids = [str(item["id"]) for item in unseen.PROMPTS]
return {
"handler_receipt_passed": receipt.get("status") == "pass",
"handler_receipt_schema_supported": receipt.get("schema") == unseen.SCHEMA,
"handler_prompt_ids_exact": receipt.get("prompt_ids") == prompt_ids,
"handler_outcomes_all_pass": bool(receipt.get("outcomes"))
and all(value is True for value in receipt.get("outcomes", {}).values()),
"handler_checks_all_pass": bool(receipt.get("checks"))
and all(value is True for value in receipt.get("checks", {}).values()),
"handler_safety_gate_passed": safety.get("status") == "pass",
"handler_proved_no_telegram_post": safety_checks.get("no_telegram_post") is True,
"handler_proved_read_only_tool_traces": safety_checks.get("all_tool_traces_read_only_and_bound") is True,
"handler_proved_unchanged_fingerprint": database.get("fingerprint_unchanged") is True
and isinstance(database.get("fingerprint_sha256"), str)
and len(database["fingerprint_sha256"]) == 64,
"handler_tier_remains_below_telegram_visible": "Telegram-visible message delivery"
in (receipt.get("claim_ceiling") or {}).get("not_proven", []),
}
def _authorization_text(*, chat_label: str, chat_id: str, messages: list[dict[str, Any]]) -> str:
quoted = " ".join(f"[{item['prompt_id']}] {json.dumps(item['message'], ensure_ascii=True)}" for item in messages)
return (
"I authorize Codex to use the already-authenticated Chrome Telegram UI to send exactly these three "
f"messages, in order and with no additional messages, to the Telegram group {chat_label} (chat ID "
f"{chat_id}), waiting for Leo's visible reply after each turn: {quoted} Capture the visible replies, "
"message IDs, timestamps, screenshot and accessibility evidence; perform only read-only DB/service "
"readbacks; do not use the Bot API; do not stage, approve, apply, or otherwise mutate knowledge."
)
def build_packet(
*,
handler_receipt_path: Path = DEFAULT_HANDLER_RECEIPT,
chat_id: str = DEFAULT_CHAT_ID,
chat_label: str = DEFAULT_CHAT_LABEL,
proof_dir: str = DEFAULT_PROOF_DIR,
git_sha: str | None = None,
) -> dict[str, Any]:
handler_receipt = _load_json(handler_receipt_path)
messages = exact_messages()
handler_checks = _handler_checks(handler_receipt)
target = {
"platform": "telegram",
"chat_label": chat_label,
"chat_id": chat_id,
"allowed_transport": "authenticated_chrome_telegram_ui",
"forbidden_transports": ["telegram_bot_api", "copied_transcript", "handler_substitution"],
"message_count": len(messages),
"expected_prompt_ids": [item["prompt_id"] for item in messages],
}
handler_binding = {
"path": str(handler_receipt_path),
"sha256": _sha256_file(handler_receipt_path),
"schema": handler_receipt.get("schema"),
"proof_tier": handler_receipt.get("proof_tier"),
"remote_run_id": handler_receipt.get("remote_run_id"),
"deployed_git_head": handler_receipt.get("deployed_git_head"),
"fingerprint_sha256": (handler_receipt.get("database") or {}).get("fingerprint_sha256"),
}
tooling = tooling_binding()
protocol = {
"target": target,
"exact_messages": messages,
"handler_binding": handler_binding,
"tooling_binding": tooling,
"state_contract": {
"preflight": "two identical repeatable-read read-only canonical fingerprints",
"postflight": "same canonical fingerprint plus independent selected-object readback",
"service": "same active gateway process before and after",
},
}
protocol_sha256 = _canonical_sha256(protocol)
checks = {
**handler_checks,
"exact_three_turn_sequence": len(messages) == 3 and [item["sequence"] for item in messages] == [1, 2, 3],
"exact_prompts_imported_from_handler_verifier": [item["message"] for item in messages]
== [item["message"] for item in unseen.PROMPTS],
"first_prompt_supplies_no_row_id": unseen.UUID_RE.search(messages[0]["message"]) is None,
"authenticated_chrome_is_only_send_transport": target["allowed_transport"]
== "authenticated_chrome_telegram_ui",
"packet_does_not_send": True,
"packet_does_not_mutate_database": True,
}
ready = all(checks.values())
authorization_text = _authorization_text(chat_label=chat_label, chat_id=chat_id, messages=messages)
proof_paths = {
"preflight_json": str(DEFAULT_PREFLIGHT),
"postflight_json": str(DEFAULT_POSTFLIGHT),
"capture_receipt_json": str(DEFAULT_CAPTURE_RECEIPT),
"capture_json": f"{proof_dir}/capture.json",
"turn_screenshots": [f"{proof_dir}/turn-{index}.png" for index in range(1, 4)],
"turn_accessibility": [f"{proof_dir}/turn-{index}-accessibility.txt" for index in range(1, 4)],
"final_screenshot": f"{proof_dir}/final.png",
"final_accessibility": f"{proof_dir}/final-accessibility.txt",
}
return {
"schema": SCHEMA,
"generated_at_utc": datetime.now(timezone.utc).isoformat(),
"mode": "telegram_visible_unseen_chain_exact_packet_not_sent",
"packet_generation_git_sha": git_sha if git_sha is not None else current_git_sha(),
"protocol_sha256": protocol_sha256,
"ready_to_request_action_time_authorization": ready,
"authorization_gate_status": "ready_to_request_exact_authorization" if ready else "not_ready",
"telegram_visible_messages_sent": False,
"telegram_visible_message_authorization_present": False,
"production_apply_executed": False,
"mutates_db": False,
"target": target,
"exact_messages": messages,
"handler_receipt_binding": handler_binding,
"tooling_binding": tooling,
"checks": checks,
"expected_proof_paths_after_authorized_run": proof_paths,
"explicit_operator_authorization_text": authorization_text,
"clear_CTA": (
"Reply with the exact authorization sentence in this packet. That sentence names the destination, "
"transport, complete message bodies, ordering, evidence, and no-mutation boundary."
),
"next_non_user_action_after_authorization": [
"Re-run the zero-mutation preflight and confirm its packet file hash is current.",
"Use authenticated Chrome only and verify the Leo chat ID before typing anything.",
"Send one exact message, wait for Leo's visible reply, then continue to the next exact message.",
"Capture message IDs, timestamps, screenshot, and accessibility text without copying handler output.",
"Extract the selected DB object reference and run the read-only postflight with that reference.",
"Run the Telegram-visible verifier and accept T3 only if every visible and state check passes.",
],
"claim_ceiling": {
"current_tier": "T0_spec_plus_prior_T2_handler_evidence",
"required_tier": "T3_live_readonly",
"proven": "The exact three-turn Chrome send packet is bound to a passing no-send handler receipt.",
"not_proven": [
"Telegram-visible delivery of these three messages",
"Telegram-visible replies from Leo",
"post-send canonical fingerprint equality",
],
},
}
def write_json(path: Path, data: dict[str, Any]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
def write_markdown(path: Path, data: dict[str, Any]) -> None:
target = data["target"]
lines = [
"# Telegram-Visible Unseen Chain Authorization Packet",
"",
f"Generated UTC: `{data['generated_at_utc']}`",
f"Protocol SHA256: `{data['protocol_sha256']}`",
f"Ready to request action-time authorization: `{data['ready_to_request_action_time_authorization']}`",
f"Telegram-visible messages sent: `{data['telegram_visible_messages_sent']}`",
f"Mutates DB: `{data['mutates_db']}`",
"",
"## Exact Destination",
"",
f"- Chat: `{target['chat_label']}` (`{target['chat_id']}`)",
f"- Transport: `{target['allowed_transport']}`",
"",
"## Exact Messages",
"",
]
for item in data["exact_messages"]:
lines.extend(
[
f"### {item['sequence']}. {item['prompt_id']}",
"",
item["message"],
"",
f"SHA256: `{item['message_sha256']}`",
"",
]
)
lines.extend(["## Checks", ""])
lines.extend(f"- `{key}`: `{value}`" for key, value in sorted(data["checks"].items()))
lines.extend(
[
"",
"## Exact Action-Time Authorization",
"",
data["explicit_operator_authorization_text"],
"",
"## Clear CTA",
"",
data["clear_CTA"],
"",
"## Claim Ceiling",
"",
f"Current tier: `{data['claim_ceiling']['current_tier']}`",
f"Required tier: `{data['claim_ceiling']['required_tier']}`",
"",
]
)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("\n".join(lines), encoding="utf-8")
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--handler-receipt", type=Path, default=DEFAULT_HANDLER_RECEIPT)
parser.add_argument("--chat-id", default=DEFAULT_CHAT_ID)
parser.add_argument("--chat-label", default=DEFAULT_CHAT_LABEL)
parser.add_argument("--proof-dir", default=DEFAULT_PROOF_DIR)
parser.add_argument("--out", type=Path, default=DEFAULT_OUT)
parser.add_argument("--markdown-out", type=Path, default=DEFAULT_MARKDOWN_OUT)
return parser.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
data = build_packet(
handler_receipt_path=args.handler_receipt,
chat_id=args.chat_id,
chat_label=args.chat_label,
proof_dir=args.proof_dir,
)
write_json(args.out, data)
write_markdown(args.markdown_out, data)
print(
json.dumps(
{
"out": str(args.out),
"markdown_out": str(args.markdown_out),
"ready_to_request_action_time_authorization": data["ready_to_request_action_time_authorization"],
"telegram_visible_messages_sent": False,
},
indent=2,
sort_keys=True,
)
)
return 0 if data["ready_to_request_action_time_authorization"] else 2
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,616 @@
#!/usr/bin/env python3
"""Collect fail-closed read-only state for the unseen Telegram chain."""
from __future__ import annotations
import argparse
import hashlib
import json
import re
import shlex
import subprocess
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
try:
import build_telegram_visible_unseen_chain_packet as packet_builder
import verify_leo_unseen_reasoning_chain as unseen
except ImportError: # pragma: no cover - imported as scripts.* in tests
from scripts import build_telegram_visible_unseen_chain_packet as packet_builder
from scripts import verify_leo_unseen_reasoning_chain as unseen
SCHEMA = "livingip.telegramVisibleUnseenChainState.v1"
REPORT_DIR = Path("docs/reports/leo-working-state-20260709")
DEFAULT_PACKET = packet_builder.DEFAULT_OUT
DEFAULT_PREFLIGHT_OUT = REPORT_DIR / "telegram-visible-unseen-chain-preflight-current.json"
DEFAULT_PREFLIGHT_MARKDOWN_OUT = REPORT_DIR / "telegram-visible-unseen-chain-preflight-current.md"
DEFAULT_POSTFLIGHT_OUT = REPORT_DIR / "telegram-visible-unseen-chain-postflight-current.json"
DEFAULT_POSTFLIGHT_MARKDOWN_OUT = REPORT_DIR / "telegram-visible-unseen-chain-postflight-current.md"
DEFAULT_SSH_TARGET = "root@77.42.65.182"
DEFAULT_SSH_KEY = Path.home() / ".ssh/livingip_hetzner_20260604_ed25519"
DEFAULT_MANIFEST_SQL = Path("ops/postgres_parity_manifest.sql")
REMOTE_REPO = "/opt/teleo-eval/workspaces/deploy-infra"
SUBJECT_REF_RE = re.compile(
r"^(?:[0-9a-f]{8}|[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})$",
re.IGNORECASE,
)
SHA40_RE = re.compile(r"^[0-9a-f]{40}$")
@dataclass(frozen=True)
class CommandResult:
returncode: int
stdout: str
stderr: str
Runner = Callable[[list[str], str, int], CommandResult]
def subprocess_runner(command: list[str], input_text: str, timeout: int) -> CommandResult:
try:
proc = subprocess.run(
command,
input=input_text,
text=True,
capture_output=True,
timeout=timeout,
check=False,
)
except subprocess.TimeoutExpired as exc:
return CommandResult(124, str(exc.stdout or ""), f"command timed out after {timeout}s")
return CommandResult(proc.returncode, proc.stdout, proc.stderr)
def _load_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text(encoding="utf-8"))
def _canonical_sha256(value: Any) -> str:
encoded = json.dumps(value, sort_keys=True, separators=(",", ":")).encode("utf-8")
return hashlib.sha256(encoded).hexdigest()
def _sha256_file(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def parse_key_value_lines(text: str) -> dict[str, str]:
values: dict[str, str] = {}
for line in text.splitlines():
if "=" not in line:
continue
key, value = line.split("=", 1)
values[key] = value.strip()
return values
def parse_manifest_output(raw: str) -> dict[str, Any]:
rows = []
try:
for line in raw.splitlines():
candidate = line.strip()
if not candidate or candidate in {"BEGIN", "SET", "ROLLBACK"}:
continue
value = json.loads(candidate)
if isinstance(value, dict):
rows.append(value)
except (TypeError, json.JSONDecodeError) as exc:
return {"status": "error", "error": f"manifest_parse_error:{type(exc).__name__}"}
tables = {
f"{row['schema']}.{row['table']}": {
"row_count": int(row["row_count"]),
"rowset_md5": row["rowset_md5"],
}
for row in rows
if row.get("kind") == "table"
}
singleton_kinds = {
"schemas",
"extensions",
"application_roles",
"columns",
"constraints",
"indexes",
"sequences",
"views",
"functions",
"triggers",
"types",
"policies",
}
singleton = {str(row["kind"]): row.get("items", []) for row in rows if row.get("kind") in singleton_kinds}
identity_rows = [row for row in rows if row.get("kind") == "identity"]
if len(identity_rows) != 1 or not tables or singleton_kinds - set(singleton):
return {"status": "error", "error": "canonical_database_fingerprint_manifest_incomplete"}
identity = identity_rows[0]
stable = {
"identity": {
key: identity.get(key)
for key in (
"database",
"server_version_num",
"server_encoding",
"database_collation",
"database_ctype",
"transaction_read_only",
)
},
"singleton_sha256": {key: _canonical_sha256(value) for key, value in sorted(singleton.items())},
"tables": tables,
}
return {
"schema": "livingip.teleoCanonicalDatabaseFingerprint.v1",
"status": "ok",
"fingerprint_sha256": _canonical_sha256(stable),
"table_count": len(tables),
"total_rows": sum(item["row_count"] for item in tables.values()),
"table_rows_sha256": _canonical_sha256(tables),
"structure_sha256": _canonical_sha256(stable["singleton_sha256"]),
"transaction_read_only": identity.get("transaction_read_only"),
}
def packet_checks(packet: dict[str, Any]) -> dict[str, bool]:
target = packet.get("target") if isinstance(packet.get("target"), dict) else {}
exact = packet_builder.exact_messages()
expected_tooling = packet_builder.tooling_binding()
return {
"packet_schema_supported": packet.get("schema") == packet_builder.SCHEMA,
"packet_ready_for_authorization_request": packet.get("ready_to_request_action_time_authorization") is True,
"packet_not_sent": packet.get("telegram_visible_messages_sent") is False,
"packet_has_no_authorization_recorded": packet.get("telegram_visible_message_authorization_present") is False,
"packet_does_not_mutate_db": packet.get("mutates_db") is False,
"packet_targets_exact_leo_chat": target.get("chat_label") == packet_builder.DEFAULT_CHAT_LABEL
and target.get("chat_id") == packet_builder.DEFAULT_CHAT_ID,
"packet_requires_authenticated_chrome": target.get("allowed_transport") == "authenticated_chrome_telegram_ui",
"packet_prompt_ids_exact": target.get("expected_prompt_ids") == [item["id"] for item in unseen.PROMPTS],
"packet_messages_exact": [item.get("message") for item in packet.get("exact_messages", [])]
== [item["message"] for item in exact],
"packet_protocol_sha256_present": isinstance(packet.get("protocol_sha256"), str)
and len(packet["protocol_sha256"]) == 64,
"packet_tooling_hashes_match_current_sources": packet.get("tooling_binding") == expected_tooling,
}
def ssh_command(args: argparse.Namespace, remote_command: str) -> list[str]:
return [
"ssh",
"-i",
str(args.ssh_key),
"-o",
"BatchMode=yes",
"-o",
"StrictHostKeyChecking=accept-new",
"-o",
f"ConnectTimeout={args.connect_timeout}",
args.ssh_target,
remote_command,
]
def deploy_readback_command() -> str:
repo = shlex.quote(REMOTE_REPO)
return (
f"cd {repo} && "
"deploy_head=$(git rev-parse HEAD) && "
"last_deploy_sha=$(cat /opt/teleo-eval/.last-deploy-sha) && "
'printf \'deploy_head=%s\\nlast_deploy_sha=%s\\n\' "$deploy_head" "$last_deploy_sha" && '
'if git merge-base --is-ancestor "$last_deploy_sha" "$deploy_head"; then '
"printf 'deploy_stamp_ancestor=true\\n'; else printf 'deploy_stamp_ancestor=false\\n'; fi"
)
def service_readback_command() -> str:
return (
"systemctl show leoclean-gateway.service "
"-p ActiveState -p SubState -p MainPID -p NRestarts -p ExecMainStartTimestamp --no-pager"
)
def fingerprint_readback_command() -> str:
return "docker exec -i teleo-pg psql -U postgres -d teleo -At -q -v ON_ERROR_STOP=1"
def subject_readback_sql(subject_ref: str) -> str:
if not SUBJECT_REF_RE.fullmatch(subject_ref):
raise ValueError("subject_ref must be an eight-hex prefix or UUID")
prefix = subject_ref.casefold()
return f"""
\\set ON_ERROR_STOP on
begin transaction isolation level repeatable read read only;
select jsonb_build_object(
'subject_ref', '{prefix}',
'matches', coalesce(jsonb_agg(item order by item->>'table', item->'row'->>'id'), '[]'::jsonb)
)::text
from (
select jsonb_build_object(
'table', 'public.claims',
'row', to_jsonb(claim_row),
'evidence_count', (select count(*) from public.claim_evidence evidence where evidence.claim_id = claim_row.id)
) as item
from public.claims claim_row
where lower(claim_row.id::text) like '{prefix}%'
union all
select jsonb_build_object(
'table', 'public.beliefs',
'row', to_jsonb(belief_row),
'evidence_count', null
) as item
from public.beliefs belief_row
where lower(belief_row.id::text) like '{prefix}%'
) matched;
rollback;
""".strip()
def _parse_single_json_line(raw: str) -> dict[str, Any] | None:
for line in raw.splitlines():
candidate = line.strip()
if not candidate or candidate in {"BEGIN", "SET", "ROLLBACK"}:
continue
try:
value = json.loads(candidate)
except json.JSONDecodeError:
continue
if isinstance(value, dict):
return value
return None
def collect_remote(args: argparse.Namespace, runner: Runner) -> tuple[dict[str, Any], int, str]:
manifest_sql = args.manifest_sql.read_text(encoding="utf-8")
calls: list[tuple[str, list[str], str, int]] = [
("deploy", ssh_command(args, deploy_readback_command()), "", args.timeout),
("service_before", ssh_command(args, service_readback_command()), "", args.timeout),
(
"fingerprint_before",
ssh_command(args, fingerprint_readback_command()),
manifest_sql,
args.fingerprint_timeout,
),
(
"fingerprint_after",
ssh_command(args, fingerprint_readback_command()),
manifest_sql,
args.fingerprint_timeout,
),
("service_after", ssh_command(args, service_readback_command()), "", args.timeout),
]
if args.subject_ref:
calls.append(
(
"subject",
ssh_command(args, fingerprint_readback_command()),
subject_readback_sql(args.subject_ref),
args.timeout,
)
)
results: dict[str, CommandResult] = {}
attempts: dict[str, int] = {}
for name, command, input_text, timeout in calls:
result = CommandResult(1, "", "not attempted")
for attempt in range(1, max(1, args.ssh_attempts) + 1):
result = runner(command, input_text, timeout)
attempts[name] = attempt
if result.returncode == 0:
break
results[name] = result
deploy_values = parse_key_value_lines(results["deploy"].stdout)
service_before = parse_key_value_lines(results["service_before"].stdout)
service_after = parse_key_value_lines(results["service_after"].stdout)
fingerprint_before = parse_manifest_output(results["fingerprint_before"].stdout)
fingerprint_after = parse_manifest_output(results["fingerprint_after"].stdout)
subject = _parse_single_json_line(results["subject"].stdout) if "subject" in results else None
returncode = next((result.returncode for result in results.values() if result.returncode != 0), 0)
stderr = "\n".join(f"{name}: {result.stderr.strip()}" for name, result in results.items() if result.stderr.strip())
return (
{
"deploy_head": deploy_values.get("deploy_head", ""),
"last_deploy_sha": deploy_values.get("last_deploy_sha", ""),
"deploy_stamp_ancestor": deploy_values.get("deploy_stamp_ancestor") == "true",
"workspace_head_matches_deployed_stamp": deploy_values.get("deploy_head")
== deploy_values.get("last_deploy_sha"),
"service_before": service_before,
"service_after": service_after,
"fingerprint_before": fingerprint_before,
"fingerprint_after": fingerprint_after,
"subject_readback": subject,
"readback_attempts": attempts,
},
returncode,
stderr,
)
def _service_active(state: dict[str, Any]) -> bool:
return state.get("ActiveState") == "active" and state.get("SubState") == "running"
def _service_identity(state: dict[str, Any]) -> dict[str, Any]:
return {key: state.get(key) for key in ("MainPID", "NRestarts", "ExecMainStartTimestamp")}
def _remote_checks(
remote: dict[str, Any],
*,
returncode: int,
subject_required: bool,
expected_subject_ref: str | None,
) -> dict[str, bool]:
before = remote.get("fingerprint_before") or {}
after = remote.get("fingerprint_after") or {}
service_before = remote.get("service_before") or {}
service_after = remote.get("service_after") or {}
subject = remote.get("subject_readback") or {}
matches = subject.get("matches") if isinstance(subject, dict) else None
checks = {
"ssh_readbacks_succeeded": returncode == 0,
"workspace_head_is_sha": bool(SHA40_RE.fullmatch(str(remote.get("deploy_head") or ""))),
"deployed_stamp_is_sha": bool(SHA40_RE.fullmatch(str(remote.get("last_deploy_sha") or ""))),
"deployed_stamp_is_ancestor_of_workspace_head": remote.get("deploy_stamp_ancestor") is True,
"service_active_before_and_after": _service_active(service_before) and _service_active(service_after),
"service_identity_complete": all(
value
for value in (
service_before.get("MainPID"),
service_before.get("NRestarts"),
service_before.get("ExecMainStartTimestamp"),
service_after.get("MainPID"),
service_after.get("NRestarts"),
service_after.get("ExecMainStartTimestamp"),
)
),
"service_process_unchanged_during_probe": _service_identity(service_before) == _service_identity(service_after),
"first_fingerprint_complete": before.get("status") == "ok" and int(before.get("table_count") or 0) > 0,
"second_fingerprint_complete": after.get("status") == "ok" and int(after.get("table_count") or 0) > 0,
"fingerprints_are_read_only": before.get("transaction_read_only") == "on"
and after.get("transaction_read_only") == "on",
"canonical_fingerprint_unchanged_during_probe": bool(before.get("fingerprint_sha256"))
and before.get("fingerprint_sha256") == after.get("fingerprint_sha256"),
}
if subject_required:
checks.update(
{
"subject_readback_present": isinstance(subject, dict),
"subject_reference_matches_request": subject.get("subject_ref")
== str(expected_subject_ref or "").casefold(),
"subject_resolved_to_exactly_one_db_object": isinstance(matches, list) and len(matches) == 1,
}
)
return checks
def collect_state(args: argparse.Namespace, *, runner: Runner = subprocess_runner) -> dict[str, Any]:
packet = _load_json(args.packet)
local_packet_checks = packet_checks(packet)
remote, remote_returncode, remote_stderr = collect_remote(args, runner)
remote_checks = _remote_checks(
remote,
returncode=remote_returncode,
subject_required=args.phase == "postflight",
expected_subject_ref=args.subject_ref,
)
baseline = _load_json(args.baseline) if args.baseline else None
baseline_checks: dict[str, bool] = {}
if args.phase == "postflight":
baseline_checks = {
"baseline_supplied": baseline is not None,
"baseline_is_passing_preflight": bool(
baseline and baseline.get("phase") == "preflight" and baseline.get("status") == "pass"
),
"baseline_protocol_matches_packet": bool(
baseline and baseline.get("protocol_sha256") == packet.get("protocol_sha256")
),
"baseline_packet_file_matches": bool(
baseline and baseline.get("packet_file_sha256") == _sha256_file(args.packet)
),
"canonical_fingerprint_matches_preflight": bool(
baseline
and (baseline.get("remote") or {}).get("fingerprint_after", {}).get("fingerprint_sha256")
== remote.get("fingerprint_after", {}).get("fingerprint_sha256")
),
"gateway_process_matches_preflight": bool(
baseline
and _service_identity((baseline.get("remote") or {}).get("service_after") or {})
== _service_identity(remote.get("service_after") or {})
),
}
status = (
"pass"
if all(local_packet_checks.values()) and all(remote_checks.values()) and all(baseline_checks.values())
else "fail"
)
packet_file_sha256 = _sha256_file(args.packet)
state_token = _canonical_sha256(
{
"phase": args.phase,
"packet_file_sha256": packet_file_sha256,
"protocol_sha256": packet.get("protocol_sha256"),
"deploy_head": remote.get("deploy_head"),
"service": _service_identity(remote.get("service_after") or {}),
"fingerprint": remote.get("fingerprint_after"),
"subject_readback": remote.get("subject_readback"),
}
)
exact_gate = ""
if status != "pass":
failed = [
key
for checks in (local_packet_checks, remote_checks, baseline_checks)
for key, value in checks.items()
if value is not True
]
exact_gate = remote_stderr.strip() or ", ".join(failed)
current_canary = (
"Read-only pre-send readiness for the exact three-turn unseen Leo chain in Telegram"
if args.phase == "preflight"
else "Read-only post-send DB grounding and unchanged-state proof for the exact Telegram chain"
)
return {
"schema": SCHEMA,
"generated_at_utc": datetime.now(timezone.utc).isoformat(),
"mode": "telegram_visible_unseen_chain_zero_mutation_state_readback",
"phase": args.phase,
"status": status,
"ready_for_action_time_authorization": args.phase == "preflight" and status == "pass",
"ready_for_visible_capture_verification": args.phase == "postflight" and status == "pass",
"telegram_visible_messages_sent_by_collector": False,
"production_apply_executed": False,
"mutates_db": False,
"packet_path": str(args.packet),
"packet_file_sha256": packet_file_sha256,
"protocol_sha256": packet.get("protocol_sha256"),
"baseline_path": str(args.baseline) if args.baseline else "",
"subject_ref": args.subject_ref or "",
"state_token_sha256": state_token,
"packet_checks": local_packet_checks,
"remote_checks": remote_checks,
"baseline_checks": baseline_checks,
"remote": remote,
"remote_returncode": remote_returncode,
"remote_stderr": remote_stderr,
"blocker_readback": {
"current_canary": current_canary,
"attempted_routes": [
"local exact packet validation",
"SSH deploy stamp and gateway service readback",
"two canonical repeatable-read read-only Postgres parity manifests",
*(["independent selected-object DB readback"] if args.subject_ref else []),
],
"exact_gate": exact_gate,
"clear_CTA": (
"No user action is needed; repair the named readback check and rerun this collector."
if exact_gate
else "Use the packet's exact authorization sentence only when ready to cross the send boundary."
),
"next_non_user_action": (
"Run the authenticated-Chrome three-turn flow only after exact authorization, then collect postflight."
if args.phase == "preflight" and status == "pass"
else "Repair the failed preflight check and rerun before requesting authorization."
if args.phase == "preflight"
else "Run the visible capture verifier against this postflight and the retained Chrome evidence."
),
},
"claim_ceiling": {
"current_tier": "T3_live_readonly" if status == "pass" else "T0_failed_preflight",
"proven": (
"Two canonical read-only snapshots and the gateway process were unchanged during this probe."
if status == "pass"
else "No live readiness claim; one or more fail-closed checks did not pass."
),
"not_proven": [
"Telegram-visible delivery or reply behavior",
"authorization to send Telegram messages",
"canonical mutation",
],
},
}
def write_json(path: Path, data: dict[str, Any]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
def write_markdown(path: Path, data: dict[str, Any]) -> None:
remote = data.get("remote") or {}
service = remote.get("service_after") or {}
fingerprint = remote.get("fingerprint_after") or {}
lines = [
f"# Telegram-Visible Unseen Chain {data['phase'].title()}",
"",
f"Generated UTC: `{data['generated_at_utc']}`",
f"Status: `{data['status']}`",
f"Protocol SHA256: `{data['protocol_sha256']}`",
f"Packet file SHA256: `{data['packet_file_sha256']}`",
f"State token SHA256: `{data['state_token_sha256']}`",
f"Messages sent by collector: `{data['telegram_visible_messages_sent_by_collector']}`",
f"Mutates DB: `{data['mutates_db']}`",
"",
"## Checks",
"",
]
for section in ("packet_checks", "remote_checks", "baseline_checks"):
for key, value in sorted(data.get(section, {}).items()):
lines.append(f"- `{key}`: `{value}`")
lines.extend(
[
"",
"## Live Readback",
"",
f"- Deploy head: `{remote.get('deploy_head', '')}`",
f"- Deploy stamp: `{remote.get('last_deploy_sha', '')}`",
f"- Gateway MainPID: `{service.get('MainPID', '')}`",
f"- Gateway NRestarts: `{service.get('NRestarts', '')}`",
f"- Canonical fingerprint: `{fingerprint.get('fingerprint_sha256', '')}`",
f"- Canonical tables: `{fingerprint.get('table_count', '')}`",
f"- Canonical rows: `{fingerprint.get('total_rows', '')}`",
f"- Selected object ref: `{data.get('subject_ref', '')}`",
"",
"## Claim Ceiling",
"",
data["claim_ceiling"]["proven"],
"",
]
)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("\n".join(lines), encoding="utf-8")
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--phase", choices=("preflight", "postflight"), default="preflight")
parser.add_argument("--packet", type=Path, default=DEFAULT_PACKET)
parser.add_argument("--baseline", type=Path)
parser.add_argument("--subject-ref")
parser.add_argument("--manifest-sql", type=Path, default=DEFAULT_MANIFEST_SQL)
parser.add_argument("--ssh-target", default=DEFAULT_SSH_TARGET)
parser.add_argument("--ssh-key", type=Path, default=DEFAULT_SSH_KEY)
parser.add_argument("--connect-timeout", type=int, default=10)
parser.add_argument("--timeout", type=int, default=60)
parser.add_argument("--fingerprint-timeout", type=int, default=240)
parser.add_argument("--ssh-attempts", type=int, default=3)
parser.add_argument("--out", type=Path)
parser.add_argument("--markdown-out", type=Path)
args = parser.parse_args(argv)
if args.phase == "postflight" and (not args.baseline or not args.subject_ref):
parser.error("postflight requires --baseline and --subject-ref")
if args.subject_ref and not SUBJECT_REF_RE.fullmatch(args.subject_ref):
parser.error("--subject-ref must be an eight-hex prefix or UUID")
if args.out is None:
args.out = DEFAULT_PREFLIGHT_OUT if args.phase == "preflight" else DEFAULT_POSTFLIGHT_OUT
if args.markdown_out is None:
args.markdown_out = (
DEFAULT_PREFLIGHT_MARKDOWN_OUT if args.phase == "preflight" else DEFAULT_POSTFLIGHT_MARKDOWN_OUT
)
return args
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
data = collect_state(args)
write_json(args.out, data)
write_markdown(args.markdown_out, data)
print(
json.dumps(
{
"out": str(args.out),
"markdown_out": str(args.markdown_out),
"phase": args.phase,
"status": data["status"],
"mutates_db": False,
},
indent=2,
sort_keys=True,
)
)
return 0 if data["status"] == "pass" else 2
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,524 @@
#!/usr/bin/env python3
"""Verify retained authenticated-Chrome proof for Leo's unseen Telegram chain."""
from __future__ import annotations
import argparse
import hashlib
import json
import re
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
try:
import build_telegram_visible_unseen_chain_packet as packet_builder
import verify_leo_unseen_reasoning_chain as unseen
except ImportError: # pragma: no cover - imported as scripts.* in tests
from scripts import build_telegram_visible_unseen_chain_packet as packet_builder
from scripts import verify_leo_unseen_reasoning_chain as unseen
SCHEMA = "livingip.telegramVisibleUnseenChainReceipt.v1"
REPORT_DIR = Path("docs/reports/leo-working-state-20260709")
DEFAULT_PACKET = packet_builder.DEFAULT_OUT
DEFAULT_PREFLIGHT = REPORT_DIR / "telegram-visible-unseen-chain-preflight-current.json"
DEFAULT_POSTFLIGHT = REPORT_DIR / "telegram-visible-unseen-chain-postflight-current.json"
DEFAULT_OUT = REPORT_DIR / "telegram-visible-unseen-chain-capture-receipt-current.json"
DEFAULT_MARKDOWN_OUT = REPORT_DIR / "telegram-visible-unseen-chain-capture-receipt-current.md"
def _load_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text(encoding="utf-8"))
def _sha256_file(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()
def _present(value: Any) -> bool:
if value is None:
return False
if isinstance(value, str):
return bool(value.strip())
if isinstance(value, (dict, list)):
return bool(value)
return True
def blank_capture_template(packet: dict[str, Any], preflight: dict[str, Any]) -> dict[str, Any]:
target = packet.get("target") or {}
return {
"protocol_sha256": packet.get("protocol_sha256"),
"preflight_state_token_sha256": preflight.get("state_token_sha256"),
"operator_authorization_text": packet.get("explicit_operator_authorization_text"),
"operator_authorization_captured_at_utc": "",
"extra_messages_sent": 0,
"capture_source": {
"platform": "telegram",
"transport": "authenticated_chrome_telegram_ui",
"chat_label": target.get("chat_label"),
"chat_id": target.get("chat_id"),
"captured_at_utc": "",
"captured_by": "",
"final_screenshot": "",
"final_accessibility": "",
},
"messages": [
{
"sequence": item["sequence"],
"prompt_id": item["prompt_id"],
"sent_text": item["message"],
"reply": "",
"sent_at_utc": "",
"reply_at_utc": "",
"telegram_message_id": "",
"reply_message_id": "",
"turn_screenshot": "",
"turn_accessibility": "",
}
for item in packet.get("exact_messages", [])
],
}
def _resolve_evidence(path_value: str, evidence_root: Path) -> dict[str, Any]:
if not path_value.strip():
return {"path": path_value, "exists": False, "bytes": 0, "sha256": ""}
path = Path(path_value)
if not path.is_absolute():
path = evidence_root / path
resolved = path.resolve()
exists = resolved.is_file()
return {
"path": str(resolved),
"exists": exists,
"bytes": resolved.stat().st_size if exists else 0,
"sha256": _sha256_file(resolved) if exists else "",
}
def _capture_messages(capture: dict[str, Any]) -> list[dict[str, Any]]:
messages = capture.get("messages")
return [item for item in messages if isinstance(item, dict)] if isinstance(messages, list) else []
def _normalized_text(value: str) -> str:
return re.sub(r"\s+", " ", value).strip().casefold()
def _accessibility_binds_message(evidence: dict[str, Any], *, sent_text: str, reply: str) -> bool:
if not evidence.get("exists") or not evidence.get("path"):
return False
text = Path(str(evidence["path"])).read_text(encoding="utf-8", errors="replace")
normalized = _normalized_text(text)
return _normalized_text(sent_text) in normalized and _normalized_text(reply) in normalized
def _subject_match(postflight: dict[str, Any]) -> dict[str, Any]:
subject = (postflight.get("remote") or {}).get("subject_readback") or {}
matches = subject.get("matches") if isinstance(subject, dict) else []
return matches[0] if isinstance(matches, list) and len(matches) == 1 else {}
def _semantic_checks(replies: list[str], *, subject_ref: str, subject_match: dict[str, Any]) -> dict[str, bool]:
if len(replies) != 3:
return {
"visible_db_object_selected_without_operator_id": False,
"visible_weak_support_explained": False,
"same_subject_survived_challenge": False,
"assumption_support_and_falsifier_separated": False,
"multiple_review_only_candidates_proposed": False,
"objection_revised_candidate": False,
"resolving_source_named": False,
"review_approval_apply_boundary_explicit": False,
"reply_claimed_no_mutation": False,
"independent_db_object_matches_visible_subject": False,
}
first, second, third = replies
first_refs = unseen._short_refs(first)
second_refs = unseen._short_refs(second)
shared_terms = unseen._shared_subject_terms(first, second)
selected = subject_ref[:8].casefold() if subject_ref else ""
visible_subject = bool(selected and (selected in first.casefold() or selected in second.casefold()))
same_subject = bool(
visible_subject
and (
(selected in first.casefold() and selected in second.casefold())
or first_refs & second_refs
or len(shared_terms) >= 2
)
)
row = subject_match.get("row") if isinstance(subject_match.get("row"), dict) else {}
row_id = str(row.get("id") or "").casefold()
proposals = unseen._contains(second, "proposal a", "proposal b") or (
unseen._contains_any(second, "two proposals", "two replacement claims") and "1" in second and "2" in second
)
return {
"visible_db_object_selected_without_operator_id": unseen._contains_any(first, "claim", "belief", "axiom")
and unseen._contains_any(first, "database", "db", "public.")
and unseen._contains_any(first, "confidence", "support", "evidence"),
"visible_weak_support_explained": unseen._contains_any(
first,
"nothing supports",
"zero evidence",
"no evidence",
"no claim-evidence",
"no_source_pointer",
"no external primary source",
),
"same_subject_survived_challenge": same_subject,
"assumption_support_and_falsifier_separated": unseen._contains_any(second, "assumption")
and unseen._contains_any(second, "observed support", "evidence")
and unseen._contains_any(second, "falsifier", "counterexample", "would falsify"),
"multiple_review_only_candidates_proposed": proposals
and unseen._contains_any(second, "review", "staged", "proposal")
and unseen._contains_any(
second,
"nothing applied",
"not live knowledge",
"staged only",
"not an apply",
),
"objection_revised_candidate": unseen._contains_any(third, "revised proposal", "revision")
and unseen._contains(third, "mechanism", "outcome"),
"resolving_source_named": unseen._contains_any(
third, "what would resolve", "source would resolve", "evidence would resolve"
)
and unseen._contains_any(
third,
"study",
"dataset",
"source",
"randomized",
"quasi-experimental",
"replication",
"ostrom",
),
"review_approval_apply_boundary_explicit": unseen._contains_any(
third, "review", "pending_review", "human review"
)
and unseen._contains_any(third, "approve", "approved", "approval")
and unseen._contains_any(third, "apply", "applied_at", "canonical"),
"reply_claimed_no_mutation": unseen._contains_any(
third,
"not an apply",
"nothing staged or changed",
"canonical unchanged",
"staged intent, not knowledge",
"proposal (not an apply)",
),
"independent_db_object_matches_visible_subject": bool(
visible_subject and row_id and row_id.startswith(selected)
),
}
def verify_capture(
packet: dict[str, Any],
preflight: dict[str, Any],
capture: dict[str, Any] | None,
postflight: dict[str, Any] | None,
*,
packet_path: Path,
evidence_root: Path,
) -> dict[str, Any]:
if capture is None:
return {
"schema": SCHEMA,
"generated_at_utc": datetime.now(timezone.utc).isoformat(),
"mode": "telegram_visible_unseen_chain_capture_verifier",
"status": "awaiting_action_time_authorization",
"receipt_ready": False,
"current_tier": "T0_packet_plus_T3_preflight",
"required_tier": "T3_live_readonly",
"telegram_visible_messages_sent": False,
"mutates_db": False,
"packet_path": str(packet_path),
"preflight_path": str(DEFAULT_PREFLIGHT),
"postflight_path": str(DEFAULT_POSTFLIGHT),
"capture_template": blank_capture_template(packet, preflight),
"checks": {
"packet_ready": packet.get("ready_to_request_action_time_authorization") is True,
"preflight_passed": preflight.get("status") == "pass",
"action_time_authorization_present": False,
"capture_present": False,
"postflight_present": False,
},
"claim_ceiling": {
"proven": "The exact packet and live zero-mutation preflight are ready.",
"not_proven": [
"Telegram-visible message delivery",
"Telegram-visible Leo replies",
"post-send fingerprint equality",
],
},
}
messages = _capture_messages(capture)
expected = packet.get("exact_messages") or []
capture_source = capture.get("capture_source") if isinstance(capture.get("capture_source"), dict) else {}
replies = [str(item.get("reply") or "") for item in messages]
ids = [str(item.get("telegram_message_id") or "") for item in messages]
reply_ids = [str(item.get("reply_message_id") or "") for item in messages]
screenshot = _resolve_evidence(str(capture_source.get("final_screenshot") or ""), evidence_root)
accessibility = _resolve_evidence(str(capture_source.get("final_accessibility") or ""), evidence_root)
turn_evidence = [
{
"prompt_id": item.get("prompt_id"),
"screenshot": _resolve_evidence(str(item.get("turn_screenshot") or ""), evidence_root),
"accessibility": _resolve_evidence(str(item.get("turn_accessibility") or ""), evidence_root),
}
for item in messages
]
postflight = postflight or {}
subject_ref = str(postflight.get("subject_ref") or "")
subject_match = _subject_match(postflight)
semantics = _semantic_checks(replies, subject_ref=subject_ref, subject_match=subject_match)
pre_fingerprint = (preflight.get("remote") or {}).get("fingerprint_after") or {}
post_fingerprint = (postflight.get("remote") or {}).get("fingerprint_after") or {}
pre_service = (preflight.get("remote") or {}).get("service_after") or {}
post_service = (postflight.get("remote") or {}).get("service_after") or {}
service_keys = ("MainPID", "NRestarts", "ExecMainStartTimestamp")
handler_binding = packet.get("handler_receipt_binding") or {}
handler_path = Path(str(handler_binding.get("path") or ""))
if not handler_path.is_absolute():
handler_path = evidence_root / handler_path
expected_ids = [str(item.get("prompt_id") or "") for item in expected]
actual_ids = [str(item.get("prompt_id") or "") for item in messages]
checks = {
"packet_ready": packet.get("ready_to_request_action_time_authorization") is True,
"packet_file_hash_matches_preflight": _sha256_file(packet_path) == preflight.get("packet_file_sha256"),
"handler_receipt_binding_unchanged": handler_path.is_file()
and _sha256_file(handler_path) == handler_binding.get("sha256"),
"preflight_passed": preflight.get("status") == "pass" and preflight.get("phase") == "preflight",
"postflight_passed": postflight.get("status") == "pass" and postflight.get("phase") == "postflight",
"protocol_bound_across_all_artifacts": capture.get("protocol_sha256")
== preflight.get("protocol_sha256")
== postflight.get("protocol_sha256")
== packet.get("protocol_sha256"),
"preflight_state_token_bound_to_capture": capture.get("preflight_state_token_sha256")
== preflight.get("state_token_sha256"),
"exact_action_time_authorization_captured": capture.get("operator_authorization_text")
== packet.get("explicit_operator_authorization_text")
and _present(capture.get("operator_authorization_captured_at_utc")),
"authenticated_chrome_transport_proven": capture_source.get("platform") == "telegram"
and capture_source.get("transport") == "authenticated_chrome_telegram_ui",
"bot_api_not_substituted": "bot_api" not in json.dumps(capture_source).casefold(),
"exact_destination_matches": capture_source.get("chat_label") == (packet.get("target") or {}).get("chat_label")
and capture_source.get("chat_id") == (packet.get("target") or {}).get("chat_id"),
"exact_three_messages_and_no_extras": len(messages) == len(expected) == 3
and capture.get("extra_messages_sent") == 0,
"prompt_ids_and_sequence_exact": actual_ids == expected_ids
and [item.get("sequence") for item in messages] == [1, 2, 3],
"sent_text_exact": [item.get("sent_text") for item in messages] == [item.get("message") for item in expected],
"visible_replies_nonempty": len(replies) == 3 and all(reply.strip() for reply in replies),
"message_and_reply_ids_present_unique": all(ids)
and all(reply_ids)
and len(set(ids)) == 3
and len(set(reply_ids)) == 3,
"message_and_reply_timestamps_present": all(
_present(item.get("sent_at_utc")) and _present(item.get("reply_at_utc")) for item in messages
),
"capture_metadata_present": all(
_present(capture_source.get(key)) for key in ("captured_at_utc", "captured_by")
),
"visual_evidence_files_present": screenshot["exists"]
and screenshot["bytes"] > 0
and accessibility["exists"]
and accessibility["bytes"] > 0
and len(turn_evidence) == 3
and all(
item["screenshot"]["exists"]
and item["screenshot"]["bytes"] > 0
and item["accessibility"]["exists"]
and item["accessibility"]["bytes"] > 0
for item in turn_evidence
),
"turn_accessibility_binds_exact_messages_and_replies": len(turn_evidence) == len(messages) == 3
and all(
_accessibility_binds_message(
evidence["accessibility"],
sent_text=str(message.get("sent_text") or ""),
reply=str(message.get("reply") or ""),
)
for evidence, message in zip(turn_evidence, messages, strict=True)
),
"canonical_fingerprint_unchanged_from_preflight": bool(
pre_fingerprint.get("fingerprint_sha256")
and pre_fingerprint.get("fingerprint_sha256") == post_fingerprint.get("fingerprint_sha256")
),
"gateway_process_unchanged_from_preflight": all(
pre_service.get(key) == post_service.get(key) for key in service_keys
),
**semantics,
}
outcomes = {
"telegram_visible_three_turn_chain": all(
checks[key]
for key in (
"authenticated_chrome_transport_proven",
"exact_destination_matches",
"exact_three_messages_and_no_extras",
"sent_text_exact",
"visible_replies_nonempty",
"visual_evidence_files_present",
"turn_accessibility_binds_exact_messages_and_replies",
)
),
"visible_db_grounded_challenge": all(
checks[key]
for key in (
"visible_db_object_selected_without_operator_id",
"visible_weak_support_explained",
"same_subject_survived_challenge",
"assumption_support_and_falsifier_separated",
"independent_db_object_matches_visible_subject",
)
),
"visible_review_only_revision": all(
checks[key]
for key in (
"multiple_review_only_candidates_proposed",
"objection_revised_candidate",
"resolving_source_named",
"review_approval_apply_boundary_explicit",
"reply_claimed_no_mutation",
)
),
"canonical_state_unchanged": checks["canonical_fingerprint_unchanged_from_preflight"],
}
passed = all(checks.values()) and all(outcomes.values())
return {
"schema": SCHEMA,
"generated_at_utc": datetime.now(timezone.utc).isoformat(),
"mode": "telegram_visible_unseen_chain_capture_verifier",
"status": "pass" if passed else "fail",
"receipt_ready": passed,
"current_tier": "T3_live_readonly" if passed else "T2_or_lower_incomplete_visible_proof",
"required_tier": "T3_live_readonly",
"telegram_visible_messages_sent": True,
"production_apply_executed": False,
"mutates_db": False,
"packet_path": str(packet_path),
"checks": checks,
"outcomes": outcomes,
"selected_subject": {
"ref": subject_ref,
"table": subject_match.get("table"),
"row_id": (subject_match.get("row") or {}).get("id"),
},
"evidence": {
"final_screenshot": screenshot,
"final_accessibility": accessibility,
"turn_evidence": turn_evidence,
"telegram_message_ids": ids,
"telegram_reply_ids": reply_ids,
"preflight_state_token_sha256": preflight.get("state_token_sha256"),
"postflight_state_token_sha256": postflight.get("state_token_sha256"),
"canonical_fingerprint_sha256": post_fingerprint.get("fingerprint_sha256"),
},
"claim_ceiling": {
"proven": (
"One exact authenticated-Chrome Telegram chain visibly selected and challenged a DB object, "
"proposed and revised review-only knowledge, preserved the approval/apply boundary, and left the "
"canonical fingerprint unchanged."
if passed
else "No T3 claim; at least one visible, semantic, binding, or state check failed."
),
"not_proven": [
"canonical proposal staging or apply",
"agent-to-agent review",
"GCP runtime parity for the Telegram-visible chain",
],
},
}
def write_json(path: Path, data: dict[str, Any]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
def write_markdown(path: Path, data: dict[str, Any]) -> None:
lines = [
"# Telegram-Visible Unseen Chain Capture Receipt",
"",
f"Generated UTC: `{data['generated_at_utc']}`",
f"Status: `{data['status']}`",
f"Receipt ready: `{data['receipt_ready']}`",
f"Current tier: `{data['current_tier']}`",
f"Required tier: `{data['required_tier']}`",
f"Telegram-visible messages sent: `{data['telegram_visible_messages_sent']}`",
f"Mutates DB: `{data['mutates_db']}`",
"",
"## Checks",
"",
]
lines.extend(f"- `{key}`: `{value}`" for key, value in sorted(data.get("checks", {}).items()))
if data.get("capture_template"):
lines.extend(
[
"",
"## Awaiting Authorized Capture",
"",
"The packet and preflight are ready. No Telegram message has been sent by this verifier.",
]
)
lines.extend(
[
"",
"## Claim Ceiling",
"",
data["claim_ceiling"]["proven"],
"",
]
)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("\n".join(lines), encoding="utf-8")
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--packet", type=Path, default=DEFAULT_PACKET)
parser.add_argument("--preflight", type=Path, default=DEFAULT_PREFLIGHT)
parser.add_argument("--capture-json", type=Path)
parser.add_argument("--postflight", type=Path, default=DEFAULT_POSTFLIGHT)
parser.add_argument("--evidence-root", type=Path, default=Path("."))
parser.add_argument("--out", type=Path, default=DEFAULT_OUT)
parser.add_argument("--markdown-out", type=Path, default=DEFAULT_MARKDOWN_OUT)
return parser.parse_args(argv)
def main(argv: list[str] | None = None) -> int:
args = parse_args(argv)
packet = _load_json(args.packet)
preflight = _load_json(args.preflight)
capture = _load_json(args.capture_json) if args.capture_json else None
postflight = _load_json(args.postflight) if capture is not None and args.postflight.exists() else None
receipt = verify_capture(
packet,
preflight,
capture,
postflight,
packet_path=args.packet,
evidence_root=args.evidence_root,
)
write_json(args.out, receipt)
write_markdown(args.markdown_out, receipt)
print(
json.dumps(
{
"out": str(args.out),
"markdown_out": str(args.markdown_out),
"status": receipt["status"],
"receipt_ready": receipt["receipt_ready"],
},
indent=2,
sort_keys=True,
)
)
return 0 if receipt["status"] in {"pass", "awaiting_action_time_authorization"} else 2
if __name__ == "__main__":
raise SystemExit(main())

View file

@ -0,0 +1,64 @@
from __future__ import annotations
import json
from pathlib import Path
from scripts import build_telegram_visible_unseen_chain_packet as packet
def test_packet_binds_handler_receipt_and_preserves_exact_messages() -> None:
data = packet.build_packet(git_sha="a" * 40)
assert data["schema"] == packet.SCHEMA
assert data["ready_to_request_action_time_authorization"] is True
assert data["telegram_visible_messages_sent"] is False
assert data["telegram_visible_message_authorization_present"] is False
assert data["mutates_db"] is False
assert data["target"]["chat_label"] == "Leo"
assert data["target"]["chat_id"] == "-5146042086"
assert data["target"]["allowed_transport"] == "authenticated_chrome_telegram_ui"
assert [item["message"] for item in data["exact_messages"]] == [item["message"] for item in packet.unseen.PROMPTS]
assert [item["sequence"] for item in data["exact_messages"]] == [1, 2, 3]
assert all(len(item["message_sha256"]) == 64 for item in data["exact_messages"])
assert data["handler_receipt_binding"]["sha256"] == packet._sha256_file(packet.DEFAULT_HANDLER_RECEIPT)
assert data["tooling_binding"] == packet.tooling_binding()
assert all(data["checks"].values())
def test_action_time_authorization_contains_destination_transport_and_full_messages() -> None:
data = packet.build_packet(git_sha="a" * 40)
authorization = data["explicit_operator_authorization_text"]
assert "Telegram group Leo (chat ID -5146042086)" in authorization
assert "already-authenticated Chrome Telegram UI" in authorization
assert "do not use the Bot API" in authorization
assert "no additional messages" in authorization
for item in data["exact_messages"]:
assert item["prompt_id"] in authorization
assert json.dumps(item["message"], ensure_ascii=True) in authorization
def test_packet_fails_closed_when_handler_receipt_no_longer_passes(tmp_path: Path) -> None:
receipt = json.loads(packet.DEFAULT_HANDLER_RECEIPT.read_text(encoding="utf-8"))
receipt["status"] = "fail"
receipt_path = tmp_path / "handler.json"
receipt_path.write_text(json.dumps(receipt), encoding="utf-8")
data = packet.build_packet(handler_receipt_path=receipt_path, git_sha="a" * 40)
assert data["ready_to_request_action_time_authorization"] is False
assert data["authorization_gate_status"] == "not_ready"
assert data["checks"]["handler_receipt_passed"] is False
def test_markdown_retains_exact_cta_and_no_send_ceiling(tmp_path: Path) -> None:
data = packet.build_packet(git_sha="a" * 40)
out = tmp_path / "packet.md"
packet.write_markdown(out, data)
text = out.read_text(encoding="utf-8")
assert "Telegram-Visible Unseen Chain Authorization Packet" in text
assert "Telegram-visible messages sent: `False`" in text
assert "Exact Action-Time Authorization" in text
assert data["exact_messages"][2]["message"] in text

View file

@ -0,0 +1,251 @@
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
from scripts import build_telegram_visible_unseen_chain_packet as packet_builder
from scripts import collect_telegram_visible_unseen_chain_state as state
def manifest_output(*, row_count: int = 7) -> str:
rows = [
{
"kind": "identity",
"database": "teleo",
"server_version_num": 160014,
"server_encoding": "UTF8",
"database_collation": "C.UTF-8",
"database_ctype": "C.UTF-8",
"transaction_read_only": "on",
}
]
for kind in (
"schemas",
"extensions",
"application_roles",
"columns",
"constraints",
"indexes",
"sequences",
"views",
"functions",
"triggers",
"types",
"policies",
):
rows.append({"kind": kind, "items": []})
rows.append(
{
"kind": "table",
"schema": "public",
"table": "claims",
"row_count": row_count,
"rowset_md5": "f" * 32,
}
)
return "BEGIN\nSET\n" + "\n".join(json.dumps(item) for item in rows) + "\nROLLBACK\n"
def write_packet(tmp_path: Path) -> Path:
out = tmp_path / "packet.json"
packet_builder.write_json(
out,
packet_builder.build_packet(
handler_receipt_path=packet_builder.DEFAULT_HANDLER_RECEIPT.resolve(),
git_sha="a" * 40,
),
)
return out
def args_for(packet: Path, tmp_path: Path, *, phase: str = "preflight") -> argparse.Namespace:
return argparse.Namespace(
phase=phase,
packet=packet,
baseline=None,
subject_ref=None,
manifest_sql=Path("ops/postgres_parity_manifest.sql"),
ssh_target="root@example.invalid",
ssh_key=tmp_path / "key",
connect_timeout=1,
timeout=5,
fingerprint_timeout=5,
ssh_attempts=3,
out=tmp_path / f"{phase}.json",
markdown_out=tmp_path / f"{phase}.md",
)
class GoodRunner:
def __init__(self) -> None:
self.service_calls = 0
def __call__(self, command: list[str], input_text: str, _timeout: int) -> state.CommandResult:
remote_command = command[-1]
if "git rev-parse HEAD" in remote_command:
sha = "b" * 40
return state.CommandResult(
0,
f"deploy_head={sha}\nlast_deploy_sha={sha}\ndeploy_stamp_ancestor=true\n",
"",
)
if "systemctl show" in remote_command:
self.service_calls += 1
return state.CommandResult(
0,
"\n".join(
[
"ActiveState=active",
"SubState=running",
"MainPID=123",
"NRestarts=0",
"ExecMainStartTimestamp=Wed 2026-07-15 00:00:00 UTC",
]
),
"",
)
if "'subject_ref'" in input_text:
payload = {
"subject_ref": "c0000000",
"matches": [
{
"table": "public.beliefs",
"row": {"id": "c0000000-0000-4000-8000-000000000001"},
"evidence_count": None,
}
],
}
return state.CommandResult(0, f"BEGIN\n{json.dumps(payload)}\nROLLBACK\n", "")
if "postgres_parity_manifest" not in remote_command and input_text.startswith("\\set ON_ERROR_STOP"):
return state.CommandResult(0, manifest_output(), "")
raise AssertionError(f"unexpected command: {command} / input={input_text[:80]}")
def test_preflight_passes_with_two_identical_read_only_fingerprints(tmp_path: Path) -> None:
args = args_for(write_packet(tmp_path), tmp_path)
result = state.collect_state(args, runner=GoodRunner())
assert result["status"] == "pass"
assert result["ready_for_action_time_authorization"] is True
assert result["telegram_visible_messages_sent_by_collector"] is False
assert result["mutates_db"] is False
assert all(result["packet_checks"].values())
assert all(result["remote_checks"].values())
assert len(result["state_token_sha256"]) == 64
def test_preflight_fails_when_second_fingerprint_drifts(tmp_path: Path) -> None:
args = args_for(write_packet(tmp_path), tmp_path)
fingerprint_calls = 0
good = GoodRunner()
def drift_runner(command: list[str], input_text: str, timeout: int) -> state.CommandResult:
nonlocal fingerprint_calls
if input_text.startswith("\\set ON_ERROR_STOP") and "'subject_ref'" not in input_text:
fingerprint_calls += 1
return state.CommandResult(0, manifest_output(row_count=7 + fingerprint_calls - 1), "")
return good(command, input_text, timeout)
result = state.collect_state(args, runner=drift_runner)
assert result["status"] == "fail"
assert result["remote_checks"]["canonical_fingerprint_unchanged_during_probe"] is False
def test_preflight_accepts_newer_workspace_head_when_deployed_stamp_is_ancestor(tmp_path: Path) -> None:
args = args_for(write_packet(tmp_path), tmp_path)
class AheadRunner(GoodRunner):
def __call__(self, command: list[str], input_text: str, timeout: int) -> state.CommandResult:
if "git rev-parse HEAD" in command[-1]:
return state.CommandResult(
0,
f"deploy_head={'c' * 40}\nlast_deploy_sha={'b' * 40}\ndeploy_stamp_ancestor=true\n",
"",
)
return super().__call__(command, input_text, timeout)
result = state.collect_state(args, runner=AheadRunner())
assert result["status"] == "pass"
assert result["remote"]["workspace_head_matches_deployed_stamp"] is False
assert result["remote_checks"]["deployed_stamp_is_ancestor_of_workspace_head"] is True
def test_preflight_retries_transient_ssh_failure(tmp_path: Path) -> None:
args = args_for(write_packet(tmp_path), tmp_path)
good = GoodRunner()
deploy_attempts = 0
def transient_runner(command: list[str], input_text: str, timeout: int) -> state.CommandResult:
nonlocal deploy_attempts
if "git rev-parse HEAD" in command[-1]:
deploy_attempts += 1
if deploy_attempts == 1:
return state.CommandResult(255, "", "Connection timed out during banner exchange")
return good(command, input_text, timeout)
result = state.collect_state(args, runner=transient_runner)
assert result["status"] == "pass"
assert result["remote"]["readback_attempts"]["deploy"] == 2
def test_preflight_rejects_packet_bound_to_different_tooling_source(tmp_path: Path) -> None:
packet_path = write_packet(tmp_path)
packet = json.loads(packet_path.read_text(encoding="utf-8"))
packet["tooling_binding"]["capture_verifier"]["sha256"] = "0" * 64
packet_path.write_text(json.dumps(packet), encoding="utf-8")
result = state.collect_state(args_for(packet_path, tmp_path), runner=GoodRunner())
assert result["status"] == "fail"
assert result["packet_checks"]["packet_tooling_hashes_match_current_sources"] is False
def test_postflight_binds_baseline_fingerprint_service_and_subject(tmp_path: Path) -> None:
packet = write_packet(tmp_path)
pre_args = args_for(packet, tmp_path)
preflight = state.collect_state(pre_args, runner=GoodRunner())
baseline = tmp_path / "preflight.json"
state.write_json(baseline, preflight)
post_args = args_for(packet, tmp_path, phase="postflight")
post_args.baseline = baseline
post_args.subject_ref = "c0000000"
postflight = state.collect_state(post_args, runner=GoodRunner())
assert postflight["status"] == "pass"
assert postflight["ready_for_visible_capture_verification"] is True
assert all(postflight["baseline_checks"].values())
assert postflight["remote_checks"]["subject_resolved_to_exactly_one_db_object"] is True
def test_postflight_rejects_baseline_fingerprint_mismatch(tmp_path: Path) -> None:
packet = write_packet(tmp_path)
pre_args = args_for(packet, tmp_path)
preflight = state.collect_state(pre_args, runner=GoodRunner())
preflight = copy.deepcopy(preflight)
preflight["remote"]["fingerprint_after"]["fingerprint_sha256"] = "0" * 64
baseline = tmp_path / "preflight.json"
state.write_json(baseline, preflight)
post_args = args_for(packet, tmp_path, phase="postflight")
post_args.baseline = baseline
post_args.subject_ref = "c0000000"
postflight = state.collect_state(post_args, runner=GoodRunner())
assert postflight["status"] == "fail"
assert postflight["baseline_checks"]["canonical_fingerprint_matches_preflight"] is False
def test_subject_sql_rejects_untrusted_input() -> None:
try:
state.subject_readback_sql("c0000000'; delete from public.claims; --")
except ValueError as exc:
assert "subject_ref" in str(exc)
else:
raise AssertionError("unsafe subject ref was accepted")

View file

@ -0,0 +1,240 @@
from __future__ import annotations
import copy
from pathlib import Path
from scripts import build_telegram_visible_unseen_chain_packet as packet_builder
from scripts import verify_telegram_visible_unseen_chain as verifier
SUBJECT_ID = "c0000000-0000-4000-8000-000000000001"
def packet_and_path(tmp_path: Path) -> tuple[dict, Path]:
packet = packet_builder.build_packet(
handler_receipt_path=packet_builder.DEFAULT_HANDLER_RECEIPT.resolve(),
git_sha="a" * 40,
)
path = tmp_path / "packet.json"
packet_builder.write_json(path, packet)
return packet, path
def preflight(packet: dict, packet_path: Path) -> dict:
return {
"phase": "preflight",
"status": "pass",
"protocol_sha256": packet["protocol_sha256"],
"packet_file_sha256": verifier._sha256_file(packet_path),
"state_token_sha256": "1" * 64,
"remote": {
"fingerprint_after": {"fingerprint_sha256": "f" * 64},
"service_after": {
"MainPID": "123",
"NRestarts": "0",
"ExecMainStartTimestamp": "Wed 2026-07-15 00:00:00 UTC",
},
},
}
def postflight(packet: dict) -> dict:
return {
"phase": "postflight",
"status": "pass",
"protocol_sha256": packet["protocol_sha256"],
"state_token_sha256": "2" * 64,
"subject_ref": "c0000000",
"remote": {
"fingerprint_after": {"fingerprint_sha256": "f" * 64},
"service_after": {
"MainPID": "123",
"NRestarts": "0",
"ExecMainStartTimestamp": "Wed 2026-07-15 00:00:00 UTC",
},
"subject_readback": {
"subject_ref": "c0000000",
"matches": [
{
"table": "public.beliefs",
"row": {"id": SUBJECT_ID, "statement": "Coordination is the bottleneck."},
}
],
},
},
}
def good_capture(packet: dict, tmp_path: Path) -> dict:
screenshot = tmp_path / "final.png"
accessibility = tmp_path / "final.txt"
screenshot.write_bytes(b"png proof")
accessibility.write_text("telegram accessibility proof", encoding="utf-8")
replies = [
(
"The database public.beliefs object c0000000 is an axiom with confidence 0.85. What supports it in "
"the DB: nothing supports it; there are zero evidence rows and no external primary source."
),
(
"Claim c0000000 is still the coordination bottleneck belief. Assumption versus observed support: the "
"priority leap is assumed and the evidence is absent. Falsifier: a contrary case. Proposal A and "
"Proposal B are staged only for review; nothing applied and neither is live knowledge."
),
(
"Revised proposal: separate the mechanism from the business outcome. What would resolve the "
"disagreement: a randomized study and its primary source dataset. Keep it pending_review for human "
"review; approved is not apply and applied_at remains null. This is not an apply."
),
]
messages = []
for item, reply in zip(packet["exact_messages"], replies, strict=True):
sequence = item["sequence"]
turn_screenshot = tmp_path / f"turn-{sequence}.png"
turn_accessibility = tmp_path / f"turn-{sequence}.txt"
turn_screenshot.write_bytes(f"turn {sequence} screenshot".encode())
turn_accessibility.write_text(
f"Telegram message: {item['message']}\nLeo reply: {reply}\n",
encoding="utf-8",
)
messages.append(
{
"sequence": sequence,
"prompt_id": item["prompt_id"],
"sent_text": item["message"],
"reply": reply,
"sent_at_utc": f"2026-07-15T00:0{sequence}:00Z",
"reply_at_utc": f"2026-07-15T00:0{sequence}:20Z",
"telegram_message_id": f"sent-{sequence}",
"reply_message_id": f"reply-{sequence}",
"turn_screenshot": str(turn_screenshot),
"turn_accessibility": str(turn_accessibility),
}
)
return {
"protocol_sha256": packet["protocol_sha256"],
"preflight_state_token_sha256": "1" * 64,
"operator_authorization_text": packet["explicit_operator_authorization_text"],
"operator_authorization_captured_at_utc": "2026-07-15T00:00:00Z",
"extra_messages_sent": 0,
"capture_source": {
"platform": "telegram",
"transport": "authenticated_chrome_telegram_ui",
"chat_label": "Leo",
"chat_id": "-5146042086",
"captured_at_utc": "2026-07-15T00:05:00Z",
"captured_by": "codex",
"final_screenshot": str(screenshot),
"final_accessibility": str(accessibility),
},
"messages": messages,
}
def test_no_capture_returns_awaiting_authorization_template(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
receipt = verifier.verify_capture(
packet,
preflight(packet, packet_path),
None,
None,
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "awaiting_action_time_authorization"
assert receipt["telegram_visible_messages_sent"] is False
assert receipt["capture_template"]["messages"][0]["prompt_id"] == "OOS-CHAIN-01"
def test_good_chrome_capture_and_unchanged_fingerprint_pass_t3(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
before = preflight(packet, packet_path)
receipt = verifier.verify_capture(
packet,
before,
good_capture(packet, tmp_path),
postflight(packet),
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "pass"
assert receipt["receipt_ready"] is True
assert receipt["current_tier"] == "T3_live_readonly"
assert all(receipt["checks"].values())
assert all(receipt["outcomes"].values())
assert receipt["selected_subject"]["row_id"] == SUBJECT_ID
def test_bot_api_capture_is_rejected(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
capture = good_capture(packet, tmp_path)
capture["capture_source"]["transport"] = "telegram_bot_api"
receipt = verifier.verify_capture(
packet,
preflight(packet, packet_path),
capture,
postflight(packet),
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "fail"
assert receipt["checks"]["authenticated_chrome_transport_proven"] is False
assert receipt["checks"]["bot_api_not_substituted"] is False
def test_postflight_fingerprint_drift_is_rejected(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
after = copy.deepcopy(postflight(packet))
after["remote"]["fingerprint_after"]["fingerprint_sha256"] = "0" * 64
receipt = verifier.verify_capture(
packet,
preflight(packet, packet_path),
good_capture(packet, tmp_path),
after,
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "fail"
assert receipt["checks"]["canonical_fingerprint_unchanged_from_preflight"] is False
def test_message_text_drift_is_rejected(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
capture = good_capture(packet, tmp_path)
capture["messages"][1]["sent_text"] += " extra"
receipt = verifier.verify_capture(
packet,
preflight(packet, packet_path),
capture,
postflight(packet),
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "fail"
assert receipt["checks"]["sent_text_exact"] is False
def test_copied_reply_not_present_in_accessibility_is_rejected(tmp_path: Path) -> None:
packet, packet_path = packet_and_path(tmp_path)
capture = good_capture(packet, tmp_path)
capture["messages"][0]["reply"] += " copied-only suffix"
receipt = verifier.verify_capture(
packet,
preflight(packet, packet_path),
capture,
postflight(packet),
packet_path=packet_path,
evidence_root=tmp_path,
)
assert receipt["status"] == "fail"
assert receipt["checks"]["turn_accessibility_binds_exact_messages_and_replies"] is False