Skip to content

Fix file/PDF add crash on a null-stat source row#418

Merged
tobocop2 merged 1 commit into
feat/local-model-apifrom
fix/source-stat-null-crash
Jun 22, 2026
Merged

Fix file/PDF add crash on a null-stat source row#418
tobocop2 merged 1 commit into
feat/local-model-apifrom
fix/source-stat-null-crash

Conversation

@tobocop2

Copy link
Copy Markdown
Owner

Problem

Adding any file (the user hit it on PDFs) fails immediately with int() argument must be a string, a bytes-like object or a real number, not 'NoneType' when the knowledge base already holds a source row whose stat columns are NULL.

source_stat() reads a row's size_bytes / mtime_ns / stat_captured_ns to decide whether a file can skip re-hashing. Those columns are nullable int64, but the reader only handled two "unknown" cases: a missing key (via .get(key, SOURCE_STAT_UNKNOWN)) and the -1 sentinel. An explicit NULL is neither, so it slipped past the guard into int(None) and crashed. The capture-time column wasn't checked at all, so a NULL there crashed even with valid size/mtime.

Solution

Treat a NULL stat column the same as unknown: return None so the caller re-hashes the file (the documented "no usable stat" path), and coerce a NULL capture time to the sentinel instead of calling int() on it. No behavior change for rows that already carry real stats or the sentinel.

Reproduced with two regression tests (NULL size/mtime, and NULL capture time alongside valid size/mtime) that fail with the exact error before the fix.

Adding any file failed with 'int() argument ... not NoneType' when the store
held a source row whose nullable stat columns (size_bytes / mtime_ns /
stat_captured_ns) were NULL. source_stat only guarded the SOURCE_STAT_UNKNOWN
sentinel and missing keys via .get-default, so an explicit NULL slipped through
to int(None). Treat NULL like unknown (return None, the caller re-hashes) and
coerce a NULL capture time to the sentinel instead of crashing.

Bug present since the stat-based sync-skip landed in #338; surfaces on any store
carrying a null-stat row.
@tobocop2 tobocop2 merged commit c43aeae into feat/local-model-api Jun 22, 2026
7 of 16 checks passed
@tobocop2 tobocop2 deleted the fix/source-stat-null-crash branch June 22, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant