Skip to content

fix: prevent fetch loops with call tracking and caching (#26)#36

Merged
vtemian merged 2 commits intomainfrom
fix/fetch-loop-prevention
Mar 10, 2026
Merged

fix: prevent fetch loops with call tracking and caching (#26)#36
vtemian merged 2 commits intomainfrom
fix/fetch-loop-prevention

Conversation

@vtemian
Copy link
Owner

@vtemian vtemian commented Mar 10, 2026

Summary

Fixes #26 — agents entering infinite loops fetching the same web documents repeatedly.

  • Re-enable doom loop detectiondoom_loop: "allow" was set as collateral in e4c2f47 when all permissions were blanket-allowed. Removing it restores OpenCode's built-in loop protection.
  • Add fetch tracker hook — per-URL call counting with LRU-cached results. Warns after 3 repeated fetches, hard-blocks after 5. Tracks webfetch, context7_query-docs, context7_resolve-library-id, btca_ask.
  • Session-scoped — cache and counts are cleaned up on session delete, following existing patterns.

26 new tests, all passing. No changes to existing test results.

…e-enable (#26)

- Remove doom_loop: 'allow' to re-enable OpenCode's built-in loop detection
- Add fetch-tracker hook that counts per-URL calls per session
- Cache fetch results with LRU eviction (50 entries, 5min TTL)
- Inject warnings after 3 repeated calls to same resource
- Hard-block after 5 repeated calls with informative message
- Track webfetch, context7_query-docs, context7_resolve-library-id, btca_ask
- Session-scoped state with cleanup on session delete

Closes #26
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/hooks/fetch-tracker.ts">

<violation number="1" location="src/hooks/fetch-tracker.ts:190">
P1: Max-call blocking is gated by cache-hit conditions, so repeated fetches can bypass the hard block when cache is expired/missing.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@vtemian vtemian merged commit 5df5cfb into main Mar 10, 2026
2 checks passed
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.

Documentation fetch loop report & cache proposal

1 participant