fix: cache already-read AGENTS.md contracts to stop re-read loops#32
Merged
Conversation
… scratch
Decoded a stuck pi-session: a local model (qwen3.6-35b) re-routed to an
already-fully-read AGENTS.md contract before each new source read, and
because a completed read clears pendingRead, planner_contract_read had
no way to recognize "already read" — it restarted the paginated dump
from cursor 0 every time. The model explicitly noticed it was looping
("I've been cycling too much") yet kept repeating the same tool call,
burning the rest of the session without ever calling
planner_discovery_submit.
planner_contract_read now serves the cached PlannerContractSummaryRecord
instead of re-reading when a path has no in-progress pendingRead and an
explicit cursor wasn't given; pass cursor explicitly to force a real
re-read. planner_contract_scan had the same shape (status guidance tells
the model to scan before every broad read) and now short-circuits once
scanComplete is true, with a force:true escape hatch for a real rescan.
Added contracts.test.ts coverage for both: the read case reproduces the
exact loop (drives a multi-page read to completion, then asserts a
re-read is served from cache, then asserts an explicit cursor still
forces a real re-read); the scan case asserts no re-walk after
completion and that force:true still does one.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contract before each new source read. Because a completed
planner_contract_readclearspendingRead,every re-read restarted the paginated dump from cursor 0 instead of recognizing it was already done —
the model explicitly noticed it was looping yet kept repeating the same tool call until the session ran
out.
planner_contract_readnow serves the cached summary instead of re-reading when there's noin-progress pendingRead and no explicit cursor; pass cursor explicitly to force a real re-read.
planner_contract_scanhad the same shape (status guidance tells the model to scan before every broadread) and now short-circuits once
scanCompleteis true, with aforce: trueescape hatch.