Skip to content

fix(agents): retry ready context-engine turns behind old admissions - #172102

Closed
Leon-SK668 wants to merge 2 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-context-outbox-retry-135628
Closed

Leon-SK668 wants to merge 2 commits into
openclaw:mainfrom
Leon-SK668:leon/fix-context-outbox-retry-135628

Conversation

@Leon-SK668

@Leon-SK668 Leon-SK668 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Refs #135628 — repairs cross-session retry starvation; historical admission retirement remains outside this PR.

What Problem This Solves

Sixteen older unresolved session heads consume the bounded context-engine retry list. A later ready turn is not selected even when an independent session finishes successfully. Protecting the current accepted turn and disposing new admissions does not make the existing retry slots available to other ready sessions.

User Impact

Ready context-engine commits can progress despite unresolved admissions in other sessions. Same-session FIFO, blocked audit evidence, engine/plugin isolation, idempotent commit, and current admissions remain intact. No historical cleanup, TTL, new queue, config/default, schema, protocol, dependency, provider-authentication, or permission change. This is a bounded part of #135628, not a claim to resolve its broader recovery request.

Why This Change Was Made

Identify each session's oldest non-blocked row before filtering for readiness and limiting the retry list. Keep ownership filters on both queries and apply the same invariant to the memory-store sibling. An unresolved head still blocks later work in its own session, without consuming another session's retry slot.

The canonical owners are the existing outbox kernel and memory session store; the finalizer/drainer continues to own commit, retry accounting and acknowledgment. Existing-solutions preflight: this is a missing invariant in the current queue owner; neither an external queue nor a new plugin/library is needed. Installed Kysely aggregate/subquery types and source, database schema and executor, callers and memory sibling were inspected.

October 18 maintenance normally merges 9b707074b5f231f6976456ea7431567893fe7d1c. The query now uses main's canonical explicit enqueue_sequence and typed fn.min; it does not restore deleted rowid helpers or alter schema. The accepted-turn regression uses main's consolidated fixture and places 16 unresolved rows ahead of the ready retry. The other stale type-check failure was in unrelated memory-core Worker/MessagePort test code; no contributor workaround was added there.

Evidence

Current contributor head 1c4293e5c87f389f7e1e634859c414465da67968, tree 0d1f835de572ef70426d49346ea3228277c57085; clean checkout. Built OpenClaw 2026.10.4, Linux, Node 24.16.0. Build metadata records this exact head and 2026-10-18T03:08:46.938Z.

The original acceptance RED was captured before production edits on d4256984ac0435d8f5225e0d1706235b798f1e9e: an independent successful CLI turn left the ready backlog behind 16 unresolved admissions. The October 18 exact-head GREEN replays the same immutable native harness after integrating main:

node context-outbox-live-proof.mjs <checkout> <new output directory> green

Three real openclaw.mjs agent --local --agent main --session-key ... --message ... --thinking off --timeout 60 --json processes use isolated state, a normally registered context-engine fixture and a loopback HTTP/SSE model endpoint. Every invocation returns the expected current answer and exits 0.

Native scenario Authoritative SQLite/engine-ledger readback
Warm control 1 real engine commit; 0 outbox rows
A new turn's genuine engine commit fails once 16 historical admitted rows + 1 ready row; recorded attempt count 1
Independent successful turn triggers normal drain 3 engine commits; ready row acknowledged; 16 historical rows retained byte-for-byte

The recovered ledger contains the exact closed-turn user/assistant payload. 1/1 ready backlogs drain, compared with 0/1 on historical RED. 16/16 historical admission hashes remain identical. Fixture initialization represents reported persisted state; it does not claim to recreate the original crash. No external model account, channel recipient, production state or Mac environment is used.

GREEN completed 2026-10-18T03:16:14.687Z; three CLI invocations took 30.60 / 31.45 / 29.58 seconds. Harness SHA-256 c217e70233acdfc99d10341774048fc4c549f91ac5b5e62459673376dc261a3b; current receipt SHA-256 d5f2e9e303906f3fe41cbd2635a7a9f1e108542959c3c6f872b836f68cd04ac0. Local logs/databases/receipts retained; the table supplies sanitized observations, without claiming a hosted artifact.

OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs \
  src/agents/harness/context-engine-turn-outbox-selection.test.ts \
  src/agents/harness/context-engine-turn-attempt.test.ts \
  src/config/sessions/session-actor-memory-side-effects.test.ts --maxWorkers=1
  38 passed across 3 files/shards; wrapper 468.58 s; exit 0
node scripts/run-tsgo.mjs --project <external scoped test config>
  changed sources and actual dependency closure; exit 0
OPENCLAW_OXLINT_SKIP_PREPARE=1 node scripts/run-oxlint.mjs --tsconfig <same scoped config> <five changed TS files>
  typed lint, exit 0
oxfmt --check <five changed TS files>
  exit 0
git diff 9b707074b5f231f6976456ea7431567893fe7d1c --check -- <five changed files>
  exit 0
node --import ./scripts/tsx.mjs scripts/build-all.mts sourcePerformance
  exit 0; 315.5 s

Vitest file durations: selection 137.33 s, memory 128.26 s, accepted-turn 157.18 s. Cold compiler/import preparation dominated this invocation; overlapping local type probes caused memory pressure and were stopped and resumed with bounded concurrency. No assertion, production timeout, test limit, or guard was weakened. Checks cover readiness selection, FIFO/owner separation, memory sibling and the actual finalizer.

Against merged main: 5 files; production +25/-9, net +16; tests +83/-9, net +74. No contributor generated/lock/release-changelog changes. Added production lines implement the shared session-head invariant. No speculative index/schema expansion.

Not tested: original crash generation, historical cleanup, sustained load, PostgreSQL, external providers/channels, Windows/macOS, browser, all suites, or packaged declaration bootstrap. Earlier synthetic rowid-based query timing is not represented as a fresh benchmark of this integrated head. Broad exact-head PR CI remains separate. The user waived independent automated autoreview; no automated review pass is claimed.

AI assistance: implemented and maintained for Leon-SK668 after source/owner/sibling/dependency inspection, native RED and same-scenario GREEN, focused checks and committed-head readback. Credentials, private configuration, unrelated sessions and raw agent logs are omitted.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Oct 14, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 14, 2026
@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR selects only sessions whose oldest non-blocked context-engine turn is ready for bounded retry.

Example: A ready turn from an idle session sits behind 16 other sessions with unresolved admissions.

  • Before: The 16 unresolved sessions consume every retry slot, leaving the ready turn uncommitted.
  • After: The ready session receives a retry and its committed turn is acknowledged; the unresolved admissions remain intact.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, correct repair with shipped CLI evidence and passing current-head CI; overall scope remains partial against the linked historical-recovery request.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies exact-head Linux CLI observations through a normally registered context engine and loopback provider: a real failed-once commit is retried after an independent turn, its payload reaches the engine ledger and is acknowledged, and all 16 historical admission hashes remain unchanged.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Previously accepted turns from idle sessions can remain absent from durable context-engine state because unrelated unresolved admissions occupy every retry slot.
Reason: Production evidence supports a bounded repair to an existing retry contract; the PR correctly uses a related reference and leaves broader historical cleanup unresolved.

Merge readiness

✅ Ready for maintainer review

Keep this PR: current main still permits retry starvation, and this focused repair preserves session ordering and owner isolation without introducing a new queue or cleanup policy.

Priority: P1
Reviewed head: 1c4293e5c87f389f7e1e634859c414465da67968

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A base-failing run of the exact added regression tests is not supplied; the native CLI scenario instead records historical RED and exact-head GREEN.
Agent review details

How this fits together

Accepted agent turns enter the context-engine outbox through the existing worker or memory actor; finalization selects pending sessions, invokes the engine's idempotent commit, and acknowledges successful rows.

flowchart TD
  A[Accepted agent turn] --> B[Outbox store]
  B --> C[Database worker]
  B --> D[Memory actor]
  C --> E[Ready session heads]
  D --> E
  E --> F[Bounded drain]
  F --> G[Engine commit and acknowledgment]
Loading

Technical review

Best possible solution:

Land the focused session-head selection repair while retaining the broader issue for historical admission recovery.

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

Current-main source establishes the 16-slot starvation path, corroborated by production reports and the contributor's historical native CLI RED; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch fixes eligibility at the existing selection owners, preserving same-session FIFO, blocked audit records, owner filters, retry accounting, and acknowledgment without speculative cleanup machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4f8cf06b1892.

Provenance checked

  • Durable outbox session selection changes intended behavior with a stated reason (e63b5a0: Moved outbox SQL into the existing execution worker; the later explicit-sequence change preserved FIFO through database rebuilds.)
  • Memory outbox selection keeps the original intent (b8441e0: Restored the deliberately retained standalone memory foundation; this patch retains it and aligns its selection contract with the durable owner.)
  • Accepted-session finalization regression keeps the original intent (5360b70: Protect accepted-session commits while retaining bounded retries for other sessions; the changed fixture now places 16 unresolved sessions before the ready retry.)
  • Explicit FIFO sequence keeps the original intent (35dbd07: Preserve surviving queue order across migration, VACUUM, reopen, and payload updates using enqueue_sequence.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e63b5a0 adds src/agents/harness/context-engine-turn-outbox.kernel.worker.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e63b5a01cf26; files: src/agents/harness/context-engine-turn-outbox.kernel.worker.ts)
  • Josh Lehman: Raw commit be39fa3 adds src/agents/harness/context-engine-turn-outbox.kernel.worker.ts:287 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: be39fa3f3a44; files: src/agents/harness/context-engine-turn-outbox.kernel.worker.ts)

PR surface

Source +16, Tests +74. Total +90 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 2 25 9 +16
Tests 3 83 9 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 108 18 +90

Root-cause cluster

Relationship: partial_overlap
Canonical: #135628
Summary: This PR repairs cross-session retry starvation within the broader orphan-admission report; historical admission retirement remains separate.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Reported production backlogs silently prevent durable context-engine commits for idle sessions, and current main retains the selection failure.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-14T11:57:29.618Z sha 3fb9c88 :: needs maintainer review before merge. :: none

Reviewed October 22, 2026, 8:37 PM ET / October 23, 2026, 00:37 UTC (Revision 2).

@Leon-SK668

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review current head 1c4293e5c87f389f7e1e634859c414465da67968; the durable review still covers 3fb9c88.

The upstream conflict repair and current-head proof are published in the PR body. The native CLI / registered context-engine / loopback-provider scenario retries a real failed-once engine commit, independently verifies its acknowledgment and ledger contents, and preserves all 16 historical admission payload hashes. The exact committed build and focused validation commands/results are included.

This remains a bounded retry-starvation repair related to the broader issue, not a claim that all historical recovery is solved.

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 23, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @Leon-SK668 for this fix! The credited replacement #190165 is now merged as b68d571, with fresh red/green regressions and green CI. It preserves ready-head selection and same-session FIFO; broader historical admission cleanup remains in #135628.

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

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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.

2 participants