Skip to content

fix(runtime): classify execution authority activation conflicts - #909

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
loveRhythm1990:fix/906-execution-authority-error
Sep 28, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
loveRhythm1990:fix/906-execution-authority-error

Conversation

@loveRhythm1990

Copy link
Copy Markdown
Collaborator

Summary

Give the three start-activation Superseded conflicts a stable execution_authority_not_current code and a safe message asking the user to check session status before trying again. Record the activation stage, user/session/run IDs and expected generation in structured logs without asserting that lease expiry was the cause.

Related issue

Refs #906. Implements the confirmed error-contract/diagnostic gap described in the correction comment. The QA zero-row renewal incident is not root-caused by this PR; keep the issue open for that investigation.

Change type

  • Bug fix
  • Test
  • Documentation

User and compatibility impact

HTTP status remains 409; error_code is now populated. English response text no longer claims proven expiry. This is not pre-admission rejection: the durable run already exists, so no admission_state: rejected or automatic retry advice is added. No schema/config/client changes.

Architecture and complexity delta

  • Canonical owner changed or extended: run lifecycle activation error projection.
  • Existing implementations and callers searched: create_run, ordinary/idempotent stream_chat, confirm_execution_authority, DatabaseRunStateStore insert/renew, existing coded 409 helpers and fault-injected lifecycle tests.
  • Superseded code removed: three duplicated uncoded activation responses share one response/log helper.
  • No parallel state machine. Lease TTL, locks, SQL, renewal policy, local cleanup and durable recovery are unchanged.

Verification

  • cargo test -p astra-runtime --lib refused_activation -- --nocapture: 3 passed, including existing subrun refusal coverage.
  • make format-check and git diff --check: passed.
  • cargo clippy -p astra-runtime --lib -- -D warnings: passed.
  • Public entrypoints exercised: create_run, stream_chat, idempotent stream_chat with owner renewal returning false. Assert coded 409, no false pre-admission rejection, no local run execution, and retained durable row for recovery.
  • Diagnostic test: all three stage labels, session/run/generation and non-expiry reason are captured from tracing.
  • Database verification: not applicable to changed code (no SQL/schema/transaction changes); no live QA reproduction. Full offline/online workspace suites remain for CI. macOS runtime test linking emits an unwind-table size warning; tests pass.

Final checklist

  • Tests cover the changed owner and unhappy path.
  • Durable-run design contract updated.
  • Diff checked for sensitive data and unrelated changes.
  • Conventional Commit title; based on github/main.

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

Deep review of e2d6f86: no actionable findings.

Reviewed all three changed files and issue #906, then traced create_run, ordinary streaming activation, idempotent streaming activation, execution-authority confirmation, the database renewal predicate, and HTTP/SSE-to-CLI error handling.

  • All three Superseded branches preserve the existing 409 classification and now expose the same stable domain code. The confirmed and storage-error paths, local cleanup, heartbeat startup, and durable recovery behavior remain unchanged.
  • Superseded comes from a false renewal result, which does not identify the failed predicate. owner_renewal_not_matched and the new user message accurately describe that uncertainty; the log records the correct stage, user/session/run identities, and expected generation at each call site.
  • The durable start precedes these failures. The response correctly omits pre-admission rejection metadata. The SSE adapter preserves the domain code, classifies the conflict by HTTP status, and keeps it non-retryable; CLI admission detection additionally requires metadata.admission_state == "rejected", so merely adding this code does not turn an already-persisted run into a rejected submission.
  • The helper adds only error-path formatting/logging, with no extra storage query, lease extension, retry loop, or recovery state.

Validation: git diff --check passed and all workflows for this head passed. Inspected the runtime CI logs: 6,196 tests passed, including both new tests and the existing refused-subrun-activation regression. The new public-entrypoint test exercises all three response branches, verifies the coded response and absence of local execution state, and confirms the idempotent run remains durable. HTTP/admin/settings contract checks also passed.

Limit: Rust/Cargo are unavailable locally, so I did not independently rerun the Rust tests. This review establishes the error-contract/diagnostic change; it does not reproduce or explain the original QA zero-row renewal incident. Keeping #906 open for that investigation is appropriate.

@mergify mergify Bot added the queued label Sep 28, 2026
@mergify

mergify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-28 09:55 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-09-28 10:16 UTC · at 5f59bad591bd1ca5b475c26bdd52e325b6053684 · squash

This pull request spent 21 minutes 4 seconds in the queue, including 20 minutes 35 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-skipped = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-success = 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)

@mergify
mergify Bot force-pushed the fix/906-execution-authority-error branch from e2d6f86 to bbb0a46 Compare September 28, 2026 09:56
@mergify
mergify Bot merged commit 5f59bad into matrixorigin:main Sep 28, 2026
35 of 36 checks passed
@mergify mergify Bot removed the queued label Sep 28, 2026
mergify Bot pushed a commit that referenced this pull request Oct 10, 2026
## 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

- [x] Bug fix (diagnostic gap)
- [x] Documentation
- [x] 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

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


Approved-by: XuPeng-SH <[email protected]>
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