Skip to content

feat(system-agent): durable rolling transcript with openclaw.chat.history - #111440

Merged
steipete merged 14 commits into
mainfrom
claude/custodian-durable-transcript-110896
Jul 19, 2026
Merged

steipete merged 14 commits into
mainfrom
claude/custodian-durable-transcript-110896

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #110896

What Problem This Solves

Ask OpenClaw conversations were process-local by design (8-session LRU in the gateway) — a restart, eviction, or reload erased the operator's exchange with the system agent. Admins could not revisit yesterday's setup conversation, and the model lost all cross-restart context.

Why This Change Was Made

Phase 4 of #110896 — the conversation becomes the machine's durable logbook:

  • Durable rolling transcript: completed turns (welcome + user/assistant pairs) persist to a bounded system-agent-transcript scope in the shared state DB (newest 1000 rows; scope reuse, no schema change). Only the engine's already-masked history is ever persisted — sensitive wizard replies are redacted before they enter history, so credentials structurally cannot reach the store.
  • openclaw.chat.history (additive operator.admin RPC, Swift/Kotlin clients regenerated): serves the transcript tail; the custodian UI renders it above an "Earlier" divider before the live welcome, with a bounded (15s) load that can never block chat.
  • Cross-restart model context: fresh engine sessions seed from the persisted tail (30 turns). reset: true writes a durable boundary marker — reset survives eviction and restarts without deleting the logbook; markers never appear in RPC output.
  • Session-ownership rework: the client-side transcript-wipe machinery is replaced by a slim volatile-session boundary — same-ownership transport swaps keep the rendered thread and rotate only wizard/approval state (capability-gated, with a persistent flag-backed unknown-outcome warning for abandoned non-idempotent turns); credential/gateway ownership changes clear and reload from the new gateway's history. Event nudges survive transient drops and clear only at real boundaries.

User Impact

The Ask OpenClaw thread persists across gateway restarts and reconnects — one continuous maintenance logbook per machine, with the model remembering prior exchanges. Sensitive input remains masked everywhere (live, persisted, and re-rendered history).

Evidence

Focused suites (all pass): server handler 29 (persist-on-turn, tail seeding, reset boundary, history limits/order, sensitive masking), transcript store 4 (append/tail/prune/reset marker with real SQLite reopen), custodian UI 42 across 6 files (history render + divider, rotation matrix: same-ownership swap, ownership change, unsupported gateway, transient drop, abandoned-turn warning, nudge survival), protocol schema 6, gateway chat 87; full UI shard 337 files / 4734 tests green post-rebase; pnpm protocol:check-equivalent regen clean.

Live proof on a session-owned dev gateway built from this branch (isolated state dir, port 19877, Anthropic key via 1Password env-injection):

  • openclaw.setup.detect found the env key; openclaw.setup.activate verified anthropic/claude-haiku-4-5 with a real completion (28s).
  • openclaw.chat welcome + a real agentic turn ("is my gateway healthy?" → live model reply).
  • Gateway restarted; openclaw.chat.history returned the full prior conversation — durability proven end-to-end.
  • Same session verified the landed journal stack live: CLI write, live hand-edit (exact path), invalid hand-edit (invalid: true), content-identical restore (opaqueChange), offline edit across restart (startup record), all visible via openclaw.changes.list; fingerprint key file created 0600.
  • Config-compat audit: phases A–D touch zero config schema/validation surfaces; openclaw doctor on a pre-program config reports no repairs (the doctor invariant holds — nothing to migrate).

Autoreview (codex/gpt-5.6-sol, xhigh): two-pass reviews (scanner-safe split) iterated through session-boundary, reset-durability, and resilience findings to convergence; the final flagged item (client-side re-masking of history) was consciously resolved by localizing the server's mask marker — the server-side masking guarantee is the boundary, proven by tests and the live run.

@openclaw-barnacle openclaw-barnacle Bot added app: android App: android app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Jul 19, 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: 7ca1e10ae4

ℹ️ 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 on lines +521 to +525
if (!params.reset) {
engine.seedHistory(
readTranscriptTail(SYSTEM_AGENT_SEED_HISTORY_LIMIT, { afterLastReset: true }).map(
({ role, text }) => ({ role, text }),
),

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.

P1 Badge Isolate durable context from delegated callers

Do not seed every fresh engine from the machine-wide transcript when params.delegation is present. The openclaw tool is exposed to regular, non-sandboxed agent runs through src/agents/tools/openclaw-delegate-tool.ts:59-73, and delegation sessions are otherwise isolated by resolveSystemAgentDelegationKey; with this unconditional seed, one agent/session's messages become model-visible history for another agent or the admin UI. Besides disclosing prior conversation text, an externally influenced delegated call can persist instructions that poison later system-agent sessions. Scope stored context by delegation identity, or omit shared transcript seeding for delegated sessions.

Useful? React with 👍 / 👎.

Comment on lines +139 to +145
function persistEngineHistory(engine: SystemAgentChatSession["engine"], startIndex: number): void {
const at = Date.now();
for (const turn of engine.historySince(startIndex)) {
// Engine history is authoritative here: sensitive user text has already
// been replaced by the mask marker before it crosses this boundary.
appendTranscriptTurn({ ...turn, at });
}

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.

P2 Badge Persist asynchronously resolved approval replies

Persist history added by delegated approval resolution, not only history added during an openclaw.chat RPC. When the approval manager later invokes engine.resolveOperatorApproval(...), that method appends a non-null assistant reply to engine history, but this helper is never called for that asynchronous path; the next chat call snapshots historyLength() after the reply, so it can never pick the omitted entry up. After an approved or denied delegated proposal, the durable transcript and post-restart model context therefore lose the approval outcome.

Useful? React with 👍 / 👎.

@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: a2b79463db

ℹ️ 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 on lines +522 to +525
engine.seedHistory(
readTranscriptTail(SYSTEM_AGENT_SEED_HISTORY_LIMIT, { afterLastReset: true }).map(
({ role, text }) => ({ role, text }),
),

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.

P1 Badge Seed durable history into the primary agent turn

For a fresh engine after restart or eviction, this seed never reaches the normal model path. resolveAssistantTurn invokes runAgentTurn with only the current input, overview, and a newly created agent session (src/system-agent/chat-engine.ts:697-718); that session receives a random ID and a new session file in src/system-agent/agent-turn.ts:70-81 and src/system-agent/agent-turn.ts:307-327. The seeded this.history is supplied only to the fallback planner at src/system-agent/chat-engine.ts:739-752. Consequently, whenever the primary embedded/CLI turn succeeds, it answers without the persisted conversation, so the advertised cross-restart model context is absent; seed the primary agent session or prompt as well.

Useful? React with 👍 / 👎.

@@ -578,7 +573,7 @@ export class CustodianPage extends OpenClawLightDomElement {
const client = this.activeClient;
const params = this.retryParams;
if (client && params && params.message === undefined && this.chatAvailable && !this.sending) {
void this.requestReply(client, params);
void this.initializeSession(client, params);

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.

P2 Badge Avoid duplicating a persisted welcome on retry

When the initial openclaw.chat completes server-side but its response times out or is lost, the welcome has already been persisted. Retrying now calls initializeSession with transcript loading enabled, so history reloads that welcome and the subsequent request with the same session ID returns the stored welcome again; appendAssistant then renders an identical second row after the “Earlier” divider. Skip the history refresh for a same-session welcome retry or deduplicate the replayed welcome.

Useful? React with 👍 / 👎.

@steipete
steipete force-pushed the claude/custodian-durable-transcript-110896 branch from a2b7946 to 58d97e9 Compare July 19, 2026 15:00

@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: 58d97e99e0

ℹ️ 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 on lines +550 to +551
if (params.reset) {
appendTranscriptReset();

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.

P2 Badge Record the reset boundary before fallible initialization

When a reset: true request arrives while inference verification or welcome construction fails, openclaw.chat has already removed and disposed the existing session, but execution returns before this marker is written. A later ordinary fresh request therefore seeds the replacement engine from the pre-reset durable transcript, undoing the reset across recovery or restart. Persist the boundary when the old session is reset, before the fallible inference/welcome steps.

Useful? React with 👍 / 👎.

Comment on lines +295 to +296
if (loadTranscript) {
await this.refreshTranscriptHistory(client, epoch);

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.

P2 Badge Do not serialize chat startup behind history loading

When openclaw.chat.history is slow or stops responding, this awaited refresh delays the welcome request for the full 15-second history timeout; sending also remains true, so the composer is disabled during that delay. This contradicts the additive-history behavior promised by refreshTranscriptHistory: a history failure eventually falls through, but it still blocks chat startup. Start the welcome independently of the bounded history read and reconcile the rows without delaying interaction.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 8c7f09a into main Jul 19, 2026
123 checks passed
@steipete
steipete deleted the claude/custodian-durable-transcript-110896 branch July 19, 2026 15:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 20, 2026
…tory (openclaw#111440)

* feat(system-agent): durable rolling transcript with openclaw.chat.history

* chore(ui): scanner-safe auth root in custodian session ownership key

* fix(system-agent): durable reset boundary for transcript seeding

* fix(ui): ownership-aware custodian session rotation with capability gating

* fix(ui): bounded history load and reconnect-safe transcript refresh

* fix(ui): keep unknown-outcome warning and event nudges across transport transitions

* fix(ui): flag-backed unknown-outcome warning independent of retry state

* fix(ui): armed ownership boundaries and abandon-before-rotate ordering

* chore(ui): localize the server-side sensitive mask in durable history

* fix(ui): repair rebase-dropped import and mock arity

* chore: gate fixes — void history handler, module-local transcript internals

* refactor(gateway): leaf history-turn contract to keep the module graph acyclic

* chore(gateway): stamp openclaw.chat.history with its introduction train

* test(gateway): record openclaw.chat.history in the 2026.7 train pin
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…tory (openclaw#111440)

* feat(system-agent): durable rolling transcript with openclaw.chat.history

* chore(ui): scanner-safe auth root in custodian session ownership key

* fix(system-agent): durable reset boundary for transcript seeding

* fix(ui): ownership-aware custodian session rotation with capability gating

* fix(ui): bounded history load and reconnect-safe transcript refresh

* fix(ui): keep unknown-outcome warning and event nudges across transport transitions

* fix(ui): flag-backed unknown-outcome warning independent of retry state

* fix(ui): armed ownership boundaries and abandon-before-rotate ordering

* chore(ui): localize the server-side sensitive mask in durable history

* fix(ui): repair rebase-dropped import and mock arity

* chore: gate fixes — void history handler, module-local transcript internals

* refactor(gateway): leaf history-turn contract to keep the module graph acyclic

* chore(gateway): stamp openclaw.chat.history with its introduction train

* test(gateway): record openclaw.chat.history in the 2026.7 train pin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant