fix(agents): wait for cron media completions#88695
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 31, 2026, 3:40 PM ET / 19:40 UTC. Summary PR surface: Source +381, Tests +469. Total +850 across 27 files. Reproducibility: yes. at source level: current main wires cron media async starts to Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Refresh the branch against current main, preserve the registry-backed wait and duplicate-guard behavior, and have a maintainer land it after accepting the cron session-lifecycle change. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main wires cron media async starts to Is this the best way to solve the issue? Yes, this looks like the right owner-boundary fix: keep media generation detached, suppress only the cron interactive-yield path, and make the embedded runner wait on the task registry before closeout. A fully inline media tool path would have lost duplicate-guard and detached-task behavior, which the final PR avoids. AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 6b2cb4db67a0. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +381, Tests +469. Total +850 across 27 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09d9130eb3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| export function shouldDetachMediaGenerationTask(sessionKey: string | undefined): boolean { | ||
| const normalizedSessionKey = sessionKey?.trim(); | ||
| return Boolean(normalizedSessionKey && !isCronRunSessionKey(normalizedSessionKey)); |
There was a problem hiding this comment.
Preserve duplicate guarding for inline cron media
When a cron run session returns false here, the image/video/music tools skip the recordRecentMediaGenerationTaskStartForSession(...) block that is currently the only place caching the requestKey used by findDuplicateGuardMediaGenerationTaskForSession to suppress recent successful duplicate requests. In cron runs that now execute inline, an agent retrying the same image_generate/video_generate/music_generate call after the first inline completion will generate the media again instead of getting the recent-task guard that interactive async sessions still get; keep recording the recent start for inline cron task handles or otherwise persist the request key for the completed task.
Useful? React with 👍 / 👎.
09d9130 to
76ae8c4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76ae8c421a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ( | ||
| requiresCompletionRequiredAsyncTaskWait({ | ||
| sessionKey: params.sessionKey, | ||
| toolMetas, | ||
| }) | ||
| ) { |
There was a problem hiding this comment.
Do not wait with a finished agent registered active
For cron media runs where the model returns after starting image_generate/video_generate/music_generate, this wait happens after activeSession.prompt(...) has already resolved, so the underlying agent loop has emitted agent_end and will not drain new steering messages again (packages/agent-core/src/agent.ts:306, packages/agent-core/src/agent-loop.ts:324). Because onBeforeLifecycleTerminal now keeps the embedded run registered as active until this wait finishes, the media completion path sees an active requester and tries to queue the completion back into this finished run; that queued completion cannot be committed, so delivery stalls until the active-wake timeout or the cron run deadline instead of completing inline.
Useful? React with 👍 / 👎.
76ae8c4 to
4275a00
Compare
Summary
Fixes #88001.
Verification
node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run/attempt.async-tasks.test.ts src/agents/subagent-announce-delivery.test.ts src/agents/tools/image-generate-tool.test.ts src/agents/tools/media-generate-background-shared.test.ts src/agents/openclaw-tools.tts-config.test.ts(7 unit-fast tests, 157 agent tests)node scripts/run-vitest.mjs src/agents/tools/video-generate-tool.test.ts src/agents/tools/music-generate-tool.test.ts src/agents/subagent-announce-delivery.test.ts src/agents/embedded-agent-runner/run/attempt-trajectory-status.test.ts src/agents/embedded-agent-runner/run.incomplete-turn.test.ts src/cron/isolated-agent.session-identity.test.ts src/cron/isolated-agent/run.message-tool-policy.test.ts(16 unit-fast tests, 49 cron tests, 253 agent tests)git diff --checkpnpm exec oxlint ...on touched lint-fix files and async-task runner files.agents/skills/autoreview/scripts/autoreview --mode local(first pass found timeout/video wait gaps; fixed; rerun clean with no accepted/actionable findings)tbx_01kszpcj4j4w3w4v2343bsgw4p, Actions run26721537214:corepack pnpm check:changedpassedtbx_01kszqtqh324fypas2y1yaz3c7, Actions run26722125851: finalcorepack pnpm check:changedpassedReal behavior proof
Behavior addressed: isolated cron
agentTurnruns that callimage_generatefollowed bymusic_generateshould not finish the cron turn while media tasks are still running.Real environment tested: direct AWS Crabbox live cron harness with real provider credentials. OpenAI and MiniMax API keys were injected from 1Password for the command only; secret values were not printed. The direct lease was released after the run.
Exact steps or command run after this patch: Crabbox live cron harness executing an isolated cron agent turn that generated one image with OpenAI and one music track with MiniMax, then asserted the task registry for succeeded
image_generationandmusic_generationtask records.Evidence after fix: live run
run_f0087434d34breturned statusok; markercron-media-live-1780249952289; image tasktool:image_generate:7a25d54e-d1e7-4b8b-af56-4ec315028e70; music tasktool:music_generate:05703bea-b42c-45f9-9b49-46e5282e2f63; task statusesimage_generation:succeededandmusic_generation:succeeded.Observed result after fix: the cron agent turn waited through image completion, continued into music generation, waited for the music task, and returned final output containing both generated media paths instead of closing after the async-start response.
What was not tested: live video generation. Video uses the same registry-backed completion wait and has regression coverage here; the requested live proof was image plus music.