Skip to content

fix: let first chats wait for agent startup before authorization - #200510

Merged
RomneyDa merged 1 commit into
mainfrom
fix/chat-startup-admission
Nov 17, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/chat-startup-admission

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

What Problem This Solves

A first chat sent while its agent database is starting can fail with “session changed before chat.send” before reaching the provider. Session authorization captures an absent database, then ordinary chat preparation joins startup and observes the database registration as an unrelated change.

User Impact

First messages join the existing startup readiness boundary before capturing session authority. /stop remains usable without waiting for startup. No configuration loading, database schema, registry acceptance, permissions, or revocation rules change.

Why This Change Was Made

Join the existing input-readiness owner before capturing chat session facts, and recheck the invocation afterward. Keep the later preparation guard. Cancellation uses the existing message sanitizer and abort parser; suppressed commands and goal inputs still join readiness.

This is a new, isolated correction on main, not a revival of closed #200474. It includes none of that PR’s receipt-sharing or actor-acquisition changes. The earlier receipt experiments did not clear the original failure.

Evidence

  • Deterministic first-turn regression on main 4c61c20fb1a7e0e98c994ec48b16284f2dd8ce0a: cold registration fails with SESSION_MUTATION_AUTHORIZATION_CHANGED; absent/admitted controls pass (1 failed, 2 passed). The barrier invokes the actual startup cold-open operation through the readiness observation, without sleeps.
  • With this correction: 99 tests pass across five files, including that regression, the original isolated-Gateway xAI fallback flow, first-turn admission, chat request parsing, and pre-admission.
  • Direct authorization tests preserve /stop during pending startup, sanitized stop text, command suppression, and goal intent. The initial all-chat wait was rejected by this regression before publication.
  • Targeted type-aware lint, formatting, git diff --check, and 12 GiB pnpm tsgo:core pass.
  • Self-simplification: 25 production lines added, 53 test lines added / 1 removed. No new state owner, API, configuration, dependency, or registry exception. Independent review was waived by the requesting maintainer; CI and applicable security gates remain required.

Not yet release-qualified: hosted CI, verified merge, release backport, and a fresh exact-candidate FRV remain outstanding.

@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@RomneyDa
RomneyDa marked this pull request as ready for review November 17, 2026 08:58
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 276dbaa5557224fc5b43e2fb627d3f0dc786f2ae
  • Maintainer: @RomneyDa
  • Repository role: maintain

These security sensitive changes were made:

  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@RomneyDa
RomneyDa enabled auto-merge (squash) November 17, 2026 09:02
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR waits for agent startup before capturing chat session authority while preserving the cancellation exception.

Example: Send “Start a new conversation.” to agent:main:first-turn while main’s database is starting.

  • Before: Authorization captures database absence, and startup registration can cause SESSION_MUTATION_AUTHORIZATION_CHANGED.
  • After: Authorization joins startup readiness before capturing the session facts.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation has no identified correctness defect, but required real-behavior evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A first chat can fail before reaching the provider while its agent database starts.
Reason: The source-supported failure warrants this narrow ordering correction, and maintainer authorship establishes direction approval.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a source-supported first-chat startup failure with a focused change, and no actionable introduced defect was found.

Priority: P2
Reviewed head: 276dbaa5557224fc5b43e2fb627d3f0dc786f2ae

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs from an isolated Gateway showing a first chat during pending startup reaching a real agent/model after readiness, with cancellation remaining responsive; redact IPs, keys, phone numbers, and non-public endpoints.
Agent review details

How this fits together

Gateway chat admission turns an authenticated chat.send request into retained session authority before preparing and dispatching agent work.

flowchart TD
  A[Authenticated chat request] --> B[Resolve session target]
  B --> C[Join startup readiness]
  C --> D[Capture session facts]
  D --> E[Authorize session access]
  E --> F[Prepare and dispatch chat]
  B --> G[Cancellation exception]
  G --> D
Loading

Technical review

Best possible solution:

Join the existing readiness owner before capturing session authority, preserve cancellation and final checks, and qualify the corrected first-chat flow.

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

Current-main source exposes the capture-before-startup ordering, and the added deterministic regression exercises real cold registration; the reported base failure was not independently executed in this read-only review.

Is this the best way to solve the issue?

The patch repairs the ordering at the existing authorization boundary without weakening identity checks or adding another state owner, and every introduced hunk serves that repair.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 6747b1ec5ae3.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +25, Tests +52. Total +77 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 25 0 +25
Tests 2 53 1 +52
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 78 1 +77

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: A startup-specific ordering can reject a first chat, with no evidence of widespread or persistent runtime failure.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A startup-specific ordering can reject a first chat, with no evidence of widespread or persistent runtime failure.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed November 17, 2026, 4:14 AM ET / 09:14 UTC.

@RomneyDa
RomneyDa merged commit e10285f into main Nov 17, 2026
207 of 208 checks passed
@RomneyDa
RomneyDa deleted the fix/chat-startup-admission branch November 17, 2026 09:16
RomneyDa added a commit that referenced this pull request Nov 17, 2026
RomneyDa added a commit that referenced this pull request Nov 17, 2026
…0510)

Wait for the existing startup owner before capturing chat authorization facts,
while keeping ordinary and sanitized stop commands independent of startup.
Recheck invocation authority after the wait.

Release adaptation: use waitForAgentDatabaseWriteAdmission, the signed baseline
input-preparation contract, rather than importing the later input-recovery
stack from #187822. Remove only newer recovery fields from test fixtures.
No schema, persisted state, permission, or recovery contract is added.

Self-review: the existing startup owner retains completion and timeout custody;
existing authorization cleanup and currency checks remain in force. Companion
audit through c8d5cf5 found no later required repair; sibling assessments absent.

(cherry picked from commit e10285f)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant