Fold the sentinel into the scraper and drop the sentinel service (BL-0046)

The stall watchdog now runs inside the scraper (ScraperService.checkStalls,
every 30 s from the work loop): same rule as before, one checkpoint-safe
restart, quarantine on the second stall, missing checkpoint is no evidence,
and paused time no longer counts. Stalls are recorded as scraper incidents
(failure.kind 'stall'). The private /api/recovery endpoint is gone.

Dropped with the service: reader/scraper-unreachable incidents (supervisor
and Docker handle crashes; the health page shows "Scraper: unreachable"),
duplicate job-failure incidents and the unused /metrics endpoint.
The stack is now reader + scraper (+ optional peer-gateway).
The supervisor test moved to runtime/test (npm run test:runtime stays).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MaashkinoozheandClaude Opus 5.5 committed 2026-10-22 22:58:03 +02:00
1 parent 88555d4780
commit b2bb34174c
37 files changed
+163 -311

No files matched your search

-1
View File
@@ -3,7 +3,6 @@ const fs = require('fs'), path = require('path'), { spawn } = require('child_pro
const SPECS = {
reader: { script: 'server.js', port: () => process.env.PORT || 8080, file: () => path.join(process.env.DATA || 'data', 'runtime-reader.json') },
scraper: { script: 'scraper/daemon.js', port: () => process.env.SCRAPER_PORT || 8091, file: () => path.join(process.env.SCRAPER_DATA || path.join(process.env.DATA || 'data', 'scraper'), 'runtime.json') },
sentinel: { script: 'sentinel/daemon.js', port: () => process.env.SENTINEL_PORT || 8092, file: () => path.join(process.env.SENTINEL_DATA || path.join(process.env.DATA || 'data', 'sentinel'), 'runtime.json') },
};
class Supervisor {
constructor(name, options = {}) {
+28
View File
@@ -0,0 +1,28 @@
'use strict';
const test = require('node:test'), assert = require('node:assert/strict');
const fs = require('fs'), os = require('os'), path = require('path'), { EventEmitter } = require('events');
const { Supervisor } = require('../supervisor');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
test('supervisor isolates a child crash and persists its bounded restart budget', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-supervisor-')), file = path.join(dir, 'runtime.json');
let starts = 0;
const spawn = () => { const child = new EventEmitter(); child.pid = ++starts; child.kill = () => { child.emit('exit', 0); child.emit('close', 0); }; return child; };
const supervisor = new Supervisor('reader', { file, spawn, retryBaseMs: 1 });
try {
supervisor.start();
for (let n = 0; n < 3; n++) {
supervisor.child.emit('close', 1, null);
for (let i = 0; i < 50 && supervisor.state.status === 'retry_wait'; i++) await delay(2);
}
assert.equal(starts, 3); assert.equal(supervisor.state.status, 'parked'); assert.equal(supervisor.child, null);
const restored = new Supervisor('reader', { file, spawn, retryBaseMs: 1 }); restored.start();
assert.equal(starts, 3); assert.equal(restored.state.status, 'parked'); await restored.close();
} finally { await supervisor.close(); fs.rmSync(dir, { recursive: true, force: true }); }
});
test('intentional supervisor shutdown does not consume the crash budget', async () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mc-supervisor-stop-'));
const child = new EventEmitter(); child.pid = 1; child.kill = () => { child.emit('exit', 0); child.emit('close', 0); };
const supervisor = new Supervisor('scraper', { file: path.join(dir, 'runtime.json'), spawn: () => child });
try { supervisor.start(); await supervisor.close(); assert.equal(supervisor.state.status, 'stopped'); assert.equal(supervisor.state.failures.length, 0); }
finally { await supervisor.close(); fs.rmSync(dir, { recursive: true, force: true }); }
});