Skip to content

feat: Wire memory hygiene retention policy into heartbeat loop - #629

Merged
nickpismenkov merged 5 commits into
mainfrom
feat/wire-memory-hygiene
Mar 6, 2026
Merged

nickpismenkov merged 5 commits into
mainfrom
feat/wire-memory-hygiene

Conversation

@nickpismenkov

Copy link
Copy Markdown
Contributor

No description provided.

@nickpismenkov nickpismenkov linked an issue Mar 6, 2026 that may be closed by this pull request
10 tasks
@github-actions github-actions Bot added scope: agent Agent core (agent loop, router, scheduler) scope: workspace Persistent memory / workspace size: L 200-499 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: regular 2-5 merged PRs labels Mar 6, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the agent's memory hygiene capabilities by extending automatic cleanup to conversation documents. It introduces granular control over retention periods for different data types and fortifies the system against accidental deletion of critical identity files. The changes aim to improve resource management and maintain a tidy workspace without compromising essential agent knowledge.

Highlights

  • Extended Memory Hygiene: The memory hygiene system now includes automatic cleanup for conversations/ documents, in addition to existing daily/ logs. This allows for separate retention policies for different types of workspace data.
  • Configurable Retention Policies: Introduced distinct environment variables (MEMORY_HYGIENE_DAILY_RETENTION_DAYS and MEMORY_HYGIENE_CONVERSATION_RETENTION_DAYS) to configure retention periods for daily logs and conversation documents independently. Default retention for conversations is set to 7 days.
  • Protection for Identity Documents: A new mechanism has been implemented to explicitly prevent the deletion of critical identity documents (e.g., IDENTITY.md, SOUL.md, MEMORY.md) during hygiene passes, ensuring essential context is always preserved.
  • Enhanced Logging and Reporting: The heartbeat logging and hygiene reports now include counts for deleted conversation documents, providing better visibility into the cleanup process.
  • New Integration Tests: Added comprehensive async integration tests to verify the correct behavior of the memory hygiene system, including identity document preservation, handling of empty directories, cadence enforcement, and accurate deletion reporting.
Changelog
  • .env.example
    • Added new environment variables MEMORY_HYGIENE_DAILY_RETENTION_DAYS and MEMORY_HYGIENE_CONVERSATION_RETENTION_DAYS for configuring retention policies.
  • src/agent/heartbeat.rs
    • Updated tracing::info! calls to include conversation_docs_deleted in the log output for memory hygiene reports.
  • src/config/hygiene.rs
    • Modified HygieneConfig struct to replace retention_days with daily_retention_days and conversation_retention_days.
    • Updated Default implementation to set default values for new retention fields.
    • Adjusted resolve method to parse new environment variables for daily and conversation retention.
    • Updated to_workspace_config method to map new retention fields to the workspace hygiene configuration.
  • src/workspace/hygiene.rs
    • Updated module-level documentation to reflect the inclusion of conversation documents in hygiene cleanup.
    • Modified the internal process diagram in comments to include steps for conversation document cleanup.
    • Introduced IDENTITY_PATHS constant and is_identity_path function to identify and protect critical documents from deletion.
    • Updated HygieneConfig struct to use daily_retention_days and conversation_retention_days.
    • Modified HygieneReport to include conversation_docs_deleted count and updated had_work logic to consider both daily logs and conversation deletions.
    • Updated run_if_due function to log both daily and conversation retention days, and to call cleanup_conversation_docs.
    • Added cleanup_conversation_docs asynchronous function to delete old conversation documents based on their retention policy.
    • Integrated is_identity_path check into cleanup_daily_logs to prevent deletion of identity documents.
    • Updated unit tests (default_config_is_reasonable, report_had_work_when_deleted) to reflect changes in HygieneConfig and HygieneReport.
    • Added new unit tests (report_had_work_when_conversation_deleted, is_identity_path_excludes_sacred_docs, is_identity_path_allows_normal_docs) for the new functionality.
    • Introduced a new async_tests module with integration tests for cleanup_daily_logs (identity preservation), cleanup_conversation_docs (empty directory handling), run_if_due (cadence), and cleanup_reports_deletion_counts_correctly.
  • tests/e2e_routine_heartbeat.rs
    • Updated HygieneConfig instantiations in end-to-end tests to use the new daily_retention_days and conversation_retention_days fields.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

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

Copy link
Copy Markdown
Contributor

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 separate retention policy for conversation documents, a useful feature for memory hygiene, implemented across configuration, heartbeat loop, and workspace hygiene logic. While the changes include added protection for "identity" documents and are well-tested, a medium-severity security vulnerability was identified. The is_identity_path function uses case-sensitive comparison to protect 'identity' documents, which could be bypassed on case-insensitive filesystems or through inconsistent casing, potentially leading to unintended data loss of critical configuration files.

Comment thread src/workspace/hygiene.rs
@nickpismenkov
nickpismenkov merged commit d195222 into main Mar 6, 2026
16 checks passed
@nickpismenkov
nickpismenkov deleted the feat/wire-memory-hygiene branch March 6, 2026 20:47
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
…i#629)

* feat: Wire memory hygiene retention policy into heartbeat loop

* review fix

* linter fix

* fix tests
drchirag1991 pushed a commit to drchirag1991/ironclaw that referenced this pull request Apr 8, 2026
…i#629)

* feat: Wire memory hygiene retention policy into heartbeat loop

* review fix

* linter fix

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: regular 2-5 merged PRs risk: medium Business logic, config, or moderate-risk modules scope: agent Agent core (agent loop, router, scheduler) scope: workspace Persistent memory / workspace size: L 200-499 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wire memory hygiene retention policy into heartbeat loop

2 participants