Skip to content

fix(runtime): do not report a poison disposition that never committed - #49

Open
waldemort-auto[bot] wants to merge 1 commit into
mainfrom
waldemort/fix-47-poison-disposition-reporting
Open

fix(runtime): do not report a poison disposition that never committed#49
waldemort-auto[bot] wants to merge 1 commit into
mainfrom
waldemort/fix-47-poison-disposition-reporting

Conversation

@waldemort-auto

Copy link
Copy Markdown

Refs #47. Core half of the livelock analysed in #46.

Problem

When a message exceeds max_attempts the runtime marks it as poison. The poison marking, the backoff, and the attempt-count increment all commit through a single ack keyed on the message's current lock token. If that lease has expired, the ack fails and all three are lost together, so the message is never terminated — it becomes visible again and is redelivered for as long as the provider keeps handing out dead leases.

The runtime reported that outcome as a success:

  1. The ack result was discarded (let _ = ...), so a failed disposition was invisible. Operators saw

    WARN ... Orchestration message exceeded max attempts, marking as poison
             instance=<id> attempt_count=78874 max_attempts=10
    WARN ... ack_orchestration_item failed with non-retryable error
             error=ack_orchestration_item: Invalid lock token
    

    Two adjacent lines at the same level, with nothing connecting them. The first reads as "the runtime is handling it"; the second reads as a transient. Together they mean permanently unrecoverable, and nothing said so.

  2. record_orchestration_poison() was called unconditionally afterwards, so duroxide_orchestration_poison_total counted poison attempts rather than messages actually taken out of circulation. With attempt_count=78874 against max_attempts=10, that counter read tens of thousands while zero messages were ever poisoned. A dashboard showing a large poison count for messages that are still circulating is worse than no metric at all.

Changes

Both poison paths — corrupted-history and normal — now route their ack result through record_poison_disposition:

Outcome Behaviour
Ack committed Record duroxide_orchestration_poison_total, as before
Ack failed Log at ERROR, record the new duroxide_orchestration_poison_failed_total, do not record a poisoning

The error log names the instance, the attempt count, the underlying error, the fact that the orchestration was not terminated and will be redelivered, and where to look — a provider handing out leases that are already expired on arrival. Actual output from the test suite:

ERROR duroxide::runtime::dispatchers::orchestration: Poison disposition FAILED to commit:
  the orchestration was NOT terminated and this message will be redelivered. The poison
  marking, the backoff, and the attempt-count increment all commit through this ack, so all
  three were lost. If the lock lease was already expired when the item was fetched, this will
  repeat on every delivery and the message can never leave the queue -- check the provider's
  fetch path for leases that are expired on arrival.
  instance=poison-disposition-fails attempt_count=11 max_attempts=10
  error=ack_orchestration_item: Invalid lock token

MetricsSnapshot gains orch_poison_failed so the condition is assertable in tests and alertable in production.

What this deliberately does not do

It does not make terminal disposition survive a dead lease. It cannot: both ack_orchestration_item and abandon_orchestration_item take a lock token, and the trait requires providers to reject an invalid one (providers/mod.rs, "Invalid lock tokens MUST return an error"). Forcing termination would need a lease-independent provider operation — a Provider trait addition affecting every implementation, including third-party ones. That is an API decision for the maintainers, not something to slip into a bug fix, so this PR makes the failure honest and visible and leaves the trait alone.

Worth noting what that means in practice: with a provider that returns live leases, this path is already self-correcting. Each redelivery carries a fresh valid token, so the poison disposition commits on the next attempt. The unbounded case only arises when a provider persistently hands out expired leases — which is the defect fixed in microsoft/duroxide-pg#22.

Tests

tests/poison_disposition_tests.rs covers both directions:

  • failed_poison_disposition_is_not_counted_as_poisoned — every ack fails with a non-retryable Invalid lock token; asserts orch_poison == 0 and orch_poison_failed > 0.
  • successful_poison_disposition_is_counted_once — healthy lease; asserts the orchestration ends Failed, orch_poison >= 1, and orch_poison_failed == 0.

The second test exists so the first cannot be satisfied by simply never recording the metric.

PoisonInjectingProvider gains expire_orchestration_lease(), which makes every orchestration ack fail as a provider does when the lease it handed out was already dead. Combined with the existing attempt-count injection, this reproduces the #46 steady state in-process, with SQLite and no external database.

Verification — the repository's own two-pass suite (./run-tests.sh, matching CI):

Summary [187.241s] 1116 tests run: 1116 passed, 0 skipped
  ✓ Both passes succeeded

With the fix reverted (metric recorded unconditionally, result discarded), failed_poison_disposition_is_not_counted_as_poisoned fails and the other passes — so the test demonstrates the defect rather than merely accompanying the change.

Relationship to #46

#46 is one failure with two owners. The provider side — a lease computed from a pre-wait timestamp, plus a blocking advisory lock that made the wait long enough to matter — is microsoft/duroxide-pg#22. This is the core side. Neither alone is the whole story: the provider fix stops expired leases being produced, and this stops the runtime from silently mis-reporting when it is handed one anyway, by any provider.

When a message exceeds max_attempts the runtime marks it as poison. The
poison marking, the backoff, and the attempt-count increment all commit
through a single ack keyed on the message's current lock token. If that
lease has expired the ack fails and all three are lost together, so the
message is never terminated -- it becomes visible again and is
redelivered for as long as the provider keeps handing out dead leases.

The runtime reported that outcome as a success:

- The ack result was discarded with `let _ = ...`, so a failed
  disposition was invisible. Operators saw an 'exceeded max attempts,
  marking as poison' warning followed by a separate, transient-looking
  'Invalid lock token' warning, with nothing connecting them or saying
  the message was still circulating.

- record_orchestration_poison() was then called unconditionally, so
  duroxide_orchestration_poison_total counted poison *attempts* rather
  than messages actually taken out of circulation. In the incident
  behind #46 that meant tens of thousands of increments while zero
  messages were ever poisoned.

Both poison paths (corrupted-history and normal) now route their ack
result through record_poison_disposition, which records the poison
metric only when the ack committed and otherwise logs at ERROR --
naming the instance, the attempt count, the underlying error, the fact
that the orchestration was NOT terminated, and where to look (a
provider handing out leases that are expired on arrival).

A new duroxide_orchestration_poison_failed_total counter, surfaced as
MetricsSnapshot::orch_poison_failed, makes the condition alertable.

The runtime cannot force a terminal write without a valid lease: both
ack_orchestration_item and abandon_orchestration_item require one by
contract. Closing that gap would need a lease-independent provider
operation, which is an API decision for the Provider trait and is left
out of this change deliberately.

tests/poison_disposition_tests.rs covers both directions: a disposition
that cannot commit must not be counted as a poisoning, and one that does
commit must be counted exactly once and report no failure. The second
test exists so the first cannot be satisfied by simply never recording
the metric. PoisonInjectingProvider gains expire_orchestration_lease(),
which makes every orchestration ack fail with a non-retryable 'Invalid
lock token' -- the condition a provider produces when the lease it
handed out was already dead.

Verified with the repository's own two-pass suite (./run-tests.sh):
1116 tests run, 1116 passed, 0 failed. With the fix reverted, the
failed-disposition test fails as expected.

Refs #47, #46

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

@waldemort-auto[bot] please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

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.

0 participants