correct overlap guard + tighten maxDuration
- Two bugs in the previous patch:
- 1. Overlap guard used hb.updatedAt which does not exist on YenHeartbeat
- schema — the lease check was always falsy, meaning RUNNING state never
- actually blocked a concurrent cron tick. Fixed to use lastFiredAt (which
- IS written atomically before runAgent starts) as the lease timestamp.
- 2. maxDuration=15 was lower than DB_TIMEOUT_MS(8s) + AGENT_TIMEOUT_MS(10s).
- Raised to 20s with a comment explaining the budget arithmetic. This
- prevents Vercel from killing the function before our own timeouts fire,
- which would cause a TCP reset (NetworkError) instead of a clean JSON error.
- Control plane summary after both patches:
- maxDuration: 20s (was 60s)
- DB query timeout: 8s (fail-fast on Supabase slowness)
- Agent timeout: 10s (was 30s)
- Max heartbeats/tick: 1 (was unlimited)
- Claim written: BEFORE runAgent (atomic overlap guard)
- RUNNING lease: lastFiredAt-based (correct field)
0e3f377View on GitHub →