Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AMAP ML SkillClaw Stale Session Filtering

From Leeroopedia
Knowledge Sources
Domains Optimization, LLMs
Last Updated 2026-10-22 00:00 GMT

Overview

Stale session filtering by configurable evidence age window (`evidence_max_age_seconds`) that excludes outdated, undated, or future-dated sessions from the evolution pipeline.

Description

The evolve engine drains session JSON objects from shared storage and filters them by timestamp freshness before processing. The `evidence_max_age_seconds` config (default 0 = disabled, test default 604800 = 7 days) limits which sessions are considered fresh evidence. The `_fresh_session_evidence` function checks three conditions: (1) the session has a string `timestamp` field, (2) the timestamp has timezone info, and (3) the age is between 0 and `max_age` seconds (not future-dated). Excluded sessions are retained in storage for manual review — they are not deleted. The filter logs how many sessions were excluded.

Usage

Use this heuristic when session data accumulates over time and old sessions no longer reflect current skill quality. Set `EVOLVE_EVIDENCE_MAX_AGE_SECONDS` to filter out stale evidence from the evolution pipeline.

The Insight (Rule of Thumb)

  • Action: Set `evidence_max_age_seconds` (env: `EVOLVE_EVIDENCE_MAX_AGE_SECONDS`) to filter sessions older than N seconds.
  • Value: Default 0 (disabled). Test default: 604800 (7 days). Must be non-negative.
  • Trade-off: Smaller window = fresher evidence but fewer sessions to analyze; larger window = more data but may include outdated patterns.
  • Compatibility: Applies to both workflow and agent evolution engines via `EvolveEngineMixin._drain_sessions`.

Reasoning

Skills evolve over time — what was a good skill a month ago may now be outdated due to API changes or new tooling. Including stale sessions in the evolution pipeline would cause the LLM to "learn" from outdated patterns, potentially regressing recently improved skills. By filtering by age, only recent evidence (reflecting current skill quality) drives evolution decisions. The future-date check (`0 <= age`) prevents timezone bugs or clock skew from injecting sessions from the future. Retaining excluded sessions in storage (rather than deleting) ensures no data is lost and allows manual investigation.

Code Evidence

Freshness check from `evolve_server/engines/common.py:23-34`:

def _fresh_session_evidence(session: dict, now: datetime, max_age: int) -> bool:
    timestamp = session.get("timestamp") if isinstance(session, dict) else None
    if not isinstance(timestamp, str):
        return False
    try:
        stamp = datetime.fromisoformat(timestamp.replace("Z", "+00:00"))
        if stamp.tzinfo is None:
            return False
        age = (now - stamp).total_seconds()
        return 0 <= age <= max_age
    except (TypeError, ValueError, OverflowError):
        return False

Drain with filtering from `evolve_server/engines/common.py:98-126`:

async def _drain_sessions(self) -> tuple[list[dict], list[str]]:
    keys = await self._call_storage(list_session_keys, self._bucket, self._prefix)
    sessions: list[dict] = []
    consumed_keys: list[str] = []
    max_age = self.config.evidence_max_age_seconds
    now = datetime.now(timezone.utc)
    excluded = 0
    for key in keys:
        session = await self._call_storage(read_json_object, self._bucket, key)
        if session:
            if max_age and not _fresh_session_evidence(session, now, max_age):
                excluded += 1
                continue
            sessions.append(session)
            consumed_keys.append(key)
    if excluded:
        logger.warning(
            "[%s] excluded %d stale/undated/future session(s); retained in storage for review",
            type(self).__name__, excluded,
        )

Config validation from `evolve_server/core/config.py:146-148`:

self.evidence_max_age_seconds = int(self.evidence_max_age_seconds)
if self.evidence_max_age_seconds < 0:
    raise ValueError("EVOLVE_EVIDENCE_MAX_AGE_SECONDS must be non-negative")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment