How function timeouts work and how progress updates reset them
Agents can take an unpredictable amount of time to do their work — an LLM tool-calling loop might finish in seconds or run for hours depending on the task. Tensorlake handles this by letting functions run indefinitely as long as they keep sending heartbeats in the form of progress updates. A timeout only kicks in if a function stops making progress — it doesn’t finish within the allotted time and it doesn’t send any progress updates to reset the clock.
When a function reports progress via ctx.progress.update(), its timeout automatically resets. This allows functions to run indefinitely as long as they continue making progress.
Copy
Ask AI
from tensorlake.applications import function, RequestContext@function(timeout=300) # 5 minute timeoutdef long_running_task(items: list) -> dict: ctx = RequestContext.get() # After 3 minutes of processing... ctx.progress.update(50, 100, "Halfway done") # Timeout just reset to 5 minutes from NOW # Function can run another 5 minutes before next update # Continue processing...
Timeline:
Function starts with 5 minute timeout
At 3 minutes: progress.update() called
Timeout resets to 5 minutes from this point
Function can now run until minute 8 (3 + 5)
Next progress.update() resets timeout again
Set a short timeout (e.g., 5 minutes) and rely on progress updates to extend it. This way, if a function gets stuck and stops reporting progress, it fails fast instead of running silently for hours.
An agent that runs hundreds of iterations can use a short timeout per iteration. Each progress update resets the clock:
Copy
Ask AI
@function(timeout=300) # 5 minute timeout per iterationdef persistent_agent(task: str) -> str: ctx = RequestContext.get() for iteration in range(1000): ctx.progress.update(iteration, 1000) # resets timeout result = agent_iteration(task) if is_complete(result): return result