Skip to content

fix(cli): supervisor restarts on spontaneous exit-0 (OOM cgroup) + waits for port before respawn (#4425) - #4578

Merged
diegosouzapw merged 1 commit into
release/v3.8.33from
fix/4425-supervisor
Jun 22, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.33from
fix/4425-supervisor

Conversation

@diegosouzapw

Copy link
Copy Markdown
Owner

Closes #4425 (partial — the recovery slice)

Problem

Under load the gateway crash-looped: (1) a systemd MemoryMax cgroup kill reports a clean exit (code 0), which the supervisor treated as an intentional stop and exited — leaving the gateway dead with Restart=on-failure; (2) it respawned immediately after a crash, before the OS released the listen socket → an EADDRINUSE cascade that exhausted the restart budget; (3) the 30s reset window dropped the crash counter too fast.

Fix

New bin/cli/runtime/supervisorPolicy.mjs (pure + unit-testable): shouldExitInsteadOfRestart (only an intentional shutdown exits; a spontaneous code-0 now restarts), RESTART_RESET_MS 30s→60s, DEFAULT_MAX_RESTARTS 2→3, computeRestartDelayMs, and isPortFree/waitUntilPortFree. processSupervisor.handleExit now restarts on a spontaneous code-0 and waits (bounded) for the port to free up before respawning.

This is the recovery slice — it does not fix the underlying memory growth (tracked under the #4041/#4380 OOM work); it stops a crashed/OOM'd process from staying down or cascading on EADDRINUSE.

Validation (TDD)

New tests/unit/supervisor-policy-4425.test.ts (5/5: restart-on-code-0, constants, backoff, port-free detection + wait). Updated the existing cli-process-supervisor.test.ts to match the corrected behavior (code-0 restarts; 60s reset window). 16/16 green; lint clean.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw
diegosouzapw force-pushed the fix/4425-supervisor branch from 3f64417 to 99250c7 Compare June 21, 2026 22:50
@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.32 to release/v3.8.33 June 21, 2026 22:50
KooshaPari added a commit to KooshaPari/OmniRoute that referenced this pull request Jun 21, 2026
The Fast Quality Gates lint check was failing on every PR with
'4 arquivos cresceram alem do cap': src/lib/db/core.ts,
src/lib/usage/providerLimits.ts, src/shared/constants/providers.ts,
open-sse/services/usage.ts. The frozen baselines in
config/quality/file-size-baseline.json were last set at v3.8.30 and
had drifted past the cap=800 due to legitimate feature growth from
PR diegosouzapw#4381 (combos split), PR diegosouzapw#4433 (cluster opt-in profiles), and
PR diegosouzapw#4480 (vacuum scheduler).

This commit rebaselines those 4 frozen entries to their current
actual line count (+2 buffer to cover wc -l's off-by-one and any
stray edits during review). It does NOT change the cap=800 for new
files, nor does it shrink any of the 4 monoliths.

Structural shrink of these files is tracked separately in diegosouzapw#3501
(QG v2 chatCore split continuation). This rebaseline just restores
green CI until those structural refactors land.

Files changed: 1 (config/quality/file-size-baseline.json)
- src/lib/db/core.ts: frozen 624 -> 781 (was +157 past cap=800...wait)
  Actually frozen was 624 vs cap=800, so core.ts was 157 lines UNDER cap.
  The drift is in the 4 files whose actuals grew past their frozen values.

Verification:
- node scripts/check/check-file-size.mjs -> '[file-size] OK -- 103
  arquivos congelados, cap 800 para novos (2710 arquivos verificados)'
- node scripts/check/check-env-doc-sync.mjs -> 'Env / docs contract
  is in sync'
- node scripts/check/check-db-rules.mjs -> 'OK (85 modulos db/, 57
  re-exportados, 28 intencionalmente-internos; 2 leituras de DB
  externo permitidas)'

Unblocks every open PR currently stuck on Fast Quality Gates
(diegosouzapw#4571, diegosouzapw#4576, diegosouzapw#4577, diegosouzapw#4578 + this PR's own branch).
@diegosouzapw
diegosouzapw merged commit fbcc43c into release/v3.8.33 Jun 22, 2026
10 checks passed
@diegosouzapw
diegosouzapw deleted the fix/4425-supervisor branch June 23, 2026 13:13
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…its for port before respawn (diegosouzapw#4425) (diegosouzapw#4578)

Co-authored-by: Diego Rodrigues de Sa e Souza <diego.souza@cdwasolutions.com.br>
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