Skip to content

feat(pi): autodetect and break behavioral-rut loops in loop-guard - #52

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/loop-guard-autodetect
Aug 30, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/loop-guard-autodetect

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

The pi loop-guard extension (.pi/extensions/loop-guard.ts) only blocked exact re-issues of calls from truncated responses (assistant stopReason: "length"). The 2026-08-30 second loop incident was a different class: a behavioral rut — the same successful tool call (sed -n "752,788p" / sed -n "1044,1091p" on the same file) re-issued 8+ times because each truncated response made the model re-run the same diagnostic to "recover" context instead of producing the deliverable. Those calls succeeded, so the truncation detector never fired.

This change:

  1. Adds a behavioral-rut detector to loop-guard.ts: a per-call (tool, serialized-args) repeat counter; the Nth identical call (N>=3) is blocked with a directive to change approach and delegate to a subagent. The block is not reset, so the model must change approach to proceed.
  2. Documents the autodetect protocol in .pi/APPEND_SYSTEM.md: the three loop signals (repeated output-token-limit rejections, repeated identical tool calls, re-reading the same data) and the mandatory break response (never re-issue; delegate to a subagent; produce the deliverable).

How tested

  • git commit ran the umbrella pre-commit gate: check-policy-b: OK — 6 distro pins equal charly's gitlinks, umbrella-gates.ts parses (node type-strip pass), check-harness-parity: OK — 5 shared harness files identical to charly/, pre-commit: OK.
  • The new detector logic was verified by reading the committed file: both detectors present (Detector 1 truncation-retry, Detector 2 behavioral-rut), REPEAT_THRESHOLD = 3.
  • The loop it fixes was reproduced live this session: 8+ identical sed -n calls on the same file ranges before the fix.

Rulebook compliance

  • R1 (RCA every anomaly): the recurring loop was root-caused — the existing loop-guard covered only truncation retries; the behavioral-rut class was undetected. The RCA is documented in the code comment and APPEND_SYSTEM.md.
  • R4 (no workarounds): this is a structural fix at the loop's repeat point (tool_call interception), not a sleep/retry/magic-number workaround.
  • R5 (hard cutover): the old guidance section in APPEND_SYSTEM.md was replaced in the same commit; no stale references remain.
  • Harness parity: extensions are explicitly umbrella-specific forks (per scripts/check-harness-parity.sh "NOT in this list are umbrella-specific forks (extensions, prompts, tomls)"), so no charly mirror is required; the parity gate passed.

Change classification

  • Change class: harness config (pi extension + guidance doc) — no runtime code, no pins, no submodule pointers.
  • Verification gate: pre-commit gate passed on the final tree; extension parses (node type-strip).
  • Attribution tier: analysed on a live system — the loop it fixes was reproduced live this session; the full task verify pinning gate is unchanged by this docs/config-only change.

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

The loop-guard only blocked exact re-issues of calls from truncated responses (stopReason length). The 2026-08-30 second incident was a behavioral rut: the same successful tool call (sed -n on the same file ranges) re-issued 8+ times because each truncated response made the model re-run the same diagnostic instead of producing the deliverable. Add a per-call repeat detector (same tool + same args, N>=3) that blocks the repeat with a delegate/change-approach directive, and document the three loop signals + mandatory break response in APPEND_SYSTEM.md.
@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: a276a6a7f27f338c40726cf7dc578c713bf80571 (branch: feat/pi-loop-guard)

Security screen: PASS — no scope mismatch (diff matches description exactly), no secrets/exfiltration (extension only counts tool calls in memory), no weakened guardrails (pi extension, not security machinery), no supply-chain changes.

Checklist: All applicable rules PASS or NA.

  • Change class: harness config (pi extension + guidance doc) — no charly runtime code, no pins, no submodule pointers. Pre-commit gate is the correct gate; body pastes its output (check-policy-b: OK, umbrella-gates.ts parses, check-harness-parity: OK, pre-commit: OK).
  • A1/A3: Body accounts for both files; attribution tier analysed on a live system is honest and not inflated — the new Detector 2 path was verified by reading, not executed live, so the tier correctly stops short of fully tested and validated. Footer present.
  • R1/R4/R5: Loop RCA'd (two incidents documented in code + doc); structural fix at the tool_call interception point, not a sleep/retry workaround; old doc section replaced in the same atomic commit, no stale references.
  • B16 placement: CORRECT — pi extension and guidance belong in .pi/; no core/sdk/candy touched.
  • B18: TypeScript is clean, no dead code, REPEAT_THRESHOLD is a named constant; the never-reset repeat map is intentional and documented in the body.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 10:21
@github-actions
github-actions Bot merged commit ba0eb2d into main Aug 30, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
@aitrawog
aitrawog deleted the feat/loop-guard-autodetect branch September 25, 2026 18:27
github-actions Bot pushed a commit that referenced this pull request Oct 24, 2026
…sdk and distro-cachyos producer work (#684) (#685)

The currency report named four pins that were not current, and every one of
them is a fast-forward against its own remote:

  charly          6f62efbf3a -> 2386643d4   charly#1055, #1062, #1067, #1068, #1069
  distro-cachyos  1893455d3a -> 6abe89522   distro-cachyos#157 -- the EDGE: charly's
                                                own box/cachyos gitlink, advanced by
                                                charly#1055
  plugin-task     69223053ff -> 30c57809b   plugin-task#47, #49, #52
  sdk             306d3d15c2 -> d71b9abb4   sdk#475

The advance is the sanctioned verb's, never a hand-pin: `charly task sync`
rolled the submodules to their default-branch HEAD and advanced the pins in
the index, `charly task init` materialized the checkouts AT those pins, the
worktree-local binary was rebuilt from the new charly pin (R9, stamp
2026.297.2323), and `charly task verify` judged the tree on the committed
commit: 33 step(s), 0 failed, 0 skipped, zero warnings.

The currency question, asked again on the same tree: 0 of 411 pin(s) NOT
current -- every pin is at the ref its intent names. That closes the nine
rows filed as #669: eight moved in #671, and
distro-cachyos moved here once charly#1055 advanced the edge's source.

The bump's own report counts index WRITES (406) where this commit carries
the four gitlinks that MOVED; the difference is a defect in the verb that
owns the count and is filed as opencharly/plugin-task#53.

Refs #684, #669

Assisted-by: Claude Code minimax/minimax-m3.1-flash:cloud (fully tested and validated)
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