Compare commits

..
Author SHA1 Message Date
Andrew BeveridgeandClaude Fable 5 5222be688a docs: record deferred atomic-claim follow-up (CodeRabbit review)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 02:47:42 -04:00
Andrew BeveridgeandClaude Fable 5 42c6874257 fix: worker-side idempotency gate + surface failed video-worker dispatch
Review findings on the Cloud Run Job migration:

1. The CRJ dispatch path bypasses the HTTP endpoint's
   _check_worker_idempotency guard, and Cloud Run may re-run an execution
   (max_retries=2) after an OOM/timeout/hard kill. Re-entering
   process_render_video on a job already in RENDERING_VIDEO hit the
   same-state transition guard and hard-failed the job with a spurious
   "Invalid state transition" — worse, a stale trigger racing a job that
   just finished could resurrect a terminal job. The worker now protects
   itself regardless of dispatch path: terminal states and RENDERING_VIDEO
   are skipped cleanly (live renders undisturbed; dead ones recovered by
   the rendering_video_stuck sweep). Legacy path unaffected — the worker
   enters with REVIEW_COMPLETE.

2. trigger_video_worker's bool return was silently discarded after render
   completion (both GCE and local paths); a failed CRJ dispatch left the
   job stalled at instrumental_selected with no error anywhere. Now logged
   at ERROR so the error monitor sees it.

Also fixes a pre-existing registry leak on the job-not-found early return,
and updates test fixtures to enter the worker in REVIEW_COMPLETE (the real
dispatch state) instead of RENDERING_VIDEO.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 02:35:03 -04:00
Andrew BeveridgeandClaude Fable 5 2cc68a0bba fix: run render-video worker as Cloud Run Job to survive backend deploys
Tenant E2E #107 (job 41e06b90): a deploy landed mid-render, Cloud Run
SIGKILLed the old instance ~10s after SIGTERM, and the render poll — a
FastAPI BackgroundTask — died silently. The GCE encoder finished the
render and uploaded all outputs, but nobody polled it again; the job
froze at rendering_video until the 45-min stuck-job sweep (past the
E2E's 30-min budget, and a ~50-60 min stall + wasted re-render for a
real customer).

The lifespan "park on shutdown" hook never runs in this scenario:
uvicorn waits for background tasks BEFORE running lifespan shutdown, so
with a long render in flight it dies in that wait. Its comment claimed
a 600s grace period; Cloud Run services give 10s.

Fix — same shape as the 2026-03-08 video-worker fix (which this worker
missed): route trigger_render_video_worker through the existing
video-encoding-job Cloud Run Job with a render_video_worker args
override, behind USE_CLOUD_RUN_JOBS_FOR_RENDER (enabled in the deploy
env). Job executions run to completion; service deploys never touch
them.

- render_video_worker: new CLI entrypoint. Exit-code contract differs
  from video_worker deliberately: clean returns (True AND False) exit 0
  because process_render_video parks/fails/supersedes internally; only
  an escaped crash exits 1 (job template has max_retries=2).
- Pulumi: video-encoding-job env gains both USE_CLOUD_RUN_JOBS_FOR_*
  flags so the render execution's in-process video-worker trigger also
  dispatches a Cloud Run Job (applied to prod ahead of merge).
- main.py: corrected the false 600s comment; shrank the unreachable
  480s lifespan wait to 5s. Parking hook kept as legacy/flag-off net.
- 45-min rendering_video_stuck sweep unchanged (net for crash/OOM/
  timeout/lost-VM).

Rollback: drop USE_CLOUD_RUN_JOBS_FOR_RENDER=true from the service env.

Investigation: docs/archive/2026-09-13-render-deploy-survival-investigation.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 02:16:47 -04:00

Diff Content Not Available