Skip to content

test: remove flaky cross-file timestamp assertion in multiprocess rotation test - #1335

Merged
myakove merged 1 commit into
mainfrom
fix/issue-1334-flaky-rotation-test
Dec 1, 2026
Merged

myakove merged 1 commit into
mainfrom
fix/issue-1334-flaky-rotation-test

Conversation

@myakove

@myakove myakove commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Removes the flaky file_ts_bounds cross-file millisecond/microsecond timestamp ordering assertions from TestHelpers.test_get_logger_with_params_multiprocess_rotation_concurrency in webhook_server/tests/test_helpers.py.

Root cause

Python's logging captures LogRecord.created before MultiProcessRotatingFileHandler acquires its inter-process file lock and performs writes or rollovers. With 4 forked workers logging concurrently, a worker can construct a record, wait on the lock while another worker writes a newer record and rotates the log, and then flush its slightly older timestamp into the new file. That caused intermittent failures in CI (seen on PR #1333, check run 142150288731).

Cross-worker wall-clock timestamps are intentionally not compared across rotated files because LogRecord.created reflects pre-lock record creation time rather than write order.

What remains verified

  • Every rotated backup and base log file is non-empty (assert lines).
  • Every line matches the expected log format with a valid ISO-8601 timestamp (datetime.fromisoformat(ts_str)).
  • Per-worker msg= sequence numbers strictly increase across rotated files into the base log, verifying per-worker chronological order across rotations without clock comparisons.
  • Post-barrier msg=059 final markers land in the base log only, and all rotated backups exceed 1000 bytes.

Verification

  • test_get_logger_with_params_multiprocess_rotation_concurrency (20x loop): 20/20 passed
  • uvx prek run --all-files: passed
  • uvx tox: unused-code OK, unittests 2499 passed (91.59% coverage)

Fixes #1334


Assisted-by: PI (gemini-4-neon)

…ation test

Remove file_ts_bounds cross-file timestamp ordering checks in test_get_logger_with_params_multiprocess_rotation_concurrency. Python logging captures LogRecord.created before MultiProcessRotatingFileHandler acquires its file lock, so concurrent workers can legitimately flush a record a few milliseconds older into a newly rotated file. Deterministic rotation order is already covered by per-worker monotonic msg sequence checks.

Fixes #1334

Assisted-by: PI (gemini-4-neon)
Signed-off-by: Meni Yakove <myakove@gmail.com>
@deadlock1bot

Copy link
Copy Markdown

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Pre-commit Checks: pre-commit runs automatically if .pre-commit-config.yaml exists
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (PR author or approvers)
  • /hold cancel - Unblock PR merging (PR author or approvers)
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message
  • /security-override - Set security check runs to pass (maintainers only)
  • /security-override cancel - Re-run security checks

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (effective maintainers and approvers only)
  • /automerge cancel - Remove automerge label (effective maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest build-container - Rebuild and test container image
  • /retest python-module-install - Test Python package installation
  • /retest pre-commit - Run pre-commit hooks and checks
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Container Operations

  • /build-and-push-container - Build and push container image (tagged with PR number)
    • Supports additional build arguments: /build-and-push-container --build-arg KEY=value

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3
  • /cherry-pick-retry <branch> - Retry a failed cherry-pick (merged PRs only)

Branch Management

  • /rebase - Rebase this PR branch onto its base branch

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. LGTM Count: Minimum 1 /lgtm from reviewers
  3. Status Checks: All required status checks must pass
  4. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  5. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge
AI Features
  • Conventional Title: Mode: fix (EnMaaS/rits/deepseek-ai/DeepSeek-V4.1-Flash-1017)
  • Cherry-Pick Conflict Resolution: Enabled (EnMaaS/rits/deepseek-ai/DeepSeek-V4.1-Flash-1017)
Security Checks
  • Suspicious Path Detection: Monitors paths: .claude/, .vscode/, .cursor/, .devcontainer/, .pi/, .github/workflows/, .github/actions/
  • Committer Identity Check: Verifies last committer matches PR author
  • Mandatory: Security checks block merge (use /security-override to bypass — maintainers only)

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is removed on new commits unless the push is detected as a clean rebase
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Container Builds: Container images are automatically tagged with the PR number
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@qodo-code-review

qodo-code-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

test: remove flaky cross-file timestamp assertion in rotation test

🧪 Tests 🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Removes cross-file timestamp ordering checks that flaked under concurrent multiprocess logging.
• Root cause: LogRecord.created is captured before the file lock, so older records can land in newer
 files.
• Keeps per-worker msg sequence, ISO-8601 parsing, and non-empty-file checks as deterministic
 coverage.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 0 capabilities

  • No production behavior changes identified.
Behavioral complexity 🟢 Low 🧩 Assessed behavior

  • No production behavior changes identified.
Potential damage 🟢 Low 🩹 Assessed behavior

  • No production behavior changes identified.
Assessed commit 469dd01
Diagram

graph TD
    A["Forked workers x4"] --> B["MultiProcessRotatingFileHandler"]
    B --> C["Rotated backups"]
    B --> D["Base log"]
    E["Test: msg seq check"] --> C
    E --> D
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Record timestamps inside the handler lock
  • ➕ Cross-file timestamp ordering would hold true
  • ➕ Keeps the stronger assertion
  • ➖ Changes production logging behavior for a test-only issue
  • ➖ Requires a custom Formatter or record-time hook that adds complexity
2. Loosen the tolerance on timestamp comparisons
  • ➕ Keeps a timestamp check in place
  • ➕ Minimal code change
  • ➖ Any tolerance is arbitrary and can still flake under load
  • ➖ Adds a time-based assertion that is not deterministic

Recommendation: Dropping the assertion is the right fix. Timestamps are captured before lock acquisition, so cross-file ordering cannot hold under concurrency. Monotonic per-worker sequence numbers already prove rotation order deterministically. An alternative is to capture timestamps inside the handler lock, which would change production code for a test-only problem, so it was dismissed.

Files changed (1) +4 / -10

Tests (1) +4 / -10
test_helpers.pyDrop cross-file timestamp ordering checks from rotation test +4/-10

Drop cross-file timestamp ordering checks from rotation test

• Removes the file_ts_bounds accumulation and the cross-file min/max timestamp comparisons. Adds an explicit non-empty assertion per file and keeps per-line format and ISO-8601 parsing plus monotonic per-worker msg sequence checks.

webhook_server/tests/test_helpers.py

@qodo-code-review

qodo-code-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Informational

1. Rotation-order coverage is narrower than the PR claims ✗ Dismissed Bug Maintainability

Dismissed as Intentional

Description
The removed zip(file_ts_bounds, file_ts_bounds[1:]) loop was the only check that compared
timestamps across rotated files, so a handler bug that moves a later record into an earlier backup
now passes unless that record's worker also has a msg= sequence violation. The PR description says
per-worker msg= sequence checks "deterministically verify chronological rotation order", but those
checks only enforce per-worker monotonicity and never compare different workers' records across
files.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR removed the cross-file timestamp ordering loop in `test_get_logger_with_params_multiprocess_rotation_concurrency`. The remaining per-worker `msg=` sequence check does not verify global chronology across workers, but the PR description and commit message state that rotation order is now deterministically verified.

## Fix Focus Areas
- webhook_server/tests/test_helpers.py[708-731]

## Recommended Fix
Either (a) reword the code comment or PR text so it claims only per-worker ordering is verified, or (b) keep a timing-independent cross-file check, such as asserting that every backup's max `msg=` sequence per worker is less than or equal to that worker's first `msg=` sequence in the next file. Do not reintroduce wall-clock comparisons.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Linked PRs:
  🌐 PR #1333
⚠️ Tickets: not configured — No jira, linear integration is connected for the linked tickets
✅ Compliance rules (platform): 13 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🚀 Fast: Localized test assertion removal with preserved deterministic coverage and no production behavior changes.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread webhook_server/tests/test_helpers.py Resolved
@myakove

myakove commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

/qodo dismiss finding 1

By design: cross-worker wall-clock timestamps are intentionally not compared across rotated files because Python's logging captures LogRecord.created before MultiProcessRotatingFileHandler acquires its inter-process file lock, so cross-worker timestamps are not monotonic with write/rotation order (causing the 2.8 ms flake on PR #1333). The PR description has been updated to accurately describe the remaining deterministic checks: per-worker monotonic msg= sequence numbers across rotated files plus post-barrier msg=059 placement in the base log only.


Assisted-by: PI (gemini-4-neon)

@qodo-code-review

Copy link
Copy Markdown

dismiss finding 1

By design: cross-worker wall-clock timestamps are intentionally not compared across rotated files because Python's logging captures LogRecord.created before MultiProcessRotatingFileHandler acquires its inter-process file lock, so cross-worker timestamps are not monotonic with write/rotation order (causing the 2.8 ms flake on PR #1333). The PR description has been updated to accurately describe the remaining deterministic checks: per-worker monotonic msg= sequence numbers across rotated files plus post-barrier msg=059 placement in the base log only.


Assisted-by: PI (gemini-4-neon)

Dismissed finding 1 ("Rotation-order coverage is narrower than the PR claims") and recorded it as intentional.

The by-design rationale holds up against the diff: the removed loop compared wall-clock timestamps across files, which are not monotonic across workers because LogRecord.created is captured before the rotating handler's file lock is taken. The remaining checks are per-worker msg= sequence monotonicity, which is what the updated PR description now claims.

@myakove

myakove commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

/approve
/verified

Verification at 469dd016 (tests-only change covering webhook_server/tests/test_helpers.py; no runtime surface):

  • test_get_logger_with_params_multiprocess_rotation_concurrency (20x loop): 20/20 passed
  • uvx prek run --all-files: passed
  • uvx tox: unused-code OK, unittests 2499 passed (91.59% coverage)
  • CI checks: tox, build-container, pre-commit, pre-commit.ci - pr, python-module-install, conventional-title, no-generated-docs, security-committer-identity, security-suspicious-paths all green
  • Qodo review: approved: true at 469dd016 (0 open threads)

@myakove
myakove merged commit 1f17aeb into main Dec 1, 2026
10 of 11 checks passed
@myakove
myakove deleted the fix/issue-1334-flaky-rotation-test branch December 1, 2026 10:30
@myakove-bot1

Copy link
Copy Markdown

New container for ghcr.io/myk-org/github-webhook-server:latest published

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: remove flaky cross-file timestamp ordering assertion in multiprocess rotation test

3 participants