Skip to content

fix(selfhost): gate maintenance admission on genuine live pressure, not raw pending count#4674

Merged
JSONbored merged 1 commit into
mainfrom
fix/maintenance-admission-runnable-signal
Jul 10, 2026
Merged

fix(selfhost): gate maintenance admission on genuine live pressure, not raw pending count#4674
JSONbored merged 1 commit into
mainfrom
fix/maintenance-admission-runnable-signal

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • evaluateMaintenanceAdmission's live_pending_high/live_job_age_high checks gated on livePendingCount/oldestLivePendingAgeMs — a raw pending/processing count and created-at age that include work deliberately deferred to the future (e.g. agent-regate-pr's normal, expected, staggered per-PR backlog, index.ts:24-29). On edge-nl-01 this let a routine backlog (not real load: host load was ~0.01/core, zero foreground jobs runnable for a sustained 100s sample) starve the maintenance lane for hours — 69% of admission denials in an 18-minute window were live_pending_high, and the maintenance_pending_high drain escape built specifically to prevent lane self-pinning never got a chance to fire because this check denies first.
  • Switches both checks to the runnable-now signal (liveRunnableNowCount/oldestLiveRunnableAgeMs), and broadens that signal's SQL in both queue backends (sqlite + pg) to also count actively processing foreground jobs as genuine current pressure, not just due-and-unclaimed pending ones — a processing job is real, in-flight resource use and arguably more legitimate pressure than a merely-due-but-waiting one.
  • No new config surface: the existing global MAINTENANCE_ADMISSION_MAX_LIVE_PENDING/MAINTENANCE_ADMISSION_MAX_LIVE_AGE_MS env knobs are unchanged — they now simply measure what their doc comments always said they measured.

Closes #4669

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • This is a backend-only change to src/selfhost/{maintenance-admission,sqlite-queue,pg-queue}.ts with no UI, MCP, OpenAPI, wrangler binding, or workflow surface, so actionlint/test:workers/build:mcp/test:mcp-pack/ui:* are not applicable. test:coverage was run targeted (vitest run test/unit/selfhost-{maintenance-admission,sqlite-queue,pg-queue}.test.ts --coverage, 330 tests, all green) rather than the full unsharded suite; maintenance-admission.ts's only reported uncovered line (106) is a pre-existing JSDoc comment line outside this diff, unrelated to the change.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. (N/A — no auth/session surface touched)
  • API/OpenAPI/MCP behavior is updated and tested where needed. (N/A — internal queue admission logic only, no external API surface)
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. (N/A — no UI changes)
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. (N/A — no visible UI change)
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs. (N/A)

UI Evidence

N/A — no UI/frontend/docs-visible change; this is an internal self-host queue admission fix.

Notes

…ot raw pending count (#4669)

evaluateMaintenanceAdmission's live_pending_high/live_job_age_high checks used
livePendingCount/oldestLivePendingAgeMs, which include work deliberately deferred
to the future (e.g. agent-regate-pr's normal, staggered per-PR backlog). That let
a routine, expected backlog starve the maintenance lane for hours even when the
box was otherwise idle, since the checks never reached the drain escape meant to
prevent exactly this. Switch both checks to the runnable-now/processing signal
they were always meant to use, and broaden that signal to also count actively
processing jobs as genuine current pressure (not just due-and-unclaimed ones).
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@JSONbored JSONbored self-assigned this Jul 10, 2026
@JSONbored
JSONbored merged commit 4887998 into main Jul 10, 2026
8 checks passed
@JSONbored
JSONbored deleted the fix/maintenance-admission-runnable-signal branch July 10, 2026 11:19
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.13%. Comparing base (6dcd997) to head (6332f3d).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4674   +/-   ##
=======================================
  Coverage   94.13%   94.13%           
=======================================
  Files         434      434           
  Lines       38541    38541           
  Branches    14054    14054           
=======================================
  Hits        36281    36281           
  Misses       1601     1601           
  Partials      659      659           
Files with missing lines Coverage Δ
src/selfhost/maintenance-admission.ts 100.00% <100.00%> (ø)
src/selfhost/sqlite-queue.ts 99.60% <ø> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

fix(selfhost): maintenance-admission gates on raw live-pending count, not runnable-now, starving the maintenance lane

1 participant