* fix(knowledge): make update_kb_status write failures observable
The ready-transition metadata refresh swallowed every exception
(`except Exception: pass`), and a kb_config.json persist failure
surfaced only as an opaque raise inside fire-and-forget callers, so
a lost status update left the persisted KB state stale with no
diagnostic.
- Log a warning naming the KB when the best-effort ready-transition
metadata refresh fails, instead of silently passing.
- Log an error with the KB name and status when persisting the
config fails, then re-raise so callers still receive the exception
(the write is authoritative, not best-effort).
Tests: a persist failure is logged and re-raised; a metadata refresh
failure is logged and does not propagate.
* fix(knowledge): make progress WS failures visible instead of silent
The websocket_progress endpoint swallowed five failure points with
`except Exception: pass`: timestamp parsing (x2), error-frame delivery,
socket close, and user-context reset. A corrupt progress snapshot or a
broken teardown path therefore vanished without a trace.
- Share a _progress_age_seconds helper for both freshness checks: narrow
the catch to (TypeError, ValueError), keep the inactive/stale fallback,
and log unparseable timestamps at warning level.
- Reuse the already-parsed snapshot age in the replay decision, so one
corrupt timestamp warns once per connection instead of once per
freshness check.
- Trace failed error-frame delivery and failed close at debug level
(usually an already-disconnected client, not a fault).
- Log a failed reset_current_user at warning level: leaking the user
context is a real fault, not a disconnect.
Tests: malformed timestamp degrades with a warning; cleanup failures are
logged and never propagate; normal disconnects stay silent.
* fix(knowledge): stop swallowing a failed reindex error-progress write
The reindex failure path wrapped its ProgressTracker ERROR update in
`except Exception: pass`, so when that write itself failed the rebuild's
failure alert disappeared and the KB progress view silently stayed stale.
Log a warning instead; the task-level error status remains authoritative.
* fix(knowledge): log folder sync state recording failures
update_folder_sync_state() swallowed per-file mtime recording errors
with 'except Exception: pass', so a file whose state could not be
recorded silently degraded the persisted sync state while last_sync
still advanced. Log the failure at WARNING and keep the un-recorded
fallback so the next scan re-syncs the file.
* test(codebuddy): make credential fixture expiry relative to now
test_load_credentials_parses_session wrote a hard-coded expiresAt of
1791055241000 (2026-10-03 15:40:41 UTC) and asserted is_expired() is
False. Once that instant passed the assertion flipped, so the test now
fails on every Python version for every branch.
Derive expiresAt / refreshExpiresAt from time.time() so the fixture
always describes a live session, and assert against the value written.
---------
Co-authored-by: XZH <cto@xzh.ai>
Follow-up to #619: every kb_config.json / metadata.json write in
KnowledgeBaseManager now goes through atomic_write_json (temp file +
fsync + os.replace) instead of the truncate-then-lock pattern, so a
crash mid-write can no longer leave a truncated config and concurrent
readers always see a complete previous or new file. The JSON variant
in services.file_io gains the same tolerant fsync as its text sibling,
the now-redundant private helper and dead file_lock_exclusive are
removed, and the atomicity-contract test moves next to the shared
writer in tests/services/test_file_io.py.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
update_folder_sync_state() mutated the loaded metadata dict and
returned without writing it back, so last_sync/synced_files never
reached metadata.json while the API layer logged success. Future
scans re-treated already-synced files as new.
Write back through a same-directory temp file + os.replace so
readers never observe a truncated metadata.json.