Skip to content

fix(gateway): keep chat admission responsive and bound to current authority - #164682

Merged
steipete merged 34 commits into
mainfrom
fix/pr-156941-current-chat-authority
Oct 4, 2026
Merged

steipete merged 34 commits into
mainfrom
fix/pr-156941-current-chat-authority

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #156941. Credited replacement for Galin Iliev's (@galiniliev) contributor PR. His original commits are retained, with Co-authored-by: Galin Iliev <[email protected]> on the maintainer integration. The native squash message will also preserve his linked public GitHub noreply identity, since GitHub does not associate the original commit email with an account.

What Problem This Solves

The initial chat.send session lookup admitted a writable agent database on the Gateway thread. Delayed preparation could also outlive its original caller, physical store, or session authority. This repair moves initial lookup and participation preparation through existing workers and rechecks current authority at admission and commit.

User Impact

Ordinary chat admission no longer performs those session reads on the caller thread. Each agent's global conversation keeps its own physical storage and replay identity. Failed preparation clears only its matching reservation; cleanup joins started work before releasing custody.

Request preparation, invocation authority, and accepted-input custody retain distinct lifetimes. A replaced caller or expired invocation cannot produce new effects. Merging another profile into a surviving sender preserves valid accepted work; retiring the sender's canonical identity still revokes execution authority.

Implementation and Compatibility

The repair reuses main's Goal, retry, pending-input, shutdown, and worker owners. Physical-store publication facts prevent one agent's global updates from invalidating another's. Stop, process-held incognito, explicit recovery, and released synchronous SDK contracts retain their existing boundaries. The released SessionMutationAuthorization, reachable through GatewayRequestHandlerOptions, keeps its existing members and gains optional withCurrent / withPreparedCurrent methods.

This integrates the landed schema-facts prerequisite #164490 and per-turn worker cutover #164779 through current main d9f36acbe3b6c8a29ddeffe1e89ebe2b6992d085. The first integration preserves async native ownership preparation and main's awaited harness-admission type. The latest integration also preserves #164744's prepared placement reads: preparation awaits outside the synchronous authority consumer, and a fresh Goal incarnation releases the old reader before reacquiring placement and rechecking admission. Tests cover caller revocation during placement preparation and a distinct Goal incarnation despite a non-local provisional placement; fixture retirement uses the exact generation after model cleanup. No schema-version, persisted-format, public configuration, environment, or protocol change is introduced. Consolidation precedent: #164197. #162433 overlaps the broader design space without changing this repair's ownership model.

Against that main, runtime is +3,052/−1,061, net +1,991 across 46 files; tests/support/config +3,036/−162; docs +9. Discounting inspected moves leaves roughly 3.0k substantive production changes. The growth supplies retained worker reads, physical-generation facts, and separated authority lifetimes while preserving named synchronous contracts. Independent cleanup review found no safe material simplification.

Evidence

Current candidate: d00859d968c6015cdd8208b29bf21cbd4a43111e. Full independent source review 27 is clean through P2. This latest commit changes only two test files; production and SDK inputs remain byte-identical to 11bf8b703660ca8358bdaae04e8d25f2062c7363. Current CI 37204185415 completed with 94 successful jobs, 21 skipped, and only the independently attributed cron shard plus its aggregate gate failing. The owner-authorized native pre-existing-failure route is being prepared; normal CI is not claimed green. No contributor-derived code executed on the maintainer host; runtime proof used secretless GitHub CI.

  • Combined production qualification on 11bf8b7…: 37202553583 passed the unchanged real Gateway case in 54.409 seconds, all eight focused owner files / 146 tests, the new fresh-Goal negative control, and both worker/mock ratchets. Removing the inner placement-incarnation refresh guard reached the named durable Goal assertion, with one intended assertion failure and exact source restoration. Together with the eight earlier controls, nine regressions are qualified.

  • Cycle-check result and diagnostic limitation: the standalone owner job was terminated with exit 143 during Madge, so its final integrity/upload steps did not run. The complete job log retains all eight positive results and the control’s checked restoration verdict; no raw owner artifact is claimed. Separately, current CI architecture job 111442082172 passed on tested merge 7f1d05b0…, containing d00859d…, and reported zero cycles. The termination’s origin remains unknown; the interrupted job is not relabeled green.

  • Prior-head CI passed on 850cfd2b…: 37195445051, with 93 successful jobs, 21 skipped, zero failures, and a successful openclaw/ci-gate.

  • Broad positive qualification passed on 58c25f9b…: 37190956731 completed 54 files / 924 tests, build, the thirteen-turn SQL workload, SDK comparison, worker/mock ratchets, and Madge with zero cycles. Its overall workflow result is failed because a later negative-control checker could not recognize a redacted stack location.

  • All eight regression controls now qualify: five source-derived pre-fix controls reached their intended assertions in the broad run. 37195940455 passed 74 unmodified positive tests on 850cfd2b…, then qualified the remaining receipt, prepared-profile, and physical-store controls. The checker preserves credential redaction and requires exact case/type/count, owner frame, distinctive failure evidence, clean teardown, and source restoration. These are restored pre-fix hunks on compatible candidates, not a full old-main execution.

  • Qualification of 850cfd2b… completed in scoped runs: 37195508583 passed build, the complete thirteen-turn SQL workload, released-SDK comparison, and 13 files / 324 tests, then the real Gateway scenario hit its unchanged 90-second limit. Diagnostic and remaining-owner run 37199124103 passed: the Gateway scenario completed in 67.903 seconds with all assertions, request order, and deadlines unchanged; the six previously unreached files passed 189 tests; worker/mock ratchets and Madge (zero cycles) passed. The diagnostic overlay contains only bounded timing/provider counters and strips byte-for-byte to the original fixture; source was restored exactly. This passing replay does not establish the earlier timeout's cause or claim a fix.

  • Bounded timing comparison passed all ten observations: 37199979004 completed five serial whole-file observations on 850cfd2b… (53.281–71.141 seconds) and five on prior qualified candidate 58c25f9b… (57.055–82.669 seconds), using Node 24.21.0 and the identical fixture/diagnostic overlay with the original 90-second limit. Every observation reached all 19 provider requests, scenario completion, and cleanup, with clean error accounting and source restoration. No owner stall was reproduced. The prior candidate is not main; this does not establish inheritance or explain/fix the earlier timeout. Further attribution is deferred after this bounded investigation under the maintainer test-failure policy.

The completed real-I/O scenario uses authenticated TLS Gateway clients, actual worker reads and SQLite, and an HTTP fixture provider. It proves membership revocation, session/caller replacement before effects, independent global conversations, and accepted steering after an alias merges into the surviving sender. Both terminal outcomes are successful, each user input persists once, two assistant replies settle, and no pending input remains. The 850cfd2b… diagnostic observed all 19 provider requests, two holds and two resumes, successful terminals, durable assertions, and completed cleanup. The earlier dedicated integration timeout remains a separate failed observation.

The completed SDK report for 11bf8b7… compares both beta/latest selectors (v2026.9.8, commit fc23bc864e45), digest d548a2924c967cf996ea12b41419f78b73138086d17130d18aad98f28424e00e. Its reachable SessionMutationAuthorization adds only optional withCurrent and withPreparedCurrent; removing those additions leaves every existing member byte-identical. The later d00859d… changes only test code. Broad release-to-main API evolution, including an async agent-end export already on the merged base, is not a global compatibility-clean verdict.

CI Repairs and Remaining Limits

Latest CI fixture repairs: 11bf CI 37202513412 had 91 passed, 21 skipped and five failed jobs, including its aggregate gate. Docs and lint failed the same 101-column test call. Main’s new async-reader mock also used the existing synthetic session-ID map; the binding test seeded a real target but omitted that map entry, so the production expected-ID guard correctly refused persistence. d00859d… formats the call and restores the fixture binding while retaining all durable transcript, source-isolation and media assertions. Current-head CI passed docs/lint and all 132 directive cases, including the repaired binding-owned transcript case. Only the matching cron shard and derived gate remain failed.

Historical cron failure independently reproduced on main: 37203864122 completed five unchanged whole-file observations on the failed CI’s tested merge 5a4737dccfdf04a9769294857e9eeff3ad6bb1a1 and five on its actual main parent 85124fe108f74a7cfc52d4c5a0cf5fc589583fd6. Every run failed only the scheduler-disabled edit case with the same file_lock_timeout and .cron-authority.lock path; the other two cases passed every time, with zero errors/skips or teardown indicators. Both revisions used the observed Node 24.19.0 and QA-runtime build contract, with unchanged assertions, order and timeouts.

Main #164805 introduced exclusive host-lifetime cron custody. The fixture calls cron.add on a live Gateway, then starts a second scheduler process against that same store; child startup collides with the existing owner before the runtime-edit assertion. The owner’s own regression requires rejecting foreign custody. The relevant cron, fixture/helper, lock and dependency sources match between the historical tested merge and main parent. This establishes the historical CI failure as inherited; it does not claim the newer head’s CI passed. Current-head CI tested merge 7f1d05b0b2a05f54b6240393da18879f0b653d92 of d00859d… into main 82adb7a49d36e844e4ea1989bc5d865abac916f0 and reports the same sole case/code/lock-path failure. The relevant owner inputs are byte-identical from the reproduced main parent through that current tested merge. Native admin evidence binds this exact head, failed run/attempt, merge tree, source paths, retained artifacts and the derived gate. Named follow-up: align the passive-manager E2E fixture with the exclusive cron-authority ownership contract; this PR does not weaken locks or change the cron lifecycle.

Main #164779 moved reply finalization to a worker reader while the binding-owned reply test still required the retired synchronous mock call. CI 37194510129 captured that failure. Commit 850cfd2b… replaces the spy assertion with actual bound-session transcript text/idempotency and absence of a source-session copy, retaining canonical event/media checks. CI on 850cfd2b… passed without a rerun. One superseded integration run was cancelled before any job started.

Restored-requester timeout attribution remains open. Earlier CI reported failed rather than timeout, with active state cleared. Comparison 37192341351 completed five whole-file runs on the exact tested merge and five on its main parent, using the observed Node 24.19.0. Both revisions failed earlier, before provider execution; the original terminal-status assertion was not reached. This does not prove inheritance or a fix. ClawSweeper timeout rank-up disposition: further attribution is deferred after the bounded investigation under the maintainer test-failure policy. CI on 850cfd2b… passed normally; no inherited-failure waiver or admin bypass is requested.

Worker-backed reply initialization lifecycle snapshot remains a separate follow-up. Later reply initialization still reads lifecycle/header and terminal transcript facts synchronously (src/auto-reply/reply/session.ts:662), as on main. Move those facts together through the existing exact-entry owner while preserving revision/rollover guards. Only the initial lookup boundary is zero caller-thread SQL; the whole first turn is not. The 850cfd2b… workload recorded 9,259 Gateway-main, 36,801 worker-thread, and 498 child-process statement executions; its first-turn phase recorded 911 / 4,262 / 75 respectively. Four connect-phase lock errors occurred despite successful outcomes across all thirteen turns, 38 RPCs, child execution, cron, compaction, and shutdown. These are candidate-only counts, not paired-baseline improvement measurements.

Usage-cache close-fence cleanup: an earlier failure remains unreproduced after five exact-candidate and five parent runs in 37184239731, followed by passing CI. No fix or inherited-failure waiver is claimed.

ClawSweeper revision 22 reviewed exact head d00859d… at 2026-10-04 13:12 UTC, accepted the production/placement proof and found no introduced correctness or security defect. Its remaining request was to inspect matching cron failure signatures before an exception. All ten comparison reports and the current failure were inspected as recorded above; the native exception retains the failed CI result and does not waive security or review requirements.

Galin Iliev and others added 14 commits September 30, 2026 14:49
Reconcile the aggregate published repairs on current main.
Refresh freshness at read admission and after BEGIN while reusing
handle-owned facts for runtime schema checks. Validate canonical
triggers before exposing agent readers and classify shared-state
failures only after failed admission.

Focused runtime checks execute zero SQL statements, versus 30 with
the baseline owner. Preserve foreign-commit and snapshot semantics.
Full workload measurement and remote integration checks remain merge
preconditions after remote runner and fleet-capacity admission failed.
Integrate the pinned measurement baseline and retain main-key facts through the existing connection and reader-admission owners. Preserve raw writes, foreign commits, transaction snapshots, authorizers, and continuation authority.
Use the existing worker generation claim for maintenance metadata instead of
retaining a host read handle. Keep both live ownership checks around the
required transaction-entry freshness probe.

Consolidate shared-state cache initialization, refresh, and terminal failures
in its admission sibling and update the compiled-wrapper inventory. This
keeps the cache within the existing module-size limit without changing stored
schema or quarantine semantics.

Focused maintenance, ownership, schema, worker, wrapper, and quarantine proof
passed. Independent Codex review is clean through P2. Full landing validation
remains required before merge.
Refresh canonical readiness when it consumes schema facts. Retention only
holds native lifetime, so cold restore and other worker handoffs no longer
execute host SQLite before dispatch.

Protect foreign schema invalidation at the warm readiness fast path. Tighten
retained-reader budgets to the optimized counts, and require early missing-table
diagnosis before callbacks while preserving handle-cleanup assertions.

Validation: 93 focused tests, production types, state/config test types, and
independent review clean through P2.
Integrate the released-SDK diff tooling fix and the inherited child-coordination fixture correction. The merge preserves every authored source, test, and documentation blob; the wrapper inventory combines both branches.
Include main's failed-placement publication fix after the paired-node lifecycle CI failure. Authored schemafacts source, tests, and documentation remain byte-identical to the reviewed head; the wrapper inventory includes current main dependencies.
…ority

Integrate main with the contributor work from #156941. Prepare first-turn
session and membership reads through the existing workers, retain the
original caller and physical store, and revalidate authority before admission
and effects. Use the same global alias for chat routing and authorization.

Preserve main's Goal, retry, pending-input and shutdown owners. Clear failed
reservations and join started admission work before releasing custody when
retained-reader cleanup fails. Add first-turn SQL, authority, real Gateway
main/work, source-retirement and cleanup regressions.

Co-authored-by: Galin Iliev <[email protected]>
The maintenance scheduler starts worker-backed completion without joining it. Wait for the real recorder's accepted write before reading its receipt, while preserving the held producer and lifecycle writes and all timeout outcome assertions.
Merge aa1df7b, including the per-turn
worker patches from #164514 and the current worker-runtime package.
The production files in the chat admission repair are unchanged; recovery
fixture and documentation changes merged without conflicts.
@clawsweeper

clawsweeper Bot commented Oct 4, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 4, 2026
@steipete
steipete marked this pull request as ready for review October 4, 2026 01:44
@github-actions

github-actions Bot commented Oct 4, 2026 •

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: d00859d968c6015cdd8208b29bf21cbd4a43111e
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/operator-role-policy.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/request-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-access-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization-async.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/session-sharing-authorization.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 4, 2026
@steipete
steipete merged commit 00daeeb into main Oct 4, 2026
197 of 200 checks passed
@steipete
steipete deleted the fix/pr-156941-current-chat-authority branch October 4, 2026 13:44
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged as 00daeeb and verified on main. Galin Iliev's linked co-author trailer is present in the landed commit.

Correction to the squash description: its sentence “no inherited-failure exception is used for landing” was stale. This landed through the native, explicitly approved pre-existing-failure admin route. Exact-head CI run 37204185415 had 94 passing jobs, 21 skipped jobs, and the cron shard plus its derived aggregate failure. Attribution run 37203864122 reproduced the same cron-authority lock failure in five whole-file runs on main and five on the historical PR merge; the 17 causal source inputs were unchanged through the current tested merge. No CI rerun or cron-lock relaxation was used. The PR body retains the detailed qualification and separate historical uncertainties.

The latest completed ClawSweeper review covered d00859d968c6015cdd8208b29bf21cbd4a43111e with no actionable code or security findings. All candidate-code execution remained in secretless GitHub CI.

@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

steipete added a commit that referenced this pull request Oct 4, 2026
Integrate main bb5656b, including the
chat-admission and current-authority repairs from #164682. The merge is
conflict-free and keeps P7b production actor routing inactive.

Preserve the ACP facades' existing empty-key null/no-op results when an
actor binding is supplied, and retain trimmed reader keys without turning
valid missing entries into null. Empty mutations never invoke their mutator.
The released one-argument SDK contracts remain unchanged.

The read, write, and normalization controls failed before repair. Actor
and native reader suites passed 16 tests, and actor/native writer suites
passed 20 tests. Fresh P2 review against the integrated main base is clean.
steipete added a commit that referenced this pull request Oct 4, 2026
Merge main to resolve session admission and event-test conflicts. Preserve the qualified worker-backed admission owner from #164682 and main's consolidated tests, awaiting asynchronous event handling where required. Reuse internal-effects filtering across both Gateway read paths.\n\nThe complete candidate is clean through P2 autoreview. Focused conflict tests and remaining changed-check and published-driver update gates are tracked on #165028.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…hority (openclaw#164682)

Move initial chat-session and membership preparation through existing database
workers, retaining current caller and physical-session authority through admission
and commit. Combine main's placement preparation without awaiting inside the
synchronous authority consumer; refresh placement for a fresh Goal incarnation.
Preserve distinct preparation, invocation, and accepted-input
lifetimes; keep agent-specific global sessions independent; clear matching retry
reservations and join started work before releasing custody.

Adopt and improve Galin Iliev's contributor work from openclaw#156941 through openclaw#164682.
Preserve released synchronous SDK contracts and qualify real Gateway/provider
behavior, durable transcript ownership, zero-caller-SQL lookup boundaries, and
source-derived regression controls. The later synchronous reply lifecycle read
and investigated historical timeout/cleanup observations remain documented
follow-ups; no inherited-failure exception is used for landing.

Co-authored-by: Galin Iliev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: XL 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