Skip to content

Commit 6456b95

Browse files
committed
fix: URI collision, retry off-by-one, scheduler interval validation
- backend_memory: use uuid4 hex suffix instead of time() for duplicate URIs - async_jobs: get_retryable_jobs uses < max_retries (was <=, ran one extra) - scheduler: clamp interval to min 1h, prevent 0/negative crash
1 parent 5f1acc0 commit 6456b95

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎curator/async_jobs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,4 @@ def is_transient_error(error: str) -> bool:
127127
def get_retryable_jobs(max_retries: int = 3) -> list[dict]:
128128
"""Return failed jobs that are retryable (transient error + under retry limit)."""
129129
failed = list_failed()
130-
return [j for j in failed if is_transient_error(j.get("error", "")) and j.get("retries", 0) <= max_retries]
130+
return [j for j in failed if is_transient_error(j.get("error", "")) and j.get("retries", 0) < max_retries]

‎curator/backend_memory.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def ingest(self, content: str, title: str = "", metadata: dict | None = None) ->
142142
"""
143143
safe = title.replace(" ", "_").replace("/", "_") if title else str(uuid.uuid4())[:8]
144144
uri = f"mem://{safe}"
145-
# Handle duplicate URIs by appending suffix
145+
# Handle duplicate URIs by appending random suffix
146146
if uri in self._store:
147-
uri = f"{uri}_{int(time.time())}"
147+
uri = f"{uri}_{uuid.uuid4().hex[:8]}"
148148
self._store[uri] = {
149149
"content": content,
150150
"title": title,

‎curator/scheduler.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def start_scheduler() -> bool:
269269
try:
270270
from apscheduler.schedulers.background import BackgroundScheduler
271271

272-
freshness_h = float(env("CURATOR_FRESHNESS_INTERVAL_HOURS", "24"))
273-
strengthen_h = float(env("CURATOR_STRENGTHEN_INTERVAL_HOURS", "168"))
272+
freshness_h = max(1.0, float(env("CURATOR_FRESHNESS_INTERVAL_HOURS", "24") or "24"))
273+
strengthen_h = max(1.0, float(env("CURATOR_STRENGTHEN_INTERVAL_HOURS", "168") or "168"))
274274

275275
governance_enabled = env("CURATOR_GOVERNANCE_ENABLED", "").lower() in _ENABLED_VALUES
276276
governance_replaces_strengthen = (
@@ -298,7 +298,7 @@ def start_scheduler() -> bool:
298298
)
299299

300300
if governance_enabled:
301-
governance_h = float(env("CURATOR_GOVERNANCE_INTERVAL_HOURS", "168"))
301+
governance_h = max(1.0, float(env("CURATOR_GOVERNANCE_INTERVAL_HOURS", "168") or "168"))
302302
_scheduler.add_job(
303303
_run_governance,
304304
"interval",

0 commit comments

Comments
 (0)