Skip to content

fix(runtime): release superseded interaction waits - #986

Merged
mergify[bot] merged 6 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/waiting-guidance-ack
Oct 13, 2026
Merged

mergify[bot] merged 6 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/waiting-guidance-ack

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix the Ask User / follow-up guidance lifecycle conflict reported in #985.

An exact live Ask User, approval or provider interaction can be superseded by newer durable guidance. Previously, interaction resolution recorded the superseded receipt but left the run in waiting. The executor then returned from the interaction and attempted to acknowledge guidance at its next action boundary; the database store rejected that acknowledgement because the run was not running, ending the turn with contract_violation.

Release that exact live wait in the existing resolution transaction while preserving its superseded receipt. Old answers/provider responses are not applied and old approvals are denied, even when their recorded decision was allow. The same owner can then acknowledge guidance before admitting its next fresh action. Also distinguish supersession from a late response or lost execution ownership in the existing runtime consumers and Edge approval sink.

Review follow-up 4edabe37 also classifies shared Edge approval receipts explicitly. A superseded receipt observed before the guidance poll wakes enters the existing supersession continuation, not FailedClosed. The recorded old decision is never replayed as approval; authority_lost, invalid decisions/kinds and mismatched request/tool identities remain rejected. Both the ordinary shared wait and the nested shared wait after a local callback hint use this classification.

Related issue

Closes #985

Change type

  • Bug fix
  • Test
  • Documentation
  • Feature
  • Refactor or performance improvement
  • Build, CI, or maintenance

User and compatibility impact

Waiting for Ask User and then sending follow-up guidance no longer leaves an already-resolved questionnaire blocking guidance acknowledgement. This requires a Server update; no CLI protocol, configuration or database schema changes are introduced.

The same exact-wait release rule applies to all three existing interaction kinds; the duplicated AskUser-only predicates are removed rather than introducing a separate policy mechanism. This does not broaden the database guidance-apply status guard, convert guidance into an answer/approval, or auto-resume a terminal, cancelled, stale-frontier or ownership-lost run. Existing HTTP superseded conflict codes remain unchanged.

Architecture and complexity delta

  • Canonical owner changed or extended: existing resolve_run_interaction implementations in the in-memory and database Run stores, plus the existing durable interaction consumers and Edge approval sink.
  • Existing implementations and callers searched: interaction registration/wait/resolution, exact frontier/owner/lease validation, resolution receipts, projection/replay, guidance acknowledgement, and questionnaire/approval/provider tests.
  • Superseded code, states, tables, shims, or self-only tests removed: none; the existing transaction and events are reused.
  • If parallel implementations remain, their boundary and retirement condition: existing deterministic in-memory fixture and production database implementation retain the same interaction behavior; no new lifecycle implementation is added.

Verification

  • UT correction 3522749b updates the sole failing runtime regression, newer_guidance_fences_an_approved_stale_tool_before_execution: the superseded exact wait must now be running with no waiting reason, while the old approval remains denied with a superseded receipt. The test additionally checks exactly one resume and idempotent durable guidance acknowledgement using the existing helper. Merge commit b58267e9 includes upstream main at a41e48a4 without conflicts, including the already-reviewed quinn-proto 0.11.18 security fix from feat(tui): add explicit next-turn follow-up submission #992. Formatting, diff checks and repository metadata validation passed; source review covered this one changed test with no blocking findings. The focused local test is still compiling, so no passing result on this updated head is claimed. New CI must validate the merged head.
  • Previous-head evidence (4edabe37): GitHub runtime execution ran 5914 tests, with 5913 passed and one failed due to the stale waiting expectation fixed above. The shared supersession race regression and authority-lost rejection regression passed. CI Clippy and formatting passed; Static Checks failed only at dependency audit on the old quinn-proto 0.11.15. Serial local Clippy also completed successfully. Upstream feat(tui): add explicit next-turn follow-up submission #992 security audit passed, but that is not a passing audit result for this new PR head.
  • Review follow-up 4edabe37: added shared_superseded_approval_wins_before_guidance_poll_wakes, with six paused-clock cases (local hint present/absent × old allow/deny/timeout); it exercises the reader/wait path rather than calling the settlement sink directly. Existing authority-lost denial rejection coverage is retained. Both regressions subsequently passed in CI as recorded above. The earlier local cargo test --locked -p astra-runtime --lib shared_ was stopped during compilation under severe memory pressure; serial CARGO_BUILD_JOBS=1 cargo clippy --locked -p astra-runtime --lib --tests -- -D warnings later passed. This follow-up changes no database code/schema, and no new database verification is claimed.
  • Commands and results: formatting and git diff --check passed. cargo test --locked -p astra-services --lib runs::tests::: 191 passed, 0 failed, 67 ignored. The MatrixOne-backed database_superseded_interaction_releases_wait_for_guidance regression passed (six cases across all three kinds), and database_terminal_statuses_close_all_interactions_and_replay_authority_loss_on_matrixone passed. cargo clippy --locked -p astra-services -p astra-runtime --lib --tests -- -D warnings passed, including runtime test type checking. The initial runtime test build and CI failed because the new test imported a nonexistent RunControl trait; follow-up commit 5e99ef9d fixed that import. Full local runtime execution was stopped after excessive compilation time; runtime regression execution and broader gates must run in CI. No passing runtime execution is claimed.
  • Public entrypoint exercised: production durable questionnaire gate and Run store registration/resolution/guidance APIs in targeted tests; no authenticated production interaction was replayed or mutated.
  • Unhappy paths covered: guidance arriving after an exact interaction wait starts; approval/answer/provider-response and timeout supersession; callback replay; exactly-once guidance acknowledgement; admission of a fresh subsequent action. Runtime regressions cover Server and Edge approvals, provider submission and Ask User timeout, preserving rejection of old responses and ownership-lost waits.
  • Database verification: targeted regression uses a dedicated disposable local MatrixOne database. No schema change. Existing owner/generation/lease/frontier checks and atomic status/event/session-slot update are retained.

Final checklist

  • I added or updated tests at the layer that owns the behavior.
  • I updated design documentation for the lifecycle contract.
  • I checked the diff for credentials, private URLs, customer data, generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@loveRhythm1990 loveRhythm1990 changed the title fix(runtime): release superseded questionnaire waits fix(runtime): release superseded interaction waits Oct 12, 2026
@loveRhythm1990
loveRhythm1990 marked this pull request as ready for review October 12, 2026 12:47

@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 all three commits from 2873a950f2c9fea00343757933e96070d1631596 to c53dc5d194a4bc5a49912dccab6efc4d029066e7.

The core fix is appropriate: release the exact live interaction wait in the existing transaction, preserve the superseded receipt, and retain the owner/generation/lease/frontier checks. This adds no schema, background worker, or additional query. The production change is small relative to the regression coverage.

Requesting changes for one incomplete Edge consumer update, detailed inline: the shared approval polling path still classifies a superseded receipt as lost authority before it reaches the updated settlement sink. Please cover the ordering where the shared receipt is observed before the guidance poll and route that receipt through the existing supersession control path.

The current Edge regression invokes the sink directly and manually acknowledges guidance, so it cannot detect this ordering. Keep the authority-lost rejection coverage alongside the new regression.

Non-blocking existing limitation: Ask User and provider waits still await a callback or their deadline before processing guidance; the new 200 ms questionnaire timeout test establishes post-timeout recovery, not immediate guidance responsiveness.

Validation: source-level review and git diff --check passed. This review environment has no Rust toolchain, so I did not execute the Rust tests or independently reproduce the author's reported MatrixOne results. Runtime test execution remains unverified here.

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

Re-reviewed all four commits from 2873a950f2c9fea00343757933e96070d1631596 through 4edabe3769783ea91c5f6f1877586a5f6835e714. The P2 in my previous review is addressed; no new actionable findings.

The shared Edge approval reader now classifies supersession explicitly, and both the ordinary shared wait and the nested wait after a local callback hint enter the existing guidance continuation. Old allow/deny/timeout decisions are not replayed as execution permission. Request/tool identity, decision and approval-kind validation remain mandatory, and authority-lost receipts still fail closed.

The new paused-clock regression exercises the actual reader/wait path with the shared receipt visible at 100 ms while the guidance poll remains asleep for 250 ms. Its six cases cover local hint present/absent and old allow/deny/timeout. This closes the coverage gap in the previous sink-only test.

Rechecked the store-to-consumer path: the exact live wait is released atomically while retaining its superseded receipt; owner, generation, lease, frontier and cancellation checks remain in place. Callback replay does not double-resume, and guidance acknowledgement precedes fresh action admission. The implementation reuses existing transactions and continuation paths without adding queries, background tasks or a parallel state machine.

Existing non-blocking limitation remains: Ask User and provider waits process guidance after their callback or deadline rather than immediately on guidance arrival.

Validation: source review and git diff --check passed. Latest CI Clippy and formatting steps passed. Static Checks failed at dependency audit on the existing quinn-proto 0.11.15 advisories; this PR does not change Cargo.lock. The Test Suite is still in progress at submission time. This environment has no Rust toolchain, so I did not independently execute Rust or MatrixOne tests.

Approve from the code-review perspective. Required CI still needs to complete successfully, including the dependency fix already addressed in #992.

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

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-13 10:37 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-13 10:37 UTC · at 07813786fb24ee717b4aaed6ab6efe16c10503b7 · squash

This pull request spent 21 seconds in the queue, including 1 second 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 merged commit 0781378 into matrixorigin:main Oct 13, 2026
@mergify mergify Bot removed the queued label Oct 13, 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.

[Bug] ask_user 等待期间追加指导后触发 waiting 状态冲突,运行以 contract_violation 终止

2 participants