{"record":{"id":"6b3be317482bede7","repo":"Hmbown/CodeWhale","slug":"heavy-command-canceled-while-queued-for-resource-a","errorCode":null,"errorMessage":"heavy command canceled while queued for resource admission","messagePattern":"heavy command canceled while queued for resource admission","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/tools/resource_admission.rs","lineNumber":189,"sourceCode":"    acquire_heavy_command_permit_at(&root, limit, cancel, &probe)\n        .await\n        .map(Some)\n}\n\nasync fn acquire_heavy_command_permit_at(\n    root: &Path,\n    limit: usize,\n    cancel: Option<&CancellationToken>,\n    probe: &dyn MemoryProbe,\n) -> Result<HeavyCommandPermit> {\n    tokio::fs::create_dir_all(root)\n        .await\n        .with_context(|| format!(\"creating resource admission directory {}\", root.display()))?;\n    let started = Instant::now();\n\n    loop {\n        if cancel.is_some_and(|token| token.is_cancelled()) {\n            return Err(anyhow!(\n                \"heavy command canceled while queued for resource admission\"\n            ));\n        }\n        // Re-measure each iteration: under memory pressure the effective limit\n        // tightens so a saturated host stops admitting new heavy link graphs\n        // (#4864 req 7). Critical pressure yields zero slots, so the command\n        // waits for recovery instead of snowballing.\n        let pressure = classify_memory_pressure(probe.free_fraction());\n        let effective = effective_admission_limit(limit, pressure);\n        for slot in 0..effective {\n            let path = root.join(format!(\"heavy-{slot}.lock\"));\n            match try_lock_slot(&path) {\n                Ok(Some(slot)) => {\n                    return Ok(HeavyCommandPermit {\n                        _slot: slot,\n                        queued_for: started.elapsed(),\n                        limit,\n                        memory_pressure: pressure,","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/resource_admission.rs#L171-L207","documentation":"A heavy command (e.g. cargo build) waiting in the resource-admission queue was canceled via its CancellationToken before a slot became available. The queue loop checks the token each iteration and aborts with this error instead of acquiring a permit.","triggerScenarios":"The user pressed Esc / canceled the tool call while the command sat queued because all heavy-command slots were busy; memory-pressure limiting reduced admission slots to zero so the queue drained slowly; the engine canceled the task on shutdown or timeout.","commonSituations":"Running many parallel cargo commands on a saturated host; #4864-style critical memory pressure where effective slots drop to 0; user aborts a long-waiting tool call.","solutions":["Expected on cancellation — treat as benign abort and do not retry automatically","Re-run the command when host load drops so admission slots free up","If it fires without user action, check for runaway tasks holding permits (leaked permit without release)","Verify cancellation tokens are only canceled on real user/shutdown requests"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before launching, check the token so you rarely queue into a cancel\nif token.is_cancelled() { return; }","typeGuard":null,"tryCatchPattern":"match acquire_heavy_command_permit(&token).await { Err(e) if e.to_string().contains(\"canceled while queued\") => info!(\"user canceled queued command\"), ... }","preventionTips":["Check cancellation before submitting heavy commands","Avoid saturating all admission slots with parallel cargo invocations","Always release permits promptly so the queue drains"],"tags":["cancellation","resource-limit","queue"],"backgroundTag":"operation-cancelled","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}