Skip to content

Make pause state durable and survive process restarts#240

Merged
mikewheeleer merged 1 commit into
StableRoute-Org:mainfrom
greatest0fallt1me:fix/issue-29
Jun 29, 2026
Merged

Make pause state durable and survive process restarts#240
mikewheeleer merged 1 commit into
StableRoute-Org:mainfrom
greatest0fallt1me:fix/issue-29

Conversation

@greatest0fallt1me

Copy link
Copy Markdown
Contributor

Fixes #29

Summary

  • Add src/pauseState.ts with loadPausedState / savePausedState helpers that persist the pause flag to a small JSON file (path configurable via PAUSE_STATE_FILE env var)
  • Update stores.ts so setPaused() persists state on every call and the flag is restored from disk at module load (skipped in NODE_ENV=test for test isolation)
  • Emit admin.paused / admin.unpaused audit events via recordEvent on every pause/unpause action
  • Add src/__tests__/durablePause.test.ts with 18 tests covering persistence helpers, simulated restart, audit events, and reflection in /api/v1/admin/status, deep health, and metrics
  • Fix pre-existing TypeScript compile errors (duplicate BULK_ABSOLUTE_MAX, missing evictRateBuckets, HEALTH_PROBE_KEY, trimEventLog, effectiveEventLogCap, WEBHOOK_MAX_EVENTS, etc.) that prevented the test suite from running

Changes

Implements the feature as described in the issue, following existing code patterns. Pause state is stored in .pause_state.json (overridable via PAUSE_STATE_FILE). I/O errors are logged but never propagated — the in-process state always takes effect even if the filesystem is unavailable. The recovery path (POST /api/v1/admin/unpause) remains always reachable regardless of pause state.

Persists the service pause flag to a small JSON state file so the
paused state survives process restarts. An operator who pauses the
service before a deploy will find it still paused afterward.

- Add src/pauseState.ts with loadPausedState/savePausedState helpers
- Update stores.ts to restore pause state at startup (skipped in test env
  for isolation) and persist it on every setPaused call
- Emit admin.paused / admin.unpaused events via recordEvent for audit log
- Add comprehensive tests in src/__tests__/durablePause.test.ts covering
  persistence, simulated restart, audit events, and status/health/metrics
- Fix pre-existing TS compile errors (duplicate consts, missing exports,
  undefined references) that prevented the test suite from running at all

Fixes StableRoute-Org#29

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mikewheeleer

Copy link
Copy Markdown
Contributor

lgtm — merging this 🙌

@mikewheeleer mikewheeleer merged commit dc481db into StableRoute-Org:main Jun 29, 2026
1 check failed
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.

Make pause state durable and survive process restarts

2 participants