Skip to content

Add ACP session load event ledger - #79093

Merged
amknight merged 6 commits into
mainfrom
codex/acp-load-event-ledger
May 8, 2026
Merged

amknight merged 6 commits into
mainfrom
codex/acp-load-event-ledger

Conversation

@amknight

@amknight amknight commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

  • add an ACP event ledger with in-memory and file-backed storage for bridge sessions
  • replay complete ledger-backed ACP history in loadSession, with older or incomplete sessions still falling back to Gateway transcript replay
  • update ACP docs and changelog

Verification

  • pnpm test src/acp/event-ledger.test.ts src/acp/translator.event-ledger.test.ts src/acp/translator.session-rate-limit.test.ts src/acp/translator.lifecycle.test.ts src/acp/translator.stop-reason.test.ts
  • pnpm test:changed
  • pnpm check:changed
  • pnpm check:docs
  • git diff --check origin/main...HEAD

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels May 7, 2026
@clawsweeper

clawsweeper Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Summary
Adds an ACP event ledger with in-memory/file-backed storage, ledger-first loadSession replay, canonical session-key reconciliation, tests, docs, and changelog coverage.

Reproducibility: not applicable. to the feature as a user bug; yes for the PR-introduced regression path by source inspection. A send accepted before a Gateway disconnect can finish through agent.wait while the bridge records no missed chat/tool events, then loadSession trusts the complete ledger.

Real behavior proof
Not applicable: Not applicable because this is a maintainer-authored PR; the author did post real Gateway plus ACP stdio E2E output for the latest head, but the external-contributor proof gate does not apply.

Next step before merge
A narrow ACP translator/test repair can address the remaining merge blocker by invalidating ledger replay after disconnect/reconcile stream gaps.

Security
Cleared: No workflow, dependency, install, or supply-chain change was found; the new local ledger uses the OpenClaw state directory with file locking, 0700 parent dirs, 0600 writes, and a byte cap.

Review findings

  • [P2] Mark ledger replay incomplete after stream gaps — src/acp/translator.ts:707-709
Review details

Best possible solution:

Keep the ledger-backed replay approach, but invalidate ledger completeness whenever the bridge may have missed Gateway stream events so loadSession falls back to the Gateway transcript.

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

Not applicable to the feature as a user bug; yes for the PR-introduced regression path by source inspection. A send accepted before a Gateway disconnect can finish through agent.wait while the bridge records no missed chat/tool events, then loadSession trusts the complete ledger.

Is this the best way to solve the issue?

No. Ledger-first replay is a maintainable direction, but this PR should first mark affected ledgers incomplete or force transcript fallback after stream gaps.

Full review comments:

  • [P2] Mark ledger replay incomplete after stream gaps — src/acp/translator.ts:707-709
    After a Gateway disconnect, reconcilePendingPrompt can finish a run via agent.wait without the bridge receiving missed chat/tool stream events. Because loadSession now skips sessions.get whenever the ledger is complete, a later load can replay only ledgered prompts/snapshots and omit assistant or tool output that still exists in the Gateway transcript. Mark affected ledger sessions incomplete when the stream is interrupted, or otherwise force transcript fallback for those sessions.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.86

Acceptance criteria:

  • pnpm test src/acp/translator.event-ledger.test.ts src/acp/event-ledger.test.ts
  • pnpm test src/acp/translator.lifecycle.test.ts src/acp/translator.session-rate-limit.test.ts src/acp/translator.stop-reason.test.ts
  • pnpm exec oxfmt --check --threads=1 src/acp/translator.ts src/acp/translator.event-ledger.test.ts src/acp/event-ledger.ts src/acp/event-ledger.test.ts

What I checked:

  • Protected maintainer PR: The live pull request is open, authored by a MEMBER, and carries the protected maintainer label, so it should not be cleanup-closed by this review. (33f710024405)
  • Current main baseline: Current main documents loadSession as replaying stored user/assistant text only; the ledger implementation is new to this PR. Public docs: docs/cli/acp.md. (docs/cli/acp.md:47, a1ac559ed7e6)
  • Ledger replay bypasses transcript fallback: The PR skips sessions.get whenever ledgerReplay.complete is true, making ledger completeness the gate for avoiding Gateway transcript fallback. (src/acp/translator.ts:707, 33f710024405)
  • Disconnect reconciliation still does not invalidate the ledger: reconcilePendingPrompt can finish a prompt from agent.wait status ok without marking the ledger incomplete, so missed stream updates can remain hidden by a complete ledger. (src/acp/translator.ts:1438, 33f710024405)
  • Normal replay and retention coverage exists: New tests cover normal ledger replay, rejected sends, write-failure incompleteness, canonical session-key preservation, retention trimming, reset, and file-backed persistence, but not the disconnect/reconcile stream-gap path. (src/acp/translator.event-ledger.test.ts:75, 33f710024405)
  • Contributor E2E update: The author posted an E2E update for 33f710024405edcac6bcee4865ca85a9e053caf5 showing real Gateway plus real openclaw acp stdio clients replaying two ledger-backed turns and fixing canonical key mismatch, but that proof does not cover Gateway disconnect recovery. (33f710024405)

Likely related people:

  • amknight: Commit 6a8b4e422e82 introduced the current-main ACP lifecycle handlers adjacent to loadSession, and this PR implements the new ledger behavior in the same surface. (role: recent ACP lifecycle maintainer; confidence: high; commits: 6a8b4e422e82, 33f710024405; files: src/acp/translator.ts, src/acp/session.ts, src/acp/event-ledger.ts)
  • vincentkoc: Current-main blame attributes the nearby disconnect/reconcile helper block in src/acp/translator.ts to Vincent Koc's recent commit, making this a useful secondary routing candidate for stream-gap behavior. (role: adjacent ACP translator maintainer; confidence: medium; commits: 8e88c7b29768; files: src/acp/translator.ts)

Remaining risk / open question:

  • The latest E2E proof covers normal multi-process ledger replay but not the Gateway disconnect plus agent.wait reconciliation path that can miss stream events.
  • One GitHub check run was still in progress during review, though no failing check runs were observed.

Codex review notes: model gpt-5.5, reasoning high; reviewed against a1ac559ed7e6.

@amknight

amknight commented May 7, 2026 •

Copy link
Copy Markdown
Member Author
Severity Issue
Medium Fire-and-forget void this.recordUserPrompt(...) — if this disk write fails, the session stays marked complete: true but the replay will be missing the user prompt. A "complete" replay that jumps straight to tool calls.
Medium No byte-size cap on the ledger file — 200 sessions × 5000 events of full SessionUpdate payloads (including tool results with file contents) could produce a very large JSON file with no upper bound.
Medium trimLedger runs on every appendUpdate — full store serialization + atomic write on every event, plus a scan of all sessions for trimming. Could be deferred to threshold crossings.
Low Multi-process file races — two ACP servers sharing ~/.openclaw will silently discard each other's ledger writes.
Low readReplayBySessionId bypasses sessionKey check — intentional for discovery, but could serve stale events if sessionId is reused with a different key.
Low Missing tests for readReplayBySessionId, session eviction, reset flag, and multi-block prompt recording.

Re-review progress:

@amknight
amknight marked this pull request as ready for review May 8, 2026 00:09
@amknight

amknight commented May 8, 2026 •

Copy link
Copy Markdown
Member Author

E2E validation update for 33f710024405edcac6bcee4865ca85a9e053caf5:

  • Ran a local isolated real Gateway process plus real openclaw acp stdio clients. The model provider was a deterministic local OpenAI Responses mock so the ACP/Gateway path was real and repeatable.
  • First ACP process: initialize negotiated protocol 1, newSession created 5673c7cd-66f7-4d26-9d40-72fddc2d3426, first session/prompt returned end_turn, and ACP received agent_message_chunk text OPENCLAW_E2E_OK_1.
  • session/list returned canonical Gateway key agent:main:acp:5673c7cd-66f7-4d26-9d40-72fddc2d3426.
  • Second ACP process: loadSession using that listed Gateway key replayed the ledger user text and assistant text for OPENCLAW_E2E_OK_1, then a second prompt returned end_turn with OPENCLAW_E2E_OK_2.
  • Third ACP process: loadSession replayed both turns from the ledger. Ledger evidence: complete: true, canonical sessionKey, eventCount: 9, update sequence included both user_message_chunk and agent_message_chunk for both prompts. Mock OpenAI request log had exactly 2 model requests.

This E2E initially exposed a real mismatch: ACP tracked the provisional acp:<uuid> key while Gateway finalized/broadcast using agent:main:acp:<uuid>, so the prompt could hang even though Gateway had persisted the assistant response. The latest commit fixes that by reconciling pending prompts by runId and preserving ledger history when the session key becomes canonical.

Re-review progress:

@amknight
amknight merged commit b1eedb2 into main May 8, 2026
111 checks passed
@amknight
amknight deleted the codex/acp-load-event-ledger branch May 8, 2026 03:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* Add ACP session load event ledger

* Record ACP prompts after send acceptance

* Support ACP ledger replay by session key

* Harden ACP ledger replay completeness

* Harden ACP ledger review gaps

* Fix ACP canonical session key handling

---------

Co-authored-by: Alex Knight <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* Add ACP session load event ledger

* Record ACP prompts after send acceptance

* Support ACP ledger replay by session key

* Harden ACP ledger replay completeness

* Harden ACP ledger review gaps

* Fix ACP canonical session key handling

---------

Co-authored-by: Alex Knight <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* Add ACP session load event ledger

* Record ACP prompts after send acceptance

* Support ACP ledger replay by session key

* Harden ACP ledger replay completeness

* Harden ACP ledger review gaps

* Fix ACP canonical session key handling

---------

Co-authored-by: Alex Knight <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant