Unify halt and fire cancellation by verified run identity with durable first-owner receipts and shared deadlines. Integrate the instance control with the current host, library and tester-socket paths. Focused nine-file evidence is 62 passing tests; broad suites, mutants and review remain pending.
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
// Host-only adapters for the root coordinator. Workers cannot select these paths.
|
|
import { lstatSync } from 'node:fs';
|
|
import { dirname } from 'node:path';
|
|
import { bindingDataDir } from './binding.mjs';
|
|
import { requestProcessingStop, clearProcessingStop } from './journal.mjs';
|
|
import { listRuntimes, unregisterRuntime } from '../../processing-control/src/runtimes.mjs';
|
|
function journal(root, record) {
|
|
const dir = bindingDataDir(root, record.run);
|
|
for (const path of [dirname(dir), dir]) {
|
|
const st = lstatSync(path);
|
|
if (!st.isDirectory() || st.isSymbolicLink() || st.uid !== process.getuid() || (st.mode & 0o077))
|
|
throw new Error('processing-discord-path-unsafe');
|
|
}
|
|
return dir;
|
|
}
|
|
export function discordProcessingHooks(dataRoot) {
|
|
return {
|
|
beforeStop(record, generation) {
|
|
if (record.kind === 'discord') requestProcessingStop(journal(dataRoot, record), generation);
|
|
},
|
|
onResume(generation) {
|
|
for (const r of listRuntimes(dataRoot)) {
|
|
if (r.kind === 'discord' && r.haltGeneration === generation) {
|
|
clearProcessingStop(journal(dataRoot, r), generation);
|
|
unregisterRuntime(dataRoot, r.id);
|
|
}
|
|
}
|
|
},
|
|
};
|
|
}
|