Skip to content

fix(context): stop the artifact_read retrieval loop - #14

Merged
ayman3000 merged 1 commit into
mainfrom
fix/contextsift-artifact-read-loop
Jul 27, 2026
Merged

fix(context): stop the artifact_read retrieval loop#14
ayman3000 merged 1 commit into
mainfrom
fix/contextsift-artifact-read-loop

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

Problem

Observed live (native macOS app on glm-5.2:cloud): asking the agent to list a directory made it call artifact_read ~6 times in a row and never present the listing, exhausting maxTurns.

Root cause — a self-defeating loop in ContextManager:

  1. run_shell returns a large listing → it's the active exchange → activeDisplay shows a 2000-char preview + "use artifact_read" and spills to artifact-A.
  2. Model calls artifact_read(A). That read's result becomes the new active exchange → activeDisplay truncates it again to 2000 chars and spills to artifact-B.
  3. Model still sees "truncated" → reads B → C → … until maxTurns.

Retrieval was re-truncating itself.

Fix

  • Exempt retrieval tools (artifact_read, artifact_search) from both active-display truncation and receipt spilling — their output is the mechanism for surfacing full content, and they already page via offset/limit.
  • Raise default maxActiveResultChars 2000 → 8000 so ordinary tool outputs fit inline with no artifact round-trip at all.

Tests

  • New testContextManagerDoesNotRetruncateArtifactReads: an active artifact_read result larger than the bound is shown in full, with no "truncated" marker.
  • All 95 tests pass.

🤖 Generated with Claude Code

A large active tool result was bounded to maxActiveResultChars and spilled
to an artifact with a "use artifact_read" hint. When the model called
artifact_read, that retrieval result was itself re-truncated and re-spilled,
so the model looped calling artifact_read to fetch the "full output" that
never surfaced (seen as ~6 repeated calls until maxTurns).

Fix: exempt the retrieval tools (artifact_read, artifact_search) from
active-display truncation and receipt spilling — show their output in full
(they already page via offset/limit). Also raise the default
maxActiveResultChars 2000 -> 8000 so ordinary tool outputs fit inline
without an artifact round-trip.

Regression: an active artifact_read result larger than the bound is shown
in full, never re-truncated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@ayman3000
ayman3000 merged commit 71edaa8 into main Jul 27, 2026
1 check passed
@ayman3000
ayman3000 deleted the fix/contextsift-artifact-read-loop branch July 27, 2026 16:45
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.

1 participant