fix/maintenance-lifecycle-and-sweep #1

Merged
gozen merged 8 commits from fix/maintenance-lifecycle-and-sweep into main 2026-11-15 19:34:09 +01:00
Owner

Summary

Maintenance / WHMCS

  • Closing a Network Issue in WHMCS now marks the window Completed. It shows Cancelled only if closed before it started, or deleted in WHMCS.
  • Reopening and deleting in WHMCS are now synced.
  • The WHMCS cron sync reconciles windows whose issue was closed while a hook call was missed.
  • The hook currently installed on WHMCS sends cancel when an issue is closed; the API treats that as a close, so this works before the hook is redeployed.
  • Each window keeps a timeline of updates.
  • Emails keep the WHMCS formatting (cleaned HTML or Markdown), escape the title and services, and honour notify.
  • Emails go out for scheduled, rescheduled, completed and cancelled windows. Text-only edits don't send email.
  • No more duplicate windows or emails: the existing-window check and the create run as one locked step.
  • JSON data files are written safely: a crash mid-write can't truncate them, and a corrupt file is never overwritten with an empty list.

Security and reliability

  • Fixed script injection through the SVG badge.
  • A failed Kuma heartbeat request no longer shows all-green or automatically closes real incidents.
  • A service that goes down, recovers and goes down again within minutes no longer loses its second alert.
  • Fixed unhandled errors in the alert webhook that could crash the process.
  • Rate limits now use the IP added by our own proxy, so a client can't forge its way around them.
  • Input validation on the admin API.

UI

  • Maintenance: formatted descriptions, Completed vs Cancelled, an updates timeline, UTC times.
  • Calendar: no longer crashes on a malformed ?month=.
  • Accessibility: no screen-reader countdown spam, status text next to the colour dots, collapsed groups no longer focusable.
  • Live updates stay in sync after a recovery.
  • Polling pauses while the tab is hidden and backs off after errors.

Ops

  • CI deploys build in a staging directory and swap in only after the build succeeds; the previous build is kept for rollback.
  • The health check confirms the new build is the one being served.
  • The collector and archiver can no longer wipe history.
  • Archiver month calculations use UTC.
  • Cron wrappers use locking and write log files.
  • Docker Compose starts as shipped.
  • The broken webhook deploy server is removed, and the docs match the real setup.

Dependencies

  • Astro 5 → 7 and @astrojs/node 11. npm audit goes from 27 advisories (1 critical) to 2 moderate, build-time only.
  • Tailwind now runs through PostCSS.
  • Node 22.23.4 or newer is required.

Deploy notes

  • The server's Node must be 22.23.4 or newer. If it isn't, the staged build fails and the live site is left untouched.
  • Set TRUSTED_PROXY_HOPS=2 if a CDN or WAF sits in front of the site.
  • Set MAILWIZ_TIMEZONE if the MailWizz account isn't on UTC.
  • Copy whmcs-hooks/maintenance_sync.php to WHMCS, and add define('STATUSPAGE_ADMIN_TOKEN', '…') to its configuration.php.
  • Check the server crontab against docs/DEPLOY_ENHANCE.md; the monthly archiver needs CRON_TZ=UTC.
  • data/history and data/monthly-uptime are no longer tracked in git. On any install that updates with git pull, back up data/ first.

Test plan

  • npm test: 34 tests (lifecycle, email rendering, storage safety, client IP)
  • astro check: 0 errors; production build succeeds
  • Built server replaying the WHMCS sequence (create, re-sync, old-hook close, reopen, close, delete), pages, feed and badge
  • After deploy: create a test Network Issue in WHMCS, edit it, close it; check the page and the emails
  • Check the home page in a browser with live Kuma data (service cards, live updates)
## Summary **Maintenance / WHMCS** - Closing a Network Issue in WHMCS now marks the window **Completed**. It shows Cancelled only if closed before it started, or deleted in WHMCS. - Reopening and deleting in WHMCS are now synced. - The WHMCS cron sync reconciles windows whose issue was closed while a hook call was missed. - The hook currently installed on WHMCS sends `cancel` when an issue is closed; the API treats that as a close, so this works before the hook is redeployed. - Each window keeps a timeline of updates. - Emails keep the WHMCS formatting (cleaned HTML or Markdown), escape the title and services, and honour `notify`. - Emails go out for scheduled, rescheduled, completed and cancelled windows. Text-only edits don't send email. - No more duplicate windows or emails: the existing-window check and the create run as one locked step. - JSON data files are written safely: a crash mid-write can't truncate them, and a corrupt file is never overwritten with an empty list. **Security and reliability** - Fixed script injection through the SVG badge. - A failed Kuma heartbeat request no longer shows all-green or automatically closes real incidents. - A service that goes down, recovers and goes down again within minutes no longer loses its second alert. - Fixed unhandled errors in the alert webhook that could crash the process. - Rate limits now use the IP added by our own proxy, so a client can't forge its way around them. - Input validation on the admin API. **UI** - Maintenance: formatted descriptions, Completed vs Cancelled, an updates timeline, UTC times. - Calendar: no longer crashes on a malformed `?month=`. - Accessibility: no screen-reader countdown spam, status text next to the colour dots, collapsed groups no longer focusable. - Live updates stay in sync after a recovery. - Polling pauses while the tab is hidden and backs off after errors. **Ops** - CI deploys build in a staging directory and swap in only after the build succeeds; the previous build is kept for rollback. - The health check confirms the new build is the one being served. - The collector and archiver can no longer wipe history. - Archiver month calculations use UTC. - Cron wrappers use locking and write log files. - Docker Compose starts as shipped. - The broken webhook deploy server is removed, and the docs match the real setup. **Dependencies** - Astro 5 → 7 and @astrojs/node 11. `npm audit` goes from 27 advisories (1 critical) to 2 moderate, build-time only. - Tailwind now runs through PostCSS. - Node 22.23.4 or newer is required. ## Deploy notes - The server's Node must be 22.23.4 or newer. If it isn't, the staged build fails and the live site is left untouched. - Set `TRUSTED_PROXY_HOPS=2` if a CDN or WAF sits in front of the site. - Set `MAILWIZ_TIMEZONE` if the MailWizz account isn't on UTC. - Copy `whmcs-hooks/maintenance_sync.php` to WHMCS, and add `define('STATUSPAGE_ADMIN_TOKEN', '…')` to its `configuration.php`. - Check the server crontab against `docs/DEPLOY_ENHANCE.md`; the monthly archiver needs `CRON_TZ=UTC`. - `data/history` and `data/monthly-uptime` are no longer tracked in git. On any install that updates with `git pull`, back up `data/` first. ## Test plan - [x] `npm test`: 34 tests (lifecycle, email rendering, storage safety, client IP) - [x] `astro check`: 0 errors; production build succeeds - [x] Built server replaying the WHMCS sequence (create, re-sync, old-hook close, reopen, close, delete), pages, feed and badge - [ ] After deploy: create a test Network Issue in WHMCS, edit it, close it; check the page and the emails - [ ] Check the home page in a browser with live Kuma data (service cards, live updates)
data/history and data/monthly-uptime are written by the collector and
archiver on the server; tracking them made any git-based install revert or
conflict with live data. Files stay on disk. Also drop .superpowers state
files and fix the 'data/   ' ignore line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- NetworkIssueClose ("resolved") now completes the window (cancelled only if
  it never started); reopen and delete hooks are handled; the cron poller
  reconciles windows whose issue is no longer open in WHMCS.
- Legacy hooks that send action=cancel on close are treated as a close, so
  this works before the WHMCS hook is redeployed.
- Every change is recorded in a per-window updates timeline.
- Emails keep WHMCS formatting (sanitised HTML/Markdown), escape title and
  services, honour notify, and cover scheduled/rescheduled/completed/
  cancelled. Content-only edits don't email.
- Upserts run find-or-create under one lock (no duplicate windows/emails),
  omitted fields no longer erase stored values, input is validated.
- Crash-safe JSON store: atomic writes; a corrupt file is never overwritten.
- Hook: logs curl/HTTP failures, shows server names, token docs fixed.
- Add vitest; npm start runs the built server; engines >=22.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- badge.svg: escape label in aria-label/title (reflected XSS); SVG responses
  get a no-script CSP; middleware no longer overrides badge cache to 1 day.
- Webhook: incident state always saved and awaited; only duplicate EMAILS are
  suppressed (flapping no longer drops alerts); real outage duration; segment
  targeting resolves the monitor's group; shared escaped template filling.
- Kuma: a failed heartbeat fetch no longer shows all-green or auto-resolves
  incidents; auto-resolve only for monitors seen operational; corrected beats
  kept; UTC day bucketing; DATA_DIR honoured; staff/WHMCS in-progress windows
  drive the banner and verdict (never masking an outage).
- Incidents store: atomic writes, unique ids, unhandled rejections fixed.
- Rate limits use the proxy-added X-Forwarded-For hop (TRUSTED_PROXY_HOPS).
- Subscribe: null-body crash, fetch timeout, optional double opt-in.
- Feed includes maintenance windows and renders rich text safely.
- Remove dead CSRF bypass that never ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Maintenance: rich-text descriptions, Completed vs Cancelled, 'finished
  early', updates timeline, UTC times on overnight windows, correct duration
  rounding; calendar skips cancelled windows, marks every day of overnight
  windows, and rejects malformed ?month= (was a 500).
- Accessibility: no live-region countdown spam, status text beside colour
  dots, collapsed groups inert, modal focus handling.
- Live updates: card dots and halos stay in sync, recovery from the
  no-monitors fallback, dismissed banner stays dismissed, banner height
  measured; shared non-overlapping polling with visibility pause and backoff.
- Hydration-safe times, dark-mode muted headings, touch tooltips, theme
  follows the OS until chosen, storage access guarded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CI: gate (tests + build) on every push/PR; deploy builds in a staging dir
  and swaps dist/node_modules only after success (previous kept for
  rollback); validates DEPLOY_* vars; optional pinned host key; health check
  verifies the new build id is live.
- Collector: atomic writes, never overwrites unparseable history, per-monitor
  errors; archiver aborts on an empty monitor list and moves orphans instead
  of deleting; UTC month maths.
- Cron wrappers: strict mode, derived paths, flock, dotenv, log files.
- Docker: compose starts (image name), monthly archiver service, Node 24;
  deploy.sh docker uses compose instead of deleting the Dockerfile.
- send-alert.cjs needs --yes; send-test-email.cjs needs --to; MailWizz
  send_at honours MAILWIZ_TIMEZONE; fix-false-positives keeps file perms.
- Remove the broken webhook deploy server; docs match the real setup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clears the critical (AVIF image RCE) and high advisories in astro,
@astrojs/node, vite, devalue, dompurify and ws: npm audit goes from
27 (1 critical, 16 high) to 2 moderate (build-time only, in
@tailwindcss/typography's bundled postcss-selector-parser).

- @astrojs/tailwind does not support Astro 6+: Tailwind 3 now runs via
  postcss.config.mjs (+ autoprefixer); generated CSS is unchanged.
- Content collections move to src/content.config.ts with the glob loader;
  entry.render() becomes render(entry).
- Requires Node >= 22.23.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs: Astro 7 needs Node 22.23.4+
Some checks failed
CI/CD / Build (type-check gate) (pull_request) Failing after 10s
CI/CD / Deploy to production (staged build on server) (pull_request) Has been skipped
bd034795b4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gozen force-pushed fix/maintenance-lifecycle-and-sweep from bd034795b4
Some checks failed
CI/CD / Build (type-check gate) (pull_request) Failing after 10s
CI/CD / Deploy to production (staged build on server) (pull_request) Has been skipped
to 01b115c89a
All checks were successful
CI/CD / Build (type-check gate) (pull_request) Successful in 26s
CI/CD / Deploy to production (staged build on server) (pull_request) Has been skipped
2026-11-15 18:34:12 +01:00
Compare
gozen merged commit 4cc1e3cfba into main 2026-11-15 19:34:09 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
GOZEN-HOST/status-page!1
No description provided.