{"record":{"id":"a5d1fda4cec46162","repo":"kovidgoyal/kitty","slug":"failed-to-write-to-disk-cache-file","errorCode":null,"errorMessage":"Failed to write to disk-cache file","messagePattern":"Failed to write to disk-cache file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kitty/disk-cache.c","lineNumber":463,"sourceCode":"}\n\nstatic bool\nwrite_dirty_entry(DiskCache *self) {\n    size_t left = self->currently_writing.val.data_sz;\n    uint8_t *p = self->currently_writing.val.data;\n    if (self->currently_writing.val.pos_in_cache_file < 0) {\n        self->currently_writing.val.pos_in_cache_file = self->end_of_data_offset;\n        if (self->currently_writing.val.pos_in_cache_file < 0) {\n            perror(\"Failed to seek in disk cache file\");\n            return false;\n        }\n    }\n    off_t offset = self->currently_writing.val.pos_in_cache_file;\n    while (left > 0) {\n        ssize_t n = pwrite(self->cache_file_fd, p, left, offset);\n        if (n < 0) {\n            if (errno == EINTR || errno == EAGAIN) continue;\n            perror(\"Failed to write to disk-cache file\");\n            self->currently_writing.val.pos_in_cache_file = -1;\n            return false;\n        }\n        if (n == 0) {\n            fprintf(stderr, \"Failed to write to disk-cache file with zero return\\n\");\n            self->currently_writing.val.pos_in_cache_file = -1;\n            return false;\n        }\n        left -= n;\n        p += n;\n        offset += n;\n        self->end_of_data_offset = MAX(self->end_of_data_offset, offset);\n    }\n    return true;\n}\n\nstatic void\nretire_currently_writing(DiskCache *self) {","sourceCodeStart":445,"sourceCodeEnd":481,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/disk-cache.c#L445-L481","documentation":"pwrite() to the disk-cache file failed with an errno other than EINTR/EAGAIN while the background thread flushed a dirty scrollback entry. The entry's offset is reset to -1 so it can be retried at a new offset later; scrollback stays in memory. ENOSPC is the most common cause.","triggerScenarios":"write_loop -> write_dirty_entry -> pwrite returning -1, e.g. ENOSPC (cache filesystem full), EBADF (cache fd closed during shutdown), EIO (disk error).","commonSituations":"Full home/tmpfs partition with heavy scrollback usage; cache file deleted while running; failing disk.","solutions":["Free space on the filesystem holding the cache (df -h).","Delete kitty's disk cache directory with kitty closed, so it starts fresh.","Reduce scrollback history size to lower write volume.","If EBADF during shutdown, it's benign — upgrade kitty."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"df -h \"${XDG_CACHE_HOME:-$HOME/.cache}\"  # check free space before long scrollback-heavy sessions","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain free disk space for scrollback caching.","Set reasonable scrollback limits in kitty.conf.","Treat shutdown-time EBADF variants as benign."],"tags":["disk-cache","pwrite","enospc","kitty"],"backgroundTag":"disk-write-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}