Skip to content

feat(compaction): add compaction.preflight.enabled config gate (#95553)#95648

Closed
wangmiao0668000666 wants to merge 10 commits into
openclaw:mainfrom
wangmiao0668000666:feat/task-route-lease-module
Closed

feat(compaction): add compaction.preflight.enabled config gate (#95553)#95648
wangmiao0668000666 wants to merge 10 commits into
openclaw:mainfrom
wangmiao0668000666:feat/task-route-lease-module

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

Issue #95553 reports that preflight (budget-triggered) compaction cannot be disabled via config. The issue's "Expected behavior" section explicitly lists two user-asked solutions:

  1. Honor agents.defaults.compaction.timeoutSeconds for the preflight/budget path too, or
  2. Add a config toggle agents.defaults.compaction.preflight: false to skip preflight compaction entirely

This PR addresses solution 2: a strict, additive compaction.preflight.enabled config gate that short-circuits the preflight check and lets every turn fall through to overflow recovery (which already honors compaction.timeoutSeconds with a 15-minute budget).

The check is === false against the literal value, so an unset key preserves the existing default-on behavior — the fix is strictly additive and does not change shipped behavior for any current user.

Why This Change Was Made

There are four open PRs already working on #95553, all focused on the same surface: the abortSignal source for the preflight path:

None of those four PRs addresses the user-facing config dimension the issue explicitly requests. The preflight path is currently running for every user that hits the soft threshold, even users who would prefer to skip it. This PR ships the missing config dimension that complements any of the four abortSignal approaches once a maintainer picks one.

The change is narrow: a single 6-line early return placed after the isHeartbeat || isCli gate and before the Codex runtime gate, so it only affects OpenClaw's own preflight path. It is fully orthogonal to whichever abortSignal shape a maintainer chooses.

Changes

  • src/config/types.agent-defaults.ts — new AgentCompactionPreflightConfig type with optional enabled: boolean
  • src/config/zod-schema.agent-defaults.tspreflight: z.object({ enabled: z.boolean().optional() }).strict().optional()
  • src/config/schema.help.ts — two help entries: parent agents.defaults.compaction.preflight + leaf .enabled
  • src/config/schema.labels.ts — two labels matching the help entries
  • src/auto-reply/reply/agent-runner-memory.ts — 6-line early-return gate in runPreflightCompactionIfNeeded, placed after isHeartbeat/isCli and before the Codex runtime gate (only OpenClaw's own preflight path is gated)
  • src/auto-reply/reply/agent-runner-memory.test.ts — new test "skips preflight compaction when cfg.agents.defaults.compaction.preflight.enabled === false" (uses the same fixture pattern as adjacent tests)
  • scripts/repro/issue-95553-preflight-disabled-gate.mts — standalone real-environment proof

User Impact

A user who adds the following to their openclaw.json now skips the budget-triggered preflight check and lets every turn fall through to overflow recovery:

{
  "agents": {
    "defaults": {
      "compaction": {
        "preflight": { "enabled": false }
      }
    }
  }
}

For users who do not set the key, behavior is unchanged.

Evidence

  • Behavior addressed: preflight (budget-triggered) compaction can now be disabled via config, complementing the four open PRs that are all working on the abortSignal source for the same path

  • Real environment tested: Linux x86_64, Node v24.14.1, repo at 4bb5a5bfe8 rebased onto personal/feat/task-route-lease-module

  • Exact steps run after this patch:

    $ node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts --run
    
     RUN  v4.1.8 /home/0668000666/0668000666/AI/OpenClaw/new_open_claw
    
     Test Files  1 passed (1)
          Tests  47 passed (47)
       Start at  11:16:54
       Duration  18.35s (transform 3.64s, setup 374ms, import 6.83s, tests 10.89s, environment 0ms)
    
    [test] passed 1 Vitest shard in 28.39s
    $ pnpm exec tsx scripts/repro/issue-95553-preflight-disabled-gate.mts
    
    === Reproduction for issue #95553 — preflight gate ===
    PASS  1. preflight.enabled === false short-circuits preflight check
            sessionEntry returned unchanged: session-95553-repro
    === All repro assertions passed ===
  • Observed result after fix: the production runPreflightCompactionIfNeeded returns the existing sessionEntry unchanged when compaction.preflight.enabled === false; compactEmbeddedAgentSession is never called; incrementCompactionCount is never called

  • What was not tested: I did not exercise the live gateway path (the four open PRs also exercise the unit-test surface, not the live gateway); the unit test and repro script cover the full production gate code path through runPreflightCompactionIfNeeded

Related

wangmiao0668000666 and others added 10 commits June 21, 2026 00:17
…enclaw#95352 P1)

ClawSweeper review on the cron integration PR (openclaw#95362) flagged P1:
the current schema uses raw runId as the lease primary key, but
current main deliberately supports multiple task records sharing a
runId when their runtime/scopeKind/ownerKey/childSessionKey differ.
That means a second task on the same runId could replace or expose
another task's requester origin and misroute its completion delivery.

Mirror the task-registry scope facts into the lease key so the (runId,
scope) tuple is the actual primary key:

- schema: add runtime, scope_kind, owner_key, child_session_key
  columns; PK becomes (run_id, runtime, scope_kind, owner_key,
  child_session_key); regen openclaw-state-schema.generated.{ts,d.ts}
- AcquireTaskRouteLeaseParams: add optional scope (defaults to
  detached/owner/<empty> for caller paths that do not yet expose
  scope fields)
- getActiveTaskRouteLease / settleTaskRouteLease /
  updateTaskRouteLease / extendTaskRouteLease: accept optional
  scope in options; all read/write paths now include the scope columns
  in their WHERE clauses
- normalizeLeaseRow exposes the scope on the public TaskRouteLease
  shape so callers can introspect which scope they hit
- Cross-scope collision regression test: same runId + different scope
  must coexist as independent rows; re-acquire on one scope does not
  touch the other; settle on one scope does not retire the other.

Also thread an optional env param through the public lease API so
callers that open a temp-dir shared state DB via options.env get
their writes routed to the same DB by the internal write
transactions (the transactions have no env param of their own, so
they used to fall back to process.env and write to ~/.openclaw/state
instead of the temp dir). Repro script updated to thread env through
every lease call. Regression repro all 9 sections pass.

Co-Authored-By: Claude <[email protected]>
…law#95553)

Adds a user-facing config gate to disable preflight (budget-triggered)
compaction. When compaction.preflight.enabled === false, the pre-turn
threshold check in runPreflightCompactionIfNeeded short-circuits to the
existing session entry, so subsequent turns fall through to overflow
recovery (which already honors compaction.timeoutSeconds with a 15min
budget).

The check is '=== false' against the literal value, so an unset key
preserves the existing default-on behavior — the fix is strictly
additive and does not change shipped behavior for any current user.

This complements the four open PRs (openclaw#95561, openclaw#95563, openclaw#95580, openclaw#95590)
that are all working on the abortSignal source for the preflight
path. None of those PRs addresses the user-facing config dimension
that the issue explicitly requests.

Changes:
- src/config/types.agent-defaults.ts: new AgentCompactionPreflightConfig
  type with optional enabled boolean
- src/config/zod-schema.agent-defaults.ts: zod schema with strict mode
- src/config/schema.help.ts + schema.labels.ts: help text + label
- src/auto-reply/reply/agent-runner-memory.ts: 6-line early return in
  runPreflightCompactionIfNeeded, placed after isHeartbeat/isCli and
  before codex runtime so the gate is the only OpenClaw-specific path
  affected
- src/auto-reply/reply/agent-runner-memory.test.ts: 1 new test
  (skips preflight compaction when enabled === false) using the
  same test fixture pattern as adjacent tests
- scripts/repro/issue-95553-preflight-disabled-gate.mts: standalone
  real-environment proof that exercises the production gate

Refs openclaw#95553
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: XL labels Jun 22, 2026
@clawsweeper

clawsweeper Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. I reviewed the branch, and this PR is not a good landing base for OpenClaw.

Close: the compaction config-gate idea is understandable, but this submitted branch is not a useful landing candidate because it mixes a small new config surface with a large unrelated task-route-lease storage/runtime series that is already represented by #95481 and is older than that foundation's scoped hook repair.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #95553
Summary: This PR is a candidate for the canonical preflight compaction config/timeout issue, but it is not a viable landing branch because it carries unrelated route-lease foundation work that belongs to a separate open PR.

Members:

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

So I’m closing this PR rather than keeping an unmergeable branch open. A new narrow PR that carries only the useful part is welcome.

Review details

Best possible solution:

Close this mixed branch, keep #95553 open for the canonical preflight cancellation/config decision, and ask for any config-gate work to return as a narrow compaction-only PR after maintainer direction.

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

Yes, at source level: this PR head adds route-lease acquisition without the TaskRecord scope tuple, while the table/API are scope-sensitive. The linked preflight compaction issue is also source-reproducible on current main because the budget path still passes replyOperation.abortSignal into compaction.

Is this the best way to solve the issue?

No. The compaction gate may be a plausible escape hatch, but the submitted branch is not the best fix because it bundles unrelated route-lease storage work and an older route-hook defect; the maintainable path is a narrow compaction-only PR after the linked issue's product decision.

Security review:

Security review needs attention: Needs attention because the branch adds durable requester-origin route storage and a default-scope hook that can cross requester/task boundaries.

  • [high] Default-scoped route leases can expose requester routes — src/tasks/task-executor.ts:132
    requester_origin_json is persisted for completion delivery, but the production acquire hook in this branch does not pass the task scope tuple; same-runId tasks in different scopes can overwrite or recover another task's route and send completion text to the wrong conversation.
    Confidence: 0.88

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Root AGENTS.md and scoped docs/scripts/agents guides were read; the review applied config-surface, stored-state, best-fix, proof, and low-signal PR cleanup guidance. (AGENTS.md:1, 17dc9902f2a8)
  • PR branch scope: Live PR metadata shows 18 changed files, 10 commits, and 1772 additions; the first 9 commits are task-route-lease work and only the final commit is the compaction config gate. (bc2c49ce9d45)
  • Unrelated route-lease hook in this branch: The branch adds task-route lease acquisition in createRunningTaskRun without passing the task runtime/scope tuple; this is route-state work, not part of the compaction config gate, and it matches the older foundation shape later repaired in the dedicated route-lease PR. (src/tasks/task-executor.ts:126, bc2c49ce9d45)
  • Current main still has the preflight abort path: Current main still passes params.replyOperation.abortSignal into required budget/preflight compaction, so this is not an implemented-on-main close and the canonical issue should remain open. (src/auto-reply/reply/agent-runner-memory.ts:981, 17dc9902f2a8)
  • Current config has timeout but no preflight gate: Current main exposes agents.defaults.compaction.timeoutSeconds and related compaction fields, but no preflight config object; this confirms the small config-gate part is unique but product-direction/config-surface work. (src/config/types.agent-defaults.ts:545, 17dc9902f2a8)
  • Dedicated route-lease foundation exists: The open route-lease foundation PR owns the durable task-route lease table/API/hooks and includes the later scoped lifecycle hook repair commit 319bef76bf1f8fcc20a17e415779925750e715a3. (319bef76bf1f)

Likely related people:

  • vincentkoc: Current blame/log history places Vincent Koc on the current split preflight memory runner, compaction timeout wrapper, and task executor facade touched by this PR. (role: recent current-source contributor; confidence: high; commits: a09e1b9aa0e4, c645ec4555c0, 5b2d9b6505db; files: src/auto-reply/reply/agent-runner-memory.ts, src/agents/embedded-agent-runner/compaction-safety-timeout.ts, src/tasks/task-executor.ts)
  • jared596: The central budget/preflight compaction behavior traces to commit c6d8318d07f5, which expanded runPreflightCompactionIfNeeded around transcript estimates. (role: preflight compaction feature contributor; confidence: high; commits: c6d8318d07f5; files: src/auto-reply/reply/agent-runner-memory.ts, src/auto-reply/reply/agent-runner.ts)
  • wangmiao0668000666: This contributor also has current-main history changing the compaction timeout default in bb6e47729cf8 and owns the open route-lease foundation PR whose newer scoped repair supersedes the route-lease part carried here. (role: timeout contract contributor and route-lease proposer; confidence: high; commits: bb6e47729cf8, 319bef76bf1f; files: src/agents/embedded-agent-runner/compaction-safety-timeout.ts, docs/gateway/config-agents.md, src/tasks/task-executor.ts)
  • dutifulbob: Commit 3f6840230b86 unified reply lifecycle behavior around stop, rotation, and restart, which is relevant to the cancellation contract the linked compaction issue needs maintainers to settle. (role: reply lifecycle contributor; confidence: medium; commits: 3f6840230b86; files: src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/agent-runner-memory.ts)
  • steipete: Shared SQLite state and task persistence history around the durable route-state surface includes commits authored by Peter Steinberger, making him a relevant storage-boundary routing candidate. (role: adjacent storage contributor; confidence: medium; commits: bc848b367f0b, d115fb4cf9f9, 1fef20c96bdc; files: src/state/openclaw-state-schema.sql, src/tasks/task-registry.store.sqlite.ts)

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

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 22, 2026
@clawsweeper

clawsweeper Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant