Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e0c76ed
formal: model lease fencing and STOP_NOW concurrent input
mark-e-deyoung Nov 20, 2026
c5dc040
formal: specify crash-recoverable cross-layer session handover
mark-e-deyoung Nov 20, 2026
c91e1f7
formal: bind private qualification projection binary and consumer pin
mark-e-deyoung Nov 20, 2026
8d6cd27
formal: configure bounded TLC invariants for ControlLease.cfg
mark-e-deyoung Nov 20, 2026
1c0120e
formal: configure bounded TLC invariants for SessionHandover.cfg
mark-e-deyoung Nov 20, 2026
008fe0c
formal: configure bounded TLC invariants for ReleaseAdmission.cfg
mark-e-deyoung Nov 20, 2026
505ce98
ci(formal): bounded TLC on free public GitHub Actions with pinned too…
mark-e-deyoung Nov 20, 2026
423c781
test(formal): bounded crash, stale lease and artifact mutation negati…
mark-e-deyoung Nov 20, 2026
f994565
docs(formal): map bounded state machines to actual cross-layer code a…
mark-e-deyoung Nov 20, 2026
3f10971
fix(formal): bound effect observation so BFS state space terminates
mark-e-deyoung Nov 20, 2026
cd59c6c
formal(red-team): explicit stale-queue input model that TLC must reject
mark-e-deyoung Nov 20, 2026
1bbbeb0
formal(red-team): invariant expecting concrete stale-input counterexa…
mark-e-deyoung Nov 20, 2026
484c7a6
ci(formal): demand TLC counterexample for unguarded queued input
mark-e-deyoung Nov 20, 2026
951640c
docs(formal): record unguarded-input negative control and source refi…
mark-e-deyoung Nov 20, 2026
fd6b7b1
test(formal): capture real input route check-to-effect race with synt…
mark-e-deyoung Nov 20, 2026
4254bc4
docs(formal): map real click-route interleaving witness to future eff…
mark-e-deyoung Nov 20, 2026
a3a3a6b
docs(formal): pinpoint missing restart reconciliation for handover in…
mark-e-deyoung Nov 20, 2026
c0fd1c2
formal(red-team): crash-split ownership negative-control SessionHando…
mark-e-deyoung Nov 20, 2026
ee9f292
formal(red-team): crash-split ownership negative-control SessionHando…
mark-e-deyoung Nov 20, 2026
8e6bdaa
ci(formal): prove crash-split session owner invariant violation
mark-e-deyoung Nov 20, 2026
1790ced
docs(formal): classify crash-split owner negative-control and refinem…
mark-e-deyoung Nov 20, 2026
4070e62
fix(control): epoch-fence queued input admission across grant revoke …
mark-e-deyoung Nov 20, 2026
c8366f1
fix(input): revalidate generation ticket at mouse and key backend adm…
mark-e-deyoung Nov 20, 2026
aba5d74
test(control): assert STOP_NOW blocks actual click-route synthetic ef…
mark-e-deyoung Nov 20, 2026
bcdded8
test(control): fence key injection and invalidate tickets on handover…
mark-e-deyoung Nov 20, 2026
542f7bc
docs(formal): distinguish fixed queued-input race from remaining in-f…
mark-e-deyoung Nov 20, 2026
f676e30
fix(control): enforce STOP_NOW before noninteractive and agent-only i…
mark-e-deyoung Nov 20, 2026
7b7b801
test(control): STOP_NOW rejects fresh headless and agent-only input t…
mark-e-deyoung Nov 20, 2026
d00d211
docs(formal): qualify absolute STOP_NOW veto across headless policy s…
mark-e-deyoung Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/formal-cross-layer-tlc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Formal Cross-Layer Safety (TLC)

on:
pull_request:
paths:
- "formal/**"
- ".github/workflows/formal-cross-layer-tlc.yml"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: formal-cross-layer-${{ github.ref }}
cancel-in-progress: true

jobs:
check-finite-state-models:
runs-on: ubuntu-24.04
timeout-minutes: 12
steps:
- name: Checkout public synthetic model source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
- name: Install pinned public TLC v1.7.4
shell: bash
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/formal"
curl --fail --location --silent --show-error --retry 2 \
--connect-timeout 15 --max-time 90 \
https://github.com/tlaplus/tlaplus/releases/download/v1.7.4/tla2tools.jar \
-o "$RUNNER_TEMP/formal/tla2tools.jar"
printf 'bee4a54f3ee3d4afc347c3240ec2d9e93b075104 %s\n' \
"$RUNNER_TEMP/formal/tla2tools.jar" | sha1sum --check --status
java -version
- name: Exhaustive finite-state invariant checking
shell: bash
run: |
set -euo pipefail
cd formal/tla
for model in ControlLease SessionHandover ReleaseAdmission; do
echo "TLC_MODEL=$model"
timeout 90s java -Xmx768m -XX:+UseParallelGC \
-cp "$RUNNER_TEMP/formal/tla2tools.jar" tlc2.TLC \
-workers 1 -deadlock -config "$model.cfg" "$model.tla"
done
echo "FORMAL_TLC_VERDICT=PASS"
- name: Prove adversarial stale-input model is rejected by TLC
shell: bash
run: |
set -euo pipefail
cd formal/tla
if timeout 45s java -Xmx512m -XX:+UseParallelGC \
-cp "$RUNNER_TEMP/formal/tla2tools.jar" tlc2.TLC \
-workers 1 -deadlock -config ControlLeaseUnsafe.cfg \
ControlLeaseUnsafe.tla > "$RUNNER_TEMP/formal/unsafe-tlc.log" 2>&1; then
echo "FORMAL_NEGATIVE_CONTROL=FAILED_TO_DETECT_STALE_INPUT"
exit 1
fi
# A parser error or missing dependency is not a valid counterexample.
if ! grep -Fq 'Invariant NoUnauthorizedEffect is violated' \
"$RUNNER_TEMP/formal/unsafe-tlc.log"; then
echo "FORMAL_NEGATIVE_CONTROL=NO_EXPECTED_COUNTEREXAMPLE"
exit 1
fi
echo "FORMAL_NEGATIVE_CONTROL=STALE_INPUT_COUNTEREXAMPLE_CONFIRMED"
- name: Prove split-owner restart without reconciliation is rejected by TLC
shell: bash
run: |
set -euo pipefail
cd formal/tla
if timeout 45s java -Xmx512m -XX:+UseParallelGC \
-cp "$RUNNER_TEMP/formal/tla2tools.jar" tlc2.TLC \
-workers 1 -deadlock -config SessionHandoverUnsafe.cfg \
SessionHandoverUnsafe.tla > "$RUNNER_TEMP/formal/unsafe-handover.log" 2>&1; then
echo "FORMAL_HANDOVER_NEGATIVE=FAILED_TO_DETECT_SPLIT_OWNER"
exit 1
fi
if ! grep -Fq 'Invariant ConvergedAtRest is violated' \
"$RUNNER_TEMP/formal/unsafe-handover.log"; then
echo "FORMAL_HANDOVER_NEGATIVE=NO_EXPECTED_COUNTEREXAMPLE"
exit 1
fi
echo "FORMAL_HANDOVER_NEGATIVE=SPLIT_OWNER_COUNTEREXAMPLE_CONFIRMED"
- name: Run dependency-free model contract tests
shell: bash
run: |
set -euo pipefail
python3 -m unittest discover -s formal/tests -p 'test_*.py' -v
40 changes: 35 additions & 5 deletions api/core/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self):
self.last_agent_activity = 0.0
self._grant_challenge_token = None
self._grant_challenge_expiry = 0.0
self._authority_epoch = 1

@property
def last_activity(self) -> float:
Expand All @@ -53,6 +54,7 @@ def _compute_effective_mode(self) -> ControlPolicyMode:

async def set_instance_control_mode(self, mode: ControlPolicyMode):
with self._lock:
self._authority_epoch += 1
self.state.instance_control_mode = mode
self.state.effective_control_mode = self._compute_effective_mode()
if self.state.effective_control_mode == ControlPolicyMode.AGENT_ONLY:
Expand All @@ -71,6 +73,7 @@ async def issue_grant_challenge(self, ttl_seconds: int = 30) -> dict:

async def set_session_control_mode(self, mode: ControlPolicyMode):
with self._lock:
self._authority_epoch += 1
self.state.session_control_mode = mode
self.state.effective_control_mode = self._compute_effective_mode()
if self.state.effective_control_mode == ControlPolicyMode.AGENT_ONLY:
Expand All @@ -86,6 +89,7 @@ async def update_session(
session_control_mode: ControlPolicyMode = ControlPolicyMode.HYBRID,
):
with self._lock:
self._authority_epoch += 1
self.state.session_id = session_id
self.state.interactive = interactive
self.state.instance_control_mode = ControlPolicyMode(get_instance_control_mode())
Expand Down Expand Up @@ -140,6 +144,7 @@ async def grant_agent(
)
if not self.state.interactive:
return # Always implicit in non-interactive
self._authority_epoch += 1
self.state.control_mode = ControlMode.AGENT
self.state.lease_expiry = time.time() + lease_seconds
self.state.user_intent = UserIntent.WAIT
Expand All @@ -152,14 +157,17 @@ async def renew_agent(self, lease_seconds: int):
)
if self.state.user_intent == UserIntent.STOP_NOW:
raise HTTPException(status_code=403, detail="User requested STOP_NOW")
self._authority_epoch += 1
self.state.lease_expiry = time.time() + lease_seconds

def revoke_agent(self, reason: str):
# Sync version for internal calls
self.state.control_mode = ControlMode.USER
self.state.lease_expiry = None
self.state.agent_status = AgentStatus.STOPPING
print(f"Broker: Agent revoked ({reason})")
# RLock is reentrant for callers already holding the state lock.
with self._lock:
self._authority_epoch += 1
self.state.control_mode = ControlMode.USER
self.state.lease_expiry = None
self.state.agent_status = AgentStatus.STOPPING
print(f"Broker: Agent revoked ({reason})")

async def report_user_activity(self):
with self._lock:
Expand All @@ -180,6 +188,12 @@ async def set_user_intent(self, intent: UserIntent):
async def check_access(self) -> bool:
"""Returns True if agent is allowed to execute."""
with self._lock:
# STOP_NOW is an absolute veto, including headless and agent-only
# sessions. Never admit a new ticket after human emergency stop.
if self.state.user_intent == UserIntent.STOP_NOW:
if self.state.control_mode == ControlMode.AGENT:
self.revoke_agent("user_stop_now")
return False
if self.state.effective_control_mode == ControlPolicyMode.HUMAN_ONLY:
return False
if self.state.effective_control_mode == ControlPolicyMode.AGENT_ONLY:
Expand All @@ -196,6 +210,22 @@ async def check_access(self) -> bool:
return False
return True

async def issue_input_ticket(self) -> int | None:
"""Capture current authority generation for one pending input action."""
with self._lock:
if not await self.check_access():
return None
return self._authority_epoch

async def validate_input_ticket(self, ticket: int) -> bool:
"""Reject queued work after control/session changes or lease expiry.

Admission is immediately before backend invocation; it cannot stop an
external process already running. Consumer-side fencing remains needed.
"""
with self._lock:
return ticket == self._authority_epoch and await self.check_access()

def get_state(self) -> ControlState:
# Return a detached snapshot so callers cannot mutate shared broker state.
with self._lock:
Expand Down
12 changes: 10 additions & 2 deletions api/routers/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ def input_events(
async def click_at(data: ClickModel):
"""Click at coordinates (x, y)."""
op_started = time.perf_counter()
if not await broker.check_access():
authority_ticket = await broker.issue_input_ticket()
if authority_ticket is None:
raise HTTPException(status_code=423, detail="Agent control denied by policy")

await broker.report_agent_activity()
Expand Down Expand Up @@ -435,6 +436,10 @@ async def click_at(data: ClickModel):

cmd.extend(["click", str(data.button)])

# Do not execute an action queued before STOP_NOW, lease expiry, or
# session handover. This is admission fencing, not an OS-level kill switch.
if not await broker.validate_input_ticket(authority_ticket):
raise HTTPException(status_code=423, detail="Agent control revoked before input dispatch")
result = await run_async_command(cmd)
if not result.get("ok"):
emit_operation_timing(
Expand Down Expand Up @@ -507,7 +512,8 @@ async def key_press(data: KeyModel):
when configured and the explorer.exe desktop barrier is absent.
"""
op_started = time.perf_counter()
if not await broker.check_access():
authority_ticket = await broker.issue_input_ticket()
if authority_ticket is None:
raise HTTPException(status_code=423, detail="Agent control denied by policy")

await broker.report_agent_activity()
Expand Down Expand Up @@ -549,6 +555,8 @@ async def key_press(data: KeyModel):
},
)

if not await broker.validate_input_ticket(authority_ticket):
raise HTTPException(status_code=423, detail="Agent control revoked before input dispatch")
result = await _send_keys(
keys=data.keys,
window_id=target_win_id,
Expand Down
Loading
Loading