Skip to content

fix(agents): preserve context engine session ownership - #124376

Merged
steipete merged 2 commits into
mainfrom
steipete/confident-merkle-477685
Aug 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/confident-merkle-477685

Conversation

@steipete

@steipete steipete commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #123222

AI-assisted: yes (Codex).

What Problem This Solves

Fixes an issue where unbound legacy context-engine hooks could execute LLM calls as the configured default agent after runtime or compaction code replaced missing session ownership with a fallback agent. This completes the ownership repair begun in #123222 and addresses the failure exposed by the beta2 prerelease run.

Why This Change Was Made

The runtime now captures only the original pre-fallback explicit owner and original authority session key, then carries those facts through after-turn maintenance, queued and overflow compaction, recovery, post-compaction, and finalization. The context-engine LLM boundary remains the canonical authority resolver: explicit ownership, agent-scoped keys, the main alias, and persisted bindings resolve normally, while an arbitrary legacy key whose only agent came from default/fallback selection fails closed.

This adds 35 net production lines (+55/-20) to preserve and transport the ownership fact across the existing lifecycle boundary; tests add 220 net lines (+258/-38), including a bounded repair for a PID-file readiness race exposed by the first CI run. No config, protocol, storage schema, dependency, or changelog surface changes.

User Impact

Unbound legacy context-engine hooks no longer execute LLM calls under the default agent. Explicit, agent-scoped, main-alias, and persisted session ownership remain supported across normal turns, maintenance, queued compaction, overflow recovery, and finalization.

Evidence

  • Focused owner-boundary proof: 323 tests passed across session-agent binding, runtime LLM, context-engine maintenance, queued compaction, overflow recovery, attempt, and finalize lifecycle suites.
  • node scripts/check-changed.mjs --dry-run selected only core and coreTests.
  • node scripts/check-changed.mjs passed after rebase, including core production/test typechecks, targeted oxfmt and oxlint, max-lines ratchet (911 grandfathered suppressions), dead-export scan, plugin boundaries, database-first guard, runtime import cycles, and the remaining selected architecture guards. The remote fast-CI provider was unavailable, so the repository wrapper completed the gate through its supported local fallback.
  • First exact-head CI run 31923912893 exposed an unrelated current-main race in test/scripts/docker-all-scheduler.test.ts: the test waited for PID-file existence but could read between open/truncate and content write. The follow-up waits for a complete positive PID at both affected sites; node scripts/run-vitest.mjs test/scripts/docker-all-scheduler.test.ts then passed all 46 tests, and targeted oxfmt/oxlint passed.
  • git diff --check origin/main...HEAD passed on exact head 82e6228e7ce7949d7ea98982f53809efa5dd8f5e.
  • Fresh Codex autoreview of the final ownership diff and a second fresh review of the CI race repair both reported no accepted/actionable findings. The ownership rebase was conflict-free and did not change patch semantics.
  • Production LOC: +55/-20 (net +35). Tests: +258/-38 (net +220).

Release-note context: unbound legacy context-engine hooks no longer execute LLM calls under the default agent; explicit/scoped/persisted ownership remains supported.

Unbound legacy context-engine hooks no longer execute LLM calls under the default agent. Explicit, agent-scoped, main-alias, and persisted session ownership remain supported.
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling labels Aug 16, 2026
@steipete steipete self-assigned this Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 03:18
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 11:36 PM ET / August 16, 2026, 03:36 UTC.

ClawSweeper review

What this changes

The branch carries the original explicit session owner through context-engine maintenance and compaction so unbound legacy session keys cannot invoke LLM work as the default agent.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

This remains necessary: current main still forwards fallback-selected ownership into context-engine LLM capability creation. The PR preserves the original explicit owner across lifecycle paths and appears correct, but the intentional fail-closed compatibility boundary requires maintainer confirmation.

Priority: P1
Reviewed head: 82e6228e7ce7949d7ea98982f53809efa5dd8f5e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful lifecycle coverage; compatibility acceptance and exact-head CI remain merge gates.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored ownership repair is exempt from the external-contributor real-behavior-proof gate; its supplied evidence is focused boundary-test coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored ownership repair is exempt from the external-contributor real-behavior-proof gate; its supplied evidence is focused boundary-test coverage.
Evidence reviewed 7 items Current-main gap: Current main still supplies the active fallback-selected agent to after-turn context-engine capabilities; the PR replaces that input with the pre-fallback owner.
Owner-boundary implementation: The PR captures ownership before session-target fallback resolution and passes it into the prepared run lifecycle.
Canonical authority gate: The resolver accepts an explicit owner, scoped key, main alias, or persisted binding, and otherwise returns no owner; the capability then requires a bound agent.
Findings None None.
Security None None.

How this fits together

Embedded agent runs select a session and may perform after-turn maintenance or compaction through a context-engine plugin. That plugin receives an LLM capability which must be bound to the original session owner before it can select credentials and a model.

flowchart LR
  A[Incoming agent run] --> B[Session resolution]
  B --> C[Capture original explicit owner]
  C --> D[Maintenance and compaction lifecycle]
  D --> E[Bound ownership check]
  E --> F[Context-engine LLM call]
  E --> G[Reject unbound legacy key]
Loading

Decision needed

Question Recommendation
Should unbound legacy context-engine hooks fail closed rather than continue selecting the configured default agent? Accept fail-closed ownership: Land after exact-head checks are green and require affected legacy operators to provide an explicit or persisted session owner.

Why: The change narrows a credential and model-selection authority boundary; source establishes the bug and repair, but accepting the user-visible compatibility break is an owner decision.

Before merge

  • Resolve merge risk (P1) - Existing unbound legacy hooks will now receive an authorization failure instead of silently using the configured default agent; this is an intentional compatibility change requiring owner acceptance.
  • Resolve merge risk (P1) - The bug fix adds net production plumbing across lifecycle boundaries; it is justified by preserving the authority fact at its producer, but should remain the sole canonical propagation path.
  • Resolve merge risk (P1) - Exact-head CI is not complete in the supplied check rollup.
  • Complete next step (P2) - A maintainer must accept the intentional compatibility and security-boundary change; no narrow repair finding remains.
Agent review details

Security

None.

PR surface

Source +35, Tests +220. Total +255 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 17 55 20 +35
Tests 4 258 38 +220
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 313 58 +255

Review metrics

Metric Value Why it matters
Ownership propagation delta production +35 net, tests +220 net The production increase transports one authority fact across lifecycle boundaries; the substantial regression coverage spans each affected path.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-compaction-runner.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #124376
Summary: This PR is the remaining lifecycle repair after the resolver-level ownership fix merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the fail-closed boundary (recommended)
    Confirm that unknown legacy ownership must reject, then merge after the exact PR head is green.
  2. Pause for compatibility direction
    Hold the PR if operators must retain default-agent execution for an identified legacy workflow.

Technical review

Best possible solution:

Keep one pre-fallback ownership fact as the canonical authority input, merge only if maintainers accept the fail-closed legacy behavior, and require green exact-head checks.

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

Yes. Current main’s after-turn capability path supplies the fallback active agent, while the PR’s focused lifecycle tests encode the same unbound-key scenario; this read-only review did not run the tests locally.

Is this the best way to solve the issue?

Yes. Capturing the original explicit owner before fallback resolution and carrying it to the existing authority gate is safer than adding consumer-side checks after a fallback has already been accepted.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a0498f7a9c8a.

Labels

Label justifications:

  • P1: Fallback-selected default-agent execution by unbound context-engine hooks is an urgent agent authorization regression.
  • merge-risk: 🚨 compatibility: Merging intentionally changes unbound legacy hooks from default-agent execution to an authorization failure.
  • merge-risk: 🚨 security-boundary: The branch changes which session evidence is sufficient to select an agent for context-engine LLM work.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored ownership repair is exempt from the external-contributor real-behavior-proof gate; its supplied evidence is focused boundary-test coverage.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this lifecycle repair and the current-main multi-agent ownership refactor. (role: recent ownership-path contributor; confidence: high; commits: fbfc9be5ee23, 1ca60fbc3a3f; files: src/agents/embedded-agent-runner/run-orchestrator.ts, src/agents/session-agent-binding.ts)
  • vincentkoc: Authored the related merged strict session-ownership repair that this PR extends through lifecycle callers. (role: session-binding boundary contributor; confidence: high; commits: c00dd282db2f; files: src/agents/session-agent-binding.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the fail-closed legacy compatibility boundary and wait for exact-head checks to complete.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-16T03:23:54.918Z sha fbfc9be :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready on exact head 82e6228e7ce7949d7ea98982f53809efa5dd8f5e.

ClawSweeper before-merge items and rank-up move:

  • Compatibility boundary accepted: this maintainer-directed repair intentionally fails closed for arbitrary unbound legacy keys instead of executing context-engine LLM work as the default agent. Explicit ownership, agent-scoped keys, the main alias, and persisted bindings remain supported.
  • Exact-head validation is green: CI run https://github.com/openclaw/openclaw/actions/runs/31924345668 completed with openclaw/ci-gate successful and no pending selected checks.
  • The first run's checks-node-compact-small-40 failure was a current-main PID-file readiness race in test/scripts/docker-all-scheduler.test.ts, not an ownership regression. The test waited only for file existence and could read between open/truncate and content write. Commit 82e6228e7ce7949d7ea98982f53809efa5dd8f5e waits for a complete positive PID at both affected sites; the exact 46-test file passed locally and the rerun is green.
  • Production growth remains one canonical pre-fallback contextEngineAgentId fact carried through existing lifecycle structures into resolveBoundAgentIdForSession; no parallel ownership resolver or fallback path was added.
  • The review's serialized-data-model note is not applicable: src/gateway/server-methods/sessions-compaction-runner.ts only forwards the in-memory explicit owner into compaction. No stored shape, SQLite schema/version, migration, config, protocol, or sidecar changed.

Proof:

  • Focused ownership/lifecycle suites: 323 tests passed across session-agent binding, runtime LLM, maintenance, queued compaction, overflow recovery, attempt, and finalize paths.
  • node scripts/check-changed.mjs --dry-run selected core and coreTests for the ownership patch.
  • node scripts/check-changed.mjs passed after rebase, including core production/test typechecks, targeted formatting/lint, max-lines ratchet, dead exports, plugin boundaries, database-first, import-cycle, and selected architecture guards. Crabbox reported no ready fast-CI provider, so the repository wrapper used its supported local fallback.
  • node scripts/run-vitest.mjs test/scripts/docker-all-scheduler.test.ts — 46 passed.
  • node_modules/.bin/oxfmt --check test/scripts/docker-all-scheduler.test.ts — passed.
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.scripts.json test/scripts/docker-all-scheduler.test.ts — passed.
  • git diff --check origin/main...HEAD — passed.
  • .agents/skills/autoreview/scripts/autoreview --mode local — clean for the CI race repair; the preceding final ownership-diff autoreview was also clean with no accepted/actionable findings.

Production LOC: +55/-20 (net +35). Tests: +258/-38 (net +220).

Known proof gap: no live provider/channel run was used; this is a deterministic internal authorization-boundary repair with focused owner-boundary tests, and ClawSweeper classified real-behavior proof as not applicable.

@steipete
steipete merged commit a6cb2fb into main Aug 16, 2026
189 checks passed
@steipete
steipete deleted the steipete/confident-merkle-477685 branch August 16, 2026 03:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
* fix(agents): preserve context engine session ownership

Unbound legacy context-engine hooks no longer execute LLM calls under the default agent. Explicit, agent-scoped, main-alias, and persisted session ownership remain supported.

* test(ci): avoid scheduler pid file race
w3evolutions pushed a commit to W3EvolutionsLLC/openclaw that referenced this pull request Aug 16, 2026
* fix(agents): preserve context engine session ownership

Unbound legacy context-engine hooks no longer execute LLM calls under the default agent. Explicit, agent-scoped, main-alias, and persisted session ownership remain supported.

* test(ci): avoid scheduler pid file race

(cherry picked from commit a6cb2fb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant