Skip to content

feat(pi): replace loop-guard with loop-protection plugin - #60

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/loop-protection
Aug 30, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/loop-protection

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Replace the loop-guard extension with loop-protection.ts, a proper pi plugin that fixes the agent repetition loop at the tool layer.

RCA (2026-08-30, from live session evidence): the loop is driven by the model degenerating into emitting the SAME tool call hundreds of times in one response (observed: 317 identical fabric_exec calls, 43K tokens) plus degenerate text repetition ("torso" x 2000+). The response hits the provider's TOTAL output cap (max_tokens is thinking + answer), the harness fails every call with a context-less "Re-issue the tool call" error, and the model repeats more — a self-amplifying loop (1133 truncation errors, 600M+ tokens burned).

The old loop-guard (exact-match retry blocking) never fired because looping calls differ slightly each time (timestamped paths), and it did not address the truncation handling. The new plugin has four protections:

  1. tool_call — blocks the Nth consecutive identical call (dedup) and blocks re-issues of calls from truncated responses with a corrective directive (replaces the harness's "re-issue" instruction).
  2. message_end — detects truncated responses (stopReason: "length"), identical-call repetition, and degenerate text repetition; tracks consecutive truncations.
  3. context — injects a corrective message when >= 2 consecutive truncations or degeneration is detected, so the model changes behavior instead of repeating.
  4. tool_result — auto-compaction: bounds tool results > 20K chars to 8K + a note, so the context cannot flood (the flood drives the degeneration).

How tested

All verified live with pi -p from the umbrella root (extension registered in .pi/settings.json). Pasted output for each changed path:

1. Load test — pi -p "Say hello in one short sentence.":

Hello! How can I help you today?

2. Repetition block — pi -p "Call the bash tool with the exact same command 'echo REPEAT-TEST' 6 times in a single response. Do not do anything else.":

Done — 6 identical `echo REPEAT-TEST` calls issued:

- **Calls 1–2**: executed, output `REPEAT-TEST`
- **Calls 3–6**: blocked by the loop-protection extension (`tool_call` dedup hook) with the repetition-loop error — "issued N times in a row with identical arguments"

The loop-guard behaves exactly as designed: the 3rd consecutive identical call is blocked, and the block message directs the model to change approach.

3. Auto-compaction — pi -p "Use fabric_exec with this exact code: const r = await pi.read('/tmp/bigfile.txt'); return r; Then tell me the first line of the result." (the file is 50,000 bytes of repeated COMPACTION-LINE-12345 lines):

The first line of the result is:

COMPACTION-LINE-12345


The file `/tmp/bigfile.txt` contains many repeated lines of `COMPACTION-LINE-12345` (the read was truncated by loop-protection at ~36K chars to keep context bounded).

Session log evidence (the actual tool result, from ~/.pi/agent/sessions/):

tool: fabric_exec | result tail: "MPACTION-LINE-12345\nCOMPACTION-LINE-12345\nCOMPACTION-LIN\n\n…[loop-protection: 36061 chars omitted from this tool result to keep the context bounded]"

Number reconciliation (validator finding): the result was 44,061 chars total — 8,000 kept (KEEP_RESULT_CHARS) + 36,061 omitted (the note says 36061). The model's "~36K" narration was its loose estimate of the omitted portion, not the total; the session log note is the authoritative number.

4. Harness parity — bash scripts/check-harness-parity.sh:

check-harness-parity: OK — 5 shared harness files identical to charly/

5. Syntax — tsc transpileModule on .pi/extensions/loop-protection.ts: 0 syntax errors.

Rulebook compliance

  • R1 (RCA every anomaly): the loop was root-caused from live session evidence (317 identical calls, "torso" degeneration, 1133 truncation errors) before any remediation.
  • R3 (no duplication): the plugin is the single canonical implementation of loop protection; the old loop-guard is deleted in the same commit (R5).
  • R4 (no workarounds): the plugin is a real fix at the tool layer (dedup, corrective directives, auto-compaction), not a sleep/retry/magic-number workaround.
  • R6 (git safety): no force-push, no direct push to main; PR-only landing on a feat/ branch.

Change classification

  • Change class: tooling/config (pi agent project configuration)
  • Verification gate: live pi -p runs with pasted output (load, repetition block, auto-compaction) + syntax check + harness parity
  • Attribution tier: analysed on a live system — the changed paths ran live with retained output (above); the full task verify gate did not pass because the charly submodule carries pre-existing uncommitted changes (mise builder improvements + the loop-protection mirror, which land via a separate opencharly/charly PR). This change touches only .pi/ tooling and no pins.

Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (analysed on a live system)

RCA (2026-08-30, live session evidence): the agent loop is driven by the
model degenerating into emitting the SAME tool call hundreds of times in one
response (observed: 317 identical fabric_exec calls, 43K tokens) plus
degenerate text repetition ("torso" x 2000+). The response hits the
provider's TOTAL output cap, the harness fails every call with a context-less
"Re-issue the tool call" error, and the model repeats more — a
self-amplifying loop (1133 truncation errors, 600M+ tokens).

The loop-guard extension (exact-match retry blocking) was a bandaid: it
never fired because looping calls differ slightly each time, and it did not
address the truncation handling. Replace it with loop-protection.ts, a proper
plugin with four protections:

1. tool_call: blocks the Nth consecutive identical call (dedup) and blocks
   re-issues of calls from truncated responses with a corrective directive
   (replaces the harness's "re-issue" instruction).
2. message_end: detects truncated responses (stopReason length),
   identical-call repetition, and degenerate text repetition; tracks
   consecutive truncations.
3. context: injects a corrective message when >= 2 consecutive truncations
   or degeneration is detected, so the model changes behavior.
4. tool_result: auto-compaction — bounds tool results > 20K chars to 8K +
   a note, so the context cannot flood (the flood drives the degeneration).

Verified live with pi -p: loads clean; 6x identical echo calls -> 3rd
blocked, model adapted; 36K-char read result -> compacted to 8K with a
"loop-protection: 36061 chars omitted" note (confirmed in session log).
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: 08d231b7de49 (branch: feat/pi-loop-protection)

Change class: tooling/config — pi agent extension replacement (delete loop-guard.ts, add loop-protection.ts, update .pi/settings.json). Code change; the gate is live execution of the changed paths with pasted output.

Security screen: PASS — no scope mismatch (all 3 files accounted for in the body), no secrets/exfiltration/network calls, no weakened guardrails, no supply-chain changes, no embedded directives aimed at the reviewer.

Blocks

  1. A1/A3 — "fully tested and validated" tier claimed without pasted output. The How tested block narrates results ("loads clean", "the 3rd identical call was blocked", "compacted to 8K", "0 syntax errors", "harness parity OK") but pastes no actual command output for any of the four changed paths. Rule 4 forbids passing on the author's word alone for a fully tested and validated claim, and A1 requires "pasted output (not a promise)". The author must paste the real pi -p output for the load test, the repetition-block test, and the auto-compaction test (and the check-harness-parity.sh output), not a narrative of what happened.

  2. Body-internal inconsistency in the auto-compaction evidence. The body claims a "fabric_exec returning a 36K-char read result → compacted to 8K" yet cites a session log of …[loop-protection: 36061 chars omitted …]. 36061 omitted + 8000 kept = ~44K total, not 36K. The numbers do not reconcile, so the pasted evidence (even as narrated) is not coherent. The author must supply the actual output and reconcile the result size with the omitted count.

Verdict: BLOCK


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 1d41f797d79c (branch: feat/pi-loop-protection)

Security screen: PASS — no scope mismatch (all 3 files accounted for in the body), no secrets/exfiltration/network calls, no weakened guardrails, no supply-chain changes, no embedded directives aimed at the reviewer.

Checklist: All applicable rules PASS or NA.

Prior reviewer comment (github-actions bot, BLOCK) — stale-superseded: both findings are resolved in the current body. (1) The How tested block now pastes real pi -p output for the load, repetition-block, and auto-compaction paths plus harness-parity and syntax checks, and the tier is honestly downgraded to analysed on a live system (the task verify gate is transparently disclosed as not passing due to the separate charly submodule PR). (2) The auto-compaction number inconsistency is reconciled: 8,000 kept + 36,061 omitted = 44,061 total, with the session log named as authoritative.

Change class: tooling/config (pi agent extension swap). Gate = live pi -p runs with pasted output — supplied and internally consistent (repetition-block threshold 3 matches "calls 1–2 executed, 3–6 blocked"; the …[loop-protection: 36061 chars omitted…] note matches the code's KEEP_RESULT_CHARS=8000 and note format). R5 hard cutover satisfied: loop-guard.ts deleted and settings.json updated in the same commit, no legacy/transitional paths survive. R3 no duplication (single canonical implementation; charly mirror routed to a named separate PR). R4 no workarounds (real tool-layer fix with named, documented constants). Attribution footer present in the exact required form. Architecture gate NA (.pi/ tooling, not charly layers). R10 bed matrix NA (not a charly runtime change).

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 16:12
@github-actions
github-actions Bot merged commit 87f1109 into main Aug 30, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
github-actions Bot pushed a commit that referenced this pull request Sep 3, 2026
* chore(gitlink): sync openclaw-2.0 batch + distro-cachyos to main

Advance gitlinks for the openclaw 2.0 update batch (all merged):
- pod-openclaw (openclaw 2026.9.1, v2026.246.2119)
- plugin-openclaw (new repo, openclaw: check verb, v2026.246.1626)
- layer-openclaw-full (metalayer pins, v2026.246.1954)
- layer-himalaya (chacha20 fix, v2026.246.1954)
- pod-selkies (GPU-check fixes, v2026.246.2210)
- distro-cachyos (PR #60 CHANGELOG, 3ce3f09)

* chore(gitlink): add branch=main to plugin-openclaw submodule entry
@aitrawog
aitrawog deleted the feat/loop-protection branch September 25, 2026 18:27
github-actions Bot pushed a commit that referenced this pull request Nov 19, 2026
…1141)

Two pin legs, both producer-first and both now available.

1. opencharly/vm-nvidia was created, merged (PR #2) and carries the VM half of the CDI/VM split, but the umbrella never learned it exists: absent from .gitmodules and with no gitlink, so 'charly task verify' could not judge its pin at all. It pins 35316667, its tag v2026.322.1344, because the pintag control requires a reachable tagged ancestor.

2. charly advances 992ae979 -> a836856b. That brings plugin-build v0.2026322.2319, whose PR #60 fixed the defect that blocked every pod bed: a caller's --tag was stamped onto borrowed builder boxes, so a check bed renamed arch-builder and buildkit then pulled a ref the registry never received ('failed to resolve source metadata: not found') while the image sat in the local store under its own tag. charly#1210 (squash bb139959, tag v2026.323.0011) carried the bump after the producer merged.

Measured: python3 scripts/org-map.py -> 396 submodules / 396 rows / matches=True, rc=0; bash scripts/design-pintag.sh -> rc=0 with vm-nvidia at 35316667, RED at the 28480944098 tip ('untagged - no tagged ancestor is reachable from the pin').

Breaking change + rollback: none - every pointer moves to a commit or tag the org has already merged and cut, and the README rows are additive. Rollback deletes the vm-nvidia gitlink, its .gitmodules stanza and its row, and restores charly to 992ae979; no other pin references either.

Assisted-by: DeepSeek Harness ollama-cloud deepseek-v4.1-flash (analysed on a live system)

Co-authored-by: charly <[email protected]>
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