kovidgoyal/kitty · warning

Failed to seek in disk cache file

Error message

Failed to seek in disk cache file

What it means

write_dirty_entry computes the write offset as end_of_data_offset for a new cache entry and finds it negative, which should be impossible for a valid open cache file — perror then prints whatever errno happens to hold. It's an internal invariant failure in the disk-cache writer thread; the dirty entry is not persisted.

Source

Thrown at kitty/disk-cache.c:454

                find_hole_to_use(self, self->currently_writing.val.data_sz);
                return true;
            }
            s->written_to_disk = true;
            s->pos_in_cache_file = 0;
            s->data_sz = 0;
        }
    }
    return false;
}

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;

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Quit kitty and delete the disk cache directory so it is recreated cleanly.
  2. Ensure nothing (cleanup scripts, tmp cleaners like systemd-tmpfiles) deletes kitty cache files while kitty runs.
  3. Update kitty — writer-thread offset handling has seen fixes.
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: The cache file fd's size query failed earlier (fstat/lseek returned -1) so end_of_data_offset stayed -1; happens on the background write_loop thread when flushing scrollback to a cache file that was closed, truncated externally, or never sized correctly.

Common situations: External deletion/truncation of kitty's cache file while kitty runs; a corrupted cache after a crash; racing close of the cache during shutdown.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/19616b0366ca2bcc. Report an issue: GitHub.