Skip to content

fix(logging): retarget file handler transactionally#888

Open
TZZheng wants to merge 3 commits into
Lingtai-AI:mainfrom
TZZheng:fix/issue-749-idempotent-logging-telegrambot
Open

fix(logging): retarget file handler transactionally#888
TZZheng wants to merge 3 commits into
Lingtai-AI:mainfrom
TZZheng:fix/issue-749-idempotent-logging-telegrambot

Conversation

@TZZheng

@TZZheng TZZheng commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • mark and reuse only LingTai-owned logging handlers while preserving handlers installed by embedding applications
  • serialize the complete handler discovery and mutation transaction with a shared reentrant lock
  • retarget file logging transactionally: fully open a replacement before swapping it in and closing the old handler
  • preserve the working file handler when replacement opening fails, allowing a later retry
  • cover ownership, repeatability, reconfiguration, concurrency, and failure recovery with focused regressions

Validation

Exact candidate: 51511659e6fe820c25e12046751d64806e037406

  • PYTHONPATH=src python -m pytest -q tests/test_kernel_logging.py6 passed
  • git diff --check canonical/main...HEAD — clean
  • merge-tree check — clean
  • worktree status — clean

Fresh Claude/Codex review reports are still pending; this body makes no review-verdict claim.

Risk

The process-local lock serializes rare setup calls. Unmarked external handlers remain untouched. Retargeting replaces the owned file-handler object only after its new stream opens successfully, avoiding failed-open corruption without adding rollback machinery.

Fixes #749

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.

setup_logging() is not idempotent: repeated calls duplicate FileHandlers and silently ignore verbose

1 participant