Skip to content

Fix #1052: retry a rejected summarizer span before giving up on it - #1092

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/1052-rest
Nov 1, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/1052-rest

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Second half of #1052 (first half shipped in #1084 / 735e65c: doctor reports a dropped summarizer span). This half stops scripts/save-session.sh from unconditionally advancing the saved read-position past a span the summarizer refused -- [validate] REJECTED (not an entry header) or a [summarizer] REJECTED refusal/clarification -- which previously dropped a span permanently on its first refusal.

What changed

  • New record_rejected_span() (mirrors the existing record_summary_failure()): a marker file tmp/last-rejected-span and a new config threshold thresholds.max_rejected_retries (default 3, 0 = retry forever -- same convention as max_summary_failures).
  • Below the threshold: the position is NOT advanced, so the span is retried next run (same shape [ndc] rejections already use).
  • At/above the threshold (default: 3rd consecutive rejection of the same span): the raw, unsummarized span text is parked at tmp/dropped-span-<timestamp>-$$.md and the position advances, with a WARNING logged, so one permanently-refused span cannot block all future saves.
  • scripts/doctor.sh's dropped-span section reworded to describe retry-then-park instead of claiming permanent loss.
  • config.example.json and docs/configuration.md document the new threshold.
  • REJECTED_MARKER is now explicitly cleared (rm -f) on both successful-resolution paths, matching FAILURE_MARKER's own convention.
  • tests/test_marker_write_fifo_653.py's static marker-write completeness guard now also covers REJECTED_MARKER.

Tests

Red: tests/test_save_session_gates.py::TestMalformedOutputNeverReachesMemory::test_malformed_output_still_advances_the_position failed (assert None == 904) against the old unconditional-advance behavior.
Green: python3 -m pytest tests/test_save_session_gates.py -q --no-cov -- 37 passed. New TestRejectedSpanLoop class covers retry, give-up, parking, infinite-retry (max_rejected_retries=0), and a positive control (an accepted summary still advances after prior rejections). Full targeted run across 9 related test files: 569 passed.

Self-reviewed by two spawned reviewers (Explore, oss:auditor); 6 findings, all fixed (stale comment, misleading WARN headline, missing docs row for the new threshold, missing marker cleanup, a weak test, and the marker-write guard coverage gap named above).

Closes #1052.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 3 commits November 1, 2026 15:48
A reject gate ([validate] REJECTED or [summarizer] REJECTED) is a
successful summarizer call that discards real work. Until now
save-session.sh advanced the saved position past that span
unconditionally, so a span the model refused once was never
summarized -- gone for good on the first refusal.

Add record_rejected_span(), the same bounded-retry shape
record_summary_failure() already uses for a hard call failure, with
its own separate marker/threshold (thresholds.max_rejected_retries,
default 3): a rejected span is now retried next run, and only after N
consecutive rejections of the same span does the position finally
advance -- with the raw, unsummarized span text (not just the model's
refusal) parked at tmp/dropped-span-*.md so nothing is silently lost.

Updates doctor.sh's #1084 "Dropped summarizer spans" message to
describe what now happens instead of claiming the span is still gone
for good. Pairs every "must not fire" rejection test with the
"must fire"/positive-control pair required by this repo's own
CLAUDE.md (an accepted summary still advances; 0 retries forever,
matching max_summary_failures' own convention).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Explore and oss:auditor review of 103c35e found six real issues:

- A comment directly above the validate-REJECTED branch still claimed
  "the position still advances", contradicting the bounded retry it
  introduces three lines below.
- doctor.sh's WARN headline said "span(s) dropped by a reject gate"
  while counting every REJECTED log line, including ones that are
  retried and never actually dropped. Reworded to "rejection(s) hit a
  reject gate" (and the OK line to match), with the pinned tests in
  tests/test_doctor_dropped_summarizer_spans_1052.py updated to the
  same wording.
- docs/configuration.md documented max_summary_failures but not its
  new sibling max_rejected_retries. Added the missing row.
- REJECTED_MARKER was never cleared on a successful resolution path,
  unlike FAILURE_MARKER (cleared on SKIP and on a successful append).
  Added the same clears so a stale rejection count cannot survive past
  the span it belonged to.
- test_success_clears_the_rejected_count asserted only that the
  position advances, not that the marker file was actually removed --
  it would have passed even with the bug above present. Strengthened
  to assert the marker file's absence.
- tests/test_marker_write_fifo_653.py's static completeness guard
  (_MARKERS) was not extended to cover the new REJECTED_MARKER write
  site, so a future unguarded write to it would go unnoticed by the
  test that exists specifically to catch that.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… on final flush, cap and clamp

The rejection counter keyed its span-id on $POSITION (the transcript's
current end), which grows on every save of a live session -- the counter
never saw the same span twice, the count reset to 1 forever, and a
persistently refused span blocked every later span from being saved too.
Keyed on $SKIP_LINES (the span's actual start) instead, which does not
move across retries of the same span; applied the identical fix to
record_summary_failure's own span-id for the same reason.

A rejection on the session's final --force flush had no later save to
retry it, so it was simply lost rather than parked -- now parked
immediately when $FORCE is set. dropped-span-*.md files are capped to the
newest 20, the same retention rejected-*.md already has. 0
("retry forever") for thresholds.max_rejected_retries is clamped to the
default with a log line, since it could otherwise stall saving for the
rest of a session. doctor.sh now reports how many spans are currently
parked and where, and the give-up message also reaches hook-errors.log.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@fdaviddpt
fdaviddpt merged commit 55978fa into main Nov 1, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the fix/1052-rest branch November 1, 2026 17:30
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.

Summarizer refuses over the header time, span is dropped, and doctor still reports OK

1 participant