Skip to content

[Bug]: Hardening required for Always-On Memory Agent (file ingestion crash + duplicate memory connections) #2945

Description

File Name

gemini/agents/always-on-memory-agent/agent.py

What happened?

Description

The Always-On Memory Agent has two issues that may affect stability and data integrity.

1. Memory crash risk during file ingestion

The ingest_file function reads file content using file_path.read_bytes() before validating the file size.

As a result, large files (e.g. >20MB) may be loaded entirely into memory before the size limit check is performed, potentially causing excessive memory usage, performance degradation, or process crashes.

2. Duplicate memory connections

The store_consolidation function appends memory connections without checking whether the relationship already exists.

When consolidation is executed multiple times for the same memory pair, duplicate entries may be stored in the connections field, resulting in an inflated memory graph and unnecessary storage growth.

Observed Behavior

File ingestion

  • Large files are read into memory before size validation.
  • Excessive memory consumption may occur for oversized files.
  • Agent stability may be affected when processing very large files.

Memory connections

  • Repeated consolidation operations can create duplicate relationships.
  • The connections field may contain redundant entries.
  • Memory graph data becomes unnecessarily bloated over time.

Expected Behavior

File ingestion

Prompt ingestion should:

  • Validate file size before reading file content into memory.
  • Skip files larger than 20MB safely.
  • Log a warning instead of processing oversized files.

Memory connections

Memory consolidation should:

  • Prevent duplicate (from_id, to_id) relationships.
  • Store each connection only once.
  • Maintain a clean and deduplicated memory graph.

How to reproduce

Memory ingestion issue

  1. Create a file larger than 20MB (for example, 50MB).
  2. Place the file into the monitored ./inbox directory.
  3. Run the Always-On Memory Agent.
  4. Observe memory usage while the file is processed.

Duplicate connection issue

  1. Execute store_consolidation multiple times using the same source and target memory IDs.
  2. Inspect the connections field in the memories table.
  3. Observe duplicate relationship entries.

Relevant log output

Large file detected during ingestion.

Current behavior:
- File content is read into memory before validation.
- Memory usage increases unnecessarily.
- Oversized files may affect process stability.

Repeated consolidation operations:

Current behavior:
- Duplicate relationships are appended to connections.
- Memory graph grows with redundant entries.
- Storage usage increases over time.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions