Skip to content

[agentserver] Gate blocking boot-time task recovery scan on the enablement flag - #48585

Draft
Nathandrake229 wants to merge 1 commit into
mainfrom
naman/gate-boot-recovery-scan
Draft

[agentserver] Gate blocking boot-time task recovery scan on the enablement flag#48585
Nathandrake229 wants to merge 1 commit into
mainfrom
naman/gate-boot-recovery-scan

Conversation

@Nathandrake229

Copy link
Copy Markdown
Contributor

Summary

The resilient TaskManager's cold-start recovery scan (Layer 1) blocks server lifespan startup on a task-store list() + credential-token acquisition. It previously ran whenever either a durable task was registered or the enablement switch was set.

Because the responses protocol registers internal @task / @multi_turn_task primitives at host construction, _has_registered_tasks() was always True — so every responses host, even a plain one that opted into no resilient features, paid the blocking boot-time scan.

This PR makes the blocking Layer 1 scan opt-in via the existing set_resilient_tasks_enabled() switch, while keeping background (Layer 2) and request-time (Layer 3) recovery always available.

Changes

Core

  • TaskManager.startup() gains run_initial_scan (default True — preserves the contract for direct callers and the recovery test-suite). When False, the blocking cold-start scan is skipped; the periodic background loop (Layer 2) and request-time inline reclaim (Layer 3) still provide recovery.
  • The hosted lifespan (_base.py) passes run_initial_scan=_resilient_tasks_enabled() — a host that did not enable resilient tasks boots fast, keeping Layers 2 and 3 available.

Samples

  • The invocations resilient samples (resilient_research, resilient_multiturn, resilient_langgraph) declare developer @multi_turn_tasks and now call set_resilient_tasks_enabled(True) to retain eager boot recovery — matching the responses resilient samples (19–22), which already do this.

Behavior

Deployment Layer 1 (boot scan) Layers 2 + 3
Switch ON (set_resilient_tasks_enabled(True)) runs at boot (unchanged) available
Switch OFF (plain responses host, or @task app that didn't opt in) skipped (was: ran) available

Trade-off: for switch-off hosts, proactive reclaim of orphans from a prior crash moves from boot-time to the background loop (~interval) — anything re-requested is still reclaimed immediately by Layer 3. Ideal practice is to enable the switch; this change makes the un-enabled path degrade gracefully instead of blocking boot.

Backward compatibility

  • No public API break: startup() only gains an optional keyword defaulting to today's behavior; it is internal (called by _base.py).
  • No decorator / TaskOptions changes; no version-pin bump (set_resilient_tasks_enabled already shipped).

Tests

  • test_task_manager_optin.py updated: fake startup accepts the kwarg; added run_initial_scan assertions (skipped when switch off, runs when on). 11 passed.
  • Core recovery suite unaffected (default run_initial_scan=True): test_inline_recovery / test_recovery_lease_etag / test_lifecycle28 passed.

…ement flag

The resilient TaskManager's cold-start recovery scan (Layer 1) blocks server
lifespan startup on a task-store list() + credential-token acquisition. It ran
whenever a durable task was registered OR the enablement switch was set. Because
the responses protocol registers internal @task/@multi_turn_task primitives at
host construction, every responses host — even a plain one that opted into no
resilient features — paid that boot cost.

Make the blocking Layer 1 scan opt-in via the existing
set_resilient_tasks_enabled() switch:

- TaskManager.startup() gains run_initial_scan (default True, preserving the
  contract for direct callers and the recovery test-suite). When False, the
  blocking scan is skipped; the periodic background loop (Layer 2) and
  request-time inline reclaim (Layer 3) still provide recovery.
- The hosted lifespan passes run_initial_scan=resilient_tasks_enabled(), so a
  host that did not enable resilient tasks boots fast while keeping Layers 2
  and 3 available.

Samples: the invocations resilient samples (research, multiturn, langgraph)
declare developer tasks and now call set_resilient_tasks_enabled(True) to keep
eager boot recovery, matching the responses resilient samples.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Hosted Agents sdk/agentserver/* label Aug 14, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant