feat: harden cron execution recovery and expose scheduling diagnostics

Reconcile scheduled and system cron triggers, isolate concurrent executions and retain verifiable exit statistics across restarts. Add paged task history, log and script browsing, dashboard timing details and regression coverage.
This commit is contained in:
whyour committed 2026-11-17 01:01:57 +08:00
1 parent 3b6a873520
commit 8a9e70e90b
166 files changed
+18942 -1800

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
// Run inside the dedicated bounded ext4 acceptance volume, alongside receipt-volume-full.cjs.
// Pause the actual post-commit collector before or after its filesystem call.
const fs = require('node:fs');
const path = require('node:path');
const { exhaust } = require('./receipt-volume-full.cjs');
const { sequelize } = require('/ql/static/build/data');
const { TriggerHistory } = require('/ql/static/build/shared/triggerHistory');
const [stage, id] = process.argv.slice(2);
const volume = '/ql/data/db';
const canonical = path.join(volume, 'cron-exits', id);
const control = '/tmp/journal-qa';
const capacity = () => fs.statfsSync(volume).bavail;
if (fs.statfsSync(volume).type !== 0xef53 || !/^[a-z0-9-]+$/.test(id) ||
!['rename-before','rename-after','rename-enospc','unlink-before','unlink-after','unlink-injected'].includes(stage)) {
throw Error('Expected a supported ext4 collection boundary and execution ID');
}
function hold(event) {
const target = path.join(control, stage + '-event');
fs.writeFileSync(target + '.tmp', JSON.stringify(event));
fs.renameSync(target + '.tmp', target);
// The outside observer cuts power here. A failed orchestrator has a bounded wait.
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 120000);
throw Error('Power cut did not occur');
}
async function atBoundary(source, destination, operation) {
// A hard link outside the receipt namespace keeps the allocation constant even
// if unlink succeeds.
const pin = path.join(volume, '.qa-reclaim-pin');
fs.linkSync(source, pin);
exhaust(false);
const event = {stage, id, source, destination, blocksBefore: capacity()};
if (event.blocksBefore !== 0) throw Error('Expected an exhausted data volume');
if (stage === 'rename-enospc') {
// Fill the target directory with entries the same length as the capture name.
// Hard links expend directory space without needing another inode.
const dir = path.dirname(destination);
let count = 0;
try {
for (;;) {
fs.linkSync(pin, path.join(dir, 'q' + count.toString(36).padStart(path.basename(destination).length - 1, '0')));
count++;
}
} catch (error) {
if (error.code !== 'ENOSPC') throw error;
}
event.extraDirectoryEntries = count;
}
if (stage.endsWith('-before')) hold({...event, called:false});
if (stage === 'unlink-injected') {
// Explicitly synthetic. Keep the file and let the real collector unwind.
throw Object.assign(Error('Injected unlink capacity error'), {code:'ENOSPC', event});
}
try {
await operation();
} catch (error) {
if (stage !== 'rename-enospc' || error.code !== 'ENOSPC') throw error;
hold({...event, called:true, result:error.code, errno:error.errno, syscall:error.syscall,
sourceExists:fs.existsSync(source), destinationExists:fs.existsSync(destination)});
}
if (stage === 'rename-enospc') throw Error('Expected rename to need another directory block');
hold({...event, called:true, result:'success', blocksAfter:capacity(),
sourceExists:fs.existsSync(source), destinationExists:destination && fs.existsSync(destination)});
}
const rename = fs.promises.rename.bind(fs.promises);
const unlink = fs.promises.unlink.bind(fs.promises);
let reached = false, injected;
fs.promises.rename = (from,to) => {
if (!reached && stage.startsWith('rename-') && from === canonical) {
reached = true;
const destination = path.join(fs.realpathSync(path.dirname(to)), path.basename(to));
return atBoundary(from,destination,() => rename(from,to));
}
return rename(from,to);
};
fs.promises.unlink = async file => {
if (!reached && stage.startsWith('unlink-') && path.basename(file).startsWith('.pending.' + id + '.r-')) {
reached = true;
try {return await atBoundary(fs.realpathSync(file),null,() => unlink(file));}
catch (error) { if (stage === 'unlink-injected') injected = error; throw error; }
}
return unlink(file);
};
new TriggerHistory(sequelize).complete(id,'unknown',null,null).then(() => {
if (injected?.code === 'ENOSPC') hold({...injected.event, called:false, injected:'ENOSPC',
privateFileRetained:fs.existsSync(injected.event.source)});
throw Error('Collector did not reach the expected power cut');
}).catch(error => {console.error(error); process.exitCode = 1;}).finally(() => sequelize.close());