Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: report false when cancelling a yt-dlp import that already finished (#6013)

[._.]/ Adam Eivy4c931262cba6
diff --git a/server/services/roundReferenceAudioImport.js b/server/services/roundReferenceAudioImport.js
index 62d83b97a8..e1c0fc507d 100644
--- a/server/services/roundReferenceAudioImport.js
+++ b/server/services/roundReferenceAudioImport.js
@@ -47,7 +47,10 @@ export const __testing = { importJobs };
*/
export function cancelReferenceAudioImport(jobId) {
const job = importJobs.get(jobId);
- if (!job || job.canceled) return false;
+ // The job lingers in the map after it ends (closeJobAfterDelay evicts it on
+ // a timer), so a terminal status — not just the flag — is what makes a cancel
+ // for an already-finished import report false.
+ if (!job || job.canceled || job.status !== 'running') return false;
job.canceled = true;
const proc = job.process;
if (proc) killWithEscalation(proc, { label: 'yt-dlp reference audio', stillRunning: () => job.process === proc });
@@ -121,6 +124,7 @@ export async function startReferenceAudioImport(url) {
// the core handed off and no longer owns.
await cleanupYtDlpTemp(tempPrefix);
} finally {
+ job.status = 'done';
closeJobAfterDelay(importJobs, jobId);
}
})();
diff --git a/server/services/roundReferenceAudioImport.test.js b/server/services/roundReferenceAudioImport.test.js
index 17e23be2b9..0c46deebf3 100644
--- a/server/services/roundReferenceAudioImport.test.js
+++ b/server/services/roundReferenceAudioImport.test.js
@@ -108,6 +108,14 @@ describe('cancelReferenceAudioImport', () => {
__testing.importJobs.delete('j1');
});
+ it('returns false once the job has finished, while it lingers in the map', () => {
+ // closeJobAfterDelay evicts on a timer, so a finished job is still present —
+ // cancelling it must not report an accepted cancel to the client.
+ __testing.importJobs.set('j3', { id: 'j3', status: 'done', clients: [], process: null, canceled: false });
+ expect(cancelReferenceAudioImport('j3')).toBe(false);
+ __testing.importJobs.delete('j3');
+ });
+
it('signals a running child and refuses a second cancel', () => {
const proc = { pid: 4321 };
const job = { id: 'j2', status: 'running', clients: [], process: proc, canceled: false };
diff --git a/server/services/trackYoutubeImport.js b/server/services/trackYoutubeImport.js
index 26f6f3e62c..bd1e8ffda1 100644
--- a/server/services/trackYoutubeImport.js
+++ b/server/services/trackYoutubeImport.js
@@ -58,7 +58,10 @@ export const __testing = { importJobs };
*/
export function cancelYoutubeImport(jobId) {
const job = importJobs.get(jobId);
- if (!job || job.canceled) return false;
+ // The job lingers in the map after it ends (closeJobAfterDelay evicts it on
+ // a timer), so a terminal status — not just the flag — is what makes a cancel
+ // for an already-finished import report false.
+ if (!job || job.canceled || job.status !== 'running') return false;
job.canceled = true;
const proc = job.process;
if (proc) killWithEscalation(proc, { label: 'yt-dlp import', stillRunning: () => job.process === proc });
@@ -130,6 +133,7 @@ export async function startYoutubeImport(url) {
// produced outPath the core handed off and no longer owns.
await cleanupYtDlpTemp(tempPrefix);
} finally {
+ job.status = 'done';
closeJobAfterDelay(importJobs, jobId);
}
})();
diff --git a/server/services/trackYoutubeImport.test.js b/server/services/trackYoutubeImport.test.js
index 3d652229c3..4eb6fa898d 100644
--- a/server/services/trackYoutubeImport.test.js
+++ b/server/services/trackYoutubeImport.test.js
@@ -142,6 +142,14 @@ describe('cancelYoutubeImport', () => {
__testing.importJobs.delete('j1');
});
+ it('returns false once the job has finished, while it lingers in the map', () => {
+ // closeJobAfterDelay evicts on a timer, so a finished job is still present —
+ // cancelling it must not report an accepted cancel to the client.
+ __testing.importJobs.set('j3', { id: 'j3', status: 'done', clients: [], process: null, canceled: false });
+ expect(cancelYoutubeImport('j3')).toBe(false);
+ __testing.importJobs.delete('j3');
+ });
+
it('signals a running child and refuses a second cancel', () => {
const proc = { pid: 1234 };
const job = { id: 'j2', status: 'running', clients: [], process: proc, canceled: false };