Skip to content

fix(cli): queue settlement-fenced follow-up instead of showing raw 409 - #865

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/852-queue-settlement-fenced-followup
Sep 22, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/852-queue-settlement-fenced-followup

Conversation

@loveRhythm1990

@loveRhythm1990 loveRhythm1990 commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #852.

When a follow-up is submitted while the client still treats the run as active, the TUI posts it as current-run guidance. If the server has already fenced that run, admission rolls the insert back and returns HTTP 409 with error_code=run_intent_settlement_fenced. The TUI used to classify every non-408 4xx as an ordinary rejection and render HTTP 409 Conflict: plus the raw JSON. This change keeps that text for the next turn instead.

The server fence is unchanged. A visible Working indicator that outlives a completed-looking answer is a separate, still-unproven problem and is not inferred from this 409.

What was going wrong

active_submission_belongs_to_next_turn sends ordinary text as GuideCurrentRun until local output settlement or a foreground lifecycle transfer. Those client facts can lag the server fence, so a message typed after the answer is visible can still be posted to a run that no longer accepts guidance.

The server path in admit_run_guidance handles identity and duplicate cases first. Only a new submission whose latest fence event is user_intent_settlement_fenced returns SettlementFenced, and that branch rolls the transaction back before returning. The intent did not commit. Showing the protocol body asked the user to interpret a conflict and submit again by hand.

Solution

The client now treats this one response as a typed non-acceptance, not as display text.

  1. GuidanceSubmissionError::from_thin_client returns SettlementFenced only when the status is HTTP 409 and the JSON field error_code is exactly run_intent_settlement_fenced. The detail string is not consulted. submit_active_run_guidance returns that variant immediately and does not retry the fenced run.
  2. The event loop releases the local uncommitted intent (release_remote_user_intent_submission and remove_local_user_intent) and moves the original text onto the existing queue_next_turn_submission lane. It does not restore the text into the composer and does not start a run itself.
  3. It sets a turn-local guidance_admission_closed flag. Later composer input in that same turn goes through active_submission_routes_to_next_turn and is queued directly, so it is not posted to the fenced run again.
  4. The user sees: "This run is settling. Your message is queued and will be sent as the next turn."

The existing turn owner still decides what happens to that queue:

  • On a normal settlement, settle_followup_submissions appends the text to the follow-up lane, and the outer loop submits it only after ownership returns. That submission is a new turn with a new intent id.
  • If the turn fails or is interrupted, should_start_followups is false and the same helper restores the draft instead of starting it.
  • If the composer already holds a newer draft when the turn ends, the existing merge path keeps both texts.

guidance_admission_closed only changes input ownership. It does not call settle_visible_reply, clear Working, or treat the fence as proof that the visible answer stream has finished. A live tool segment therefore stays live.

What stays the same

  • Server admission, the settlement fence, and the 409 contract are not weakened.
  • A timeout or transport failure stays Unconfirmed, including a 408 whose body happens to contain this error_code. An acknowledgement that may already have committed is not turned into a second turn.
  • Any other 409, including run_intent_identity_conflict, stays Rejected: the raw HTTP error is still shown and the text returns to the composer.
  • A non-JSON 409 body stays Rejected.
  • Guidance that the server already accepted remains server-owned and is not replayed by this path.

Test plan

  • cargo test -p astra-cli --lib -- guidance_submission_errors_preserve_ambiguous_commit_ownership settlement_fenced_follow_up_is_queued_without_keeping_the_rejected_intent closed_guidance_routes_later_input_to_the_next_turn active_slash_commands_never_enter_model_guidance
    • The fenced 409 classifies as SettlementFenced and the notice does not contain the HTTP body.
    • An identity-conflict 409 stays a rendered rejection.
    • A 408 carrying the same error_code stays Unconfirmed.
    • Releasing a fenced intent clears local custody, queues the text, and the existing follow-up helper starts it only when the turn settles normally.
    • After guidance admission is closed, later plain text routes to the next turn without local output settlement.
  • Manually submit a follow-up while a run is settling and confirm it is queued, then sent once as the next turn after ownership returns.
  • Confirm a failed or interrupted turn restores the queued draft instead of starting it.

A definitive run_intent_settlement_fenced rejection did not commit, so keep the text for the next turn instead of surfacing the HTTP body.

Co-authored-by: Cursor <[email protected]>

@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 5803682: one P2 correctness issue in the new settlement-fenced handoff, detailed inline. A delayed fence response can move an earlier submission behind a later next-turn message, causing automatic execution in the wrong order.

I traced the HTTP classification and retry path, durable admission's duplicate-before-fence handling and rollback, local intent custody, turn-closure barriers, queued follow-up dispatch, cancellation/failure draft recovery, and visible-output settlement. The narrow 409 classification and continued separation of output settlement from admission are sound; the remaining issue is preserving submission order across the asynchronous response.

Validation: GitHub Static Checks and Test Suite succeeded for this head, including the CLI non-edge test job. The new queue test starts with an empty queue and does not cover this interleaving. This review used source analysis; Cargo/rustc are unavailable in the review environment, so I did not run local Rust tests.

Comment thread crates/astra-cli/src/tui/event_loop.rs Resolved
loveRhythm1990 and others added 2 commits September 22, 2026 18:13
A delayed settlement-fence response was appended behind messages submitted while that request was still in flight, so the next turn ran them backwards.

Co-authored-by: Cursor <[email protected]>

@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 re-review of 7986132. No new actionable blocking findings.

The previously reported FIFO issue is fixed: the event loop captures the next-turn queue length when guidance is submitted, then inserts a settlement-fenced submission at that position. This preserves both an earlier queued prefix and messages queued while the HTTP request was pending. The single-in-flight submission guard and turn-owned queue make the position meaningful during the handoff. The new regression covers A before B, an existing prefix before A, and the resulting draft-recovery order.

I reread the full two-file PR diff and traced submission/index lifetime, exact 409 classification, stable-identity retries, server duplicate-before-fence handling and rollback, turn-closure barriers, later-input routing, failure/cancellation draft recovery, existing-draft preservation, and outer-loop dispatch. A fence still does not stand in for visible-output settlement or grant permission to start another run early. The fix remains within the existing queue/turn owner and introduces no additional network request or parallel lifecycle.

Validation limits: reviewed source and regression tests; Cargo/rustc are unavailable locally, so I did not run Rust tests. The latest head's Static Checks and Test Suite were still running when checked; this approval is a code-review conclusion, not a claim that those checks have completed.

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

mergify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-22 10:31 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-22 10:31 UTC · at fe4f8ce6cf66e17559a787f8f6455f9e054a066c · squash

This pull request spent 34 seconds in the queue, including 2 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-skipped = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-success = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-success = 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 merged commit fe4f8ce into matrixorigin:main Sep 22, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Sep 22, 2026
@loveRhythm1990
loveRhythm1990 deleted the fix/852-queue-settlement-fenced-followup branch September 24, 2026 02:04
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] TUI exposes settlement-fenced 409 for follow-up input after visible reply

2 participants