feat(selfhost): defer maintenance work under runtime pressure#2717
Merged
Conversation
Adds a claim-time admission policy so periodic maintenance sweeps (contributor evidence, RAG indexing, drift scans, product rollups, notifications...) always yield to live webhook/review work and to host CPU pressure, instead of competing with it on equal footing. Denied jobs are deferred with jitter and force-admitted via a trickle ceiling so sustained load can slow maintenance down but never starve it forever. Also: classifies a bare 403 on the branch-protection probe as a permission gap (not GitHub rate-limit exhaustion) with its own metric, adds Grafana panels + Prometheus alerts for live vs. maintenance queue pressure, documents the three self-host runner deployment modes, and adds a safe Docker build-cache/image prune script (never touches volumes).
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gittensory-ui | b27b121 | Commit Preview URL Branch Preview URL |
Jul 03 2026, 07:30 AM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2717 +/- ##
========================================
Coverage 96.12% 96.13%
========================================
Files 240 243 +3
Lines 26988 27128 +140
Branches 9793 9858 +65
========================================
+ Hits 25943 26080 +137
Misses 433 433
- Partials 612 615 +3
🚀 New features to boost your workflow:
|
This was referenced Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/selfhost/maintenance-admission.ts) so periodic maintenance sweeps — contributor evidence, RAG re-indexing, drift scans, burden forecasts, product rollups, notifications, etc. — always yield to live webhook/review work and to host CPU pressure, instead of competing with it on equal footing. Wired into both queue backends (sqlite-queue.ts,pg-queue.ts) at the exact point they already handle GitHub rate-limit admission, using the same defer-with-jitter pattern. A denied job is pushed back topendingwith a jittered futurerun_after; its original enqueue time is preserved so a trickle ceiling (MAINTENANCE_ADMISSION_MAX_DEFER_AGE_MS, default 4h) force-admits it under sustained pressure — maintenance can slow down but never starves forever.src/selfhost/host-pressure.ts). All thresholds are env-configurable with protective defaults; existing coalescing (jobCoalesceKey) already collapses duplicate maintenance requests, so this is additive, not a rewrite of the queue.fetchRequiredStatusContexts) as a permission gap, not GitHub rate-limit exhaustion — reusesGitHubApiError.rateLimited(already correctly computed) and adds a dedicatedgittensory_github_branch_protection_permission_denied_totalcounter so a dashboard can tell "GitHub is throttling us" apart from "this token can't read branch protection" (the common case for installations/forks). The 403/404 negative-cache and rate-limit classification themselves were already correct — this only adds the missing observability.--profile runners) in.env.exampleanddocker-compose.yml, addressing the production incident this PR is a response to (3 uncapped CI-runner containers starving the review app on an 8-vCPU box).scripts/docker-prune.sh: a safe, read-only-by-default Docker build-cache/image prune script (never touches volumes/application data) plus disk-pressure guidance.Why no linked issue: this is a direct, self-scoped operational-hardening task (repo-owner-authored) responding to a live production incident on our own self-host VPS, not a community-issue-driven contribution — see Notes below for the incident detail.
Scope
type(scope): short summaryConventional Commit format.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Validation
All commands below were run locally and are portable (no repo-specific secrets required):
git diff --checknpm run actionlintnpm run typechecknpm run test:coveragelocally (unsharded) — 96.63% statements / 95.68% branches project-wide; the new/changedsrc/**files (maintenance-admission.ts,host-pressure.ts,sqlite-queue.ts,backfill.ts's changed lines) are at 100% line/branch coverage on their own diffs (verified with--coverage.includescoped runs).pg-queue.tsandsrc/server.tsare Codecov-ignored percodecov.yml(Postgres path validated by the real-Postgres integration test;server.tsby the Docker boot smoke test) but still have unit tests for parity/correctness.npm run test:workersnpm run build:mcpnpm run test:mcp-packnpm run ui:openapi:checknpm run ui:lintnpm run ui:typechecknpm run ui:buildnpm audit --audit-level=moderate— 0 vulnerabilitiesnpm run test:ci(the full local gate, all steps above plusdb:migrations:check,db:schema-drift:check,selfhost:env-reference:check,selfhost:validate-observability,cf-typegen:check,ui:openapi:settings-parity,ui:version-audit,ui:test,build:miner,rees:test) — fully green, 7058 tests passed.npm run selfhost:env-reference(regeneratedapps/gittensory-ui/src/lib/selfhost-env-reference.tsafter adding the newMAINTENANCE_ADMISSION_*env vars to.env.example)node scripts/validate-observability-configs.mjs(new Grafana panels + Prometheus alert rules validated)Safety
apps/gittensory-uiUI changes.UI Evidencesection — N/A, no visible UI changes (Grafana dashboard JSON and shell/doc comments are not app UI)..env.example,docker-compose.yml,docker-compose.override.yml.example);CHANGELOG.mditself is untouched (not a release-prep PR).Notes
docker-compose.yml,docker-compose.override.yml.example,.env.example, andgrafana/dashboards/gittensory.jsonare outside this repo'swantedPathsgate manifest (src/,packages/,test/,migrations/,scripts/,review-enrichment/,.github/workflows/,wrangler.jsonc,apps/gittensory-ui/). Touching them is intentional and necessary here (runner-isolation docs and observability dashboards can't be delivered without them) — flagging for owner-review awareness since the automated gate treats out-of-scope paths as advisory rather than a hard requirement for owner-authored PRs.build-contributor-evidenceinto incremental computation — the former has no existing counter to build on (out of scope for a focused PR), and the latter is high-risk/high-effort for uncertain benefit given the admission policy already prevents it from running during a pressure spike, and its own scheduled cadence (every 6h,isFullSyncWindowinsrc/index.ts) is already conservative.