Skip to content

fix(sessions): stop retrying replaced delivery endpoints on every restart - #174278

Merged
steipete merged 6 commits into
mainfrom
steipete/perf-micro-endpoint-replaced-warnings-20260919
Oct 16, 2026
Merged

steipete merged 6 commits into
mainfrom
steipete/perf-micro-endpoint-replaced-warnings-20260919

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes saved sessions_send updates warning about a replaced endpoint on every Gateway boot. Recovery wrote a deduplicated notice but left the input interrupted, so every restart selected the same undeliverable work again.

User Impact

After recording a durable conversation notice, recovery cancels automatic delivery for reset, archived, or replaced endpoints. The accepted input remains stored. Permission and storage failures remain eligible for later recovery. Resend an update if it is still needed; recovery does not redirect it across an endpoint fence.

Warnings now include a hashed session key, input ID, age, endpoint side, and previous/current session identity and lifecycle generation. They do not include message content or raw session keys.

Why This Change Was Made

Reuse the existing worker-owned pending-input withdrawal operation and cancelled state. No schema, configuration, cache, or alternate delivery path is added. Save the notice before withdrawal: a crash between these writes can repeat cleanup, but cannot discard the input without a durable explanation. Existing identity checks do not establish authority to retarget a successor, so this change preserves them.

The restart test also exposed orphan repair rewinding past a notice omitted from model context. Repair now checks the already-loaded durable ancestry, including the exact rewind parent, before rewinding. When that tail contains an unloaded entry, it preserves the original conversation branch and leaves the current prompt unmerged. This retains the notice without injecting it into model context, loading more history, or replaying it.

Evidence

  • Before/after: one replacement warning per retained input on every recovery pass → one initial warning, zero on the next pass after settlement. No latency claim or benchmark.
  • The real SQLite pending-input regression fails on the original code: its notice is durable but the input stays interrupted. The fixed recovery file passes all 24 tests with fake timers (11.16 seconds wrapper wall time).
  • The notice-preservation regressions fail against the preceding repair code for notices before/after metadata and immediately before a later unanswered user message. All 17 boundary tests pass after the final fix (34.31 seconds wrapper wall time); the four embedded-attempt orphan sibling tests also pass.
  • The full Gateway two-restart test passed in CI run 38919789555 on final head d28abe4e9777 in 79.29 seconds. It verifies ordered recovery, retained cancelled receipts, permission/reset fences, no repeated replacement warning, and the visible original notice after subsequent turns and the second restart.
  • The complete CI workflow passed on exact head d28abe4e9777f8e304d03a3105828b5b85f0bb08, including production/test types, lint, guards, builds, and planned tests.
  • Targeted formatting, lint, and git diff --check pass. Independent Codex autoreview is scoped clean through P2, including the final assertion correction.

CI exposed the orphan-repair visibility defect while exercising the real restart flow; the original notice assertion remains intact. Broad validation stays in PR CI under the operator's local-compute limit. No Testbox/Crabbox lease was allocated, and no production deployment or state repair was performed.

Production delta: +84 / -10 lines (net +74). Growth implements the requested correlation fields, notice-before-withdrawal settlement, and protection against rewinding through unloaded notices. It reuses existing storage and transcript owners without adding a schema, cache, or alternate delivery path.

Review decisions: the requested diagnostic contract explicitly calls for a session-key hash, so the raw-session-key logging suggestion is not applied; input IDs, opaque session IDs, and lifecycle generations still provide correlation. The unnecessary real-timer override was removed from the persistence regression, which passes using the suite fake clock. The implementation and final test cleanup have independent review through P2.

Record a durable blocked-delivery notice before cancelling replay of inputs whose source or target was reset, archived, or replaced. Preserve accepted input data and all endpoint fences; leave permission and storage failures retryable. Add correlation identifiers without logging messages or raw session keys, and prove that a second recovery pass is silent.
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 16, 2026 13:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T14:52:34.019233Z 1d461b5 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 16, 2026
@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR cancels automatic recovery of replaced session endpoints after saving a conversation notice, while retaining the accepted input.

Example: The source of saved delivery saved-delivery changes generation from source-before-reset to source-after-reset.

  • Before: Every Gateway restart selects the interrupted input and warns again.
  • After: Recovery saves a notice, marks the input cancelled, and skips it on subsequent restarts.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production change is focused and supported by persisted-state coverage, but the exact-head cold-restart scenario remains red.
Proof confidence 🦐 gold shrimp (3/6) Ordinary contributor-proof gating is exempt for this maintainer-authored PR; exact-head CI nevertheless exercised real Gateway processes and provider sockets through two restarts, reaching the final history assertion failure recorded above.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The same undeliverable saved updates produce replacement warnings on every Gateway boot.
Reason: The maintainer-authored direction resolves a current owned defect while preserving saved content, existing permissions, and transient recovery.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it addresses a current recovery defect, but exact-head CI exposes a cold-restart test expectation that needs repair.

Priority: P2
Reviewed head: 5482090a843ea88b6250ee0f50f1e799554846da

Before merge

  • Check the replacement notice before the second restart (P2) - The new cancellation removes RESET_SOURCE_UPDATE from subsequent recovery passes, but the test still requires replacement-notice text in the final chat.history response after the second restart. Exact-head CI fails this assertion at line 356 after passing the cancelled-state and no-repeat-warning checks. Assert the initial conversation notice before restarting, retain the second-boot replay assertions, and verify the original persisted report separately if its continued accessibility is part of the contract.

Findings

  • [P2] Check the replacement notice before the second restart — src/gateway/gateway.sessions-send-recovery.test.ts:356
Agent review details

How this fits together

Gateway startup reads persisted sessions_send inputs, validates their original endpoints and current permissions, and either admits delivery or records a blocked-delivery notice.

flowchart TD
  A[Gateway startup] --> B[Persisted pending inputs]
  B --> C[Recovery owner]
  C --> D[Endpoint and permission checks]
  D --> E[Normal agent admission]
  D --> F[Durable conversation notice]
  F --> G[Existing withdrawal worker]
Loading

Technical review

Best possible solution:

Keep the existing notice-before-withdrawal implementation and repair the cold-restart assertions around initial notice persistence and subsequent replay suppression.

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

Current main visibly leaves endpoint-replaced inputs interrupted after recording their notice; the supplied persisted-input regression exercises that path, although no target code was run during this review.

Is this the best way to solve the issue?

The implementation fixes candidate settlement at the recovery owner using an existing worker operation, preserves accepted content and endpoint fences, and avoids another queue or schema.

Full review comments:

  • [P2] Check the replacement notice before the second restart — src/gateway/gateway.sessions-send-recovery.test.ts:356
    The new cancellation removes RESET_SOURCE_UPDATE from subsequent recovery passes, but the test still requires replacement-notice text in the final chat.history response after the second restart. Exact-head CI fails this assertion at line 356 after passing the cancelled-state and no-repeat-warning checks. Assert the initial conversation notice before restarting, retain the second-boot replay assertions, and verify the original persisted report separately if its continued accessibility is part of the contract.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Endpoint fences and blocked-delivery notices keeps the original intent (0d4037e: Recover accepted peer updates without reviving replaced sessions or predecessor execution authority.)
  • Transient recovery retries keeps the original intent (0ffb90a: Retry temporary admission and storage-readiness failures with the original saved delivery identity while keeping endpoint fences terminal.)
  • Repeated recovery of terminal inputs changes intended behavior with a stated reason (0d4037e: Blocked updates remained saved and inspectable; this PR explains why replay eligibility should end after a durable notice for replaced endpoints.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/session-send-recovery.test.ts --maxWorkers=1
  • pnpm test src/gateway/gateway.sessions-send-recovery.test.ts --maxWorkers=1
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0ffb90a adds src/gateway/session-send-recovery.ts:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0ffb90a19859; files: src/gateway/session-send-recovery.ts)
  • RoboClaw: Raw commit 0d4037e adds src/gateway/session-send-recovery.ts:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0d4037eea541; files: src/gateway/session-send-recovery.ts)

PR surface

Source +43, Tests +103, Docs +4. Total +150 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 52 9 +43
Tests 3 112 9 +103
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 168 18 +150

Labels

Label changes:

  • add P2: Repeated recovery of permanently fenced inputs causes warning noise and unnecessary startup work; the remaining repair is focused.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Repeated recovery of permanently fenced inputs causes warning noise and unnecessary startup work; the remaining repair is focused.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 October 16, 2026, 10:27 AM ET / 14:27 UTC.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels Oct 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 190929487c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/session-send-recovery.ts Resolved
@steipete
steipete merged commit 7593d68 into main Oct 16, 2026
152 of 153 checks passed
@steipete
steipete deleted the steipete/perf-micro-endpoint-replaced-warnings-20260919 branch October 16, 2026 15:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…tart (openclaw#174278)

* fix(sessions): settle replaced delivery endpoints after restart

Record a durable blocked-delivery notice before cancelling replay of inputs whose source or target was reset, archived, or replaced. Preserve accepted input data and all endpoint fences; leave permission and storage failures retryable. Add correlation identifiers without logging messages or raw session keys, and prove that a second recovery pass is silent.

* test(sessions): preserve cancelled delivery receipt assertions

* fix(sessions): preserve recovery notices during orphan repair

* test(sessions): assert typed recovery context messages

* fix(sessions): preserve notices at orphan rewind boundaries

* test(sessions): retain fake timers for recovery persistence
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 P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant