Skip to content

fix: messages received during preflight wait until the turn ends - #161046

Closed
creanet-64 wants to merge 1 commit into
openclaw:mainfrom
creanet-64:fix/preflight-steering-20260929
Closed

creanet-64 wants to merge 1 commit into
openclaw:mainfrom
creanet-64:fix/preflight-steering-20260929

Conversation

@creanet-64

@creanet-64 creanet-64 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #161045

What Problem This Solves

Fixes messages received during host preflight compaction waiting until the entire turn finishes instead of steering that same turn when it becomes ready.

User Impact

A message arriving while the host prepares a turn can reach that same turn once its backend is ready. This does not shorten compaction or promise universal FIFO ordering.

Why This Change Was Made

Keep a waiting admission reservation only while the same operation is in preflight without a backend. Resume after readiness, then repeat the normal injection checks using the current session identity. Cancellation or owner replacement must not transfer that authority to a successor.

Evidence

  • Red/green regression established missed injection after preflight. Coverage includes both phase/backend readiness orders, cancellation, failure, owner replacement, session rotation, authority mismatch and backend rejection.
  • Integration exercises the actual runReplyAgent/admission/queue/steering path with a synthetic backend; it does not claim an end-to-end provider transport test.
  • Core and messaging type checks, formatting and lint passed during qualification.
  • Exact contributed file blobs match qualified commit 3e5015467b, based on upstream eadee73. This PR isolates the steering fix from an unrelated update reporter fix; no full test suite on the isolated PR branch is claimed.
  • A packaged candidate also passed live successive replies, restart/context recall and a three-message burst. Those checks are supporting integration observations, not a controlled reproduction of every preflight race.

CI failure investigation

The GitHub job checks-node-changed-compact-large-32-6 failed in reply-turn-admission.module-identity.test.ts: Admission probe stalled: native-same-store parent, after the existing 5-second per-operation limit. It failed at the first parent admission, before the fixture enters its preflight phase. This observation does not establish a root cause or prove the PR unrelated.

A bounded local investigation used the original 24-file shard selection/order and worker configuration. Result: 472/472 tests passed, command wall 176.36 s, including 69.5 s of worker compilation. The unchanged module-identity file also passed alone (7.444 s test time; 26.28 s command wall). The timeout, assertions, and retry behavior were not weakened. An earlier local attempt stopped because concurrent source edits invalidated worker compilation; that attempt is not counted as a product test result.

Local Node was 26.10.0, whereas CI used 24.21.0. Relevant admission, steering, session, and lifecycle source files match the reviewed PR head; the lab checkout as a whole contains separate update changes. These passing reproductions do not prove that the CI failure is fixed. Its cause remains unresolved. No speculative source modification or CI rerun was made just to obtain green.

Exact CI Node version replay

The unchanged module-identity test also passed with official Node 24.21.0, whose Linux x64 archive SHA256 was verified against the official SHASUMS256.txt. Canonical command: node scripts/run-vitest.mjs src/auto-reply/reply/reply-turn-admission.module-identity.test.ts --maxWorkers=1, with the isolated Node binary first in PATH. Result: 1/1 passed, 10.670 s test execution, 120.16 s command wall, including 87.714 s worker generation. Node 24 versus 26 alone did not reproduce the failure. No source, dependencies, timeout, assertions, or global tools were changed for this replay. The original CI cause remains unproven.

Measured new-test costs

  • agent-runner-preflight-steering.integration.test.ts: 1/1 passed, 66 ms test case, 36.05 s command wall (includes compiler/cache/import overhead).

  • agent-runner-steer-adoption.preflight.test.ts: 7/7 passed, cases 9–51 ms, 99.66 s command wall, including 74.577 s worker preparation.

  • queue.compaction-admission.test.ts (Node 24.21.0): 2/2 passed, cases 33 ms and 6 ms, 44.89 s command wall, including 8.290 s cached worker preparation.

These are command costs on the development host, not steady-state production latency or CI performance guarantees.

Real preflight attempt: outstanding proof, not a success

An isolated installed Gateway with the real authenticated Codex engine was instrumented with a metadata-only stdio observer. The fixture requested a message on the actual preflight log event. The host compaction provider lacked its separate API authentication; ChatGPT authentication for native Codex does not satisfy that host-provider requirement.

Redacted observed sequence (UTC):

08:17:24.522 host preflight triggered
08:17:24.552 fixture watcher submitted the steering RPC
08:17:24.668 host compaction failed: auth_failed (missing provider API key)
08:17:24.696 original message operation completed
08:17:24.733 steering dispatch reached the now-idle operation path
08:17:24.952 next preflight failed: auth_failed
native observer: no turn/steer request; expected response marker absent

This is a failed qualification attempt, not evidence of same-turn delivery or a newly established patch defect. It did not exercise successful preflight followed by backend readiness; credentials, production configuration, and source were not modified to force a result. The isolated Gateway was shut down cleanly. The requested real successful preflight-to-same-turn trace remains outstanding and requires a correctly authenticated host compaction provider in the laboratory. Unit/integration successes and the Node-version replays do not close this proof gap.

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR retains incoming messages during preflight compaction so they can steer the same reply after its backend becomes ready, with cancellation and lifecycle regression coverage.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has useful lifecycle coverage and no identified correctness defect, but its changed production behavior remains unproven.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Merge readiness

⛔ Blocked before merge - 3 items remain

Current main has a merged backend-readiness fix, but the exact preflight report remains paired with an open issue and lacks a formally linked merged resolution. Keep this PR open; no concrete introduced defect was found.

Priority: P2
Reviewed head: 303ba6bedc8622068c8ce6c5c497213623f3e617

Before merge

  • Add real behavior proof - The changed reply runner and registry were exercised with a synthetic backend. The installed Gateway attempt stopped at host-compaction authentication before backend readiness, so it showed no successful same-turn consumption. The proposed local HTTP-provider route is useful but unexecuted. Supply a redacted production-path trace of successful preflight, same-owner acceptance, and consumption before terminal completion; terminal output or logs count. Redact credentials, IP addresses, private endpoints, and personal data. Updating the PR body should trigger review; otherwise ask a maintainer for @clawsweeper re-review. No stored-data contract changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk - The captured branch has merge conflicts and overlaps main's new readiness owner; combined behavior has not been established against a pinned merge result.
  • Complete next step - Reconcile the reported conflicts with current main using its existing backend-readiness owner, then verify the retained preflight behavior.

Findings

None.

Agent review details

How this fits together

The reply runner turns incoming messages into either input for an active agent turn or queued follow-up work. Its registry tracks the exact reply owner and backend readiness so messages cannot transfer to a replacement turn.

flowchart TD
A[Incoming message] --> B[Reply admission]
B --> C[Park pending input]
C --> D[Wait for same reply backend]
D --> E[Recheck owner and authority]
E --> F[Steer active turn]
E --> G[Queue follow-up]
Loading

Technical review

Best possible solution:

Use main's single backend-readiness owner and preserve any distinct preflight regression coverage without adding a second waiting mechanism.

Do we have a high-confidence way to reproduce the issue?

No current-main failing reproduction was established. The historical source defect is clear, but main now waits for backend readiness and the contributed real preflight attempt failed before that boundary.

Is this the best way to solve the issue?

The exact-owner waiting approach is appropriate, but current main now provides that responsibility with post-wait authority preparation. A narrow reconciliation using that owner is preferable to retaining parallel readiness mechanisms.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9df0cd095766.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Use main's single backend-readiness owner and preserve any distinct preflight regression coverage without adding a second waiting mechanism.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Security

None.

Evidence

What I checked:

  • Pinned introduced production change: The merge-base-to-head patch adds an exact-operation preflight waiter and readiness notifications; it leaves the existing injection and fallback checks in place. Base-branch drift was excluded from PR ownership. (src/auto-reply/reply/agent-runner-steer-adoption.ts:84, 303ba6bedc86)
  • Current-main readiness owner: Current main waits for the exact reply operation's backend, rechecks its identity, refreshes the session identity, and resolves steering authority after readiness. The caller reaches this path without the old pre-readiness authority-mismatch shortcut. (src/auto-reply/reply/agent-runner-steer-adoption.ts:186, 9df0cd095766)
  • Verified merged related implementation: GitHub verifies fix(gateway): steering during worktree creation still runs as a follow-up after the task #165537 merged on 2026-10-05. Its body explicitly describes retaining input while an existing reply prepares its backend, then revalidating ownership and authority. It reports successful live built-in and Codex runs during worktree preparation, but does not formally close the paired preflight issue or report controlled successful host-preflight proof. (145a5e58ecfb)
  • Feature-history provenance: The source history identifies the merged readiness change and earlier steering repairs. The readiness commit records publishing first-backend readiness and moving authority verification after the wait. (src/auto-reply/reply/agent-runner-steer-adoption.ts, 145a5e58ecfb)
  • Main-only provenance: The readiness commit is contained in main and origin/main. The containing local tags were release-publish staging tags, not verified shipped version tags; inclusion in a shipped release was not established. (145a5e58ecfb)
  • Proof continuity and constructive discussion: The captured PR body explicitly reports failed host-compaction authentication, no native steer request, and no expected response marker. The previous review's successful-preflight trace request remains unmet. The comment at fix: messages received during preflight wait until the turn ends #161046 (comment) positively identifies a local-provider production-path alternative, but explicitly says it was not executed. (303ba6bedc86)

PR surface

Source +91, Tests +463. Total +554 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 93 2 +91
Tests 3 463 0 +463
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 556 2 +554

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +91 net lines; tests +463 lines Production growth implements retained readiness waiting and lifecycle notifications, while most added code protects cancellation, ownership, and queue behavior.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This addresses delayed steering during reply preparation with a bounded messaging impact.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide successful production-path preflight-to-same-turn consumption evidence.
  • Reconcile the branch with main's existing readiness owner and retain distinct regression coverage.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-29T07:07:46.738Z sha 303ba6b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-29T08:31:22.655Z sha 303ba6b :: needs real behavior proof before merge. :: none

Reviewed October 7, 2026, 3:10 PM ET / 19:10 UTC (Revision 3).

@creanet-64

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Updated the PR body with exact-shard and exact-Node CI reproductions, measured costs for all three new test files, and the failed real preflight attempt with its explicit authentication blocker. No source change is claimed for the unexplained CI timeout; real successful same-turn proof remains outstanding.

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

hippoley commented Oct 7, 2026

Copy link
Copy Markdown

I found a way to close the real-proof gap without depending on an external provider credential.

Current main already has a production-path local provider harness in agent-runner-compaction-fallback.test.ts: real reply turns, real host preflight compaction, native compaction delegate, and the foreground embedded run all use a local OpenAI-compatible HTTP endpoint configured through the normal provider stack.

The real embedded injection owner is also production code: attempt-stream-prepare.ts publishes messageInjectionV2.queueMessage, which reaches steerActiveSessionWithOptionalDeliveryWait() -> activeSession.steer().

I wrote the full proof contract here:

https://github.com/hippoley/ClawManager/blob/main/docs/evidence/openclaw-161046-local-provider-real-preflight-steer-proof.md

The key shape is:

real GatewayClient
→ run R enters preflight_compacting
→ local provider receives summary request and holds it
→ second message M2 is sent through the real Gateway on the same session
→ successful summary response releases preflight
→ real embedded backend attaches for run R
→ M2 is accepted by messageInjectionV2 on run R
→ activeSession.steer consumes M2 before run R terminates
→ no successor run owns M2

This is stronger than the existing synthetic-backend integration test and avoids the previous failed qualification attempt's external host-compaction auth blocker. The local provider is controlled, but HTTP transport/config/provider dispatch, Gateway transport, backend registration, and embedded steering are real production owners.

I would require a redacted trace of both ownership and consumption (same run id + accepted steer + transcript/runtime consumption before terminal), not only registry state.

Source-reviewed against 303ba6bedc8622068c8ce6c5c497213623f3e617; not executed on my side.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 21, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale after 7 days without qualifying human activity.
Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

@vincentkoc

Copy link
Copy Markdown
Member

Thanks for working through this preflight race and adding cancellation, owner-replacement, and session-rotation coverage.

Closing as superseded by #165537, merged as 145a5e5. Main now waits for the original reply owner’s backend, rejects terminal or replaced owners, and refreshes session identity before rechecking steering authority. That covers this PR’s preflight-without-a-backend behavior; #161045 is resolved.

This qualification used source and regression-test inspection; no new runtime execution is claimed. If this reproduces on current main, please reopen with the trace.

@vincentkoc vincentkoc self-assigned this Oct 28, 2026
@vincentkoc vincentkoc closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: messages received during preflight wait until the turn ends

3 participants