Skip to content

test: settle detached autonudge writes before the restart in a reprobe test - #45124

Merged
bolichen97 merged 2 commits into
mainfrom
linuxflackyguard/autonudge-reprobe-flake
Nov 30, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
linuxflackyguard/autonudge-reprobe-flake

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop test_MUTATION_a_failed_holds_settlement_write_keeps_memory_store_and_restart_agreed from failing CI on unrelated pull requests.

The test failed Backend Tests (Linux) on at least four PRs (#45040, #45014, #43525, #6823) with AssertionError: assert False is True at assert restored.active is True. The captured log shows the restarted service loading the row stopped: loop 'monitor-terminal-holds-write-fails' was changed outside the gateway since its last save; loading it stopped (reason unverified_row). Latest failing job: https://github.com/kirodotdev/KiroCrew/actions/runs/46488430582/job/142098497691

Why it matters

A red Backend Tests shard blocks every PR it lands on and costs a rerun each time. Contributors cannot tell this red apart from a real regression.

Not a goal

  • No product code change: one gateway owns a data home, so the two-writer race exists only in the test.
  • No change to the store's digest or compaction protocol.

What changed (motivation → approach → change)

Symptom: the restarted service loads the row as unverified and stopped.

Root cause: the first service._timer(...) tick fails its settlement write (by design), then re-arms through _persist_soon. That detached store write is still running on an executor thread when the test builds a second AutoNudgeService on the same tmp_path. The second service's _load can read autonudge.json before the first write's rename and .vault/autonudge-row-digests.json after the first write compacts it to the new row's digest only. The old row's digest is gone from the record, so the load holds it as changed outside the gateway. Instrumenting the store write (which slows it) makes the failure deterministic on main.

Change:

  • test/test_autonudge_shutdown_terminal_reprobe.py: add _settle_detached_writes(service), which awaits every not-done future in _inflight_adds and _inflight_persistence (the same registries shutdown() drains, and the same pattern test_autonudge_shutdown_ledger_patrol.py uses), and call it right after the first tick, before the stored-row assertions and the restart.
  • docs/system-specs/common/testing-conventions.md: add the "restart beside a live instance" case to flake class 3 with a bad and a good example and the measured result.

Backwards compatibility

Compatible: test and docs only.

Removes nothing: the diff only adds a wait in one test and a docs paragraph.

Tests

  • The changed test now waits for the first service's detached writes before the restart.
  • Whole file: 24 passed locally and on the verification machine; whole file --count 50 -n 16 under CPU load locally: 1200 passed.
  • test/test_flake_pattern_ratchet.py: 81 passed. Comment-history and brand gates passed. scripts/docs-lint.sh passed.

Proof: not provable -- test-only change

Manual verification

Local Linux host (32 vCPU, 32 busy loops, -n 16 --count 1000): main 132 failed / 1000; branch 1000 passed / 1000. With a plugin that slows LoopStore.write_state, main fails 1/1 and the branch passes 1/1.

Real-machine verification

Machine: temporary cloud Linux VM, Amazon Linux 2023 (kernel 6.1), x86_64, 8 vCPU, Python 3.12 venv.
Before (main ba91042): 16 busy loops + python -m pytest -p no:randomly -n 16 --count 3000 test/test_autonudge_shutdown_terminal_reprobe.py::test_MUTATION_a_failed_holds_settlement_write_keeps_memory_store_and_restart_agreed -> 176 failed, 2824 passed (5.9%).
After (head d3db3e7, the test fix; the later commit is docs only): same command -> 3000 passed; whole file -> 24 passed.
Cleanup: the VM was deleted after the runs.

Related Issues

Fixes the flake reported on #45040, #45014, #43525, #6823.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

A timer tick re-arms through _persist_soon, whose store write lands
after the tick returns. The restarted service could read the row before
that write's rename and the digest record after its compaction, and
then load the row stopped as unverified. Wait for the first service's
detached writes before the restart loads the store.
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

The change only touches a test and a doc: it waits for the first service's detached writes before the restart, which fixes the actual race rather than the symptom.

[DESIGN-REVIEWED] e8ee5b7

Description read

[DESCRIPTION-READ] a9a14bde25044bd3edce25b1816328b7739e72877d91367e1f2783974b62ba93

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] e8ee5b7

Verdict parsed from the review's SHA-scoped output markers for commit e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e8ee5b7

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e8ee5b7724f47e4f9570dd3d8d0c72e07d917d2f false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 marked this pull request as ready for review November 30, 2026 21:42
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 30, 2026 21:42
@bolichen97
bolichen97 enabled auto-merge (squash) November 30, 2026 21:42
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 30, 2026

@KiroCrewCaptain KiroCrewCaptain 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 reviewed head e8ee5b7. It is a test and docs change: the reprobe test now waits for the first service's pending store writes before it starts a second service on the same data, and the testing conventions doc gets a matching flake class 3 example. I checked that the background persist writes through the store writer, not the patched snapshot writer, so the existing write-count assertions still hold. The wait is bounded and covers the same registries the shutdown drain covers. All CI checks pass on this head, including every backend shard and the new-test stability runs, and no review lane raised a finding, so nothing blocks.

@bolichen97
bolichen97 merged commit 1bcc9e0 into main Nov 30, 2026
106 checks passed
@bolichen97
bolichen97 deleted the linuxflackyguard/autonudge-reprobe-flake branch November 30, 2026 22:42
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 30, 2026
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