INITIALIZE · SERVE · DRAIN

Agent invocation lifecycle: admit, execute, commit

Follow worker lifecycles and the invocations they own. Test readiness, shutdown deadlines and the point at which results commit.

60-second deterministic hosting drill

Scroll the worker lanes horizontally. The worker inspector, sums and event trace below provide the same states as text.

Worker and invocation inspector

Committed-output fixture

Completed sums remain visible after a worker exits. This represents an external result store; browser reload does not persist it. Killed invocations have no committed output.

Recent lifecycle decisions

Your experiment

Pause a running invocation in prepare, model and tool stages. Its final sum must be absent from the committed-output panel until completion. Force termination before that boundary and verify that the killed invocation never produces a committed result. The named stages are a teaching timeline, not actual model or tool API calls.

Exactly what runs

Requests arrive from t = 1 s through t ≤ 40 s, at the selected interval. Each carries [request number, 1, 2]. The host assigns a free slot and models three equal-duration stages: prepare, model, tool. No AI is called. At completion, actual JavaScript addition computes and commits the sum. Each invocation owns one slot until it completes or its process is killed.

Ready-only routing picks the least-loaded ready worker, with worker ID as a deterministic tie-break. Without that guard it also considers starting and draining workers; those reject the request. There is no admission queue, retry, autoscaler or state transfer. A replacement is a single scheduled boot, not automatic recovery based on load. Startup failure affects only worker 1.

At the signal time, an enabled handler withdraws readiness and drains existing work; an ignored signal leaves the application ready until forced stop. A drained process exits immediately. At a shared timestamp, completions happen before readiness changes, termination and new admission; completion exactly at a shutdown deadline therefore wins in this model. Time is evaluated in 0.1 s steps.

Fixture gate, not a certification

PASS requires zero killed or still-running invocations and a final rejection percentage no greater than the selected allowance. It says nothing about authentication, model quality, real provider SLOs, latency percentiles or production correctness.

Offline, deliberately bounded lifecycle model. It does not execute an ADK Runner, Java process, container, operating-system signal or cloud deployment. Model/tool stages illustrate ownership and timing, not provider computation. The configurable grace period and router are teaching controls, not promises about any cloud runtime. Cloud Run’s documented termination contract and ADK’s invocation event loop must be consulted separately for real implementations. Cloud Run container contract · ADK runtime event loop.

Follow one invocation from admission to commitment

The opening uses two ready workers with two slots each and zero startup delay. Request 1 arrives at one second, occupies worker-1 and starts in prepare. Seek to four seconds: its illustrative model stage is active. At six seconds it has moved to tool, but no sum is committed yet. At eight seconds its output is four, calculated from [1, 1, 2], and its slot is released. Seek to sixty seconds: all twenty requests have completed, with no rejections or killed requests. These stages are a teaching decomposition of an invocation, not ADK callback names or actual inference. Compare an admitted operation that eventually commits with a request rejected before acquiring a slot. Their accounting and recovery obligations differ.

Separate invocation state from host state

Increase Invocation duration to twenty seconds and reduce Initial workers to one with one slot. Keep the two-second arrival interval. The admitted request retains its slot across prepare, model and tool; arriving requests cannot preempt it and there is no waiting queue. Set Grace period to zero and move the signal into a running invocation. The host stops and its uncommitted output is lost. Increase grace to twenty and enable signal handling: the host can finish its owned work while refusing new admissions. Replacement starts a distinct host; it never resumes the interrupted request. The lifecycle reading discusses agent creation and run boundaries, while the planning reading discusses how real agents choose actions. This fixture isolates admission, ownership and commitment; it contains no planner, agent constructor, session memory or model-generated tool call.

Trace ownership and actual output

Initial workers creates one to four workers, and Invocation slots per worker limits each worker to one to four simultaneous requests. Startup duration delays eligibility. Request interval schedules arrivals at one second and then regularly through forty seconds inclusive. Invocation duration holds each admitted slot through three illustrative stages: prepare, model and tool. At completion, JavaScript actually adds the request number, one and two. Seek to eight seconds after Common baseline settings and set startup to zero: request 1 has committed the sum four. Before completion its output is absent. These stage names do not represent real model or tool calls. There is no queue, retry, autoscaler, CPU contention or service-time slowdown as slots increase.

Withdraw readiness before draining

Route only to ready workers chooses the least-loaded ready worker, breaking ties by worker ID. Without it, starting or draining workers remain candidates and reject requests even when another worker could serve them. Fail initialization of worker 1 affects only that original worker. Signal worker 1 at chooses the termination time; Handle SIGTERM and stop admission changes that worker to draining. It accepts no new work and exits as soon as its current invocations finish. Grace period sets a forced-stop deadline. Without the handler, the worker stays eligible until that deadline and may admit requests that it cannot finish. Boot one replacement at signal time schedules one new worker with the same startup delay. It does not recover killed requests or replace every failed worker.

Account for every request

At every snapshot, arrivals equal admitted plus rejected. Admitted equals completed plus killed plus running. A killed request has no committed sum; completed sums remain in an external-store fixture after the owning worker exits. Reload does not persist that store. At equal timestamps, completion happens first, then readiness, signal and forced stop, and finally new admission. Therefore a completion exactly at the shutdown deadline wins here; real deployments need their own concurrency contract. The simulation uses tenth-second snapshots and stops at sixty seconds, after the last possible accepted request can finish. Fixture rejection allowance changes only the pass/fail threshold. Any killed or still-running invocation always fails the gate even at a one-hundred-percent rejection allowance.

Inspect time and worker state

Play runs sixty inspectable seconds at normal speed; Pause freezes time, and Play after completion replays from zero. Step 1 second advances to the next whole-second boundary and pauses. Restart preserves parameters and speed while returning to zero. Simulation time seeks directly and pauses. Speed provides quarter, half, normal and double pace; changing it settles elapsed time at the previous rate. A hidden tab pauses. Changing any model parameter rebuilds the plan and pauses at zero. Common baseline settings restores the shared model defaults, which differ from each page opening. Choose worker provides keyboard access to the same inspection as clicking its diagram lane. A replacement selected before its boot time has no state yet. Expand experiment changes the view; Exit full screen restores it.

Record evidence and understand the scope

Capture baseline saves the selected result and inputs; Replace baseline updates that comparison and Clear baseline removes it. Notes remain in this browser and Export notes downloads them. Scroll the diagram horizontally on phones, or focus its labeled region and use arrow keys. The worker inspector, committed sums and event trace provide text alternatives. The full-run preview intentionally exposes the eventual counts. This is a bounded teaching host, not an ADK Runner, Java process, operating-system signal, load balancer or cloud deployment. Grace and routing are configurable lesson assumptions, not provider guarantees. The fixture gate measures request accounting and the chosen rejection budget; it does not establish production availability, model quality, tenant isolation or real latency.

Views are my own and do not represent any employer, past or present.

Search