# NPC turn-budget planning lab

Original, dependency-free Python 3 arithmetic model. All durations are authored synthetic assumptions. This is not an Inworld benchmark, a browser trace, a timer implementation, a production scheduler, or a test of cancellation, moderation quality or model output.

Run `python turn_budget.py` to reproduce `synthetic-turns.csv`; run `python -m unittest -v test_turn_budget.py` for the 12 test methods. Files must be in the same directory. The script makes no network calls and requires no account, API key, GPU or game engine.

## Download files

- [Planner](turn_budget.py)
- [Tests](test_turn_budget.py)
- [Calculated CSV](synthetic-turns.csv)

## Assumptions

Each hypothetical turn serializes a mandatory 80 ms preflight and 120 ms state lookup. The model has 200 ms until its first token and a further 300 ms until completion. An output check takes 70 ms, then display takes 30 ms. Nothing is shown before the output check. An optional 250 ms summary can precede the reply, or start after its candidate visible time. The latter is only valid when the current reply does not depend on that summary.

The fallback example adds a 300 ms failed-primary wait before those same model durations. Switching, transport and cancellation overhead are deliberately zero in this toy model. Real applications must measure them. The slow-tail case substitutes 50 ms first-token time and 700 ms completion tail.

The illustrative overall budget is 900 ms, not a recommended universal target. A fully checked candidate arriving at or before it is accepted; a later candidate selects an authored local fallback at the budget. This arithmetic does not enforce a real deadline or cancel any job. The candidate columns describe the hypothetical completed path even when the decision rejects it. In a real implementation, do not commit rejected or superseded reply memory. Background-job persistence, retries, contention and state-version checks are outside this model.

## Interpretation

- Moving an independent summary removes 250 ms from the reply path but does not eliminate the work.
- A per-attempt first-token timeout adds to the next attempt's time; it is not a complete-turn budget.
- A fast first token can coexist with a late completed, checked reply.
- Preserve required safety and game-state checks; only defer work proven independent.

## Source context

Inworld's request-level routing documentation describes the first-token fallback setting and its 300 ms minimum: https://docs.inworld.ai/router/capabilities/request-level . The number is used here only as a synthetic scenario input, not as an observed timeout.

vLLM explains that automatic prefix caching helps prefill, not output-token decoding: https://docs.vllm.ai/en/latest/features/automatic_prefix_caching/ . This lab does not simulate caches or verify any provider's implementation.

Use the source documentation for API behavior; use this lab only to test your own scheduling assumptions. No upstream code, promotional artwork, production traffic or private approval records are included.
