Skip to content

fix(pi): break the output-token-limit retry loop with a loop-guard extension - #49

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

github-actions[bot] merged 1 commit into
mainfrom
feat/pi-loop-fix

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

The pi agent looped for hours generating hundreds of IDENTICAL tool calls, each rejected with "the response hit the output token limit, so its arguments may be truncated" (600M+ tokens burned, zero progress).

RCA (8-step): when the model's response exceeds the output token cap, the pi harness (runLoop → failToolCallsFromTruncatedMessage) rejects every tool call in the truncated message with the error "Re-issue the tool call with complete arguments" and returns terminate: false. That error message INSTRUCTS the model to re-issue the same call; the model regenerates the same oversized response; it is truncated again; the loop repeats forever. The truncated path bypasses the tool_call/tool_result extension events, so the loop cannot be intercepted at the rejection — but the RETRY goes through the normal path.

Fix (root, not workaround): a new project extension .pi/extensions/loop-guard.ts that:

  1. On message_end with stopReason === "length" (truncated response), records the tool calls the truncated message carried.
  2. On tool_call, when a call matches a recorded truncated call (same tool + same args), BLOCKS it with a corrective directive: do NOT re-issue — make a SHORTER response, split the work, or delegate to a subagent.

This changes the actual instruction that drives the loop (the harness's "Re-issue the tool call") into one that breaks it, at the exact point where the loop repeats. Plus .pi/APPEND_SYSTEM.md carries the behavioral discipline (short calls, minimal responses, subagents for exploration, never retry a truncated call).

How tested

  • node --check on the extension: syntax OK.
  • Pre-commit gates green: check-policy-b OK, umbrella-gates.ts parses, check-harness-parity OK (5 shared files identical to charly/).
  • The extension follows the documented extension API (pi.on("message_end"), pi.on("tool_call") with {block: true, reason}), same import pattern as the existing github-pr-status.ts / umbrella-gates.ts extensions.
  • Live verification pending: the next session that hits an output-token-limit rejection will exercise the block (the extension is loaded from .pi/settings.json).

Rulebook compliance

  • R1: RCA'd — the loop is a harness-instruction bug (the "Re-issue the tool call" error message drives the retry), not a model or config quirk.
  • R3: no duplication — one loop-guard implementation; the system prompt references it.
  • R4: no workaround — lowering the thinking level or shrinking maxTokens was rejected as a workaround; this fixes the actual retry mechanism.
  • R8: harness config parity — .pi/ is an umbrella-specific fork (not in the SHARED parity list); the change is scoped to the umbrella's own config.

Change classification

  • Change class: harness config + extension (project-local pi config)
  • Verification gate: live session exercising the block on a truncated response
  • Attribution tier: analysed on a live system (mechanism verified in the pi source; live block pending)

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

@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 5dba24b2250f (branch: fix/pi-loop-guard)

Change class: harness config + extension (project-local .pi/ config)

Security screen: PASS — no secrets, no exfiltration, no network calls, no weakened guardrails, no scope mismatch (diff matches description exactly: loop-guard.ts + APPEND_SYSTEM.md + settings.json), no supply-chain changes.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3: Body is complete — summary accounts for all 3 files, RCA is thorough, rulebook-compliance section present, attribution footer in exact form. Change class (pi harness config) matches the gate. This is a self-gated install (the fix's live verification requires a pi session that hits the output-token-limit rejection, unobservable before merge) — per ground rule 3, the pending live block is not a blocker. The attribution tier analysed on a live system is honest and not inflated (mechanism verified in pi source; live block explicitly pending).
  • B4–B15: R1 RCA provided with no forbidden framing; R3 no duplication; R4 real fix (explicitly rejects maxTokens/thinking-level workarounds); R8 parity addressed (.pi/ is umbrella-specific fork, not in shared parity list); R10 N/A (not a charly runtime change); one atomic commit; no parked/dismissed issues.
  • B16 placement: CORRECT — the loop-guard is a pi-harness concern, correctly placed in .pi/extensions/ and wired via .pi/settings.json.
  • B18: Extension code is syntactically valid TypeScript, logic sound (records truncated calls on message_end with stopReason === "length", blocks exact-match retries on tool_call), no obvious lint issues.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 06:08
@github-actions
github-actions Bot merged commit 77890ba 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/pi-loop-fix 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