Repository navigation
fix(gateway): retire a timed-out child session; Modal VM log forwarder follows every container (FD-7164) - #992
sarah-chitty-1 wants to merge 3 commits into
Conversation
…rigger calls out at 120 s (FD-7164) A child call that timed out left its session current, so every later call to that child queued on the same stuck stream and waited out its own timeout. In an always-on run the trigger engine's world actions and state checks then failed one 600 s timeout at a time for four hours: no world event happened after the first hang. - ChildSessions.call retires the session on a timeout: calls still on it fail with CONNECTION_CLOSED now, the next call opens a fresh session. The timed-out call isn't retried (it may have written). - The trigger engine's own child calls time out at TRIGGER_TOOL_CALL_TIMEOUT_S (120 s), not the 600 s agent limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At boot compose creates every service before starting it. The forwarder polled `docker ps -a` and started one `docker logs -f` per container id the first time it saw it; for a container not yet running that follower ends at once and was never retried, so only the servicedb's logs reached Modal (FD-7164). Restarted or recreated containers were lost the same way. The forwarder now waits for dockerd, follows the containers that exist, then follows each container start from `docker events` with `--since` the start time. A replayed start for a container the first scan already follows is skipped. Verified on a Modal VM boot of a 41-container multi env: all 41 containers' logs in the dashboard (was 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| docker events --since "$since" --filter type=container --filter event=start \ | ||
| --format '{{.Actor.ID}} {{.Time}} {{index .Actor.Attributes "name"}}' 2>/dev/null | | ||
| while read -r c t n; do | ||
| if [ "$t" -le "$since" ]; then case " $existing " in *" $c "*) continue ;; esac; fi |
There was a problem hiding this comment.
existing includes containers that have been created but not started. If the first log follower exits before one starts, and the start happens in the same second as since, this check discards its only start event. That service's logs then stay missing from Modal until another restart.
Track whether a follower is still running rather than skipping every scanned ID. Add a same-second test; the current test puts start times five seconds ahead.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/providers/sandbox_providers/modal_vm_sandbox.py
Line: 120
Comment:
**Same-second starts lose logs**
`existing` includes containers that have been created but not started. If the first log follower exits before one starts, and the start happens in the same second as `since`, this check discards its only start event. That service's logs then stay missing from Modal until another restart.
Track whether a follower is still running rather than skipping every scanned ID. Add a same-second test; the current test puts start times five seconds ahead.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.… out A call retried on a fresh session (the first was dead before the call reached the child) timed out without retiring that session, so it stayed current for the next call to wait on. Both attempts now go through one helper that retires the session on a timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| existing=$(echo $(timeout 20 docker ps -aq --no-trunc 2>/dev/null)) | ||
| for c in $existing; do | ||
| n=$(timeout 10 docker inspect -f '{{.Name}}' "$c" 2>/dev/null | sed 's#^/##') |
There was a problem hiding this comment.
The new log forwarder embeds its 20-second scan timeout and 10-second inspect timeout directly in shell commands. The repository requires magic numbers to be stored as class or instance variables with descriptive names. Give these limits named settings before merging so maintainers can find and understand them without reading the shell commands.
Rule Used: Store magic numbers as class or instance variables with descriptive names rather than using them inline in the code. (source)
Learned From
scaleapi/scaleapi#126388
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/providers/sandbox_providers/modal_vm_sandbox.py
Line: 111-113
Comment:
**Log limits lack names**
The new log forwarder embeds its `20`-second scan timeout and `10`-second inspect timeout directly in shell commands. The repository requires magic numbers to be stored as class or instance variables with descriptive names. Give these limits named settings before merging so maintainers can find and understand them without reading the shell commands.
**Rule Used:** Store magic numbers as class or instance variables with descriptive names rather than using them inline in the code. ([source](https://app.greptile.com/-/switch-tenant?tenant=scale-ai&next=%2Fcustom-context%3Fmemory%3D002e0051-41ad-46c1-9098-47433c580150))
**Learned From**
[scaleapi/scaleapi#126388](https://github.com/scaleapi/scaleapi/pull/126388)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Part of FD-7164. The root cause, a site deadlocking itself on the change-log trigger's database-wide lock, is fixed in scaleapi/synthetic-pipelines#2663. This PR stops a stuck child from freezing a whole run, and fixes the Modal VM log forwarder that hid the site logs while debugging it.
What happened: once a site's server hung, the gateway kept its child session current. Every later call to that child, the trigger engine's world actions and state checks included, queued on the same stuck stream and waited out its own 600 s timeout. In one always-on run, no world event happened for four hours after the first hang:
The change:
ChildSessions.callretires the session when a call times out. Calls still on it fail withCONNECTION_CLOSEDright away, and the next call opens a fresh session. The timed-out call isn't retried, since it may have written. This matches how a call lost in flight is handled already.Gateway.TRIGGER_TOOL_CALL_TIMEOUT_S), not the 600 s agent limit: a world event is a short write or read. Agent calls keep 600 s.docker ps -alisted it, and a follower on a container that isn't running yet ends at once and was never retried. It now waits for dockerd, follows the containers that exist, then follows each start fromdocker events. Restarted and recreated containers are caught too.Tests: four new tests in
tst/unit/env/gateway/child_sessions_test.py:a timed-out call retires its session, and the next call reopens;
calls waiting on that session fail at once, not at their own timeout;
trigger-engine calls use the shorter timeout.
a retry that times out on its replacement session retires that session too.
modal_vm_sandbox_test.pyruns the forwarder against a fake docker in which services are created first and started later, one of them restarts, and a start is replayed. It fails on the old script.The gateway unit suite passes (1,679 tests), as do the sandbox-provider tests, except
smol_vm_provider_test, which needs GNU sed and fails on macOS on main too. On a real Modal VM boot of a 41-container multi env, the dashboard showed logs from all 41 containers; before the change it showed 1.🤖 Generated with Claude Code
Confidence Score: 4/5

The retry-timeout fix is complete, but the new forwarder timeout limits must meet the repository's naming rule before merging.
Findings
Fix with agent prompt
Summary
The gateway retires child sessions after a call times out, including calls retried on a replacement session.
Reviews (7) · Last reviewed commit: "fix(gateway): retire the replacement ses..." · Reviewed by Greptile