Skip to content

fix(test): prove gateway retry and drain ordering - #132402

Merged
steipete merged 1 commit into
mainfrom
steipete/brave-dubinsky-e408c7
Aug 29, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/brave-dubinsky-e408c7

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #120089 — shared Gateway migration retry, #131890 — Gateway readiness and lifecycle cleanup.

Additional instructions

Maintainer-owned branch; maintainers can update the branch. AI-assisted, explicitly maintainer-requested test repair.

What Problem This Solves

Resolves a problem where the shared Gateway lifecycle tests could pass without proving the event ordering they claim to protect. The delayed-refusal case assumed a descendant's 50 ms timer would run after the leader exited, while the terminal-drain case released its inherited pipe before asking the helper to restart. Controlled negative tests demonstrated that those assertion flows could miss early stderr classification and skipped stale-owner cleanup.

Why This Change Was Made

The delayed writer now waits on the existing loopback control and is released only after the test observes the leader's native exit. The test also verifies that stderr remains open and the refusal has not arrived before release, then retains the original real-readiness, identical-launch-state and replacement-ownership assertions.

The terminal case now attempts a restart while the old pipe is deliberately held, requires the existing stop-deadline error and retained owner, and verifies that no second attempt was recorded. It then releases the holder, observes native closure and completes the original successful replacement/stop proof. Listener registration precedes release, but filesystem setup is outside the close-observation clock. This case uses its existing attempt trace rather than adding an HTTP launch round-trip inside its 300 ms startup budget.

All existing startup/stop values and original assertions remain. The shared instance helper and managed-child implementation are unchanged. Automatic startup-failure cleanup is not replaced by explicit-stop coverage.

User Impact

No production Gateway, configuration, dependency or public API change. Maintainers get stronger real-process regression coverage for late startup diagnostics and retained child ownership. The separate TERM-resistant case and its fixture, refusal-drain case, and intervening-stop case remain byte-identical.

This is an ordering/coverage repair, not a claim to eliminate every scheduler-sensitive startup under the existing short deadlines.

Evidence

Real subprocess and loopback HTTP proof: full 26-test file, original declaration order, one worker, no file parallelism and no isolation. Every run used fresh synthetic HOME/state/config/TMP/XDG, a literal credential-free environment and the existing external PID registry. These are real Node children, inherited pipes and process-group signals—not mocked ChildProcess objects. No operator Gateway, live credentials, provider or channel was used.

node scripts/run-vitest.mjs test/helpers/openclaw-test-instance.test.ts --maxWorkers=1 --no-file-parallelism --no-isolate
  • Node 24.20.0: 26 passed, 46.196 s runner wall time.
  • Node 26.7.0: first final-source run 25 passed / 1 failed at the previously observed replacement-readiness timeout; one bounded unchanged-source recheck 26 passed, 58.932 s. The held-owner rejection and closure checks had already completed before that timeout. The failure is retained as evidence of remaining startup timing sensitivity, not hidden by the recheck.
  • The unchanged TERM-resistant test passed in these final-source full-file runs.

Regression controls: controlled schedules retaining the old assertions passed against artifact-only helper copies that classified stderr before draining or skipped stale-owner stop. With the final assertions, both deliberately broken variants fail for the intended reason: the late refusal loses its retry (209 ms, code-1 exit—not timeout), and the blocked terminal restart incorrectly resolves instead of rejecting (497 ms—not timeout). The other 24 cases were unselected in this focused mutation run; it is not counted as a full-file pass. The tracked helper was never mutated and the temporary test import was restored exactly.

Cleanup: all post-run recorded PID checks were absent; all synthetic roots were removed after verification. No global/manual kill was needed. Recorded-PID absence is the precise claim; child-side receipts are not a complete OS-spawn ledger.

Static checks and review: focused oxfmt, git diff --check, and the complete changed gate passed, including root test typechecking and scripts lint.

node scripts/check-changed.mjs -- test/helpers/openclaw-test-instance.test.ts

Codex autoreview of the final uncommitted candidate and owner evidence completed scoped-clean at its default P0 threshold. Manual owner/caller/callee/history review and direct Node 24/26 exit/close and synchronous-receipt contract inspection also completed.

Production/shared-owner LOC: 0. Tests: +92/-27 (net +65), including existing assertions moved into failure-safe try/finally blocks. No build/package or authenticated product Gateway proof is claimed for this test-only change.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 05:35
@steipete steipete self-assigned this Aug 29, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 1:43 AM ET / 05:43 UTC.

ClawSweeper review

What this changes

The branch makes shared Gateway test-instance coverage deterministically prove delayed refusal classification and stale-child drain ordering with real child processes.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal maintainer handling: the PR adds a focused, non-duplicative regression proof that current main lacks, and no introduced correctness or security defect was found.

Priority: P3
Reviewed head: 5f14acde5915641da0f5927d461c6a006233b8b9
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is a focused, source-aligned coverage improvement with detailed self-reported subprocess evidence but no independently inspectable raw trace.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Not applicable to this member-authored, test-only PR; the supplied evidence nevertheless maps real Node child processes and loopback control to the changed lifecycle assertions.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this member-authored, test-only PR; the supplied evidence nevertheless maps real Node child processes and loopback control to the changed lifecycle assertions.
Evidence reviewed 6 items Introduced test coverage: The verified PR-introduced delta changes only the shared test file, replacing a timer-based late-refusal fixture with controlled loopback release and adding retained-owner assertions.
Lifecycle owner boundary: The helper serializes lifecycle operations, retains an unclosed failed child, and admits a retry only after cleanup and exact per-attempt stderr classification.
Current main lacks this proof: Current main retains the old timer-based late-refusal fixture and does not contain the controlled release or held-owner restart assertions.
Findings None None.
Security None None.

How this fits together

The shared test-instance helper starts Gateway child processes for integration tests and owns readiness, retries, output streams, and teardown. These tests drive synthetic child processes through that boundary and verify whether a retry or replacement is permitted.

flowchart LR
  A[Lifecycle test] --> B[Shared test helper]
  B --> C[Gateway child process]
  C --> D[Exit and stream events]
  D --> E[Retry or drain decision]
  E --> F[Startup error or replacement child]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned test-only PR be landed after its exact-head required checks complete successfully? Land after green exact-head checks: Accept the focused owner-boundary regression coverage once the remaining required checks are green.

Why: The protected maintainer label and member authorship require explicit maintainer handling even though the narrow test change has no identified defect.

Before merge

  • Complete next step (P2) - No mechanical repair is needed; this maintainer-owned protected PR should proceed through its normal exact-head CI and landing review.
Agent review details

Security

None.

PR surface

Tests +65. Total +65 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 92 27 +65
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 92 27 +65

Review metrics

Metric Value Why it matters
Production versus test LOC production +0; tests +92/-27 (net +65) All introduced lines are deterministic regression coverage; the Gateway runtime, configuration, and public API remain unchanged.

Technical review

Best possible solution:

Retain the controlled real-process tests as the canonical regression coverage for retry admission and stale-child ownership, then land through the normal maintainer gate once exact-head checks finish.

Do we have a high-confidence way to reproduce the issue?

Not applicable as an end-user issue: the PR strengthens a regression test. Its body supplies a concrete real-subprocess and loopback scenario, while this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The assertions sit at the shared lifecycle owner boundary and distinguish exit from fully drained stdio without adding a production seam or duplicating the existing deadline-drain case.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c3ff7f98d58e.

Labels

Label changes:

  • add P3: This is bounded test-infrastructure coverage work with no production behavior change.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this member-authored, test-only PR; the supplied evidence nevertheless maps real Node child processes and loopback control to the changed lifecycle assertions.

Label justifications:

  • P3: This is bounded test-infrastructure coverage work with no production behavior change.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this member-authored, test-only PR; the supplied evidence nevertheless maps real Node child processes and loopback control to the changed lifecycle assertions.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the current ordering-proof commit and the preceding merged lifecycle cleanup on the same helper surface. (role: recent lifecycle contributor; confidence: high; commits: 5f14acde5915, 1593e2908727; files: test/helpers/openclaw-test-instance.test.ts, test/helpers/openclaw-test-instance.ts)
  • Vincent Koc: Authored the merged migration-convergence retry repair that owns the retry predicate exercised here. (role: migration-retry contributor; confidence: high; commits: a6b20789627c; files: test/helpers/openclaw-test-instance.ts, test/helpers/openclaw-test-instance.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head required checks complete successfully before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready maintainer verification for commit 5f14acde5915641da0f5927d461c6a006233b8b9.

Exact-head CI run 33236537081 completed successfully. The latest ClawSweeper review found no correctness/security defects; its remaining next step and rank-up move were green exact-head checks followed by normal maintainer landing. Those checks are now green, and the explicit maintainer landing request is being handled through the native workflow. No re-review is needed for the unchanged head.

The architectural owner remains the test fixture/control, not production lifecycle policy. This removes the timer-based late-stderr assumption and adds a completed held-owner restart rejection before release. Production/shared-helper LOC is zero; tests are +92/-27. Original assertions and startup/stop values, the TERM-resistant fixture/test, refusal-drain and intervening-stop remain preserved.

Real-process proof ran the full 26-test file, serial and non-isolated, with real Node children/pipes/signals and loopback HTTP in fresh credential-free synthetic state:

node scripts/run-vitest.mjs test/helpers/openclaw-test-instance.test.ts --maxWorkers=1 --no-file-parallelism --no-isolate

Node 24.20.0 passed 26/26. Node 26.7.0 passed 26/26 on one bounded unchanged-source recheck after the documented pre-existing replacement-readiness timeout. Both final negative controls fail for the intended non-timeout reasons: premature classification loses the retry, and skipped stale-owner stop wrongly resolves the blocked start. All recorded PID checks and root-removal checks passed. This is not a claim that all short-startup flakes are eliminated, nor authenticated product Gateway proof.

Final formatting, diff checks, root test types, lint and guards passed:

node scripts/check-changed.mjs -- test/helpers/openclaw-test-instance.test.ts

Fresh Codex autoreview of the frozen candidate was scoped-clean at its default P0 threshold; direct owner/caller/callee/history and Node dependency-contract review also completed. The reviewed source was restored byte-for-byte after mutation testing. No timeout increase, weaker original assertion, production seam, dependency or changelog change is included.

@steipete
steipete merged commit a5475ea into main Aug 29, 2026
195 checks passed
@steipete
steipete deleted the steipete/brave-dubinsky-e408c7 branch August 29, 2026 06:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant