Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions .github/workflows/external-effect-replay-rdte.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: External Effect Replay Safety Model RDTE

on:
pull_request:
paths:
- 'formal/tests/test_external_effect_replay.py'
- 'formal/EXTERNAL_EFFECT_REPLAY_BOUNDARY.md'
- '.github/workflows/external-effect-replay-rdte.yml'

permissions:
contents: read

jobs:
bounded-synthetic-state-space:
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Checkout exact public PR source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
persist-credentials: false
ref: ${{ github.event.pull_request.head.sha }}
- name: Enforce both safe and deliberately unsafe traces
shell: bash
run: |
set -euo pipefail
python3 -m unittest formal.tests.test_external_effect_replay -v
echo 'EXTERNAL_EFFECT_MODEL=SAFE_VARIANT_AND_COUNTEREXAMPLE_PASS'
37 changes: 37 additions & 0 deletions formal/EXTERNAL_EFFECT_REPLAY_BOUNDARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# External guest effects: crash/replay and STOP boundary — R040

## The missing atomic transaction

Protected Go owner CAS and root-owned controller flock can serialize
control-plane state. They cannot, by themselves, atomically commit
an arbitrary Windows application's external effect and a separate
supervisor ledger acknowledgment. If the supervisor crashes after an
effect and before its acknowledgment, blindly retrying may repeat it.

The stdlib Python BFS in formal/tests/test_external_effect_replay.py
uses a bounded 12-step horizon. The UNSAFE variant requires the
exact witness: prepare -> effect -> crash -> restart -> effect again.
The CONDITIONAL SAFE variant assumes the target itself atomically
records a deduplication operation ID together with its effect; it
checks at-most-once application and STOP blocking any new effect.
STOP cannot roll back effects which were already applied.

These are abstract source models, NOT TLC, NOT a Wine/Windows test,
NOT a proof of the runtime or a guarantee of exactly once for any
uncooperative proprietary Windows application.

## Operational release rule

Classify every cross-layer action into:
(1) read-only observation;
(2) idempotent effect with target-owned operation-ID proof;
(3) non-retryable attempt requiring reconciliation when outcome UNKNOWN.

Without target-side idempotency, never silently retry potentially
effectful guest operations following a timeout, controller crash,
or ambiguous acknowledgment. Human STOP must fence admission at
the same boundary as the effect; already in-flight work needs
explicit UNKNOWN accounting until trustworthy completion evidence.

This experiment cannot close the independent guest-UID1000 writer
lock inode replacement issue or prove SO_PEERCRED production isolation.
87 changes: 87 additions & 0 deletions formal/tests/test_external_effect_replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""Finite control-plane/guest-effect model: synthetic counterexample only.

Durable owner CAS cannot make a separate Windows effect exactly once
across a supervisor crash. The safe variant assumes target idempotence.
"""
import unittest
from collections import deque
from dataclasses import dataclass, replace


@dataclass(frozen=True)
class State:
generation: int = 0
prepared: bool = False
crashed: bool = False
stopped: bool = False
effect_count: int = 0
target_seen: bool = False
retry_pending: bool = False
acked: bool = False

def successors(s: State, *, idempotent_target: bool):
if not s.prepared and not s.stopped:
yield "prepare_durable_generation", replace(s, prepared=True, generation=1)
if s.prepared and not s.crashed and not s.stopped and not s.acked:
if s.effect_count == 0 or s.retry_pending:
if idempotent_target and s.target_seen:
yield "replayed_target_dedup", replace(s, retry_pending=False)
else:
yield "guest_effect_applied", replace(
s, effect_count=min(2, s.effect_count + 1),
target_seen=idempotent_target, retry_pending=False,
)
if s.effect_count > 0:
yield "ack_durable", replace(s, acked=True)
yield "supervisor_crash", replace(s, crashed=True)
if s.crashed:
yield "supervisor_restart", replace(s, crashed=False, retry_pending=True)
if not s.stopped:
yield "human_stop", replace(s, stopped=True, generation=s.generation + 1)

def explore(*, idempotent_target: bool, max_steps: int = 12):
initial = State()
queue = deque([(initial, ())])
visited = {initial}
while queue:
current, trace = queue.popleft()
if current.effect_count > 1:
return visited, trace
if len(trace) >= max_steps:
continue
for name, next_state in successors(current, idempotent_target=idempotent_target):
if next_state not in visited:
visited.add(next_state)
queue.append((next_state, trace + (name,)))
return visited, ()

class ExternalEffectSafety(unittest.TestCase):
def test_atomic_target_dedup_required_for_at_most_once(self):
states, witness = explore(idempotent_target=True)
self.assertGreater(len(states), 10)
self.assertFalse(witness, witness)
self.assertTrue(any(s.acked and s.effect_count == 1 for s in states))
self.assertTrue(all(s.effect_count <= 1 for s in states))

def test_cas_only_has_crash_replay_duplicate_witness(self):
_, witness = explore(idempotent_target=False)
self.assertEqual(witness, (
"prepare_durable_generation",
"guest_effect_applied",
"supervisor_crash",
"supervisor_restart",
"guest_effect_applied",
))

def test_stop_blocks_future_effect_after_restart(self):
for idempotent in (True, False):
for state in explore(idempotent_target=idempotent)[0]:
if not state.stopped:
continue
for label, child in successors(state, idempotent_target=idempotent):
self.assertNotEqual(label, "guest_effect_applied")
self.assertEqual(child.effect_count, state.effect_count)
self.assertTrue(child.stopped)

if __name__ == "__main__":
unittest.main()