kovidgoyal/kitty · warning
Failed to write to disk-cache file
Error message
Failed to write to disk-cache file
What it means
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.
Source
Thrown at kitty/disk-cache.c:463
}
static bool
write_dirty_entry(DiskCache *self) {
size_t left = self->currently_writing.val.data_sz;
uint8_t *p = self->currently_writing.val.data;
if (self->currently_writing.val.pos_in_cache_file < 0) {
self->currently_writing.val.pos_in_cache_file = self->end_of_data_offset;
if (self->currently_writing.val.pos_in_cache_file < 0) {
perror("Failed to seek in disk cache file");
return false;
}
}
off_t offset = self->currently_writing.val.pos_in_cache_file;
while (left > 0) {
ssize_t n = pwrite(self->cache_file_fd, p, left, offset);
if (n < 0) {
if (errno == EINTR || errno == EAGAIN) continue;
perror("Failed to write to disk-cache file");
self->currently_writing.val.pos_in_cache_file = -1;
return false;
}
if (n == 0) {
fprintf(stderr, "Failed to write to disk-cache file with zero return\n");
self->currently_writing.val.pos_in_cache_file = -1;
return false;
}
left -= n;
p += n;
offset += n;
self->end_of_data_offset = MAX(self->end_of_data_offset, offset);
}
return true;
}
static void
retire_currently_writing(DiskCache *self) {View on GitHub (pinned to 6d5d0c4406)
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.
Defensive patterns
Strategy: validation
Validate before calling
df -h "${XDG_CACHE_HOME:-$HOME/.cache}" # check free space before long scrollback-heavy sessions Prevention
- Maintain free disk space for scrollback caching.
- Set reasonable scrollback limits in kitty.conf.
- Treat shutdown-time EBADF variants as benign.
When it happens
Trigger: write_loop -> write_dirty_entry -> pwrite returning -1, e.g. ENOSPC (cache filesystem full), EBADF (cache fd closed during shutdown), EIO (disk error).
Common situations: Full home/tmpfs partition with heavy scrollback usage; cache file deleted while running; failing disk.
Related errors
- Failed to open second file for defrag of disk cache
- Failed to allocate space for new disk cache file during defr
- Failed to copy data to new disk cache file during defrag
- Failed to seek in disk cache file
- This must be run as kitten ask
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/a5d1fda4cec46162.
Report an issue: GitHub.