Skip to content

Undo an interrupted ttp start instead of exiting 0 with its changes in place - #185

Merged
onyks-os merged 4 commits into
mainfrom
fix/l01-interrupted-start
Nov 27, 2026
Merged

onyks-os merged 4 commits into
mainfrom
fix/l01-interrupted-start

Conversation

@onyks-os

Copy link
Copy Markdown
Owner

This PR fixes a bug found while inventorying L01 of the leak-testing plan (slice 2): the startup and rollback contract.

The defect

The SIGINT/SIGTERM handler registered by ttp start called do_stop(). Before the session lock exists, that function returns immediately. Interrupting ttp start during Tor setup, the rules load or the DNS overlay therefore:

  • printed "Signal received, restoring network...";
  • left the inet ttp table, the DNS overlay and the managed Tor in place;
  • led ttp status to report INACTIVE and ttp stop to report "No active session found";
  • exited 0.

A script that trusted that exit code believed the host was protected. When the interruption came after the session lock was written, the session was stopped, but start still exited 0.

The fix

  • The handler only raises StartInterrupted, a BaseException.
    • Tearing down inside the handler could race an nft or systemctl child that is still running.
    • Raising lets the in-flight call unwind first; subprocess.run kills and reaps its child.
  • interruptible_start wraps start_command, so it also covers restart.
    • No session lock: the start is undone the way stop --restore-only undoes it. Connections redirected during the start are closed before the rules go. Exit 1.
    • Recorded session: the session is stopped. Exit 1.
    • Unchanged: a retained VPN guard (exit 10) and a latched or unreadable emergency (exit 8) behave as before.
  • SIGINT and SIGTERM are ignored while the undo runs.
  • The restore-only teardown moves to lifecycle.restore_without_session, so both paths share it.

Documentation

docs/web/explanation/startup.md states the startup contract phase by phase: what each phase changes, where the first barrier falls, and what a failure or an interruption leaves behind. The page is added to the nav and linked from the plan's L01 note. The external measurement of the first barrier is still pending; it waits for the continuous capture of slice 3.

Tests

  • New tests interrupt start inside Tor setup, the rules load and the DNS overlay, and after the session is recorded.
  • All of them fail against the old handler except the latched-emergency case, which was already correct.
  • A conftest fixture now restores SIGINT/SIGTERM after each test, because start installs its handler in the test process.
  • Hook run: 1867 passed.

🤖 Generated with Claude Code

onyks-os and others added 4 commits November 27, 2026 13:42
…n place

SIGINT or SIGTERM during ttp start ran a handler that called do_stop.
Before the session lock exists (Tor setup, rules, DNS overlay), do_stop
returns at once: the inet ttp table, the overlay and the managed Tor
stayed, ttp status said INACTIVE, ttp stop said no session was found,
and start exited 0, so a script that trusted it believed the host was
protected. After the lock it stopped the session, but still exited 0.

The handler now only raises StartInterrupted (a BaseException, so no
except Exception in the start path swallows it). Tearing down inside the
handler could race an nft or systemctl child still running under the
interrupted call; raised, that call unwinds first and kills its child.
interruptible_start, around start_command (and so restart), then:

- with no session lock: undoes the start as stop --restore-only does,
  closing connections redirected during the start before the rules go,
  and exits 1; a retained VPN guard is kept, exit 10, as before;
- with a recorded session: stops it and exits 1; a latched or
  unreadable emergency is retained, exit 8, as before.

Both signals are ignored while the undo runs. The restore-only teardown
moves from stop_command to lifecycle.restore_without_session so both
paths share it.

docs/web/explanation/startup.md states the startup contract phase by
phase (L01 of the leak-testing plan): what each phase changes, where
the first barrier falls, and what a failure or an interruption leaves.

Tests interrupt start inside Tor setup, the rules load and the DNS
overlay, and after the session is recorded; all but the latched case
fail against the old handler. A conftest fixture restores SIGINT and
SIGTERM after each test, since start installs its handler in the test
process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
…tart

Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
#	docs/web/release-notes/changelog.md
…tart

Signed-off-by: onyks-os <129986281+onyks-os@users.noreply.github.com>
@onyks-os
onyks-os merged commit 1776d0b into main Nov 27, 2026
38 checks passed
@onyks-os
onyks-os deleted the fix/l01-interrupted-start branch November 27, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant