fix(tasks): stop transient Modal snapshot timeouts creating error issues
Problem
The tasks/cloud-agent product gets a fresh error-tracking issue every time Modal's filesystem snapshotting hits a transient infrastructure timeout (CancelledError / TimeoutError: Deadline exceeded), even though the operation almost always recovers on retry.
ModalSandbox.create_snapshot() wrapped every failure from snapshot_filesystem() in a SnapshotCreationError logged at exception level and captured to error tracking. The driving Temporal activity already retries up to 3 times with a 10-minute timeout, so these recoverable deadlines are transparently retried — but each one still surfaced as a noisy exception-level issue, indistinguishable from a hard failure.
Changes
create_snapshot()now catches Modal's transient infra errors (TimeoutError,ConnectionError,CancelledError, plus Modal's ownmodal.exceptionvariants) distinctly from genuine failures.- Transient errors are logged at
warninglevel and raised as a new retryableSnapshotTimeoutErrorwith error-tracking capture disabled — Temporal still retries them, but they no longer create error-tracking issues. - Real, non-retryable snapshot failures continue to raise
SnapshotCreationErrorand are captured as before. - Added a
captureflag toProcessTaskErrorso expected, recoverable failures can skip error-tracking capture.
How did you test this code?
I'm an agent. I added unit tests in test_modal_sandbox.py covering the snapshot-success path, each transient error type (asserting the raised error stays retryable and is not captured), and a genuine failure (asserting it raises SnapshotCreationError and is captured). I verified the new logic passes by exercising create_snapshot() against mocked Modal errors; the pre-existing single-file circular import in this module (unrelated to this change) prevents running the file standalone, so the assertions were validated with the tasks package imported in the order the real test runner uses.
🤖 Agent context
Autonomy: Fully autonomous
Authored by PostHog Code (Claude) from an inbox report. Root cause was a broad except Exception in create_snapshot() that treated recoverable Modal deadline-exceeded timeouts identically to hard failures. The fix separates transient infra errors from genuine ones rather than changing the existing Temporal retry policy, which was already correct. asyncio.CancelledError is a BaseException, so the cause parameter on the shared ProcessTask* error classes was widened to BaseException to keep typing correct.
Created with PostHog Code from an inbox report.