Skip to content

Add activation resilience: state machine, mutex, connection monitor#6

Merged
ChesnoTech merged 1 commit intodevelopfrom
feature/activation-resilience
Mar 24, 2026
Merged

Add activation resilience: state machine, mutex, connection monitor#6
ChesnoTech merged 1 commit intodevelopfrom
feature/activation-resilience

Conversation

@ChesnoTech
Copy link
Copy Markdown
Owner

Summary

Complete resilience system for the activation process handling connection loss, power cuts, and duplicate instances.

Branch Type

  • feature/ — New feature (→ develop)

Changes

  • Single-instance mutex — prevents two KeyGate instances on same PC
  • Persistent state file — atomic writes to C:\ProgramData\KeyGate\activation-state.json
  • Connection monitor — 2-second polling, auto-resume on reconnect
  • Invoke-WithRetry — wraps API calls with network-aware retry
  • Boot recovery task — scheduled task reports pending activations after reboot
  • Resume-FromState — detects interrupted sessions, resumes from correct phase

Components Affected

  • Activation Client (PS1 / CMD)

Testing Checklist

  • Mutex blocks second instance (tested on Windows 11)
  • State file atomic write survives interruption
  • Connection monitor detects online/offline
  • Boot recovery task registers/unregisters (requires admin)
  • No TypeScript changes — frontend unaffected

…boot recovery

Handles connection loss, forced shutdowns, and duplicate instances:

- Single-instance mutex: prevents two KeyGate instances running simultaneously
- Persistent state file (C:\ProgramData\KeyGate\activation-state.json):
  writes state BEFORE each step, survives power cuts
- Connection monitor: 2-second polling with auto-resume on reconnect
- Invoke-WithRetry: wraps API calls with automatic retry + connection wait
- Boot recovery scheduled task: on next boot, checks for pending state
  and reports activation result to server
- Resume-FromState: on next launch, detects interrupted session and
  resumes from the correct phase (hw_submitted, key_installed, activated)

Tested on Windows 11:
- Mutex: correctly blocks second instance
- State file: atomic write (tmp + move) survives interruption
- Connection check: ping + HTTP health fallback works
- Boot recovery: requires admin (CMD launcher always runs as admin)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChesnoTech ChesnoTech merged commit de1ba62 into develop Mar 24, 2026
4 checks passed
@ChesnoTech ChesnoTech deleted the feature/activation-resilience branch March 24, 2026 17:12
ChesnoTech added a commit that referenced this pull request Mar 25, 2026
* Set up Git Flow: branch protection, PR template, contributing guide (#4)

- Protected main: require PR + CI (PHP Lint, Frontend Build, Docker)
- Protected develop: require PR + CI (PHP Lint, Frontend Build)
- Updated PR template with Git Flow branch types and testing checklist
- Rewrote CONTRIBUTING.md with full Git Flow workflow, branch naming,
  and development setup instructions
- Repo is now public (BSL licensed)

Co-authored-by: ChesnoTech <263363000+ChesnoTech@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add activation resilience: state machine, mutex, connection monitor, boot recovery (#6)

Handles connection loss, forced shutdowns, and duplicate instances:

- Single-instance mutex: prevents two KeyGate instances running simultaneously
- Persistent state file (C:\ProgramData\KeyGate\activation-state.json):
  writes state BEFORE each step, survives power cuts
- Connection monitor: 2-second polling with auto-resume on reconnect
- Invoke-WithRetry: wraps API calls with automatic retry + connection wait
- Boot recovery scheduled task: on next boot, checks for pending state
  and reports activation result to server
- Resume-FromState: on next launch, detects interrupted session and
  resumes from the correct phase (hw_submitted, key_installed, activated)

Tested on Windows 11:
- Mutex: correctly blocks second instance
- State file: atomic write (tmp + move) survives interruption
- Connection check: ping + HTTP health fallback works
- Boot recovery: requires admin (CMD launcher always runs as admin)

Co-authored-by: ChesnoTech <263363000+ChesnoTech@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: ChesnoTech <263363000+ChesnoTech@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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