feat(cloud-agent-next): add container lifecycle logging - #4898
Merged
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryObservability-only change adding Verification notes
Files Reviewed (5 files)
Reviewed by claude-opus-5 · Input: 50 · Output: 9K · Cached: 1.6M Review guidance: REVIEW.md from base branch |
jeanduplessis
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Container runs in cloud-agent-next have no log in the worker when they start.
onStartlogs only on the failure path (missing attribution), so there is norecord that a container began, why it began, or how long it ran. Answering
questions about container lifetime currently means correlating usage rows
against worker logs by hand, including decoding the epoch suffix out of a
container name to find the join key.
This adds structured lifecycle logging. Logging only, no behavior change.
New log tags:
container_started(info) incontainer-usage.ts, emitted fromstartBillingGenerationwithgeneration,startEpochMs,sandboxClass,durableObjectId, and atriggerfield that distinguishes a real SDKonStartfrom the two paths that adopt an already running container.container_stopped(info) inonStop, carrying stopreason,exitCode,and
lifetimeMs.wrapper_stop_inspection(info) inCloudflareAgentSandbox.stopWrappers,recording the observation outcome (
present,absent,inspection-failed)and the observed wrapper count for each stop attempt.
sandbox_keepalive_renewed(debug) in the ingest heartbeat debounce, withsinceLastRenewalMs.idle_kilo_server_stoppedadded to the existing "Stopping idle kilo server"log, along with a new
overdueMsfield measuring how late the sweep ranagainst its own
idleTimeoutMs.The two silent early returns in
keepSandboxAlive(agent-runtime.ts) now logwhich guard tripped. Both previously returned without any log, which in Axiom
was indistinguishable from a renewal that succeeded.
container_startedandcontainer_stoppedboth carrygenerationandstartEpochMs. WithsandboxIdthese form the usageintervalId(
service:instanceId:startEpochMs, seepackages/container-usage/src/contracts.ts),so a log line now joins directly to its usage row.
Verification
path with no behavior change, and the paths involved (container start and
stop, wrapper stop inspection, ingest heartbeat) are driven by sandbox
lifecycle events rather than by request input.
Visual Changes
N/A
Reviewer Notes
wrapper_stop_inspectionis the one worth a closer look.stopWrappersinspects by calling
listProcesses, which is a container fetch, so it wakes asleeping container. Logging the observation outcome makes it measurable how
often a stop attempt boots a container only to find no wrapper running. This
PR measures that, it does not change it.
container_startedandcontainer_stoppedfire once per containerrun.
wrapper_stop_inspectionfires once per wrapper stop attempt. Idletimeout stop reconciles alone currently run roughly 320 to 580 per hour, and
other stop reasons add to that.
sandbox_keepalive_renewedis debug level andfires at most once per 30 second heartbeat debounce per connected wrapper.
startBillingGenerationgained a requiredtriggerparameter. All three callsites are updated.
format:checkpass. 991 unit testspass across the five touched modules. Two failures in
test/unit/wrapper/server.test.ts(git co-author tests, 5s timeouts) arepre-existing and reproduce on main without these changes.