Skip to content

The agent that grows with you

fix(curator): never-used built-ins get their inactivity clock anchored at first curator sight

teknium1f64ac2fbdc34
diff --git a/agent/curator.py b/agent/curator.py
index 8f431728f79..e304b751541 100644
--- a/agent/curator.py
+++ b/agent/curator.py
@@ -213,6 +213,12 @@ def apply_automatic_transitions(now: Optional[datetime] = None) -> Dict[str, int
_u.seed_record_if_missing(name)
counts["seeded"] += 1
continue
+ # A bundled skill's telemetry record predates the curator's first sight of it; anchor the clock here, once.
+ if (row.get("provenance") == "bundled" and int(row.get("use_count", 0) or 0) == 0
+ and not _parse_iso(row.get("last_activity_at")) and not row.get("first_seen_at")):
+ _u.reanchor_clock(name)
+ counts["seeded"] += 1
+ continue
# Never-active skills anchor on created_at so they don't self-archive.
anchor = _parse_iso(row.get("last_activity_at")) or _parse_iso(row.get("created_at")) or now
if anchor.tzinfo is None:
diff --git a/tests/agent/test_curator.py b/tests/agent/test_curator.py
index cc9e7744e0e..361bbdd4525 100644
--- a/tests/agent/test_curator.py
+++ b/tests/agent/test_curator.py
@@ -484,6 +484,33 @@ def test_protected_builtin_never_archived_even_when_stale(curator_env, monkeypat
+def test_preseeded_never_used_builtin_is_reanchored_not_staled(curator_env, monkeypatch):
+ """Telemetry records a bundled skill the moment it is seeded, months before the curator's first
+ sight; anchoring on that created_at marked 71 built-ins stale on one first run (#79295). First
+ sight re-anchors the clock (and reactivates a record the bug already staled); the skill then
+ ages normally and still goes stale after a full window of non-use."""
+ u, c = curator_env["usage"], curator_env["curator"]
+ skills_dir = curator_env["home"] / "skills"
+ _write_skill(skills_dir, "bundled-helper")
+ (skills_dir / ".bundled_manifest").write_text("bundled-helper:abc\n", encoding="utf-8")
+ _enable_prune_builtins(curator_env, monkeypatch)
+ super_old = (datetime.now(timezone.utc) - timedelta(days=365)).isoformat()
+ data = u.load_usage()
+ data["bundled-helper"] = {**u._empty_record(), "created_at": super_old, "state": u.STATE_STALE}
+ u.save_usage(data)
+
+ t0 = datetime.now(timezone.utc)
+ counts = c.apply_automatic_transitions(now=t0)
+ assert (counts["marked_stale"], counts["archived"], counts["seeded"]) == (0, 0, 1)
+ rec = u.get_record("bundled-helper")
+ assert rec["state"] == "active" and rec["first_seen_at"] is not None
+ assert datetime.fromisoformat(rec["created_at"]) > datetime.fromisoformat(super_old)
+
+ # One-shot: 15 days of continued non-use (past stale_after_days=14) → stale, not deferred forever.
+ counts = c.apply_automatic_transitions(now=t0 + timedelta(days=15))
+ assert counts["marked_stale"] == 1 and u.get_record("bundled-helper")["state"] == "stale"
+
+
def test_prune_builtins_never_touches_hub_skills(curator_env, monkeypatch):
u = curator_env["usage"]
skills_dir = curator_env["home"] / "skills"
diff --git a/tools/skill_usage.py b/tools/skill_usage.py
index 5a9bcc2e7b0..43c53f6737f 100644
--- a/tools/skill_usage.py
+++ b/tools/skill_usage.py
@@ -345,7 +345,9 @@ def adopt_skill(skill_name: str) -> Tuple[bool, str]:
def _empty_record() -> Dict[str, Any]:
return {"created_by": None, "use_count": 0, "view_count": 0, "last_used_at": None, "last_viewed_at": None,
"patch_count": 0, "patch_generation": 0, "last_reused_patch_generation": 0, "last_patched_at": None,
- "created_at": _now_iso(), "state": STATE_ACTIVE, "pinned": False, "archived_at": None}
+ "created_at": _now_iso(), "state": STATE_ACTIVE, "pinned": False, "archived_at": None,
+ # When the curator first anchored this skill's inactivity clock (seed or re-anchor); None = never seen.
+ "first_seen_at": None}
def _backfilled(rec: Any) -> Dict[str, Any]:
@@ -409,10 +411,22 @@ def seed_record_if_missing(skill_name: str) -> None:
if skill_name and is_curation_eligible(skill_name):
# load_usage() already dropped non-dict values, so "missing" == key absent; dirty only when inserted.
def _seed(data):
- return None, skill_name not in data and data.setdefault(skill_name, _empty_record()) is not None
+ return None, skill_name not in data and data.setdefault(skill_name, {**_empty_record(), "first_seen_at": _now_iso()}) is not None
_locked_update(skill_name, _seed, "skill_usage.seed_record_if_missing(%s) failed: %s")
+def reanchor_clock(skill_name: str) -> None:
+ """Start a skill's inactivity clock NOW, once. Telemetry writes a record the moment a bundled skill is
+ seeded, so by the curator's first sight ``created_at`` can be months old and every never-used built-in
+ goes stale on that first pass (#79295); ``first_seen_at`` marks the clock as anchored so later runs age
+ it normally. A record the bug already marked stale is reactivated — the staleness was the artifact."""
+ def _apply(rec: Dict[str, Any]) -> None:
+ rec["created_at"] = rec["first_seen_at"] = _now_iso()
+ if rec.get("state") == STATE_STALE:
+ rec["state"] = STATE_ACTIVE
+ _mutate(skill_name, _apply)
+
+
def _mutate(skill_name: str, mutator, *, require_curation_eligible: bool = False) -> Any:
"""Load, apply *mutator(record)* in place, save; the mutator result (None if nothing landed). Telemetry is
recorded for ANY skill; lifecycle mutators pass ``require_curation_eligible=True`` (never write onto unmanaged)."""