# Diagnostic Scenario Time Budget

<!-- auto-oncall-optimization-record
{
  "schemaVersion": "auto-oncall-optimization-record-v1",
  "optimizationId": "diagnostic-scenario-time-budget-2026-07-31",
  "problems": [
    {
      "problemId": "diagnostic-scenario-expires-before-provider-investigation-completes",
      "summary": "A diagnostic scenario can exhaust the former 360-second stage cap during agent preparation and terminate before completing its bounded provider investigation and structured result.",
      "status": "candidate",
      "issueKeys": ["ST-2810"],
      "sourceRefs": [
        "https://tidb.atlassian.net/browse/ST-2810#problem:diagnostic-scenario-stage-timeout"
      ],
      "signalTextIncludesAny": [
        "diagnostic scenario timeout",
        "scenario stage cap",
        "scenario expires before provider query",
        "360 second timeout"
      ],
      "observedThrough": "2026-07-31",
      "effectiveAt": null,
      "verifiedAt": null,
      "attemptedAction": "Raise the scenario stage cap from 360 to 900 seconds while retaining the shared 1200-second pipeline deadline and downstream reserve, set the provider authentication bootstrap default and deployment value to 120 seconds, and explicitly close the streamed Codex iterator on non-natural completion so the SDK terminates and reaps its child process.",
      "evidenceUrl": "https://github.com/tidbcloud/aisupport/pull/581"
    }
  ]
}
-->

- Optimization ID: `diagnostic-scenario-time-budget-2026-07-31`
- Owner: auto-oncall-services
- Source reference: `ST-2810`
- Implementation status: implemented locally, not deployed
- Effective status: `candidate`

## Bounded problem

The scenario pipeline previously inherited a 360-second cap. In ST-2810 the
scenario spent most of that budget preparing its isolated diagnosis and was
aborted before it could finish the provider investigation and structured
handoff. The SDK stream could then remain in abort cleanup after the stage
deadline, adding avoidable wall time.

## Candidate implementation

- Configure both staging and production templates with a 900-second scenario
  cap and a 120-second authentication bootstrap default. An explicit positive
  auth value may be longer but remains bounded by the remaining pipeline
  budget.
- Keep the existing 1200-second absolute runner budget. Route, authentication,
  and downstream synthesis reserves can reduce the effective scenario
  allocation; no stage extends the shared deadline.
- On stage abort, explicitly close the Codex streamed-event iterator. The SDK
  owns the child-process handle, so closing the stream exercises its supported
  termination and cleanup path without reaching into private SDK state.

## Verification evidence

- Budget tests cover a 900-second scenario without authentication and the
  effective 840-second allocation after a 60-second route, 120-second auth,
  and 180-second downstream reserve.
- A streamed-turn regression test holds a scenario open until its stage signal
  aborts, then verifies iterator cleanup and a timeout result.
- TypeScript build, focused tests, and the full local test suite pass. This is
  implementation evidence only and does not prove runtime effectiveness.

## Unresolved gaps

- The change is not deployed.
- ST-2810 has not received a post-deployment replay with the new budget.
- The Codex SDK owns process creation and termination. This change invokes its
  public stream cleanup path; it does not add unsupported process-group access.

## Next validation action

After a separately authorized staging rollout, replay one affected diagnostic
case and verify that the scenario either returns a complete bounded packet or
uses the longer effective allocation without wall time beyond the shared
pipeline deadline.
