Skip to content

Fix durable OpenClaw chat turn coordination#356

Open
Jurij89 wants to merge 14 commits intomainfrom
codex/fix-chat-turn-durable-coordination
Open

Fix durable OpenClaw chat turn coordination#356
Jurij89 wants to merge 14 commits intomainfrom
codex/fix-chat-turn-durable-coordination

Conversation

@Jurij89
Copy link
Copy Markdown
Contributor

@Jurij89 Jurij89 commented Apr 30, 2026

Summary

  • Coordinate successful OpenClaw chat-turn persists through durable ChatTurnWriter state: W4b counts flush synchronously after daemon success, and direct-channel writes record exact, content-bound external markers.
  • Keep reset/compaction, W4a replay, W4b internal hooks, and Node-UI/direct channel paths aligned on the same restart-safe coordination file without adding daemon-wide semantic deduplication.
  • Wire DkgChannelPlugin to notify the writer only after daemon persist success, retry marker-only failures without replaying daemon writes, track first marker writes before awaiting them, drain marker jobs on shutdown with a bounded wait, preserve returned reply session keys, require legacy route fallbacks to return their real session key before writing a marker, and keep marker migration retries idempotent.

Related

Files changed

File What
packages/adapter-openclaw/src/ChatTurnWriter.ts Adds synchronous durable state commits, content-bound exact external direct-channel markers, reset/compaction gating, migration-safe marker writes, idempotent marker migration retries, and W4a/W4b coordination fixes.
packages/adapter-openclaw/src/DkgChannelPlugin.ts Notifies the writer after successful direct-channel persists, tracks first marker writes, retries marker-only failures, drains marker jobs on stop, preserves returned session keys, and avoids guessed legacy fallback session keys.
packages/adapter-openclaw/src/DkgNodePlugin.ts Passes the writer instance into the channel plugin so direct-channel persists can mark durable writer state.
packages/adapter-openclaw/src/types.ts Extends adapter API typing for route/session keys used by marker persistence and replies.
packages/adapter-openclaw/test/ChatTurnWriter.test.ts Covers reset, W4b crash/restart durability, external marker replay, reused correlation IDs, migration retry idempotence, and bounded state-write edge cases.
packages/adapter-openclaw/test/dkg-channel.test.ts Covers direct-channel marker handoff, marker retry/stop behavior, first-marker shutdown drain, reply session-key preservation, canonical marker user text, and legacy route fallback handling.
packages/adapter-openclaw/test/plugin.test.ts Verifies UI-selected context graph recall remains visible through the plugin memory resolver.

Test plan

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/dkg-channel.test.ts -t "marker" -> 9 selected tests passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/dkg-channel.test.ts -t "routeInboundMessage fallback" -> 8 selected tests passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts -t "T83|T105|T97|T103|T102|T90" -> 6 selected tests passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts test/dkg-client.test.ts -> 250 tests passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw build -> passed.
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/plugin.test.ts -t "memory resolver reads the UI-selected CG" -> passed.
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts -> 84 tests passed; command exited 0 after a trailing Windows path warning.
  • pnpm build:runtime -> passed.
  • git diff --check -> passed with CRLF warnings only.
  • Post-push PR sweep: all review threads resolved; Codex Review, CodeQL, Build packages, Knip, and Analyze checks passed at e8b666b6. The remaining red monorepo matrix jobs are unrelated known-debt/spec-gap lanes sampled in network-sim, storage parity/private-store, CLI auth/keystore/autoupdater, and agent DID/workspace-config tests.

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 30, 2026

Follow-up pushed in c1df0c69 for both review comments.

Validation after the follow-up:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts test/dkg-client.test.ts -> 229 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw build -> passed
  • pnpm build:runtime -> passed
  • git diff --check -> passed with CRLF warnings only

Note: I retried pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts after this follow-up, but the local run failed before test collection because the local RPC at 127.0.0.1:9548 refused connections. The same command passed earlier in the PR run with 84 tests before the review-fix follow-up.

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 30, 2026

Review round 2 follow-up is pushed in 417afa73.

Validation after the follow-up:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts -t T96|T98 -> 2 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts test/dkg-client.test.ts -> 232 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw build -> passed
  • pnpm build:runtime -> passed
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts -> 84 passed
  • git diff --check -> passed with CRLF warnings only

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 30, 2026

Review round 3 follow-up is pushed in c090a81f.

Validation after this follow-up:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts -t "T99|retry only the ChatTurnWriter marker" -> 3 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts test/dkg-client.test.ts -> 234 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw build -> passed
  • pnpm build:runtime -> passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/plugin.test.ts -t "memory resolver reads the UI-selected CG" -> 1 passed
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts -> 84 passed
  • git diff --check -> passed with CRLF warnings only

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
@Jurij89
Copy link
Copy Markdown
Contributor Author

Jurij89 commented Apr 30, 2026

Review round 4 follow-up is pushed in 85384992.

Validation after this follow-up:

  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts -t "T82|T84|T85|T86|T91|T92|T93|T99" -> 9 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/ChatTurnWriter.test.ts test/dkg-channel.test.ts test/dkg-client.test.ts -> 234 passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw build -> passed
  • pnpm build:runtime -> passed
  • pnpm --filter @origintrail-official/dkg-adapter-openclaw exec vitest run test/plugin.test.ts -t "memory resolver reads the UI-selected CG" -> 1 passed
  • pnpm --filter @origintrail-official/dkg exec vitest run test/daemon-openclaw.test.ts -> 84 passed
  • git diff --check -> passed with CRLF warnings only

Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts Outdated
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/ChatTurnWriter.ts
Comment thread packages/adapter-openclaw/src/DkgChannelPlugin.ts Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Codex review completed — no issues found.

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

Labels

None yet

Projects

None yet

1 participant