Skip to content

Add readiness warmup to restricted-config test to fix CI flakiness#154

Merged
kwsantiago merged 1 commit into
mainfrom
fix/flaky-restricted-config-test
Jul 12, 2026
Merged

Add readiness warmup to restricted-config test to fix CI flakiness#154
kwsantiago merged 1 commit into
mainfrom
fix/flaky-restricted-config-test

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Problem

The restricted-config integration step (NIP-42 / 70 / 13) is flaky on main. The push run for the previous merge failed at "Run restricted-config tests" while the identical commit had just passed the same job on its PR branch (29199249925 failed on main vs 29199117246 green on the PR).

Root cause: run_mode in ci.yml starts a fresh relay per mode and grades assertions as soon as nc -z reports the TCP port open. But TCP-listening is not the same as the event pipeline being ready. When the first graded assertion races relay warmup (or hits a transient connect/read timeout under runner load), an expected-accept assertion reports reject and fails CI. Expected-reject assertions are immune (a timeout already yields reject), so only the accept cases flake.

Fix

Test-only change to tests/integration_restrict.sh:

  • Readiness warmup gate. Before grading, publish an acceptable throwaway event for the mode (auth → --auth, protected → normal, pow → mined) and retry until the relay accepts it. This converts "port open" into "pipeline ready" and is independent of noz's error-output format, so it needs no reject-vs-timeout parsing. If the relay never becomes ready it fails fast (~20s) with a clear message instead of a confusing assertion failure.
  • Slightly more resilient pubres. 3 → 4 attempts, timeout 10 → 12s, to absorb the rarer mid-run blip. Kept conservative so expected-reject assertions stay fast (the warmup does the heavy lifting).

Verification

  • bash -n clean.
  • Validated control flow with a mock noz across all three modes: correct verdicts, exit 0.
  • Transient blip on an expected-accept assertion is absorbed by the retry (exit 0).
  • Relay that never warms up fails fast with a clear message and non-zero exit, without grading.

No production code changed; no relay behavior changed.

Summary by CodeRabbit

  • Tests
    • Improved integration test reliability during transient connectivity or read issues.
    • Added a warmup check to confirm the relay accepts the expected event before running assertions.
    • Increased retry attempts and command timeouts for event publishing.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The integration test increases event-publishing retry tolerance and adds a mode-specific warmup gate that must succeed before existing assertions run.

Changes

Relay readiness checks

Layer / File(s) Summary
Event publishing retries
tests/integration_restrict.sh
pubres now allows four attempts with 12-second timeouts while retaining its success and failure conditions.
Mode-aware warmup gate
tests/integration_restrict.sh
A warmup phase publishes mode-specific events and prevents assertion execution when relay acceptance fails.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit watched the relay glow,
“Try four times before you go!”
Warm up auth, protected, pow,
Then test the truth beneath the bow.
If no event arrives, stop now.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a readiness warmup to the restricted-config test to reduce CI flakiness.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/flaky-restricted-config-test

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/integration_restrict.sh`:
- Around line 42-67: Reduce the per-attempt timeout in the warmup function so
its 40 retries, including sleeps, complete within the documented approximately
20-second limit. Keep the existing success detection, retry count, and failure
behavior unchanged, and update the nearby duration comment if needed to
accurately reflect the enforced deadline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0e087357-bd50-4c5c-b0db-5caacc784291

📥 Commits

Reviewing files that changed from the base of the PR and between 5863ff4 and c492686.

📒 Files selected for processing (1)
  • tests/integration_restrict.sh

Comment on lines +42 to +67
# Block until the relay actually accepts an event of this mode's accepted class,
# not just until the TCP port is open. In CI the relay is started fresh per mode
# and `nc -z` only proves the listener is up, not that the event pipeline is
# ready; grading the first assertion against a still-warming relay is what made
# this suite flaky on main (a transient miss on an expected-accept assertion
# reports 'reject' and fails CI). Publishing an acceptable throwaway event until
# it succeeds converts "port open" into "pipeline ready", and is independent of
# noz's error-output format so it needs no reject-vs-timeout parsing.
warmup() {
local args
case "$MODE" in
auth) args=(--sec "$SEC1" --auth -c warmup) ;;
protected) args=(--sec "$SEC1" -c warmup) ;;
pow) args=(--sec "$SEC1" --pow 8 -c warmup) ;;
*) return 0 ;; # unknown mode is reported by the assertion case below
esac
for i in $(seq 1 40); do
timeout 12 noz event "${args[@]}" "$R" 2>&1 | grep -q 'success' && return 0
sleep 0.5
done
echo "warmup: relay never accepted an event in '$MODE' mode after ~20s" >&2
return 1
}

warmup || exit 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Worst-case warmup duration far exceeds the ~20s comment and "fail fast" goal.

Each of the 40 iterations can take up to 12s (timeout 12) plus 0.5s sleep, yielding a ~500s worst case if the relay accepts connections but never responds. The comment on line 62 says "~20s" but that only accounts for sleep time. If the relay is in a bad state, CI will hang for 8+ minutes before failing — contradicting the PR's "fail fast" objective.

Consider using a shorter per-attempt timeout for the warmup (readiness probe, not a full operation) or tracking total elapsed time with a hard deadline.

⏱️ Suggested fix: shorter warmup timeout
   for i in $(seq 1 40); do
-    timeout 12 noz event "${args[@]}" "$R" 2>&1 | grep -q 'success' && return 0
+    timeout 3 noz event "${args[@]}" "$R" 2>&1 | grep -q 'success' && return 0
     sleep 0.5
   done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Block until the relay actually accepts an event of this mode's accepted class,
# not just until the TCP port is open. In CI the relay is started fresh per mode
# and `nc -z` only proves the listener is up, not that the event pipeline is
# ready; grading the first assertion against a still-warming relay is what made
# this suite flaky on main (a transient miss on an expected-accept assertion
# reports 'reject' and fails CI). Publishing an acceptable throwaway event until
# it succeeds converts "port open" into "pipeline ready", and is independent of
# noz's error-output format so it needs no reject-vs-timeout parsing.
warmup() {
local args
case "$MODE" in
auth) args=(--sec "$SEC1" --auth -c warmup) ;;
protected) args=(--sec "$SEC1" -c warmup) ;;
pow) args=(--sec "$SEC1" --pow 8 -c warmup) ;;
*) return 0 ;; # unknown mode is reported by the assertion case below
esac
for i in $(seq 1 40); do
timeout 12 noz event "${args[@]}" "$R" 2>&1 | grep -q 'success' && return 0
sleep 0.5
done
echo "warmup: relay never accepted an event in '$MODE' mode after ~20s" >&2
return 1
}
warmup || exit 1
# Block until the relay actually accepts an event of this mode's accepted class,
# not just until the TCP port is open. In CI the relay is started fresh per mode
# and `nc -z` only proves the listener is up, not that the event pipeline is
# ready; grading the first assertion against a still-warming relay is what made
# this suite flaky on main (a transient miss on an expected-accept assertion
# reports 'reject' and fails CI). Publishing an acceptable throwaway event until
# it succeeds converts "port open" into "pipeline ready", and is independent of
# noz's error-output format so it needs no reject-vs-timeout parsing.
warmup() {
local args
case "$MODE" in
auth) args=(--sec "$SEC1" --auth -c warmup) ;;
protected) args=(--sec "$SEC1" -c warmup) ;;
pow) args=(--sec "$SEC1" --pow 8 -c warmup) ;;
*) return 0 ;; # unknown mode is reported by the assertion case below
esac
for i in $(seq 1 40); do
timeout 3 noz event "${args[@]}" "$R" 2>&1 | grep -q 'success' && return 0
sleep 0.5
done
echo "warmup: relay never accepted an event in '$MODE' mode after ~20s" >&2
return 1
}
warmup || exit 1
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 58-58: i appears unused. Verify use (or export if used externally).

(SC2034)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration_restrict.sh` around lines 42 - 67, Reduce the per-attempt
timeout in the warmup function so its 40 retries, including sleeps, complete
within the documented approximately 20-second limit. Keep the existing success
detection, retry count, and failure behavior unchanged, and update the nearby
duration comment if needed to accurately reflect the enforced deadline.

@kwsantiago kwsantiago merged commit 941f501 into main Jul 12, 2026
3 checks passed
@kwsantiago kwsantiago deleted the fix/flaky-restricted-config-test branch July 12, 2026 17:49
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