Repository navigation
refactor(reply): unify turn lifecycle state ownership - #117145
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 9:46 PM ET / August 1, 2026, 01:46 UTC. ClawSweeper reviewWhat this changesCentralizes reply-turn and queued-follow-up lifecycle state in the canonical session-entry handle, removes cross-phase state bindings, and reuses the transcript-session comparator for restart recovery. Merge readinessKeep open for explicit maintainer review: this is a large, proof-backed lifecycle refactor, but it remains behind current Priority: P2 Review scores
Verification
How this fits togetherThe auto-reply pipeline turns inbound channel events into agent runs, queued follow-ups, and delivered replies while preserving session ownership through cancellation, restarts, and concurrency. This change sits between session persistence and reply delivery, where it decides whether a turn still owns the current session generation before it can update or clear state. flowchart LR
A[Inbound channel event] --> B[Reply dispatch pipeline]
B --> C[Canonical session-entry handle]
C --> D[Generation fence]
D --> E[Agent run and queued follow-up]
E --> F[Reply delivery settlement]
C --> G[Restart recovery claim]
G --> F
Decision needed
Why: The change intentionally restructures the state owner for message delivery and session recovery; the protected maintainer label requires an explicit human decision beyond automated proof. Before merge
Agent review detailsSecurityNone. PR surfaceSource -330. Total -330 across 12 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Refresh the branch onto current Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a lifecycle-owner refactor rather than a report of a currently failing user path. Its supplied real Gateway scenarios exercise the relevant delivery and restart behavior after the change. Is this the best way to solve the issue? Yes, conditionally: replacing duplicate generation/session ownership with the canonical session handle is a stronger owner-boundary design than retaining dynamic cross-phase bindings, provided the refreshed merged result preserves the existing delivery contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 51bf8f8eb8db. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
* commit '475ea69f2c356104f4b601f4976788081e79b8b4': refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143)
* origin/main: (3706 commits) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) fix(doctor): persist normalized agent roster (openclaw#117115) fix(signal): avoid replay after ambiguous quote delivery errors (openclaw#117134) fix(cron): reject disabled delivery accounts when scheduling (openclaw#116899) ...
* commit '7e78de747b8a64d52f30aee948b697bf4c528691': (359 commits) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) ...
* commit '6938f7dddb63bad59862c014c427d63f0a41a6f4': (368 commits) fix: allow gateway service commands for named profiles (openclaw#116314) fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041) fix(ollama): honor model requests and pull completion contracts (openclaw#117171) fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168) fix(telegram): confirm polling before long poll (openclaw#116970) fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949) fix(gateway): yield before post-ready background work (openclaw#117083) fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173) fix(teams): restore the official square product icon (openclaw#117170) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) ...
* refactor(reply): unify turn lifecycle state ownership * fix(reply): declare unbound-safe session getter contract
* commit 'fb6c4cf5b748d913839d0fe23dbcbbf89804b882': refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143)
* commit '5148236bbe050f6c05ee59190986a7215b41ce1c': (359 commits) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) ...
* commit '55215cd9edd2b585cbaee5481d5352aabf7e4399': (368 commits) fix: allow gateway service commands for named profiles (openclaw#116314) fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041) fix(ollama): honor model requests and pull completion contracts (openclaw#117171) fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168) fix(telegram): confirm polling before long poll (openclaw#116970) fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949) fix(gateway): yield before post-ready background work (openclaw#117083) fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173) fix(teams): restore the official square product icon (openclaw#117170) refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157) fix(ui): retire stale Gateway event-log observers (openclaw#117169) fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) ...
* origin/main: (3706 commits) refactor(ui): unify filtered session list ownership (openclaw#117158) refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149) fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957) refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150) refactor(reply): unify turn lifecycle state ownership (openclaw#117145) fix(ui): preserve emoji agent avatar initials (openclaw#104912) refactor(auto-reply): unify command and directive ownership (openclaw#117143) refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146) fix(messages): reply actions leak citation markers and reply/poll answers draw the no-reply fallback (openclaw#116909) fix(slack): let durable ingress retry transient thread lookups (openclaw#117135) refactor(doctor): consolidate shipped state migration ownership (openclaw#117142) fix(ai): Codex stream shows internal parser text on a malformed frame (openclaw#116966) fix: guard every migrated session accessor path (openclaw#117140) fix(terminal): measure unicode display width consistently (openclaw#117062) fix(openai): clear ChatGPT SSE fallback per session (openclaw#117123) fix(mistral): reject incomplete streamed tool terminals (openclaw#117137) fix(ai): preserve structured chat content and refusals (openclaw#117136) fix(doctor): persist normalized agent roster (openclaw#117115) fix(signal): avoid replay after ambiguous quote delivery errors (openclaw#117134) fix(cron): reject disabled delivery accounts when scheduling (openclaw#116899) ...
What Problem This Solves
Users rely on replies, queued follow-ups, restart recovery, and intentionally silent turns continuing to behave consistently as session state changes. The auto-reply pipeline previously spread ownership of these invariants across duplicate session handles, dynamic cross-phase accessors, and a second restart-state comparator, making lifecycle regressions and message loss harder to prevent.
Why This Change Was Made
This maintainer-requested cleanup moves generation-fenced queued-follow-up ownership into the existing canonical reply session handle, replaces cross-phase getter/setter shims with explicit hook, binding, routing, and progress state owners, and reuses the canonical transcript-session comparator for restart recovery. Existing generation fences, cancellation, compaction adoption, intentional silence, delivery settlement, and public reply contracts remain unchanged.
User Impact
No intended behavior change. Direct and channel replies, queued follow-ups, thread routing, deliberate
NO_REPLY, restart recovery, and concurrent session replacement remain protected by their existing contracts. Removes 330 handwritten production lines across 12 production files; no test lines removed.Evidence
Blacksmith Testbox baseline/operator proof:
tbx_01kyxck3ep0490m610vxbpj4h0(remote run); final-head lint, regression, and changed-gate proof:tbx_01kyxf2ph4eza6wz0bza3vjgn9(remote run).Clean baseline: 353 focused tests passed across reply admission, follow-up delivery, queue draining, restart recovery, and transport settlement.
Final changed tree: 851 tests passed, including the complete 311-case dispatch suite, 160 session cases, 92 queue/collect cases, 51 run-registry cases, 47 follow-up-delivery cases, 43 turn-admission cases, and 36 queued-follow-up generation cases. Explicit direct/group
NO_REPLYregressions passed.Generation-owner equivalence: 2,400 deterministic differential transitions matched the previous implementation exactly across adoption, stale updates, concurrent replacement/deletion, and compatibility-view writes/deletes.
Real ephemeral Gateway +
qa-channel+ mock OpenAI: 7/7 operator scenarios passed (dm-chat-baseline,channel-chat-baseline,thread-follow-up,rewritten-command-single-delivery,restart-recovery-memory-flush-lifecycle-proof,message-tool-stranded-final-reply,qa-channel-reconnect-dedupe). The run proved direct replies, intentional unmentioned-channel silence, group mentions, threaded placement, exactly-once rewritten-command delivery, forced memory-flush recovery, one-shot stranded-final retry, and a real Gateway restart with no replay.Forced memory-flush lifecycle verdict from the actual Gateway/channel run:
{"verdict":"PASS","channel":"qa-channel","provider":"mock-openai","gateway":"ephemeral-child","memoryFlush":{"kind":"succeeded","compactionCount":0},"parent":{"status":"done","abortedLastRun":false},"replyDelivered":true}Stranded final fault/retry:
recovered=1; stranded turns=1; retry delivery turns=1; WARN logged=true. Gateway restart markers:before=RECONNECT-FIRST-OK; after=RECONNECT-SECOND-OK.Full remote
corepack pnpm check:changed: production and test typechecks, lint, formatting, boundary guards, and dead-export checks pass on the final head.Exact whole-repository CI lint command
node scripts/run-oxlint-shards.mjs --threads=8also passes with zero warnings/errors across 24,197 core, plugin, and script files, including the unchanged follow-up caller receiving the unbound-safe session getter.Fresh independent structured review:
.agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main; zero accepted/actionable findings.Production delta:
+594 / -924 = -330 LOC; tests:0 LOC.AI-assisted; maintainer-requested architectural cleanup.