Skip to content

fix: deflake hooks-ordering contract test#563

Merged
beekld merged 3 commits into
mainfrom
bklimt/contract-test-hook-callback-order
Jun 23, 2026
Merged

fix: deflake hooks-ordering contract test#563
beekld merged 3 commits into
mainfrom
bklimt/contract-test-hook-callback-order

Conversation

@beekld

@beekld beekld commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes flaky contract tests hooks/evaluation/executes beforeEvaluation hooks in registration order and the corresponding afterEvaluation reverse-order test, which had been intermittently red on CI.

Root cause: ContractTestHook::PostCallback was firing the harness notifications as fire-and-forget async chains (resolve -> connect -> write). The SDK invokes hooks sequentially, but the three async POSTs then race on the wire, so the harness can receive them in any order.

Fix: send each callback synchronously via the boost::beast sync HTTP API. The sync path uses blocking syscalls rather than the reactor, so there is no deadlock on the single-thread io_context, and each POST completes before the next hook's call starts.

Local repro on macOS over loopback: 2/50 fails before, 0/100 after.


Note

Low Risk
Test-only contract hook infrastructure; no production SDK behavior change beyond blocking briefly during test callbacks.

Overview
ContractTestHook::PostCallback no longer uses fire-and-forget async resolve/connect/write/read chains. Each harness notification is sent with synchronous Boost.Beast HTTP (resolve, connect, write, read, shutdown) so a POST finishes before the next hook stage runs.

That preserves callback arrival order when the SDK invokes hooks sequentially, which stabilizes hooks-ordering contract tests that assert registration order for beforeEvaluation / afterEvaluation.

The rest of the diff is import reordering and minor JSON serialization formatting; hook behavior is unchanged aside from callback delivery semantics.

Reviewed by Cursor Bugbot for commit fd2de8b. Bugbot is set up for automated code reviews on this repo. Configure here.

@beekld beekld marked this pull request as ready for review June 22, 2026 23:00
@beekld beekld requested a review from a team as a code owner June 22, 2026 23:00
@beekld beekld merged commit 3c6377d into main Jun 23, 2026
50 checks passed
@beekld beekld deleted the bklimt/contract-test-hook-callback-order branch June 23, 2026 01:11
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.

2 participants