Skip to content

fix(mcp): keep session servers alive between turns - #141125

Merged
steipete merged 2 commits into
mainfrom
codex/mcp-keep-alive
Sep 7, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/mcp-keep-alive

Conversation

@steipete

@steipete steipete commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Related: #140447 (reported by @BottaniCals).

What Problem This Solves

Fixes an issue where background MCP server work would be interrupted between turns. OpenClaw imposed a ten-minute idle eviction policy, rejected the former mcp.sessionIdleTtlMs override, and some callers requested run-end cleanup even though the receiving session continued to exist.

Why This Change Was Made

The lifetime owners are src/agents/agent-bundle-mcp-manager-lifecycle.ts, src/agents/embedded-agent-runner/run/run-settlement.ts, and the compaction acceptance/adoption paths in compaction-successor.ts and run/compaction-runtime.ts. MCP lifetime now belongs to the session by default. Unset or zero mcp.sessionIdleTtlMs keeps OpenClaw-managed runtimes alive; positive values opt into idle eviction. Doctor preserves the restored key. The approved configuration addition changes the core baseline from 2417 to 2418, with channel and plugin counts unchanged.

The manager replaces requester LRU eviction with a 256-runtime admission bound across the Gateway, including creation and cleanup in progress. Existing runtimes survive capacity pressure, and new admissions receive an actionable error. Serverless sessions and sign-in-only catalogs do not consume the limit; removing all servers frees capacity only after cleanup is confirmed, while replacements retain their transferred slot. The idle sweep is absent from acquisition and its timer exists only for an enabled override. Reset/delete, explicit Stop, relevant server configuration changes, and shutdown retain cleanup ownership and terminate owned stdio children.

Gateway agent turns and nested session messages preserve the receiving session's runtime. Truly run-owned local CLI, detached cron, and run-mode subagent runtimes still retire at completion. Embedded settlement uses exact run-owned IDs, including an accepted transient compaction successor, instead of following a session key that may already point at another run. CLI dispatch delegates cleanup to the existing CLI settlement owner. Compaction retires each ended predecessor at the acceptance owner, covering repeated ID rotations, manual/CLI compaction, and cancellation after a committed rotation; transient in-memory adoption has the same cleanup boundary. The successor remains alive for its own session lifetime.

Restoring only the knob or increasing the hardcoded TTL would leave run-end retirement unresolved. MCP task-protocol tracking is unnecessary for the approved session-lifetime contract. Retained transcripts alone do not extend a detached run's process lifetime.

Comparison: sibling Codex was personally inspected at 64b482500d00b331189beefd173a5e08b4060ff2. codex-rs/codex-mcp/src/runtime.rs:92–103,692–694 owns MCP connections per thread; codex-rs/codex-mcp/src/connection_manager.rs:846–860 shuts down clients; codex-rs/rmcp-client/src/rmcp_client.rs:1010–1025 terminates owned stdio processes, and codex-rs/rmcp-client/src/local_child.rs:20–26 enables kill-on-drop. The inspected runtime/config has operation deadlines and no server-inactivity eviction policy. Claude Code's MCP reference and environment-variable reference expose call-level startup, execution, and unanswered-call timeouts, rather than a configurable post-response server-idle eviction policy; pending background calls remain session-bound. This change aligns OpenClaw's managed runtime lifetime with that session ownership model.

User Impact

Session MCP servers can finish background work through quiet periods and between turns. Operators can explicitly opt into idle cleanup with the restored setting, and can stop or reset unused sessions when the Gateway reaches its runtime bound. If an earlier Doctor run deleted the setting, its former value must be restored from an operator backup.

Evidence

The isolated default-lifetime regression failed before the repair because the manager discarded the session runtime during a quiet period. Additional before/after regressions cover uncertain replacement cleanup, stale TTL snapshots, compaction predecessor cleanup (including cancellation and transient adoption), and retirement surviving an in-flight acquisition.

Focused validation passed 940 distinct tests across 21 files (including reruns of the changed MCP suites); one Linux-only procfs case was skipped on macOS. Real stdio fixtures verify survival after a day of synthetic idle time and child termination on reset/shutdown; existing active lease/database-lock lifecycle tests also pass. Config validation and Doctor migration preserve zero, fractional, and positive overrides. Admission tests exercise all 256 slots, 300 serverless sessions, in-flight creation, pending cleanup, configuration removal racing replacement, and both static and requester runtimes. The real-child clock proof was corrected to advance the manager clock; both reset/shutdown cases were rerun against the original implementation and failed from idle eviction, then passed with this repair. Two sibling CI fixtures were corrected to honor cleanup ownership and release held disposal before awaiting publication, without weakening assertions or timeouts.

  • pnpm build: passed on the initial feature payload, including declaration/export checks and built plugin control-plane/Doctor loads.
  • node scripts/check-docs-mdx.mjs docs/cli/mcp.md docs/gateway/config-extensions.md: passed.
  • git diff --check: passed.
  • Independent Codex review: final complete diff scoped-clean through P2; all accepted actionable review findings were repaired and covered by regressions. Doctor cases use the public migration-validation suite, and Gateway context factories were extracted unchanged into test support to respect existing file limits. Both affected suites and focused Gateway lint passed.
  • Production: +242/-217 = +25 lines; tests/support: +629/-222 = +407; docs/generated config baseline: +28/-6 = +22. Production growth and restoring the configuration option are explicitly approved. No changelog edit or new dependency.

Exact head: 9a64a801ec7cbfd6b92919716f7960b74c3f7c94. pnpm check:changed -- <all 42 changed files> completed with exit code 0, covering formatting, typechecks, lint, dead exports, runtime import cycles, storage/schema guards, and other selected checks. Local proof validates the candidate payload committed at this head. The first hosted run found the two now-corrected MCP fixture failures, plus unrelated Telegram max-lines, UI service-worker cache-installation, and Windows transform-timeout failures. Telegram cleanup is tracked in #141136; the UI and Windows files are unchanged by this PR. The normal PR run 34115848929 then failed only the unchanged CI planner inventory-growth stress test at its 120-second timeout. The exact fix landed on main as ed86b49 (#141137), preserving the timeout and assertions. This branch was rebased onto the containing main for that failing gate; git range-diff confirms both MCP commits are patch-identical. Post-rebase proof: 213 focused tests, all 42-file changed checks, and fresh independent review through P2 passed. Final exact-head CI run 34126017734 completed successfully with 108 passing jobs and no failures. Refreshed ClawSweeper review reports no actionable findings. Native preparation and merge completed successfully on the unchanged reviewed head. Squash commit fe8f7a3 is verified as an ancestor of main; all 42 changed paths retain the landed content. The earlier GitHub API TLS/EOF failures required no retries in the successful landing attempt.

ClawSweeper's two actionable findings (empty runtime capacity and the real-child test clock) are addressed with before/after regressions. Its serialized-data-model warning on sessions-abort.ts is not applicable: the change retires an in-process runtime by its existing canonical session ID and changes no serialized format, schema, or persistent-store semantics. The existing schema guard passes. The hard cap intentionally rejects new resource-owning admissions instead of evicting another session's runtime.

Focused commands (task-local cache/log routing omitted):

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/agent-bundle-mcp-runtime.test.ts src/agents/agent-bundle-mcp-manager.lifecycle.test.ts src/agents/agent-bundle-mcp-acquisition.test.ts src/agents/agent-bundle-mcp-manager.requester-connect.test.ts src/agents/agent-bundle-mcp-reload.test.ts src/agents/embedded-agent-runner/run/run-settlement.test.ts src/agents/embedded-agent-runner/compaction-successor.test.ts src/agents/embedded-agent-runner/run.overflow-compaction.test.ts
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/commands/agent-via-gateway.test.ts src/cron/isolated-agent/run.fast-mode.test.ts src/auto-reply/reply/abort.target-owner.test.ts src/auto-reply/reply/commands-stop-target.test.ts src/auto-reply/reply/commands-abort-trigger.test.ts src/gateway/server-methods/sessions.abort-agent-scope.test.ts src/config/config-misc.test.ts src/config/dead-config-keys.test.ts src/commands/doctor/shared/legacy-config-migrations.runtime.retired.test.ts
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/agent-bundle-mcp-runtime.test.ts src/agents/agent-bundle-mcp-manager.lifecycle.test.ts src/agents/embedded-agent-runner/run/run-settlement.test.ts src/agents/embedded-agent-runner/cli-backend-dispatch.test.ts src/agents/tools/agent-step.test.ts src/agents/cli-runner.before-agent-reply-cron.test.ts src/agents/embedded-agent-runner/compaction-successor.test.ts src/agents/embedded-agent-runner/run.overflow-compaction.test.ts
OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/commands/doctor/shared/legacy-config-migrations.runtime.retired.test.ts src/commands/doctor/shared/legacy-config-migrate.validation.test.ts

@clawsweeper

clawsweeper Bot commented Sep 7, 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 docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 7, 2026
@steipete
steipete marked this pull request as ready for review September 7, 2026 09:55
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Please review the current head, ea5e278cb742359c4a8ccc7fa127ab19e3641725. The session-lifetime default and restored opt-in mcp.sessionIdleTtlMs are maintainer-approved for this PR. Local validation passed 904 focused tests, the full build, changed-file checks, and independent review through P2. Exact-head hosted CI is running at https://github.com/openclaw/openclaw/actions/runs/34109154841.

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 7, 2026, 10:59 AM ET / 14:59 UTC.

ClawSweeper review

What this changes

Keeps session-owned MCP servers alive between turns, restores optional idle eviction, and updates admission limits and cleanup at session boundaries.

Merge readiness

⛔ Blocked before merge - 2 items remain

The PR remains useful: current main and v2026.9.2 retain the fixed idle timeout. Both earlier findings are resolved, and no new blocking defect was found. The recorded approvals settle the configuration and capacity choices.

Priority: P2
Reviewed head: 9a64a801ec7cbfd6b92919716f7960b74c3f7c94

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent owner-level repair with resolved prior findings, focused regressions, and explicit approval of its operational tradeoffs.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Recorded real-stdio runs exercise the production manager’s idle survival and child cleanup; focused configuration, settlement, and authorization tests provide supplemental coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Recorded real-stdio runs exercise the production manager’s idle survival and child cleanup; focused configuration, settlement, and authorization tests provide supplemental coverage.
Evidence reviewed 10 items Current main still needs the change: The fetched main revision retains DEFAULT_SESSION_MCP_RUNTIME_IDLE_TTL_MS at ten minutes and the requester-runtime eviction cap. The central requested behavior is not already implemented there.
Release comparison: The latest supplied release, v2026.9.2, also contains the ten-minute idle timeout; it does not ship this PR’s lifetime policy.
Prior capacity finding resolved: Admission reserves slots only when configured servers can own connections. Empty-runtime release waits for cleanup and checks that the same runtime still owns the key. Regression coverage includes 300 serverless sessions, full capacity, and replacement racing configuration cleanup.
Findings None None.
Security None None.

How this fits together

OpenClaw’s MCP runtime manager connects agent sessions to external tool servers. It owns connection reuse and cleanup across turns, session changes, and Gateway shutdown.

flowchart TD
  A[Agent session and MCP configuration] --> B[Runtime admission]
  B --> C[Reuse existing connections]
  B --> D[Reserve available capacity]
  D --> C
  C --> E[Tool calls and background server work]
  E --> F[Keep alive between turns]
  F --> C
  F --> G[Session end, Stop, or optional idle timeout]
  G --> H[Close connections and release capacity]
Loading

Before merge

  • Resolve merge risk (P1) - Resource pressure remains workload-dependent: existing installations can retain more MCP processes and reject new resource-owning admissions at 256 runtimes. Stop/reset or opt-in idle eviction provides recovery; this operational tradeoff is explicitly approved.
  • Review config compatibility - Confirm compatibility and upgrade impact for the changed config or default surface before merge.
Agent review details

Security

None.

PR surface

Source +25, Tests +407, Docs +22, Generated 0. Total +454 across 42 files.

View PR surface stats
Area Files Added Removed Net
Source 21 242 217 +25
Tests 17 629 222 +407
Docs 2 25 3 +22
Config 0 0 0 0
Generated 2 3 3 0
Other 0 0 0 0
Total 42 899 445 +454

Review metrics

Metric Value Why it matters
Idle policy 1 restored setting; default changes from 10 minutes to session lifetime The operator-visible change and historical-value preservation are explicitly approved and documented.
Admission policy 256 resource-owning runtimes across the Gateway Capacity includes creation and cleanup while excluding empty sessions and sign-in-only catalogs.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-abort.ts, unknown-data-model-change: src/gateway/server-methods/sessions-abort.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #140447
Summary: This PR addresses the linked report’s idle-eviction problem under the approved session-lifetime contract; detached run-owned processes still end with their run.

Members:

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

Merge-risk options

Maintainer options:

  1. Retain the approved admission policy (recommended)
    Proceed with the recorded choice to preserve existing runtimes and reject new admissions at capacity, using the documented Stop/reset or idle-timeout recovery.

Technical review

Best possible solution:

Adopt the approved session-owned lifetime with explicit cleanup boundaries, optional idle eviction, and documented capacity recovery.

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

Yes, from source: current main evicts unleased MCP runtimes after ten idle minutes, and the linked report records interrupted background indexing. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. The patch repairs lifetime ownership across continuing sessions and detached runs, while preserving explicit cleanup and historical TTL values; the broader default and admission choices already have recorded approval.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Repairs interrupted background MCP work in a bounded integration subsystem.
  • merge-risk: 🚨 availability: Longer retention can reach the new admission limit and require operator cleanup, an explicitly accepted operational tradeoff.
  • 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: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Recorded real-stdio runs exercise the production manager’s idle survival and child cleanup; focused configuration, settlement, and authorization tests provide supplemental coverage.

Evidence

What I checked:

  • Current main still needs the change: The fetched main revision retains DEFAULT_SESSION_MCP_RUNTIME_IDLE_TTL_MS at ten minutes and the requester-runtime eviction cap. The central requested behavior is not already implemented there. (src/agents/agent-bundle-mcp-runtime-shared.ts:15, dd53f7fec223)
  • Release comparison: The latest supplied release, v2026.9.2, also contains the ten-minute idle timeout; it does not ship this PR’s lifetime policy. (src/agents/agent-bundle-mcp-runtime-shared.ts:15, 3928bad9badf)
  • Prior capacity finding resolved: Admission reserves slots only when configured servers can own connections. Empty-runtime release waits for cleanup and checks that the same runtime still owns the key. Regression coverage includes 300 serverless sessions, full capacity, and replacement racing configuration cleanup. (src/agents/agent-bundle-mcp-manager-lifecycle.ts:131, 9a64a801ec7c)
  • Prior real-child clock finding resolved: The stdio regression now gives the production manager a dynamic Date.now callback, advances that clock by one day, checks the child remains alive, and then verifies child disappearance after reset or shutdown. The captured PR body reports before/after failures and passes; this review inspected the test without executing it. (src/agents/agent-bundle-mcp-runtime.test.ts:3418, 9a64a801ec7c)
  • Recorded maintainer disposition: The discussion explicitly approves the session-lifetime default, restored finite nonnegative TTL setting, and 256-runtime admission tradeoff: fix(mcp): keep session servers alive between turns #141125 (comment). It also correctly distinguishes in-process retirement from a persistent schema change.
  • Configuration compatibility coverage: The schema accepts finite nonnegative values, while the public Doctor migration-validation suite preserves zero, fractional, and positive historical values. Documentation explains that values already deleted by an older Doctor cannot be recovered automatically. (src/config/zod-schema.root-support.ts:455, 9a64a801ec7c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • qingminlong: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (3 earlier review cycles)
  • reviewed 2026-09-07T10:13:51.824Z sha ea5e278 :: blocked before merge. :: [P1] Exclude empty MCP runtimes from admission capacity | [P2] Advance the clock captured by the stdio test’s manager
  • reviewed 2026-09-07T11:22:43.582Z sha 5e79337 :: blocked before merge. :: none
  • reviewed 2026-09-07T13:25:33.995Z sha 9a64a80 :: blocked before merge. :: none

@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

Both actionable findings from the prior review are fixed in 5e79337. Empty sessions and sign-in-only catalogs no longer consume runtime capacity; capacity is held through cleanup and cannot be released by a predecessor after replacement. Regressions cover 300 empty sessions, full-capacity admission, config cleanup, and concurrent replacement. The real stdio test now advances the manager clock; both cases fail against the original idle policy and pass with this repair.

The serialized-data warning on sessions-abort.ts is not applicable: retirement uses the existing canonical session ID and changes no schema or persisted format. The schema guard remains green. Configuration restoration and the admission-cap tradeoff are expressly approved for this work order.

Focused tests, pnpm check:changed, docs MDX, git diff --check, and complete-diff independent review through P2 are green. The two MCP fixture failures in the first hosted run were also reproduced and corrected without timeout or assertion weakening. Fresh exact-head CI is pending.

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 7, 2026
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer disposition for the three checklist items at 5e79337:

  • Capacity: retain the approved 256-runtime admission policy and documented Stop/reset or opt-in idle-timeout recovery. Existing connected runtimes remain alive; empty sessions and sign-in-only catalogs consume no capacity. This operational tradeoff was explicitly approved for S21.
  • Config compatibility: restoring mcp.sessionIdleTtlMs is explicitly approved. The schema accepts the prior finite nonnegative contract, Doctor preserves the key, and regression tests cover zero, fractional, and positive values. Unset now means session lifetime, as requested. The docs explain restoring values that an older Doctor already deleted from operator backups.
  • Stored data: no migration applies. sessions-abort.ts calls in-process retirement with the existing canonical session ID; it changes no schema, serialized field, or persistent-store semantics. The native-state schema guard passes at v16, and the authorized Stop scope is covered by the focused Gateway suite.

The refreshed review identifies no actionable code or security finding and confirms both earlier findings resolved. Required exact-head CI remains pending before native preparation and merge.

Keep OpenClaw-managed MCP runtimes for their owning session by default and
restore mcp.sessionIdleTtlMs as an opt-in override. Preserve the key in Doctor.
Replace requester LRU eviction with a Gateway-wide admission bound that holds
capacity through creation and confirmed cleanup.

Preserve continuing Gateway and nested sessions at run settlement. Retire
ended compaction predecessors and explicit stops at their lifetime owners,
with required retirement surviving pending acquisition and weaker run cleanup.

Reported by @BottaniCals in #140447.
Reserve capacity only for runtimes that can own server connections, and
retain the reservation until cleanup is confirmed. Reclaim emptied slots
without allowing late reload cleanup to release a successor's reservation.

Correct the real-child idle clock proof and sibling cleanup fixtures.
Add regressions for serverless admission and concurrent config retirement.
@steipete
steipete force-pushed the codex/mcp-keep-alive branch from 5e79337 to 9a64a80 Compare September 7, 2026 13:11
@steipete
steipete merged commit fe8f7a3 into main Sep 7, 2026
186 checks passed
@steipete
steipete deleted the codex/mcp-keep-alive branch September 7, 2026 15:50
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
* fix(mcp): keep session servers alive between turns

Keep OpenClaw-managed MCP runtimes for their owning session by default and
restore mcp.sessionIdleTtlMs as an opt-in override. Preserve the key in Doctor.
Replace requester LRU eviction with a Gateway-wide admission bound that holds
capacity through creation and confirmed cleanup.

Preserve continuing Gateway and nested sessions at run settlement. Retire
ended compaction predecessors and explicit stops at their lifetime owners,
with required retirement surviving pending acquisition and weaker run cleanup.

Reported by @BottaniCals in openclaw#140447.

* fix(mcp): exclude empty sessions from runtime capacity

Reserve capacity only for runtimes that can own server connections, and
retain the reservation until cleanup is confirmed. Reclaim emptied slots
without allowing late reload cleanup to release a successor's reservation.

Correct the real-child idle clock proof and sibling cleanup fixtures.
Add regressions for serverless admission and concurrent config retirement.
@jb510

jb510 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Getting error/warnings due to this.
CleanShot 2026-09-09 at 17 11 59@2x

Heartbeat check failed before it could produce an update. The main chat session remains available.

I think this is in part because we use isolated crons. We do that so that we can pin them to Luna instead of Astra.

The install this happeend on has 9 agents, all with isolated crons. IDK, maybe I'm "doing it wrong", I haven't seen this on the other 5 installs yet which are basically the same config shape.

I'm setting the timeout to 10 minutes, but the "indefinte" default seems problematic to me.

I'm not certain enough on any of this to even attempt to code a solution, but figured it was worth documenting as it seems like it'll soon bite more users.

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

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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