Skip to content

t247.1: Context-remaining guard in loop-common.sh#987

Merged
marcusquinn merged 2 commits intomainfrom
feature/t247.1
Feb 10, 2026
Merged

t247.1: Context-remaining guard in loop-common.sh#987
marcusquinn merged 2 commits intomainfrom
feature/t247.1

Conversation

@marcusquinn
Copy link
Copy Markdown
Owner

Summary

Adds a context-remaining guard to loop-common.sh that detects approaching context exhaustion and proactively emits FULL_LOOP_COMPLETE + pushes uncommitted work before the AI tool exits silently. This prevents the clean_exit_no_signal retry pattern that affected 16 tasks (100% eventually succeeded on retry, but each retry wasted ~300s).

Changes

New functions in loop-common.sh

  • loop_check_context_exhaustion() — Four detection heuristics:

    1. Iteration threshold: triggers when iteration >= 80% of max_iterations
    2. Explicit context markers: regex match for context/token limit messages in tool output
    3. Empty output: tool produced < 100 bytes after first iteration
    4. Output shrinkage: output drops below 20% of rolling average (needs 3+ iterations baseline)
  • loop_emergency_push() — Commits any uncommitted work and pushes to preserve it before exit

  • loop_emit_completion_signal() — Emits <promise>FULL_LOOP_COMPLETE</promise> to stdout (captured in worker log for supervisor detection)

  • loop_context_guard() — Orchestrates all three: check → push → signal. Returns 0 if guard triggered (caller should exit cleanly).

Integration points

  • loop_run_external() in loop-common.sh — guard check added after each iteration
  • run_loop_v2() in ralph-loop-helper.sh — guard check added after each iteration (this is the production code path)
  • Re-anchor prompt — Added context guard awareness section telling the AI tool to self-signal when context is low

Configurable thresholds (env vars)

Variable Default Purpose
LOOP_CONTEXT_ITER_THRESHOLD 80 % of max_iterations to trigger
LOOP_CONTEXT_SHRINK_THRESHOLD 20 % of avg output size to trigger
LOOP_CONTEXT_SHRINK_MIN_ITERS 3 Min iterations before shrinkage detection
LOOP_CONTEXT_MIN_OUTPUT_BYTES 100 Min bytes for "productive" output

Testing

  • ShellCheck: zero violations on both modified files
  • Bash syntax: verified on loop-common.sh, ralph-loop-helper.sh, full-loop-helper.sh
  • Backward compatible: all new functions use type guards in ralph for graceful degradation

Task

Closes t247.1. Part of t247 (reduce clean_exit_no_signal retries).

Prevents clean_exit_no_signal retries by detecting context exhaustion
before the AI tool exits silently. Four detection heuristics:
1. Iteration threshold (>= 80% of max)
2. Explicit context limit markers in output
3. Empty/near-empty output after first iteration
4. Output shrinkage (< 20% of rolling average)

When triggered: emergency commit+push, emit FULL_LOOP_COMPLETE signal,
create receipt for audit trail, store memory for pattern tracking.

Also adds context guard awareness to re-anchor prompt so the AI tool
itself can signal when running low on context.
Ralph is the actual production loop runner. Adds output_sizes_file
tracking and loop_context_guard() call after each iteration, matching
the integration in loop_run_external(). Uses type-guard pattern
consistent with existing ralph code for graceful degradation when
loop-common.sh is not loaded.
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@marcusquinn marcusquinn marked this pull request as ready for review February 10, 2026 19:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 10, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/t247.1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 37 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Tue Feb 10 19:45:46 UTC 2026: Code review monitoring started
Tue Feb 10 19:45:46 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 37

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 37
  • VULNERABILITIES: 0

Generated on: Tue Feb 10 19:45:48 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-reviews-actioned All review feedback has been actioned

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant