Skip to content

A fresh random fence per call makes budget plans non-reproducible run to run #604

Description

@devops-thiago

Found while diagnosing #586.

PromptTemplateEscaper.fence() mints a fresh 32-hex-char CSPRNG token per call. A random hex string does not tokenize to a fixed BPE width — measured over 2000 draws: min 53, max 81 tokens, spread 28.

Both AbstractPrSuggestionGenerator.sharedPromptOverhead (shared by /describe, /improve, /add-docs, /generate-tests) and DiffBudgetPlanner.plan(...) size their overhead by drawing a live fence. So the overhead subtracted from the budget varies by up to ~30 tokens between runs of the same input, and the resulting batch plan is not reproducible.

This is not a production bug. The sample is an unbiased estimate of an overhead that genuinely is random per call, and a ~30-token error is absorbed by token-safety-margin at real budgets of 10⁵. It is recorded because:

  1. It cost real time to diagnose. In Disclosure classification races under the parallel batch pass (flaky test, possible real bug) #586 it was the entire cause of a 1-in-1500 CI failure that had been filed as a possible concurrency race in the review pipeline — a hypothesis it took a full investigation to refute.
  2. Sibling tests that set a small max-input-tokens carry the same latent fragility, and will fail the same way, rarely, for the same reason. Disclosure classification races under the parallel batch pass (flaky test, possible real bug) #586's fix pads its own fixtures past the jitter but does not address the others.
  3. Non-reproducible planning is awkward to reason about generally — the same PR can batch differently on two runs with no input change.

Suggested direction: size the overhead from a fixed-width representative fence (the width is what matters, not the value; the real fence still gets used in the emitted prompt). Plans then become reproducible for a given input, and the class of rare test flake disappears rather than being padded around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions