{"record":{"id":"d2b101370eb19c5d","repo":"iOfficeAI/OfficeCLI","slug":"resident-close-reported-error-exit-closeresp-exi","errorCode":null,"errorMessage":"Resident close reported error (exit {closeResp.ExitCode})","messagePattern":"Resident close reported error \\(exit (.+?)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/officecli/CommandBuilder.cs","lineNumber":88,"sourceCode":"        var closeFileArg = new Argument<FileInfo>(\"file\") { Description = \"Office document path (required even with open/close mode)\" };\n        var closeCommand = new Command(\"close\", \"Flush in-memory changes to disk and stop the resident (releases the file). Use 'save' instead to flush but keep the resident warm. Either is needed before a non-officecli program reads the file; a live resident also auto-flushes shortly after going idle (adaptive 2-10s; see OFFICECLI_RESIDENT_FLUSH: each|auto|<seconds>|off).\");\n        closeCommand.Add(closeFileArg);\n        closeCommand.Add(jsonOption);\n\n        closeCommand.SetAction(result => { var json = result.GetValue(jsonOption); return SafeRun(() =>\n        {\n            var file = result.GetValue(closeFileArg)!;\n            if (ResidentClient.SendCloseWithResponse(file.FullName, out var closeResp))\n            {\n                // BUG-BT-R26-2: resident may report a non-zero shutdown\n                // (e.g. file vanished mid-session → data loss). Bubble\n                // that up instead of pretending the close succeeded.\n                if (closeResp != null && closeResp.ExitCode != 0)\n                {\n                    var err = !string.IsNullOrEmpty(closeResp.Stderr)\n                        ? closeResp.Stderr\n                        : $\"Resident close reported error (exit {closeResp.ExitCode})\";\n                    throw new InvalidOperationException(err);\n                }\n                // BUG-INTERVIEW-EDIT-R10-B: resident reports advisory warnings\n                // (e.g. backing file missing at original path) via Stderr with\n                // exit=0. Forward to the client's stderr so the user sees the\n                // warning instead of a silent success.\n                if (closeResp != null && !string.IsNullOrEmpty(closeResp.Stderr))\n                    Console.Error.WriteLine(closeResp.Stderr);\n                var msg = $\"Resident closed for {file.Name}\";\n                if (json) Console.WriteLine(OutputFormatter.WrapEnvelopeText(msg));\n                else Console.WriteLine(msg);\n            }\n            else\n            {\n                // No resident is holding this file. In the non-resident model\n                // every mutation already eager-saved to disk, so there is\n                // nothing to flush or shut down — treat close as an idempotent\n                // no-op SUCCESS, not an error. This lets \"edit, then close when\n                // done\" be a safe habit regardless of whether a resident was","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/CommandBuilder.cs#L70-L106","documentation":"Thrown by the `close` command when the resident process responded with a non-zero exit code AND an empty Stderr. The resident's shutdown failed (e.g. the backing file vanished mid-session, a final flush could not write). This is the fallback message when the resident gave no detail. Surfaced as InvalidOperationException so data-loss is not silently masked as a successful close.","triggerScenarios":"Calling `officecli close deck.xlsx` after the file was deleted, moved, or locked by another process while the resident held it open; disk full during the final flush; antivirus quarantining the file mid-session.","commonSituations":"Temp/workspace directory cleaned while a resident was warm; user moved or renamed the file in Explorer; concurrent non-officecli writer grabbed an exclusive lock; low-disk or quota exhaustion on the save path.","solutions":["Confirm the file still exists at the original path the resident was opened with.","Use `save` to flush earlier and more frequently so a close-time failure loses less.","Reopen the document from a known-good copy and reapply the intended edits.","Free disk space / release competing locks, then retry open -> edit -> save -> close.","If reproducible, run close with --json to capture the structured error envelope and inspect ExitCode."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the backing file is still present and writable before closing.\nif (!File.Exists(path)) throw new FileNotFoundException(\"backing file missing\", path);","typeGuard":null,"tryCatchPattern":"try { officecli close file.xlsx; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Resident close reported error\"))\n{\n    // shutdown failed — treat edits since last 'save' as at risk;\n    // reopen from a known-good copy and reapply.\n    logger.Error(\"resident close failed: {Msg}\", ex.Message);\n}","preventionTips":["Flush with `save` frequently so a close-time failure loses little.","Do not move/delete the file while a resident is warm.","Keep free disk space on the save path.","Run close with --json to capture the structured error envelope."],"tags":["resident","close","data-loss","io","officecli"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}