From d49907aefe070f175f13f5cb01576da54e8ed26c Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Mon, 12 Oct 2026 22:55:33 -0400 Subject: [PATCH] Sync YNAB in the background inside the tools' freshness window Agent tools call ensure_fresh(120s) but the background loop ran every 900s, so most finance questions waited on an inline YNAB fetch. Default the loop to 90s (40 requests/hour, well under YNAB's 200/hour limit). Co-Authored-By: Claude Opus 5.5 --- .env.example | 5 +++-- blueprints/ynab/sync.py | 3 ++- docker-compose.yml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 373eba9..09ce499 100644 --- a/.env.example +++ b/.env.example @@ -72,8 +72,9 @@ OIDC_USE_DISCOVERY=true YNAB_ACCESS_TOKEN=your-ynab-personal-access-token # Optional: Specify a budget ID, or leave empty to use the default/first budget YNAB_BUDGET_ID= -# Seconds between background YNAB delta syncs (agent tools also sync on demand) -YNAB_SYNC_INTERVAL=900 +# Seconds between background YNAB delta syncs. Keep under the agent tools' 120s +# freshness window so tools rarely wait on an inline YNAB fetch. +YNAB_SYNC_INTERVAL=90 # Mealie Configuration # Base URL for your Mealie instance (e.g., http://192.168.1.5:9000 or https://mealie.example.com) diff --git a/blueprints/ynab/sync.py b/blueprints/ynab/sync.py index 3ddb27e..b73e36c 100644 --- a/blueprints/ynab/sync.py +++ b/blueprints/ynab/sync.py @@ -630,7 +630,8 @@ async def ensure_fresh(max_age_seconds: int = 120) -> YnabSyncState | None: async def ynab_sync_loop() -> None: """Background task: delta-sync YNAB every ``YNAB_SYNC_INTERVAL`` seconds.""" - interval = int(os.getenv("YNAB_SYNC_INTERVAL", "900")) + # Below ensure_fresh's 120s window, so tool calls rarely sync inline. + interval = int(os.getenv("YNAB_SYNC_INTERVAL", "90")) logger.info(f"YNAB sync loop started (interval={interval}s)") while True: try: diff --git a/docker-compose.yml b/docker-compose.yml index 59bde2f..982aae3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ x-raggr-common: &raggr-common - TAVILY_API_KEY=${TAVILIY_API_KEY} - YNAB_ACCESS_TOKEN=${YNAB_ACCESS_TOKEN} - YNAB_BUDGET_ID=${YNAB_BUDGET_ID} - - YNAB_SYNC_INTERVAL=${YNAB_SYNC_INTERVAL:-900} + - YNAB_SYNC_INTERVAL=${YNAB_SYNC_INTERVAL:-90} - MEALIE_BASE_URL=${MEALIE_BASE_URL} - MEALIE_API_TOKEN=${MEALIE_API_TOKEN} - MEALIE_GROUP_SLUG=${MEALIE_GROUP_SLUG:-home} -- 2.52.0