Skip to content

fix(agents): resolve authoritative session keys for delegated compaction - #120047

Merged
steipete merged 2 commits into
mainfrom
codex/fix-119018-compaction-sessionkey
Aug 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-119018-compaction-sessionkey

Conversation

@steipete

@steipete steipete commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a plugin owns the contextEngine slot and delegates compaction back to the runtime, every LLM compaction fails as outcome=failed reason=unknown. Two independent defects: the sessionId UUID was silently substituted for a missing sessionKey (three layers deep), so the sqlite transcript write matched no row; and the failed append collapsed into a generic no-cause error, leaving the operator zero diagnostic signal.

Fixes #119018 (reported by @abacha).

Why This Change Was Made

Provenance: 4273ca9dbd9b3 added the bare sessionId fallback in run-session-target.ts; 40dafc5c332d added the compatibility projection that strips sessionKey/sessionTarget for undeclared engines — together they let a UUID masquerade as a session key.

The repair establishes two explicit ownership boundaries instead of patching the symptom:

  1. resolveAgentRunSessionTarget now requires explicit intent — missingSessionKey: "create" | "resolve-existing". Only new-run admission (runEmbeddedAgent, whose public input legitimately permits an omitted key) may mint a canonical agent-scoped key. Every keyed-store consumer (compaction, persistence, locks, successor paths) resolves the authoritative key through the session store or throws a typed session-key-missing error. All compaction-side ?? sessionId sentinels were removed (queued/direct compaction, hooks, CLI compaction, recovery targets, transcript rewrites, deferred maintenance).
  2. appendSqliteTranscriptEventSync returns Result<boolean, TranscriptEventAppendError>: missing-row and rebound-row outcomes carry typed codes and identity details; duplicate appends remain the load-bearing ok(false) no-op. SessionManager attaches the typed result as Error.cause, and compaction reports reason=transcript_persistence_failed instead of unknown.

Sibling surfaces checked: queued/manual, direct/delegated, overflow/timeout recovery, non-delegated engines (shared repaired seam), post-compaction maintenance, gateway manual compaction, Codex native compaction (separate keyed path, unaffected), Copilot (session-ID-owned lookup unaffected), ACPX (covered).

User Impact

Delegated context-engine compaction works. When transcript persistence genuinely fails, operators see a typed reason with row-identity detail instead of reason=unknown.

Evidence

  • Reproduced on baseline 9fdae501 before implementation.
  • Focused regression: OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/run-vitest.mjs src/agents/run-session-target.test.ts src/config/sessions/session-accessor.test.ts src/agents/sessions/session-manager.test.ts src/agents/embedded-agent-runner/compact-reasons.test.ts src/agents/embedded-agent-runner/compaction-runtime-context.test.ts src/agents/embedded-agent-runner/compact.hooks.test.ts — 5 shards, 319 tests passed (re-verified independently after review).
  • Touched-module suites: 8 shards, 361 tests passed. Custom runtime-store regression 25/25; final compaction regression 124/124.
  • pnpm tsgo:core, pnpm tsgo:core:test, targeted oxlint, plugin SDK API baseline: all passed.
  • Codex autoreview (gpt-5.6-sol, high), run twice (worker closeout + independent coordinator pass on the frozen diff): clean both times, no accepted/actionable findings.
  • Production +176/−51 (net +125: the two ownership boundaries above, justified per Repair Doctrine); tests +209/−53.
  • Risk: medium — cross-cutting session identity and a sync accessor return-contract change (both production consumers updated). Reviewer attention: legacy host-parameter projection, custom-store lookup through runtime config, typed error propagation through delegated compaction.

@steipete
steipete marked this pull request as ready for review August 6, 2026 20:33
@openclaw-barnacle openclaw-barnacle Bot closed this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot closed this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 6, 2026
@steipete
steipete merged commit a73910d into main Aug 6, 2026
2 checks passed
@steipete
steipete deleted the codex/fix-119018-compaction-sessionkey branch August 6, 2026 22:57
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 6, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 7, 2026
…ion (openclaw#120047)

* fix(agents): resolve authoritative session keys for delegated compaction

* refactor(agents): keep session-target resolution error class module-local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: delegated context-engine compaction gets the sessionId in place of sessionKey — every compaction fails as reason=unknown

1 participant