Skip to content

fix(auto-reply): serialize reply session initialization#96847

Merged
obviyus merged 1 commit into
mainfrom
codex/reply-session-conflict-fix
Jun 25, 2026
Merged

fix(auto-reply): serialize reply session initialization#96847
obviyus merged 1 commit into
mainfrom
codex/reply-session-conflict-fix

Conversation

@obviyus

@obviyus obviyus commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Telegram isolated-ingress replay could loop forever when reply-session initialization hit a repeated stale-snapshot conflict before the agent turn started. The conflict escaped as a retryable handler failure, so the same spooled Telegram update was released and replayed again.

Why This Change Was Made

The stale-snapshot guard was checking a snapshot that was read outside the session-store writer queue. Multiple same-session initializers could compute from the same entry and then race through the guarded commit. This makes the snapshot read and guarded commit one logical writer-lane operation, while allowing the nested commit path to re-enter the same store writer without deadlocking.

User Impact

Telegram turns no longer get stuck replaying the same spooled update because normal in-process session initialization now serializes before reading the guarded snapshot. True external/cross-process conflicts still fail loudly through the existing guard.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jun 25, 2026
@clawsweeper

clawsweeper Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 25, 2026, 3:31 PM ET / 19:31 UTC.

Summary
The PR serializes reply-session initialization inside the session-store writer lane, adds an explicit same-store reentrant writer path, and adds concurrency regression coverage.

PR surface: Source +84, Tests +114. Total +198 across 7 files.

Reproducibility: yes. at source level: current main reads the reply-session initialization snapshot before the guarded commit serializes the store mutation, allowing same-session initializers to share a stale revision. I did not run the failing path locally because this was a read-only review.

Review metrics: 2 noteworthy metrics.

  • Internal writer reentrancy surface: 1 option added. The new reentrant writer option changes queue ownership semantics and should be reviewed before merge.
  • Cited broad gate proof: 1 referenced run cancelled. The PR body's check:changed action link is not a completed pass, so maintainers should refresh broad validation before landing.

Stored data model
Persistent data-model change detected: serialized state: src/auto-reply/reply/session.test.ts, serialized state: src/auto-reply/reply/session.ts, serialized state: src/config/sessions/session-accessor.ts, serialized state: src/config/sessions/store-writer.test.ts, serialized state: src/config/sessions/store-writer.ts, serialized state: src/config/sessions/store.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Have the session/reply owner confirm the reentrant writer boundary before undrafting.
  • Refresh the broad check:changed evidence because the PR body's linked Testbox run is cancelled.

Mantis proof suggestion
A redacted Telegram live transcript would materially help confirm the visible reply path while owner review covers the core writer boundary. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram live: verify that concurrent Telegram replies hitting reply-session initialization no longer hot-loop and the SUT sends one redacted threaded reply.

Risk before merge

Maintainer options:

  1. Owner-review the writer boundary before landing (recommended)
    Have the session/reply owner confirm the same-lane AsyncLocalStorage reentrancy and lock scope are intentional, then undraft and merge after validation refresh.
  2. Narrow the locked section first
    If maintainers do not want the whole initialization path under the writer lane, move only snapshot read, decision, and guarded commit into the serialized section before merge.
  3. Pause behind the broader Telegram conflict PR
    If maintainers prefer the broader Telegram spool/backoff path as the canonical fix, pause this PR until fix(telegram): topic replies stall after session conflicts #96550 is resolved.

Next step before merge

  • [P2] The PR is draft with a protected maintainer label and needs owner review of the reentrant writer boundary; there is no narrow automated repair finding.

Security
Cleared: No concrete security or supply-chain concern was found; the diff touches session-store runtime serialization and tests, not workflows, dependencies, secrets, or package execution paths.

Review details

Best possible solution:

Land this after session/reply owner review confirms the reentrant writer scope and refreshed validation, while keeping Telegram spool backoff and skillsSnapshot fixes tracked separately.

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

Yes, at source level: current main reads the reply-session initialization snapshot before the guarded commit serializes the store mutation, allowing same-session initializers to share a stale revision. I did not run the failing path locally because this was a read-only review.

Is this the best way to solve the issue?

Yes, this appears to be the right owner-boundary fix for the in-process race because it keeps the snapshot read and guarded commit in the session-store writer lane. The remaining judgment is whether the broader writer scope is acceptable or should be narrowed before landing.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1aa7cafc35a1.

Label changes

Label changes:

  • add mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The fix changes Telegram-visible reply delivery behavior because successful proof should show replies no longer hot-loop or stall after session initialization conflicts.

Label justifications:

  • P1: The PR targets a user-facing Telegram replay loop that can keep a channel workflow stuck behind repeated reply-session initialization conflicts.
  • merge-risk: 🚨 session-state: The diff changes the serialization boundary for reply-session initialization and nested session-store commits, which can affect session identity and rollover state.
  • merge-risk: 🚨 availability: The diff changes writer reentrancy and queue ownership duration, so a mistake could stall reply-session initialization.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes live-output style proof for focused tests, a Telegram bot-to-bot mock SUT E2E reply, and the Real behavior proof check passed on the PR head.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes live-output style proof for focused tests, a Telegram bot-to-bot mock SUT E2E reply, and the Real behavior proof check passed on the PR head.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The fix changes Telegram-visible reply delivery behavior because successful proof should show replies no longer hot-loop or stall after session initialization conflicts.
Evidence reviewed

PR surface:

Source +84, Tests +114. Total +198 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 121 37 +84
Tests 2 114 0 +114
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 235 37 +198

What I checked:

Likely related people:

  • jalehman: Recent main history shows repeated session-accessor work and the guarded reply-session initialization boundary this PR changes. (role: reply-session initialization feature-history contributor; confidence: high; commits: 95e37f8e9517, 7e2b2d2987b2, b58e6e0734f2; files: src/auto-reply/reply/session.ts, src/config/sessions/session-accessor.ts)
  • vincentkoc: Path history shows this contributor introduced the shared store-writer queue and adjacent session writer abstractions now gaining reentrancy. (role: shared store-writer queue contributor; confidence: medium; commits: 27e13933c0f3, 884a6a113ccf, e3058efa1042; files: src/shared/store-writer-queue.ts, src/config/sessions/store-writer.ts, src/config/sessions/store.ts)
  • obviyus: Beyond this PR, path history shows recent merged work in Telegram polling recovery and isolated-ingress behavior related to the user-visible replay loop. (role: recent Telegram isolated-ingress contributor and current fix author; confidence: medium; commits: dc09324ec2e1, d4819948f37d, 0b26a1bca728; files: extensions/telegram/src/polling-session.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 25, 2026
@obviyus
obviyus force-pushed the codex/reply-session-conflict-fix branch from 7d6b1ec to 1c229d4 Compare June 25, 2026 19:19
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Jun 25, 2026
@clawsweeper
clawsweeper Bot temporarily deployed to qa-live-shared June 25, 2026 19:34 Inactive
@obviyus
obviyus marked this pull request as ready for review June 25, 2026 20:09
@obviyus
obviyus force-pushed the codex/reply-session-conflict-fix branch from 1c229d4 to a7e88b4 Compare June 25, 2026 20:10
@obviyus
obviyus merged commit d2da8c7 into main Jun 25, 2026
16 checks passed
@obviyus
obviyus deleted the codex/reply-session-conflict-fix branch June 25, 2026 20:10
@obviyus

obviyus commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Landed via rebase onto main.

  • Scoped tests: node scripts/run-vitest.mjs src/config/sessions/store-writer.test.ts src/auto-reply/reply/session.test.ts
  • Changelog: release-owned, not updated for this direct fix PR
  • Land commit: a7e88b4
  • Merge commit: d2da8c7

This was referenced Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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