Skip to content

[codex] Protect long-running agent goal streams#5772

Merged
diegosouzapw merged 7 commits into
diegosouzapw:release/v3.8.43from
nguyenxvotanminh3:codex/agent-goal-resilience-pr
Jul 2, 2026
Merged

[codex] Protect long-running agent goal streams#5772
diegosouzapw merged 7 commits into
diegosouzapw:release/v3.8.43from
nguyenxvotanminh3:codex/agent-goal-resilience-pr

Conversation

@nguyenxvotanminh3

Copy link
Copy Markdown
Contributor

Summary

  • detect long-running agent /goal requests from nested chat bodies or x-omniroute-agent-goal: true
  • give detected goal runs a 10 minute stream-readiness cap so slow first-token phases do not fail early
  • enable transparent early stream recovery for goal runs even when the global recovery default is off
  • document the new environment controls in .env.example

Why

Claude/Codex-style agent goal runs can spend a long time planning or waiting for tool-call orchestration before the first stream token. The normal readiness budget and recovery defaults are tuned for ordinary chat, so these long-running runs can look stalled or fail on a truncated opening stream. This keeps the special handling scoped to explicit /goal traffic and avoids changing normal chat behavior.

Stack note

This PR is stacked on #5767 (codex/performance-streaming-readiness). Until #5767 lands, GitHub will show that commit in this diff too. The new commit for this PR is Protect long-running agent goal streams.

Safety

  • does not automatically enable mid-stream continuation, because replaying advanced/tool-call streams can duplicate side effects
  • bounded nested-body scanning avoids unbounded traversal of large request payloads
  • normal requests keep the existing stream recovery and readiness behavior

Validation

  • git diff --check
  • node --import tsx/esm --test tests/unit/agent-goal-policy.test.ts tests/integration/stream-recovery-wiring.test.ts tests/unit/runtime-timeouts.test.ts tests/unit/stream-readiness-policy.test.ts
  • npm run typecheck:core
  • npx eslint open-sse/utils/agentGoalPolicy.ts open-sse/handlers/chatCore.ts tests/unit/agent-goal-policy.test.ts tests/integration/stream-recovery-wiring.test.ts
  • local runtime smoke on port 20129 before publishing

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@nguyenxvotanminh3 nguyenxvotanminh3 force-pushed the codex/agent-goal-resilience-pr branch from b932751 to 8c39f6f Compare July 1, 2026 06:43
@nguyenxvotanminh3

Copy link
Copy Markdown
Contributor Author

Rebased this stacked PR onto the updated #5767 branch, so it now includes the new /v1/chat/completions early keepalive follow-up before the goal-resilience commit. Validation rerun on this branch: node --import tsx/esm --test tests/unit/agent-goal-policy.test.ts tests/integration/stream-recovery-wiring.test.ts tests/unit/chat-combo-live-test.test.ts tests/unit/early-stream-keepalive.test.ts tests/unit/runtime-timeouts.test.ts tests/unit/stream-readiness-policy.test.ts (39/39).

@diegosouzapw diegosouzapw changed the base branch from main to release/v3.8.43 July 1, 2026 23:42
@diegosouzapw diegosouzapw marked this pull request as ready for review July 1, 2026 23:43
@diegosouzapw diegosouzapw self-requested a review as a code owner July 1, 2026 23:43
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

diegosouzapw and others added 3 commits July 1, 2026 20:46
…t-goal-resilience-pr

# Conflicts:
#	src/app/api/v1/chat/completions/route.ts
…y opt-out

The /goal detector's stream-recovery override was fail-open: it could
re-enable recovery even when an operator explicitly turned it off via
STREAM_RECOVERY_ENABLED or a DB/settings override. Make it fail-closed —
the goal-policy heuristic may only fill in recovery when nothing is
explicitly configured, and now logs when it does. Also add
OMNIROUTE_AGENT_GOAL_POLICY_ENABLED (default true) as a full kill-switch
for the heuristic to mitigate client-controlled timeout amplification.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
…t-goal-resilience-pr

Resolve conflicts against release/v3.8.43 (which now contains diegosouzapw#5767):
preserve the agentGoalPolicy Math.max readiness-timeout guard and the
OMNIROUTE_AGENT_GOAL_* env docs/example blocks, keep release's version
of everything already delivered by diegosouzapw#5767.

Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
@diegosouzapw diegosouzapw merged commit f6100d6 into diegosouzapw:release/v3.8.43 Jul 2, 2026
3 of 7 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @nguyenxvotanminh3! Merged into release/v3.8.43 on top of #5767. We hardened it together: goal detection can no longer override an operator's explicit stream-recovery opt-out (fail-closed) and the whole heuristic is now toggleable via OMNIROUTE_AGENT_GOAL_POLICY_ENABLED. 🙌

@diegosouzapw diegosouzapw mentioned this pull request Jul 2, 2026
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.

2 participants