gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Stop Auto Memory from retrying low-signal sessions indefinitely

Open SandyTao520 opened this issue 7 months ago • 5 comments

Problem

Auto Memory only records a candidate session as processed when the extraction agent successfully reads the transcript with read_file. If the agent sees a session in the index and decides not to read it because it looks low-signal, that session remains unprocessed and can be surfaced again in future runs.

Relevant code:

  • packages/core/src/services/memoryService.ts

The current flow tracks processed sessions through processedSessionKeys, which is populated from successful read_file activity. Sessions that are surfaced to the agent but intentionally skipped are recorded as candidates, but not as processed.

Impact

  • Low-signal sessions can repeatedly consume background extraction runs.
  • The 30-minute throttle reduces frequency but does not solve repeated work.
  • Backlog rotation helps, but repeated retries still make the service less predictable and more expensive over time.

Expected Behavior

Auto Memory should distinguish between:

  • sessions successfully inspected via read_file
  • sessions intentionally skipped as low-signal
  • sessions that failed to read and may need retry

Low-signal skipped sessions should not keep resurfacing as new candidates on every extraction run.

Acceptance Criteria

  • Candidate sessions can be recorded as skipped or attempted even if not read.
  • Repeated low-signal sessions do not keep resurfacing every extraction interval.
  • Failed reads remain distinguishable from intentional skips.
  • Tests cover a candidate session that is surfaced but not read by the extraction agent.

Notes

This is primarily a background reliability and cost-control issue. The goal is not to force the extractor to read more sessions, but to persist a terminal or backoff state when it chooses not to inspect a candidate.

SandyTao520 avatar May 05 '26 18:05 SandyTao520

There is a problem with the Gemini CLI issue triaging. Please check the action logs for details.

gemini-cli[bot] avatar May 05 '26 18:05 gemini-cli[bot]

A significant efficiency bug where Auto Memory repeatedly processes low-signal sessions, wasting tokens and background capacity.

gemini-cli[bot] avatar May 07 '26 17:05 gemini-cli[bot]

The root cause is coupling session completion tracking strictly to tool execution (read_file). When the extraction agent inspects metadata and makes an intentional decision to skip a low-signal session, that decision is never recorded as durable state, causing the background scanner to re-surface it on every cycle.

Session evaluation should use a deterministic Tri-State Processing Ledger:

export type ProcessingOutcome = 'extracted' | 'skipped_low_signal' | 'failed_retryable';

export interface SessionProcessingLedger {
  sessionKey: string;
  evaluatedAt: string;
  outcome: ProcessingOutcome;
  signalScore?: number;
  extractedFactCount: number;
}

export async function recordSessionEvaluation(
  db: MemoryStorage,
  sessionKey: string,
  outcome: ProcessingOutcome,
  factCount: number = 0
): Promise<void> {
  // Atomically record evaluated status regardless of whether extraction tool was called
  await db.execute(`
    INSERT INTO session_processing_ledger (session_key, evaluated_at, outcome, fact_count)
    VALUES ($1, NOW(), $2, $3)
    ON CONFLICT (session_key) 
    DO UPDATE SET evaluated_at = NOW(), outcome = $2, fact_count = $3
  `, [sessionKey, outcome, factCount]);
}

// Candidate discovery queries strictly un-evaluated sessions
export async function getUnprocessedSessions(db: MemoryStorage): Promise<string[]> {
  return db.query(`
    SELECT s.session_key 
    FROM candidate_sessions s
    LEFT JOIN session_processing_ledger p ON s.session_key = p.session_key
    WHERE p.session_key IS NULL
  `);
}

Recording skipped_low_signal explicitly into the ledger guarantees that intentionally skipped sessions are tombstoned immediately, stopping background loop churn without wasting extraction tokens.

RemanenetSpy avatar Aug 30 '26 06:08 RemanenetSpy

Hit this same class of problem building an external memory engine: the fix that held was making "decided not to remember" a first-class, recorded outcome rather than an absence. Every candidate gets exactly one verdict at encode time - encoded, or explicitly skipped with the reason - and the processed set is the union of both. Retries become deterministic (nothing is re-surfaced unless its content hash changes), and the skip reasons turn out to be useful telemetry for tuning the signal threshold later.

Treating low-signal as a verdict instead of a non-event also stops the subtler failure where a session hovers below threshold forever and gets re-evaluated at full cost each run.

(Context: I build juvina.ai, a local memory engine over MCP - same design space, different host.)

1picassoai avatar Sep 06 '26 18:09 1picassoai