feat: implement background process logging and cleanup#21189
Conversation
- Add persistent logging for backgrounded shell processes in ~/.gemini/tmp/background-processes - Implement automatic cleanup of background logs older than 7 days on CLI startup - Support real-time output syncing to log files for both PTY and child_process execution - Update UI to indicate log file availability for background tasks - Add comprehensive unit and integration tests for logging and cleanup logic
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the observability and maintainability of backgrounded shell processes within the CLI. By introducing persistent logging, users can now review the full output of long-running tasks even after they've been backgrounded or the CLI has been restarted. The accompanying cleanup mechanism ensures that these logs do not accumulate indefinitely, providing a balanced approach to data retention. These changes enhance the overall stability and user experience when interacting with background tasks. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively implements persistent logging for background processes and adds a cleanup mechanism for old logs. The changes are well-structured, with new utilities for log cleanup, updates to the ShellExecutionService to handle log streams, and UI enhancements to display log file information. The inclusion of comprehensive integration and unit tests is also a great addition.
I've found one potential issue related to how wrapped lines are written to the log file, which could lead to corrupted logs in some streaming scenarios. My detailed comment provides a suggested fix.
Note: Security Review did not run due to the size of the PR.
adamfweidman
left a comment
There was a problem hiding this comment.
LGTM with a few comments
- Add 'error' listener to background log WriteStreams to prevent unhandled errors - Switch to incremental logging via 'decodedChunk' in handleOutput for PTY and child_process - Improve newline handling for wrapped lines in writeBufferToLogStream - Remove obsolete lastSyncedLine and lastSyncedOffset tracking - Update unit tests to match refactored logging logic and interfaces
|
Size Change: +6.46 kB (+0.02%) Total Size: 26.5 MB
ℹ️ View Unchanged
|
3626ee5 to
9dbc082
Compare
Summary
This PR implements persistent logging and automatic cleanup for backgrounded shell processes. It ensures that when a process is moved to the background, its output (both historical and real-time) is captured in
~/.gemini/tmp/background-processes/*.logfiles. It also adds a background cleanup task that runs on CLI startup to remove logs older than 7 days.Details
backgroundLogStreamsto track active writable streams for background processes.writeBufferToLogStreamfornode-ptyto sync terminal buffer content to disk without ANSI codes.child_processoutput chunks.cleanupBackgroundLogsutility inpackages/cli/src/utils/logCleanup.ts.gemini.tsx) to run once per session.BackgroundShellDisplayto show a "Log file" indicator when a process is running in the background.UIActionsContextand hooks to handle asynckillanddismissoperations.Related Issues
Related to the background execution stability and observability efforts.
How to Validate
npm run startping google.combackgroundtool or the UI button.~/.gemini/tmp/background-processes/background-<PID>.log.npm test -w @google/gemini-cli -- packages/cli/src/utils/logCleanup.test.tsnpm test -w @google/gemini-cli-core -- src/services/shellExecutionService.test.tsnpm run test:e2e -- integration-tests/background_shell_output.test.tsPre-Merge Checklist