Fix immediate automation pause, restored queue rendering and bounded disk reads; release 2.1.75
CI / verify (push) Canceled after 0s

This commit is contained in:
Sucukdeluxe committed 2026-10-20 13:56:04 +02:00
1 parent 267a840853
commit 80eb878f1b
12 files changed
+168 -68

No files matched your search

+12 -2
View File
@@ -535,12 +535,22 @@ class ConfigStore {
_enqueueWrite(fn, options = {}) {
if (this._writesQuiesced && !options.allowDuringQuiesce) return Promise.reject(this._quiescedWriteError());
const previous = this._lastQueuedWrite;
if (options.coalesceKey && previous?.key === options.coalesceKey && !previous.started) {
previous.fn = fn;
return previous.operation;
}
const queued = { key: options.coalesceKey, fn, started: false, operation: null };
this._lastQueuedWrite = queued;
this._wqDepth++;
const execute = async () => {
queued.started = true;
if (this._lastQueuedWrite === queued) this._lastQueuedWrite = null;
if (!options.skipRefresh) await this._refreshConfigFromDisk();
return fn();
return queued.fn();
};
const operation = this._writeQueue.then(execute, execute);
queued.operation = operation;
this._pendingWriteOperations.add(operation);
this._writeQueue = operation.then(
() => { this._wqDepth--; },
@@ -613,7 +623,7 @@ class ConfigStore {
};
await this._guardHosters(current, false);
return this._commit(current);
}, options);
}, { ...options, coalesceKey: 'pending-queue' });
}
saveFolderMonitorRuntimeState(folderMonitor, options = {}) {
+7
View File
@@ -1,4 +1,5 @@
const { randomUUID } = require('node:crypto');
const { getUploadReadSnapshot, setUploadReadLimit } = require('./upload-file-io');
const path = require('node:path');
const { McpAccessError, resolveGrantedFile } = require('./mcp-access');
const { createMcpFiles } = require('./mcp-files');
@@ -59,6 +60,7 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
canWrite(); guard(context);
const result = await invoke(channel);
if (result?.error || result?.monitorError) throw new McpAccessError(code);
if (channel === 'automation:resume') await renderer('automation-resume', {}, context);
return result;
};
const handlers = {
@@ -76,6 +78,11 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
})), boundaries: ['Permissions and directory grants can only be changed locally.', 'Destructive actions require an exact local confirmation; MCP cannot approve it.', 'No arbitrary shell, SQL, mouse/keyboard or screen control.', 'Paused automation is resumed with mhu_automation_resume. A disabled monitor requires mhu_automation_start.'] };
},
mhu_performance_get: () => getPerformance(),
mhu_io_limits_get: () => getUploadReadSnapshot(),
mhu_io_limits_update: ({ readConcurrency }, context) => {
canWrite(); guard(context);
return setUploadReadLimit(readConcurrency);
},
mhu_system_metrics: args => getSystemMetrics(args),
mhu_app_state: async (args, context) => ({ ...(await renderer('state', {}, context)), automation: await invoke('automation:get-status') }),
mhu_queue_list: (args, context) => renderer('queue-list', args, context),
+4 -2
View File
@@ -19,13 +19,15 @@ const definitions = [
['app_info', 'Read application version and runtime information.', 'read', {}, []],
['capabilities', 'Read effective permissions, the supported action catalog and local security boundaries. This cannot grant permissions or approve actions.', 'read', {}, []],
['performance_get', 'Read bounded in-memory main-thread, renderer, CPU, memory, I/O and transfer-slot measurements. Missing samples do not prove a freeze.', 'read', {}, []],
['io_limits_get', 'Read active, waiting and maximum concurrent upload file reads.', 'read', {}, []],
['io_limits_update', 'Adjust bounded upload file-read concurrency in memory. Does not abort transfers or persist settings; default returns after restart.', 'control', { readConcurrency: integer(1, 32) }, ['readConcurrency']],
['system_metrics', 'Read cached system CPU, RAM, disk activity, read/write throughput, cumulative byte counters and volume capacity. No shell commands. Samples every 10 seconds; null or stale values are not freeze evidence.', 'read', { limit: integer(1, 60) }, []],
['app_state', 'Read live transfer and automation summary.', 'read', {}, []],
['queue_list', 'Read a bounded page of upload jobs.', 'read', { ...page, status: text(40) }, []],
['queue_job_log', 'Read a bounded, secret-filtered log for one upload job.', 'read', { jobId: id, ...page }, ['jobId']],
['queue_add', 'Add files from a granted directory to the upload queue.', 'control', { rootId: id, paths: array(text(), 1000), hosters: array(hoster, 5) }, ['rootId', 'paths', 'hosters']],
['queue_start', 'Start eligible queued uploads.', 'control', jobIds, []],
['queue_pause', 'Pause new uploads after current transfers.', 'control', {}, []],
['queue_pause', 'Immediately abort active uploads and pause new work. Paused files restart from the beginning on resume.', 'control', {}, []],
['queue_resume', 'Resume the shared upload and automation pause.', 'control', {}, []],
['queue_retry', 'Retry selected failed jobs.', 'control', jobIds, ['jobIds']],
['queue_cancel', 'Cancel selected running or queued jobs.', 'control', jobIds, ['jobIds']],
@@ -63,7 +65,7 @@ const definitions = [
queueLimitJobs: integer(0, 100000), reconcileIntervalMinutes: integer(1, 1440)
}, ['rootId'], true],
['automation_start', 'Start configured folder monitoring.', 'control', {}, []],
['automation_pause', 'Pause the shared upload queue and folder automation after active transfers. Does not disable the configured monitor.', 'control', {}, []],
['automation_pause', 'Immediately abort active uploads and pause the shared queue and folder automation. Resume restarts paused files from the beginning. Does not disable the configured monitor.', 'control', {}, []],
['automation_resume', 'Resume the shared upload queue and configured folder automation. Use this for paused=true, not automation_start. Does not enable a disabled monitor.', 'control', {}, []],
['automation_stop', 'Stop folder monitoring without removing queued jobs.', 'control', {}, []],
['automation_scan', 'Run a read-only folder monitoring test scan.', 'read', {}, []],
+39 -14
View File
@@ -1,23 +1,48 @@
const fs = require('node:fs');
const { runtimePerformance } = require('./performance-monitor');
const Semaphore = require('./semaphore');
const statUploadFile = file => runtimePerformance.measure('file.stat', () => fs.promises.stat(file));
async function* readUploadFile(file, signal) {
signal?.throwIfAborted();
const stream = fs.createReadStream(file, { highWaterMark: 1024 * 1024, ...(signal ? { signal } : {}) });
const iterator = stream[Symbol.asyncIterator]();
try {
for (;;) {
const result = await runtimePerformance.measure('file.read', () => iterator.next());
if (result.done) break;
function createUploadFileReader({ limit = 4, open = file => fs.promises.open(file, 'r') } = {}) {
const slots = new Semaphore(limit);
const admitted = async (signal, action) => {
await runtimePerformance.measure('file.read.wait', () => slots.acquire(signal));
try {
signal?.throwIfAborted();
yield result.value;
return await action();
} finally {
slots.release();
}
} finally {
stream.destroy();
await iterator.return?.();
}
};
return {
snapshot: () => ({ limit: slots.limit, active: slots.active, waiting: slots.pending }),
updateLimit(value) {
if (!Number.isInteger(value) || value < 1 || value > 32) throw new Error('Ungültiges Lese-Limit.');
slots.updateLimit(value);
return this.snapshot();
},
async *read(file, signal) {
signal?.throwIfAborted();
const handle = await admitted(signal, () => open(file));
try {
for (;;) {
const buffer = Buffer.allocUnsafe(1024 * 1024);
const result = await admitted(signal, () => runtimePerformance.measure('file.read', () => handle.read(buffer, 0, buffer.length, null)));
signal?.throwIfAborted();
if (!result.bytesRead) break;
yield buffer.subarray(0, result.bytesRead);
}
} finally {
await handle.close();
}
}
};
}
module.exports = { statUploadFile, readUploadFile };
const uploadFileReader = createUploadFileReader();
const readUploadFile = (file, signal) => uploadFileReader.read(file, signal);
const getUploadReadSnapshot = () => uploadFileReader.snapshot();
const setUploadReadLimit = value => uploadFileReader.updateLimit(value);
module.exports = { statUploadFile, readUploadFile, getUploadReadSnapshot, setUploadReadLimit, createUploadFileReader };
+23 -1
View File
@@ -11,6 +11,7 @@ const ClouddropUploader = require('./clouddrop-upload');
const Semaphore = require('./semaphore');
const Throttle = require('./throttle');
const { runtimePerformance } = require('./performance-monitor');
const { getUploadReadSnapshot } = require('./upload-file-io');
const { probeFileHead } = require('./file-probe');
const { normalizeFailureDetails } = require('./upload-diagnostics');
const { classifyAccountFailure, selectFallbackAccount } = require('./account-rotation');
@@ -126,7 +127,7 @@ class UploadManager extends EventEmitter {
}
let pending = 0;
for (const sem of Object.values(this.semaphores)) pending += (sem && sem.pending) || 0;
return { activeByHoster, transientErrors: this._transientErrorTotal, pending, active: this.activeJobs.size,
return { activeByHoster, transientErrors: this._transientErrorTotal, pending, active: this.activeJobs.size, diskReads: getUploadReadSnapshot(),
globalSlots: this.globalSemaphore ? { active: this.globalSemaphore.active, pending: this.globalSemaphore.pending, limit: this.globalSemaphore.limit } : null,
hosterSlots: Object.fromEntries(Object.entries(this.semaphores).map(([hoster, sem]) => [hoster, { active: sem.active, pending: sem.pending, limit: sem.limit }])),
sessionBytes: this.sessionBytes, transferredBytes: this.transferredBytes, batchStartedAt: this.startTime,
@@ -526,6 +527,7 @@ class UploadManager extends EventEmitter {
let finalAttempt = 0;
const recordFinalResult = (status, payload = {}) => {
if (status === 'aborted' && jobAbortController.signal.reason === 'automation-pause' && !this.cancelledJobIds.has(jobId) && !batchSignal.aborted) payload = { ...payload, error: 'Warteschlange angehalten' };
if (finalResultRecorded) return;
finalResultRecorded = true;
finalStatus = status;
@@ -550,6 +552,7 @@ class UploadManager extends EventEmitter {
};
const emitFinalStatus = (status, payload = {}) => {
if (status === 'aborted' && jobAbortController.signal.reason === 'automation-pause' && !this.cancelledJobIds.has(jobId) && !batchSignal.aborted) payload = { ...payload, error: 'Warteschlange angehalten' };
if (status === 'aborted' && this.abortController.signal.aborted) return;
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
jobId,
@@ -1575,8 +1578,27 @@ class UploadManager extends EventEmitter {
if (!this.queueAdmissionAbortController.signal.aborted) this.queueAdmissionAbortController.abort();
}
pauseImmediately() {
this.finishAfterActive();
for (const controller of this.jobAbortControllers.values()) {
if (!controller.signal.aborted) controller.abort('automation-pause');
}
}
async resumeAfterActive() {
const stoppedController = this.queueAdmissionAbortController;
const pausedJobs = new Set([...this.jobAbortControllers].filter(([, controller]) => controller.signal.reason === 'automation-pause').map(([jobId]) => jobId));
if (pausedJobs.size) {
await new Promise(resolve => {
const settled = ({ jobId }) => {
pausedJobs.delete(jobId);
if (pausedJobs.size) return;
this.off('job-settled', settled);
resolve();
};
this.on('job-settled', settled);
});
}
await this._waitForQueueAdmissionIdle();
if (this.queueAdmissionAbortController === stoppedController && stoppedController.signal.aborted) {
this.queueAdmissionAbortController = new AbortController();