Skip to content

test(postgres): stop the provisioning worker in the pass that ends the first attempt - #2667

Merged
freeqaz merged 2 commits into
mainfrom
flake-fix-1610
Oct 17, 2026
Merged

freeqaz merged 2 commits into
mainfrom
flake-fix-1610

Conversation

@freeqaz

@freeqaz freeqaz commented Oct 17, 2026

Copy link
Copy Markdown
Collaborator

Problem

The PostgreSQL test "losing native Sandbox containment before the worker runs leaves provisioning retryable without effects" passed 19 of 20 runs at 2 CPUs (finding 1610). In the failing run, occ.controller_work showed attempt_count: 2.

This is a race in the test, not a product bug:

  • The test waited for its work's first worker.completed event, then called stopWorker().
  • Provisioning retries use full-jitter backoff (1000 ms * 2^(n-1) * random), so the first retry can be due almost at once.
  • After each pass the worker claims again without its idle delay.
  • So a legal second attempt (maxAttempts is 3) could run between the test seeing the event (it polls every 20 ms) and the stop.

Two other cases in the same file have the same shape: "an unusable Secret Driver leaves the provisioning work retryable" and "guided source provisioning authorizes its source and rechecks ownership before worker effects". Their assertions happened to tolerate a second attempt.

Separately, no test pinned what a replay of an already-accepted request ID returns after containment is lost (finding 1614). It should be the stored work's retryable 503, not the 409 a new request gets. Changing the replay branch to full admission broke no test.

Change

Test-only, in tests/integration/postgres-agent-provisioning.test.mjs:

  • New fixture option stopWorkerAfter(event). It stops the worker inside the pass that emitted the matching event, as stopAfterProvisioning already does, so no further claim can start. The emit hook now holds its own worker reference and does not replace a stop that is already in flight (??=).
  • The three cases use it, keyed to their own workId. Each now asserts its full list of passes: exactly one retry / PROVISIONING_DEPENDENCY_UNAVAILABLE attempt. The Secret Driver case also pins queued with attempt_count: 1.
  • The containment case replays the same request ID on the switched fixture and asserts 503 with the generic dependency message (finding 1614).

Every other stopWorker() in the file follows a terminal state, a permanent outcome or a deferred settle-window row, so none of them can race this way.

Verification

All runs at 2 CPUs (taskset -c 0,1) against a prepared postgres-application database:

  • Before the fix, with no changes: 40/40, then the first failure at run 64 of a longer loop (attempt_count: 2). That is about 1 in 104.
  • Before the fix, with a 300 ms wait added between the event and the stop: 9 of 30 runs failed, all with attempt_count: 2.
  • After the fix, all three cases: 40/40.
  • After the fix, containment case with a 1.5 s wait: 20/20.

Mutants (all three cases in one prepared run; queued leftovers parked between runs):

Mutant Result
M1: the worker's Sandbox check drops process killed (containment: attempt goes on to PROVISIONING_DEPLOYMENT_PENDING)
M2: stored work that lost containment is refused permanently killed (containment: permanent / PROVISIONING_REJECTED)
M3: every dependency outage becomes a permanent refusal killed (all three cases)
M5: 1.5 s window, fix kept survives (race closed)
M6: containment case without stopWorkerAfter, 1.5 s window killed (second attempt seen)
M8: guided source case without stopWorkerAfter, 1.5 s window killed (second attempt seen)
M7 (1614): replay branch calls authorizeProvisioningRecord(..., { admission: true }) killed (409 instead of 503)
baseline, twice pass

Other checks:

Risks

Low. The change is test-only. The new fixture option is opt-in, and stopAfterProvisioning behaves as before, except that a second matching event no longer replaces the stop that is already in flight.

…e first attempt

The "losing native Sandbox containment" case waited for its work's first
worker.completed event, then stopped the worker. A retry's backoff is
full-jitter (up to 1 s on attempt 1) and the worker claims back to back,
so a legal second attempt could land in between and the case read
attempt_count 2 (finding 1610; 1 in 104 natural runs at 2 CPUs, 9 in 30
with a 300 ms window between the event and the stop).

Add a fixture option, stopWorkerAfter(event), that stops the worker
inside the pass that emitted the event, as stopAfterProvisioning already
does, and key it to the work item. Apply it to the same shape in "an
unusable Secret Driver leaves the provisioning work retryable", which
now also pins that only one attempt ran.

Also pin the replay of the accepted request ID after containment loss
to the stored work's retryable 503, not the new-request 409
(finding 1614).
Internal review found the same race shape in "guided source provisioning
authorizes its source and rechecks ownership before worker effects":
it waited for the first worker.completed, then stopped the worker, so a
legal retry could run in between. Stop in the pass instead and pin its
single retryable attempt. Label the fixture comment per option and say
why the Secret Driver case guards an unset workId.
@freeqaz
freeqaz requested a review from a team as a code owner October 17, 2026 01:23
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@freeqaz
freeqaz temporarily deployed to integration-qa-pr October 17, 2026 01:23 — with GitHub Actions Inactive
@freeqaz
freeqaz temporarily deployed to integration-qa-pr October 17, 2026 01:23 — with GitHub Actions Inactive
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR stops three provisioning tests inside their first completed worker pass and checks replay behavior after Sandbox containment is lost.

Example: An accepted provisioning request loses process containment before its first worker attempt.

  • Before: A legal immediate retry could raise attempt_count to 2 before the test stopped the worker, causing an intermittent failure.
  • After: The completion hook stops the worker before another claim, leaving exactly one retryable attempt; replay also verifies HTTP 503.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported test repair with meaningful integration assertions; confidence rests on reported harness results and successful CI rather than shipped-entry-point proof.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored test-only PR exercises the existing controller and worker through a PostgreSQL integration harness; reported repetition and mutation results support the repair, while the inspected plugin UI screenshots are unrelated.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Contributors can receive intermittent PostgreSQL integration failures even when provisioning correctly remains retryable.
Reason: The collaborator-authored change fixes a demonstrated scheduling race and adds a meaningful accepted-request replay check without expanding product scope.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a credible integration-test race and adds useful replay coverage without changing production behavior; no actionable patch defects were found.

Priority: P3
Reviewed head: 51a9995abe7a5205233d052ea95371311a5a50cc

Before merge

None.

Findings

None.

Agent review details

How this fits together

The PostgreSQL integration fixture sends authenticated requests through the controller app and runs the real durable worker against PostgreSQL, using fixture Drivers to inspect provisioning outcomes.

flowchart LR
  A[Integration scenario] --> B[Controller API]
  B --> C[PostgreSQL work queue]
  C --> D[Controller worker]
  D --> E[Completion hook]
  E --> F[Stop before next claim]
Loading

Technical review

Best possible solution:

Use completion-hook shutdown to make first-attempt assertions deterministic while preserving production retry behavior.

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

Source establishes the race: jitter permits an immediate retry, the worker claims back to back, and the original tests stop only after polling completion; the PR also reports observed attempt_count 2 failures.

Is this the best way to solve the issue?

The fixture uses the existing worker shutdown contract at the completion boundary, removes the scheduling window, and retains independent queue-state and API assertions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6fd73ecd514a.

Provenance checked

  • Fixture shutdown at durable provisioning handoff keeps the original intent (5591960: Repository-scoped provisioning tests stop at durable handoff before credential dispatch; the later bounded OAuth bootstrap change selected PROVISIONING_DEPLOYMENT_PENDING.)
  • Containment and credential-source ownership scenarios keeps the original intent (e82fa9b: Native-runtime provisioning must recheck current containment and credential ownership before creating resources.)
  • Unusable Secret Driver retry classification keeps the original intent (f116a05: A generic Secret Driver outage remains retryable, whereas a definite ownership refusal fails permanently.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • freeqaz: Raw commit 5ca055f adds tests/integration/postgres-agent-provisioning.test.mjs:398 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5ca055fd5ee3; files: tests/integration/postgres-agent-provisioning.test.mjs)

Review metrics

Metric Value Why it matters
Change scope Production +0/-0; integration tests +53/-18 The growth adds deterministic fixture shutdown and distinct retry/replay assertions within existing scenarios.

Labels

Label changes:

  • add P3: This is a focused test-reliability repair 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.

Label justifications:

  • P3: This is a focused test-reliability repair 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.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 16, 2026, 9:35 PM ET / October 17, 2026, 01:35 UTC.

@freeqaz-openai freeqaz-openai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I verified the race on 51a9995a. With a 1.4-second delay before the test calls stopWorker(), the published code still recorded one attempt. With the same delay and only the new in-pass stop disabled, the assertion failed on attempts 1, 2, and 3. That is the distinction we need: production may retry promptly; this test deliberately observes the end of the first attempt.

All three changed cases passed against a private PostgreSQL 18 database using the repository migrations, real worker, and fixture drivers. The containment case also exercised replay of the original accepted request (503, not fresh-admission 409), then recovered the same work ID when containment returned. In the worker, stop() sets the stopping flag before its first await; the fixture saves that promise and awaits it outside the event callback. No production timing change or exactly-once claim.

@freeqaz
freeqaz merged commit 4295ace into main Oct 17, 2026
53 of 54 checks passed
@freeqaz
freeqaz deleted the flake-fix-1610 branch October 17, 2026 01:38

This branch had an error being deployed

1 failed deployment
integration-qa-pr — 51a9995a Deployed Oct 17, 2026 by freeqaz via QA advisory (OpenShell) #1651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants