Skip to content

fix(runtime): diagnose rejected owner lease renewals - #972

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/run-renewal-rejection-diagnostics
Oct 10, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/run-renewal-rejection-diagnostics

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

When a database owner-lease renewal matches zero rows, activation currently has a stable error code but only a generic owner_renewal_not_matched diagnostic. Add elapsed renewal time, configured lease duration, and a bounded best-effort post-update authority snapshot to identify the state visible after rejection.

Reuse the canonical exact-session authority reader and database-clock classifier. Labels cover missing identity/session mismatch, owner/generation mismatch, inactive/cancellation state, expiry at the later snapshot, and authority that is current at that later observation. Both runtime callers pass their exact monotonic attempt deadline. The read uses at most 250 ms and one quarter of the remaining attempt; it is skipped below a 1 ms share. Completed SQL errors release the synchronized connection; only a timed-out exchange discards it. Every diagnostic outcome preserves the rejected result. Successful renewals do not issue a diagnostic query.

Related issue

Refs #906. This is a diagnostic follow-up, not a claimed fix for the unreproduced QA incident. Keep #906 open. The confirmed missing-error-code defect was already fixed by merged #909. A zero-row UPDATE alone does not establish its cause, and a later snapshot can race further changes.

Change type

  • Bug fix (diagnostic gap)
  • Documentation
  • Test

User and compatibility impact

Rejected renewals may spend up to the smaller of 250 ms and one quarter of the remaining caller attempt on diagnostics. Near-exhausted attempts skip the read so an already-known refusal can return without waiting on diagnostics. Existing cancellation and authority fencing remain in force. Logs carry scoped opaque run/session identity and snapshot labels; actual owner pod values are not logged. No schema/config change.

Architecture and complexity delta

  • Canonical owner extended: DatabaseRunStateStore::renew_owner_lease.
  • Existing owners inspected: activation confirmation, generation/status/cancellation/lease UPDATE predicates, exact authority reader/classifier, cancellation-safe pooled connection, and durable recovery.
  • Reuse the existing authority reader/classifier; no alternative ownership decision, new lease state, fallback, or detached diagnostic worker.
  • The snapshot cannot turn a rejected renewal into authority. Lease TTL, renewal UPDATE predicates, recovery and retry ownership remain with their existing implementations.

Verification

  • Local cargo fmt --all --check and git diff --check: passed.
  • Local compilation and database tests were not run because the workstation recently froze during builds and is low on disk. The previous head passed its execution lanes; the review-fix head is undergoing fresh CI. No QA incident reproduction pass is claimed.
  • Added opt-in real MatrixOne regression: a newly inserted run's first renewal succeeds; independently invalidating owner, generation, status, cancellation, lease expiry, or session identity rejects public renewal and asserts the actual emitted snapshot_reason for each authority predicate.
  • Added offline virtual-time regression for a 185 ms attempt, near-spent attempts, timeout and read-failure labels. A live single-slot pool regression checks connection identity reuse after a completed SQL error and replacement after a timed-out read.
  • Public entrypoint covered: RunStateStore::renew_owner_lease on DatabaseRunStateStore.
  • Database verification: new regression requires ASTRA_TEST_DB_IT=1 with live MatrixOne; retained canonical query is reused. No schema/migration change. This must pass the remote online core-services lane.

Final checklist

  • Added owning-layer regression and unhappy-path cases.
  • Documented diagnostic scope, timeout and evidence limits.
  • Diff inspected for secrets/private data and generated files.
  • Conventional Commit title; feature branch based on main.

@loveRhythm1990

Copy link
Copy Markdown
Collaborator Author

Review — fix(runtime): diagnose rejected owner lease renewals (1a6fd34)

Reviewed the full diff against main, plus DatabaseRunStateStore::renew_owner_lease
and both of its callers (RunEngine heartbeat and confirm_execution_authority
in crates/runtime/src/server/run/engine.rs), CancellationSafePoolConnection,
and the activation response mapping in run/lifecycle/mod.rs.

What holds up

  • Keeping [Bug]: 409 CONFLICT for durable execution authority expiry has no stable error code #906 open and labelling the snapshot as correlation-only is the right
    call, and the code comments say so at the point where someone would otherwise
    misread it.
  • The snapshot genuinely cannot grant authority: it reuses the canonical
    load_exact_live_run_execution_authority reader and classifier, never retries
    the UPDATE, and renewed is returned untouched on every branch.
  • Successful renewals issue no extra query.
  • user_id / session_id on the warn event match the existing logging
    convention in this file (~28 other warn sites carry user_id), and owner pod
    values are indeed not logged.
  • Label coverage over ExactLiveRunExecutionAuthority is exhaustive, and the doc
    update matches the implementation.

Important

  • crates/services/src/runs.rs (new block after the UPDATE) — the 250 ms
    diagnostic is spent inside the caller's attempt budget, so it can convert a
    decisive rejection into a timeout.
    Both callers wrap this method in
    tokio::time::timeout(policy.attempt_wait, ...)
    (engine.rs:1509 and engine.rs:1662), and OWNER_RENEWAL_DIAGNOSTIC_TIMEOUT
    is a fixed constant with no relationship to that budget. attempt_wait works
    out to about 0.185 × lease TTL for sub-45s leases
    (OwnerLeasePolicy::new, engine.rs:106, with
    run_owner_lease_renewal_interval = TTL/3), so it is below 250 ms for any
    lease TTL under roughly 1.35 s — e.g. the existing with_lease_ttl(Duration::from_secs(1))
    configuration gives 185 ms, less than the diagnostic's own budget. In that
    regime a rejected renewal that used to return Ok(false) now reliably
    exhausts the caller instead.

    The consequence is not confined to logs. In confirm_execution_authority,
    Ok(Ok(false)) returns ExecutionAuthorityConfirmation::Superseded, which
    run/lifecycle/mod.rs:16281 maps to the typed
    execution_authority_not_current_response. A timeout instead retries
    OWNER_LEASE_MAX_ATTEMPTS times and returns
    "durable execution authority activation failed after 2 attempts", which that
    same match arm maps to a 500 INTERNAL_SERVER_ERROR. So the PR's claim that
    "HTTP/API behavior remains the existing failed-renewal path" does not hold in
    this window: a clean ownership conflict can surface as a server error.

    On the production default (TTL 120 s → attempt_wait 30 s) the window is
    narrow — it needs the UPDATE to land within 250 ms of the budget — but that is
    exactly the cold-MatrixOne-metadata regime this method's own comment calls out,
    and it is the regime [Bug]: 409 CONFLICT for durable execution authority expiry has no stable error code #906 is about. A diagnostic that degrades the signal in
    its target scenario is worth bounding properly: thread the caller's remaining
    deadline into renew_owner_lease, or cap the snapshot at a small fraction of
    attempt_wait, rather than using a fixed 250 ms. (The heartbeat path is milder
    — it retries and still ends at ownership_lost = true — so the cost there is
    one extra attempt_wait of delay before fencing.)

  • Same block — if !matches!(observed, Ok(Ok(_))) discards a connection whose
    protocol is synchronized.
    The comment justifies only the timeout case ("a
    timed-out read may still be active on this physical connection"), but the
    condition also catches Ok(Err(_)), i.e. a read that completed and returned a
    SQL error. CancellationSafePoolConnection's contract
    (crates/services/src/cancellation_safe_db.rs:27) is explicit that normal
    paths call release() after a completed query and that only
    timeout/cancellation paths should reach Drop, and the
    lock-wait-timeout guard in this same file (runs.rs:10876-10922) follows
    exactly that split: release() on Ok(Err(..)), drop only on Err(_). As
    written, any benign snapshot query error tears down a pooled physical
    connection. Please split the two arms.

Important — tests

  • The new regression does not assert the behavior this PR adds. It calls
    renew_owner_lease, asserts the false result, then independently calls
    load_exact_live_run_execution_authority itself and asserts that reader's
    classification. The reader and classifier are pre-existing canonical code, so
    what the test proves is that they still work. Nothing asserts the new
    snapshot_reason label the diff produces, nothing exercises the
    snapshot_read_timed_out / snapshot_read_failed branches, and nothing covers
    the connection disposition that the second finding above is about. A
    tracing test subscriber asserting the emitted snapshot_reason per mutation
    would close the first gap cheaply, and the timeout branch needs its own case
    given it is the branch that drops a pooled connection.

  • No executed verification exists for this diff yet. The new test is
    #[ignore]-gated behind ASTRA_TEST_DB_IT=1 and live MatrixOne, the PR
    reports no local compile or test run, and when I looked the CI lanes for this
    head were still pending — including Test: online (core-services), the lane
    the PR says must pass. cargo fmt and git diff --check are not coverage.
    Worth holding the merge until that lane is green, since the added code path is
    database-only.

Summary

Correctly scoped as a diagnostic extension of the existing canonical owner
(DatabaseRunStateStore::renew_owner_lease): no new lease state, no alternative
ownership decision, no detached worker, no second writer. My objection is not to
the approach but to the diagnostic's placement on the caller's critical path with
a budget it does not share, and to the connection teardown being broader than the
comment that justifies it. Both are small, local fixes.

Review provenance

Reviewed 1a6fd3427e56a7087124eb1c588cee8c25765129 (gh pr diff 972) against
main, read-only, with no independent second-model review configured — this is a
Claude Opus 5 self-review of someone else's patch, not the independent review
required before commit. Coverage: both changed files in full, plus the two
callers, the lease policy arithmetic, the activation response mapping, and the
cancellation-safe connection contract. No code was built or executed; the
attempt_wait figures are derived from OwnerLeasePolicy::new and
run_owner_lease_renewal_interval, not measured.

@loveRhythm1990

Copy link
Copy Markdown
Collaborator Author

Addressed the review in 3ff8eea:

  • Both activation and heartbeat now pass the exact monotonic deadline used by their outer timeout_at. Diagnostics use at most a quarter of the remaining attempt (capped at 250 ms), and skip I/O when that share is below 1 ms.
  • Completed SQL errors release the synchronized checkout. Only diagnostic timeout discards the physical connection.
  • The live regression now captures and asserts the snapshot_reason emitted by public renewal rather than separately testing the existing reader. Added offline virtual-time coverage for the 185 ms/near-exhausted attempt windows and diagnostic failure labels, plus a live one-slot pool test that checks connection identity reuse after SQL error and replacement after timeout.

Formatting and diff checks passed. No local Rust compilation was started; the updated head requires fresh CI, including online core-services. The previous head's green checks are not evidence for this revision. This remains diagnostic work for #906, not a claim that its original QA incident has been reproduced or fixed.

Verification provenance: fixes and source inspection by the submitting Codex agent; no independent second-agent review is claimed.

@XuPeng-SH XuPeng-SH 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.

Reviewed 3ff8eeac8f6c14e096632689dc43697ee6834cc6 against 1b200734e8fa5c573dbe1e401b9014c130d9c108, including all six changed files, both runtime renewal callers, the canonical exact-session authority reader/classifier, cancellation-safe connection ownership, activation response mapping, and the existing PR discussion. No material correctness or design findings remain on this revision.

The design stays with the existing owner, DatabaseRunStateStore::renew_owner_lease. The additional enum represents diagnostic outcomes and connection disposition; it does not create another ownership state machine. The existing database-clock classifier remains authoritative for interpreting the later snapshot, while the original UPDATE result remains false even if the snapshot is current. There is no new writer, retry loop, detached worker, compatibility path, or production dependency.

The earlier review's concerns are addressed:

  • Heartbeat and activation pass the exact monotonic deadline also used by their outer timeout_at. Diagnostic waiting is capped at min(250 ms, remaining / 4), with I/O skipped when that share is below 1 ms. The known refusal still follows the existing Superseded/409 or heartbeat-fencing path.
  • Completed diagnostic SQL errors and skipped reads release the checkout. A timed-out exchange is discarded; ordinary cancellation retains the existing cancellation-safe guard.
  • The public renewal regression now captures the actual emitted snapshot_reason for independently invalidated owner, generation, status, cancellation, lease and session predicates, while checking a fresh run's first renewal succeeds.
  • Virtual-time coverage exercises the short/near-spent budget and failure labels. The single-slot real-database regression verifies connection ID reuse after SQL error and replacement after timeout.

Performance and complexity: successful renewal adds no query; refusal adds at most one bounded read on the existing checkout, with no extra pool acquisition. This is a bounded diagnostic cost, not a throughput or tail-latency improvement claim. The frozen 185 ms test value exercises the small-lease failure window; production behavior derives its budget from the caller deadline rather than a scenario-specific branch. The new tests cover distinct observable behavior.

Inspected completed CI logs for merge commit db69ee8467f5796f5c8f5f1434f01e54ad0b5946, which contains this exact head:

The selected executor remains unavailable, so this review did not independently run local compilation, native tests, git diff --check, or a QA harness. Inspection of added diff lines found no trailing whitespace or conflict markers. No subagent was used, and no second-model review is claimed. The original QA incident in #906 remains unreproduced and open; a later diagnostic snapshot cannot establish why an earlier UPDATE matched zero rows.

Change accounting: implementation +111/-3 (net +108); tests and dev-dependency wiring +223/-2 (net +221); documentation +13/-0.

@mergify mergify Bot added the queued label Oct 10, 2026
@mergify

mergify Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-10 08:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-10 09:07 UTC · at 3571e24745db84a7eaebc736d4ce7cfa897fb5ab · squash

This pull request spent 13 minutes 40 seconds in the queue, including 13 minutes 20 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-skipped = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: macOS workspace coordination
    • check-neutral = Test: macOS workspace coordination
    • check-skipped = Test: macOS workspace coordination

@mergify
mergify Bot force-pushed the fix/run-renewal-rejection-diagnostics branch from 3ff8eea to bb16522 Compare October 10, 2026 08:53
@mergify
mergify Bot merged commit 3571e24 into matrixorigin:main Oct 10, 2026
@mergify mergify Bot removed the queued label Oct 10, 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