Skip to content

log-pruning-7-day-default#1785

Closed
aboimpinto wants to merge 1 commit into
Hmbown:mainfrom
aboimpinto:feat/log-pruning
Closed

log-pruning-7-day-default#1785
aboimpinto wants to merge 1 commit into
Hmbown:mainfrom
aboimpinto:feat/log-pruning

Conversation

@aboimpinto
Copy link
Copy Markdown
Contributor

@aboimpinto aboimpinto commented May 18, 2026

Summary

Automatically prune old TUI log files on startup to prevent unbounded disk accumulation.

Problem

With PID-based log filenames (PR #1783), each TUI instance writes to its own file. Without cleanup, logs accumulate indefinitely.

Fix

  • prune_old_logs(log_dir, max_age) — deletes tui-*.log files older than max_age
  • Called on init() with retention from DEEPSEEK_LOG_RETENTION_DAYS (default: 7 days)
  • Best-effort: ignores I/O errors silently

Configuration

Env var Default Description
DEEPSEEK_LOG_RETENTION_DAYS 7 Delete logs older than N days

Tests (5)

Test What
prune_old_logs_deletes_old_files Zero-age prune removes files
prune_old_logs_keeps_recent_files Large-age prune keeps files
prune_old_logs_ignores_non_log_files Only tui-*.log files affected
retention_days_defaults_to_seven Default is 7
prune_old_logs_tolerates_missing_directory No panic on missing dir

Testing Strategy

Without old log files: set DEEPSEEK_LOG_RETENTION_DAYS=0 before launching. All existing tui-*.log files will be deleted on startup. Then check ~/.deepseek/logs/ — only the current session's file should remain.

Closes #1784

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a log retention mechanism for the TUI, allowing the system to automatically prune log files older than a specified number of days (defaulting to 7). The implementation includes a new prune_old_logs function and corresponding unit tests. A potential integer overflow was identified in the duration calculation, which could lead to incorrect log pruning or application panics if a very large retention value is provided.

Comment thread crates/tui/src/runtime_log.rs Outdated
@Hmbown Hmbown added this to the v0.8.42 milestone May 21, 2026
aboimpinto added a commit to aboimpinto/CodeWhale that referenced this pull request May 21, 2026
Builds on the env-var-based log pruning from PR Hmbown#1785 (already in main)
with a proper config.toml section.

Changes:
- Add LogsConfig struct to config.rs with retention_days field (default 7)
- Wire config.logs_config().retention_days into runtime_log::init()
- Env var DEEPSEEK_LOG_RETENTION_DAYS retains priority over config value
- Add [logs] section to config.example.toml with documentation
- Updated and added tests for the new config path
aboimpinto added a commit to aboimpinto/CodeWhale that referenced this pull request May 21, 2026
Builds on the env-var-based log pruning from PR Hmbown#1785 (already in main)
with a proper config.toml section.

Changes:
- Add LogsConfig struct to config.rs with retention_days field (default 7)
- Wire config.logs_config().retention_days into runtime_log::init()
- Env var DEEPSEEK_LOG_RETENTION_DAYS retains priority over config value
- Add [logs] section to config.example.toml with documentation
- Updated and added tests for the new config path
aboimpinto added a commit to aboimpinto/CodeWhale that referenced this pull request May 21, 2026
Builds on the env-var-based log pruning from PR Hmbown#1785 (already in main)
with a proper config.toml section.

Changes:
- Add LogsConfig struct to config.rs with retention_days field (default 7)
- Wire config.logs_config().retention_days into runtime_log::init()
- Env var DEEPSEEK_LOG_RETENTION_DAYS retains priority over config value
- Add [logs] section to config.example.toml with documentation
- Updated and added tests for the new config path
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 23, 2026

This PR was opened before the v0.8.41 rebrand and is now stale. Feel free to rebase onto current main and reopen. 鲸鱼兄弟们等你 🐋

@Hmbown Hmbown closed this May 23, 2026
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.

log-pruning-issue

2 participants