Skip to content

fix(gateway): retire a timed-out child session; Modal VM log forwarder follows every container (FD-7164) - #992

Open
sarah-chitty-1 wants to merge 3 commits into
mainfrom
sarahchitty/fd-7164-child-session-wedge
Open

sarah-chitty-1 wants to merge 3 commits into
mainfrom
sarahchitty/fd-7164-child-session-wedge

Conversation

@sarah-chitty-1

@sarah-chitty-1 sarah-chitty-1 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • Tyler's party email never arrived;
  • the market moves never happened;
  • the resale sales never happened;
  • every wake waited the full settle timeout.

The change:

  • ChildSessions.call retires the session when a call times out. Calls still on it fail with CONNECTION_CLOSED right 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.
  • The trigger engine's own child calls time out at 120 s (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.
  • A retry on a replacement session retires that session too when it times out (Greptile's P1): both attempts go through one helper.
  • The Modal VM log forwarder follows every container start. While debugging this, only the servicedb's logs reached the Modal dashboard. Compose creates every service before starting it. The forwarder followed each container id once, the first time docker ps -a listed 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 from docker 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.py runs 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/5RetriggerView in Greptile

The retry-timeout fix is complete, but the new forwarder timeout limits must meet the repository's naming rule before merging.

FindingsFix All in Cursor

  1. P2 Log limits lack names ▶
  2. P2 Same-second starts lose logs ▶
Fix with agent prompt
### Issue 1
src/agent_env/providers/sandbox_providers/modal_vm_sandbox.py:111-113
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.

### Issue 2
src/agent_env/providers/sandbox_providers/modal_vm_sandbox.py:undefined-120
`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.

Summary

The gateway retires child sessions after a call times out, including calls retried on a replacement session.

  • A timed-out child call clears its session for later calls.
  • Modal VM logs follow containers whenever they start.

Reviews (7) · Last reviewed commit: "fix(gateway): retire the replacement ses..." · Reviewed by Greptile

…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>
@sarah-chitty-1
sarah-chitty-1 requested a review from a team as a code owner December 2, 2026 19:50
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

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.

Fix in Cursor Fix in Claude Code Fix in Codex

… 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>
@sarah-chitty-1 sarah-chitty-1 changed the title fix(gateway): retire a child session whose call times out; trigger calls time out at 120 s (FD-7164) fix(gateway): retire a timed-out child session; Modal VM log forwarder follows every container (FD-7164) Dec 2, 2026
Comment on lines +111 to +113
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#^/##')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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)

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!

Fix in Cursor Fix in Claude Code Fix in Codex

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant