Skip to content

fix: retain compaction services through issued work - #143633

Merged
steipete merged 1 commit into
mainfrom
codex/delegate-compaction-composed
Sep 10, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/delegate-compaction-composed

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where cancelling or timing out compaction could close MCP/LSP resources while issued compaction work or plugin hooks were still using them. A timed-out hook could also escape the work owner that retained its prepared database resources.

Why This Change Was Made

Compaction now separates the caller's result from physical cleanup. Its owner waits for actual preparation, compaction, provider, and hook work before disposing tool runtimes, then joins cleanup tails before releasing the prepared generation. Partial setup failures transfer cleanup ownership before allocating resources.

Timed hook dispatch observes the already-started handler promise while preserving the original timeout race and error policy. Session disposal still retires authority at the original boundary; diagnostics, transcript fences, accounting, checkpoints, and skill-environment restoration keep their existing ordering.

User Impact

Compaction can report cancellation or timeout promptly while allowing already-issued work to finish safely. Normal compaction, native CLI routing, fallbacks, and the default 180-second watchdog remain unchanged. Hook deadlines and fail-open behavior are preserved.

Normal-run registry disposal is not enabled by this change. The database disposal regression uses the existing managed read-only producer at the native delegate input boundary. The compiled smoke uses the public delegate with the current normal-run producer; managed default-flow integration remains required before activating its disposal.

Evidence

  • Validated fixture configuration reproduces ten premature-close failures on the original code; success and raw-source controls pass. All twelve cases pass with the repair. Separate hook tests reproduce early drainage while preserving raw/closed-scope reporting controls.
  • 321 focused and sibling tests passed. The twelve delegate cases were rerun after correcting fixture configuration. Required changed checks and the affected fixture checks passed.
  • Final independent Codex review found no actionable P0–P2 issues.
  • Full build passed in 241 seconds. Compiled public-delegate proof used four loopback model completions, real MCP HTTP sessions, real LSP processes, and both timed compaction hooks. Each service stayed live through the reported result, then closed once; the LSP SQLite files reopened successfully.
  • With a declared 25 ms hook timeout, reports arrived 27–57 ms after hook entry and physical cleanup took 48–50 ms after releasing the held work. These are synthetic smoke timings, not throughput benchmarks.

@clawsweeper

clawsweeper Bot commented Sep 10, 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: XL maintainer Maintainer-authored PR labels Sep 10, 2026
@steipete
steipete marked this pull request as ready for review September 10, 2026 02:43
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 10:49 PM ET / September 10, 2026, 02:49 UTC.

ClawSweeper review

What this changes

Keep compaction’s prepared runtime and tool services alive until issued work and cleanup finish, while preserving prompt cancellation results and hook deadlines.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still disposes delegated compaction resources before outstanding work necessarily finishes. No blocking defect was found in the introduced changes, and the merged foreground-compaction repair explicitly leaves this boundary separate.

Priority: P2
Reviewed head: 34744c330cef945d2a0b571c18d0367fcd2d2fb6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused lifecycle repair with meaningful regression coverage, qualified runtime observations, and no actionable correctness findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER classification exempts this internal repair from the external-contributor gate. Its body reports compiled public-delegate MCP/LSP and timed-hook observations, separately qualifying managed-registration fixture coverage; no material authority change requires additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER classification exempts this internal repair from the external-contributor gate. Its body reports compiled public-delegate MCP/LSP and timed-hook observations, separately qualifying managed-registration fixture coverage; no material authority change requires additional final-effect proof.
Evidence reviewed 9 items Current main still needs the repair: The fetched main revision awaits session execution and immediately calls runtime.dispose() in finally; it does not join the issued work retained by the timeout wrapper. The relevant production files match the pinned PR base.
Introduced lifecycle ordering: The attempt reports its logical result separately, waits for issued work, starts tool disposal, and joins work plus cleanup descendants. The outer compactor releases its prepared lease only after that ownership drains; preparation transfers cleanup responsibility before allocating tool runtimes.
Hook deadlines and authority retirement preserved: Timed dispatch observes the already-started handler without replacing the timeout race or error policy. Session execution retains its existing dispose boundary, and session disposal aborts operations and invalidates captured extension contexts. No new authorization grant or public plugin API is introduced.
Findings None None.
Security None None.

How this fits together

OpenClaw’s built-in compactor receives manual or automatic requests and summarizes session history using model providers, plugin hooks, and tool services. Its lifecycle owner must retain those resources through outstanding work without extending session authority.

flowchart TD
  A[Compaction request] --> B[Prepared runtime]
  B --> C[Session compaction and hooks]
  C --> D[Result or cancellation]
  C --> E[Outstanding work settles]
  D --> F[Session authority retired]
  E --> G[Tool cleanup settles]
  G --> H[Prepared runtime released]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +108, Tests +724. Total +832 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 879 771 +108
Tests 2 724 0 +724
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 1603 771 +832

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +108 lines; tests +724 lines Production growth implements explicit work and cleanup ownership; the larger test addition exercises resource lifetime and retirement boundaries.

Technical review

Best possible solution:

Preserve the separation between prompt session retirement and resource cleanup, with normal-run registration-disposal activation remaining independently validated.

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

Yes, from source: a timeout can return while tracked compaction or hook work remains pending, after which main disposes its tools. The new controlled regressions exercise that ordering; they were inspected but not executed here.

Is this the best way to solve the issue?

Yes. Moving physical cleanup to the work owner repairs the lifetime mismatch while retaining existing timeout, session-disposal, fallback, and transcript contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded compaction resource-lifetime repair with no evidence of a widespread urgent outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER classification exempts this internal repair from the external-contributor gate. Its body reports compiled public-delegate MCP/LSP and timed-hook observations, separately qualifying managed-registration fixture coverage; no material authority change requires additional final-effect proof.

Label justifications:

  • P2: This is a bounded compaction resource-lifetime repair with no evidence of a widespread urgent outage.
  • 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 MEMBER classification exempts this internal repair from the external-contributor gate. Its body reports compiled public-delegate MCP/LSP and timed-hook observations, separately qualifying managed-registration fixture coverage; no material authority change requires additional final-effect proof.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main revision awaits session execution and immediately calls runtime.dispose() in finally; it does not join the issued work retained by the timeout wrapper. The relevant production files match the pinned PR base. (src/agents/embedded-agent-runner/direct-compaction.ts:28, e6a2df70bf38)
  • Introduced lifecycle ordering: The attempt reports its logical result separately, waits for issued work, starts tool disposal, and joins work plus cleanup descendants. The outer compactor releases its prepared lease only after that ownership drains; preparation transfers cleanup responsibility before allocating tool runtimes. (src/agents/embedded-agent-runner/direct-compaction.ts:60, 34744c330cef)
  • Hook deadlines and authority retirement preserved: Timed dispatch observes the already-started handler without replacing the timeout race or error policy. Session execution retains its existing dispose boundary, and session disposal aborts operations and invalidates captured extension contexts. No new authorization grant or public plugin API is introduced. (src/plugins/hooks.ts:688, 34744c330cef)
  • Regression coverage and its boundary: Twelve delegate scenarios check delayed SQLite reads, cancellation before and after commit, provider and cleanup tails, partial setup failure, and timed hooks. Six hook scenarios cover open, closing, raw, and closed owners. The delegate fixture explicitly substitutes the managed read-only producer and uses SQLite stand-ins at MCP/LSP factories; these tests do not establish normal-run registration-disposal activation. (src/agents/embedded-agent-runner/compact.delegate-resources.test.ts:74, 34744c330cef)
  • Supplied runtime observations: The complete captured PR body reports a compiled public-delegate smoke with four loopback model completions, real MCP HTTP sessions, LSP processes, and both timed hooks. It reports services surviving the result and closing once afterward, with SQLite reopening successfully. It explicitly qualifies the normal-run producer versus managed-registration fixture. These are author-reported observations; this read-only review did not execute the probe. Supplied context sourceRevision: 7035c48a574d6b5ef37c8a81304552223b454566017f36b62f1022e3ee6dc230. (34744c330cef)
  • Merged adjacent repair does not supersede this PR: GitHub verifies fix: retain foreground compaction resources through disposal #143592 as merged at the pinned base. Its body explicitly says built-in delegate cleanup is unchanged. The closed, unmerged aggregate refactor(plugins): release scoped resources after actual work #140674 identifies this PR as a remaining focused slice. (66e4de2205e9)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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.

@steipete
steipete merged commit 3b627ad into main Sep 10, 2026
249 checks passed
@steipete
steipete deleted the codex/delegate-compaction-composed branch September 10, 2026 03:02
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 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.

1 participant