Skip to content

fix(sessions): preserve authority during concurrent first use - #200474

Closed
RomneyDa wants to merge 3 commits into
mainfrom
fix/session-first-use-receipts
Closed

RomneyDa wants to merge 3 commits into
mainfrom
fix/session-first-use-receipts

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

First-use session acquisition can lose retained authority while the agent database is being created. Two deterministic orderings exposed missing registration delivery: concurrent borrowers that both captured absence, and a borrower joining an opening that began without observers.

User Impact

Concurrent requests creating their first session retain their original authorization through shared database registration. Database replacement and revocation checks remain unchanged. No configuration or migration is needed.

Why This Change Was Made

Observe registration through the existing execution owner before queued preparation, retaining callback context and failures per borrower. Keep the notification wrapper even when opening starts without listeners so a borrower joining before registration completes receives the receipt. Release the observer after acquisition.

No startup ordering or registry acceptance rules are weakened. The two deterministic receipt defects are fixed, but the original xAI chat.send authorization failure remains unresolved: it passed an earlier replay and recurred during the November 17 follow-up verification. Auto-merge is disabled; this PR is not ready to land.

Evidence

  • Both-captured-absence barrier regression fails before receipt sharing and passes with the owner fix.
  • Late-observer barrier regression fails on the initial repair because the listener receives zero receipts; removing the zero-listener fast path makes it pass.
  • Earlier proof: original xAI Gateway test and all 18 creation/settlement tests passed (19 total), with proxies unset and private fixture permissions. The later original-entry replay failed with SESSION_MUTATION_AUTHORIZATION_CHANGED before the added public sessions.create/read assertions ran. Those new assertions remain unproven and were saved separately, not committed. No timeout or assertion was relaxed.
  • Final sibling proofs pass: 18 creation/settlement, 19 async-capture, and 30 creation-witness tests (67 total), including replacement/revocation cases. Type-aware lint, formatting, and canonical core typecheck pass. The final witness replay also preserves the captured-creating-reference error contract.

CI correction and remaining blocker

  • CI run 44038280539 failed check-test-types-core-4 because the cleanup-only execution double in src/trajectory/runtime-retention.test.ts omitted the new required observeRegistration method. The aggregate ci-gate failure followed that leaf failure.
  • Reproduced the exact TS2322 locally, completed the mock without weakening the production type, and reran all six type graphs from that stripe successfully. All three retention tests and targeted lint/format checks pass. Updated-head remote CI is still required.
  • ClawSweeper reported no actionable code findings. Its unranked proof score identified the missing shipped-flow evidence and the CI failure it could not inspect; neither is treated as cleared by a score alone.
  • Landing remains on hold for the recurring original xAI authorization failure and public sessions.create followed by read/turn evidence.

Independent review waived by the requesting maintainer; required qualification and CI gates remain.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Nov 17, 2026
@RomneyDa
RomneyDa enabled auto-merge (squash) November 17, 2026 07:25
@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 delivers shared database-registration receipts to session borrowers before their queued preparation begins.

Example: Two requests acquire agent:main:shared-first-use before main's database exists.

  • Before: A borrower can miss registration receipts and lose its otherwise valid session authority.
  • After: Both borrowers observe registration and retain their original authority through acquisition.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and source-consistent, but shipped-flow proof is absent and the failed test-type check remains unattributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent first-session requests can reject valid session authority while their shared database is being registered.
Reason: The reported orderings expose a concrete missing receipt path, and maintainer authorship establishes approval for this focused repair.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a source-supported first-use race, and no definite introduced code defect was found.

Priority: P2
Reviewed head: 45f20370b53b803234ee00517db8156c9eb03044

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide a redacted runtime trace of concurrent first-use sessions.create for an explicit non-main session in an isolated Gateway, followed by a successful read or turn, including the original chat.send failure scenario.
Agent review details

How this fits together

Session actor acquisition connects prepared Gateway session authority to the shared agent database execution owner, which admits worker operations and publishes registration receipts.

flowchart TD
  A[Gateway session request] --> B[Prepared session authority]
  B --> C[Session actor acquisition]
  C --> D[Shared execution owner]
  D --> E[Database worker registration]
  E --> F[Borrower receipt observers]
  F --> B
Loading

Technical review

Best possible solution:

Keep receipt delivery in the existing execution owner, with borrower-scoped failures and cleanup while preserving native admission checks.

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

Source shows receipt delivery attached too late for queued or already-opening borrowers, and the PR reports red-to-green regressions for both orderings; this read-only review ran no target code.

Is this the best way to solve the issue?

The change repairs receipt delivery at the shared execution owner without weakening registry acceptance, adding retries, or changing storage formats.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced patch: The pinned introduction diff installs registration observation before preparation and releases it after acquisition; the execution owner broadcasts receipts while preserving each observer's context and failure. (src/config/sessions/session-actor-durable.ts:165, 45f20370b53b)
  • Distinct regression scenarios: The added regressions exercise two borrowers capturing absence and a borrower joining an opening started without observers, using real execution and storage owners with scheduling barriers. (src/gateway/session-sharing-preparation.creation-settlement.test.ts:53, 45f20370b53b)
  • Current main still needs the change: Fetched main retains the original acquisition and preparation behavior; its comparison with the merge base contains no changes to the four affected production files. (src/config/sessions/session-actor-durable.ts:160, f41651d3acb2)
  • Gateway proof contract: The scoped policy requires public sessions.create in an isolated Gateway with an explicit non-main session, followed by a read or turn; helper tests alone do not establish that flow. (src/gateway/AGENTS.md, 45f20370b53b)
  • Supplied proof: The full PR body reports barrier regressions and an xAI Gateway test passing, but supplies no runtime trace or artifact of the changed shipped flow; both discussion comments are review-status messages. (45f20370b53b)
  • Unattributed CI failure: check-test-types-core-4 failed on the reviewed head. Its annotation reports only exit code 2; the job-log download redirects to a host blocked by this review environment, so no patch attribution is established. (45f20370b53b)

Likely related people:

  • Peter Steinberger: Raw commit 161f76d adds src/config/sessions/session-actor-durable.ts:132 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 161f76d795a5; files: src/config/sessions/session-actor-durable.ts)

PR surface

Source +78, Tests +130. Total +208 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 84 6 +78
Tests 1 130 0 +130
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 214 6 +208

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.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +84/-6; tests +130/-0 The production growth supplies receipt delivery before queued preparation, caller-context isolation, and observer cleanup; the tests protect two distinct registration orderings.

Labels

Label changes:

  • add P2: The fix addresses session acquisition failures under specific concurrent first-use orderings, without evidence of widespread release impact.
  • add merge-risk: 🚨 compatibility: The patch adds observeRegistration to the SDK-exported execution type; the existing host implementation supplies it, and maintainer authorship approves the direction.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The fix addresses session acquisition failures under specific concurrent first-use orderings, without evidence of widespread release impact.
  • merge-risk: 🚨 compatibility: The patch adds observeRegistration to the SDK-exported execution type; the existing host implementation supplies it, and maintainer authorship approves the direction.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Supply runtime evidence for the Gateway scenario identified in the proof assessment.

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, 2:38 AM ET / 07:38 UTC.

@RomneyDa
RomneyDa disabled auto-merge November 17, 2026 08:17
@RomneyDa

Copy link
Copy Markdown
Member Author

Closing at the maintainer's request. The focused regressions demonstrate two first-use registration races, but we have not established that they caused the release failure actually encountered; the original xAI authorization failure still recurs. This repair will not be included in the release. Preserving the branch and reproduction evidence for diagnosis; no branch deletion requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M 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