Skip to content

Commit fc9fbaf

Browse files
mikasenghaascursoragent
authored andcommitted
warn on ambiguous prefix match in interleave_rollout
When more than one active prefix matches a step's prompt, log a warning with the example id, step index, set of matching prefix lengths, total active prefixes, and the prompt length. Longest-match still picks the correct extension; the warning just surfaces the rare ambiguous case so it's debuggable if it starts showing up in real rollouts (e.g. from compaction/rollback turns). Co-authored-by: Cursor <cursoragent@cursor.com> (cherry picked from commit ca38614)
1 parent 8bb2b22 commit fc9fbaf

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/prime_rl/orchestrator/trajectories.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,26 @@ def extend_sample(
413413
# silently absorb the longer sample's generated tokens as user input.
414414
matched_idx = None
415415
matched_len = -1
416+
matching_prefix_lens: list[int] = []
416417
for idx, (prefix_tokens, _, _) in enumerate(active_samples):
417418
pl = len(prefix_tokens)
418-
if pl > matched_len and step_prompt_ids[:pl] == prefix_tokens:
419-
matched_idx = idx
420-
matched_len = pl
419+
if step_prompt_ids[:pl] == prefix_tokens:
420+
matching_prefix_lens.append(pl)
421+
if pl > matched_len:
422+
matched_idx = idx
423+
matched_len = pl
424+
425+
if len(matching_prefix_lens) > 1:
426+
# Ambiguous extension: rare, but reachable via compaction/rollback
427+
# where a new sample's prefix happens to start with an older
428+
# sample's prefix. Longest-match is the correct choice; surface
429+
# the ambiguity so we can audit if it shows up in real rollouts.
430+
logger.warning(
431+
f"Ambiguous prefix match at step {step_idx} for example {output['example_id']}: "
432+
f"{len(matching_prefix_lens)} of {len(active_samples)} active prefixes match "
433+
f"(lens={sorted(matching_prefix_lens)}, step_prompt_len={len(step_prompt_ids)}). "
434+
f"Extending the longest (len={matched_len})."
435+
)
421436

422437
if matched_idx is not None:
423438
# Extension holds - merge into matched sample

0 commit comments

Comments
 (0)