Skip to content

fix(sessions): keep conversations with enabled automations from automatic archiving - #196297

Merged
jalehman merged 6 commits into
mainfrom
fix/187590-automation-parent-retention
Nov 10, 2026
Merged

jalehman merged 6 commits into
mainfrom
fix/187590-automation-parent-retention

Conversation

@jalehman

@jalehman jalehman commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #187590

What Problem This Solves

Fixes: an automation created in a dashboard chat pauses on its own when automatic session maintenance archives that chat for being idle. This happens after 7 days by default, or through pruneAfter or maxEntries.

User Impact

User impact: a conversation that created an enabled automation is no longer archived by automatic maintenance, so weekly reports, watchers and reminders keep running even if nobody opens the chat. Disabling or removing the automation makes the chat eligible again. Archiving or deleting the chat yourself still asks for confirmation (#184818) and still pauses its automations (#178965).

Why This Change Was Made

Since #178965, an automation pauses when the conversation that created it is archived. Scheduled runs never touch that conversation (#185341), so it looks idle to maintenance. This PR registers a session-maintenance preserve provider fed from the cron service's loaded jobs. It uses the same mechanism as pinned rows and active work, so stale-dashboard archiving, age retention and the entry cap all honor it.

  • Only enabled jobs protect a chat, and only the exact creating conversation. The provider resolves that conversation with resolveScheduledPrincipal, the same call occurrence admission uses before it pauses. Wake, delivery and run-session bindings don't pin anything.

  • Under maxEntries, a protected chat still counts toward the cap, the same as a pinned chat. If protection prevents reaching the cap, the store stays above it, as documented.

  • No new config option. Docs are updated in docs/gateway/config-agents/sessions.md and docs/automation/cron-jobs/delivery.md.

  • Gateway startup: cron loads its jobs in the background, after post-ready maintenance has started. A preserve provider can now report isPending(). While any provider is pending, the snapshot carries archivingDeferred and the planner skips only the archiving actions: stale-dashboard, pruneAfter age and maxEntries cap. Everything else runs as today, including removal of disposable runtime rows. The planner change is generic; nothing in it is cron-specific.

    • The Gateway's cron provider is pending from the moment a cron service is created until its jobs register. This includes hot-reload replacements, which are built directly: the replacement arms pending while its predecessor still serves, so the gap after the predecessor unregisters stays protected. A reload that switches cron to disabled builds its replacement with cronEnabled=false, which clears any leftover pending state, so archiving isn't paused for the rest of the process.
    • If cron is disabled (cron.enabled: false or OPENCLAW_SKIP_CRON=1), or no cron service is created, the provider never becomes pending, so archiving proceeds. A disabled scheduler still loads its jobs, and the parents of enabled jobs stay protected. That's deliberate: re-enabling cron must not find those jobs paused because maintenance archived their chats while it was off.
    • If the cron load fails, the provider stays pending, so archiving waits until a later start succeeds. Not archiving errs on the safe side: a missed archive is a cosmetic sidebar delay, but a wrong archive silently stops the user's automations.
    • Cost: while the load stays failed, automatic archiving is paused for the whole process, so the unarchived session count can grow past maxEntries until cron starts. The Gateway logs one warning per process: automatic session archiving is paused: automations failed to load. There are no timers or retries; a later successful start, such as a config reload or restart, resumes archiving.
    • Doctor runs out of process and can't see this runtime-only state, so it isn't surfaced there. The warning and the existing cron start error are the signal.
    • A commit whose planning saw "ready" but whose final protection check sees "pending" is rejected and replanned, like any newly protected row.

Known limits:

  • While a provider is pending, disposable runtime rows such as sub-agent sessions are still pruned. A job whose creating conversation is a sub-agent session can still lose its parent in that window, as it already could before this PR.
  • A local openclaw sessions cleanup --dry-run runs without the Gateway's jobs. --enforce runs in the Gateway and honors the protection.

Evidence

  • Unit (real maintenance planner): node scripts/run-vitest.mjs run src/gateway/session-automation-index.maintenance.test.ts src/gateway/session-automation-index.test.ts: 20 passed. The tests cover each of the stale-dashboard, pruneAfter and maxEntries phases:
    • An idle chat with an enabled bound automation is kept, its job stays enabled, and admission's classifyScheduledParent still reports current.
    • The same chat with a disabled automation, or none, is archived as before.
  • Red on base: with the provider registration removed, the three "keeps" tests fail.
  • Before cron loads (unit, all three phases): with the Gateway's cron service created but not yet loaded, maintenance archives nothing and still prunes the disposable subagent row. Once jobs register, only the protected parent is kept. With no cron service, archiving proceeds as before. After a failed load, archiving stays deferred and the warning is emitted once. A hot-reload test covers the predecessor-to-replacement handoff; it fails when a replacement doesn't arm pending while a source is registered. A second test covers a reload from enabled (not yet loaded) to disabled and checks that archiving resumes. Red: with isPending forced to false, the three deferral tests fail.
  • Shared maintenance suites: store.pruning, store-maintenance.dashboard-archive, the session-accessor.sqlite-maintenance-{kick,cap,worker,writer} tests, cleanup-service.{cap-archive,deferred-sources} and sqlite-exact-read: 9 files passed.
  • Static checks: pnpm tsgo:core, pnpm tsgo:core:test, oxlint and oxfmt on changed files: clean.
  • Real Gateway, local (mock-openai QA scenario):
    • A real turn in another chat triggers automatic maintenance, which archives the idle chats with a disabled automation and with none.
    • The chat with the enabled automation stays unarchived, including after sessions.cleanup --enforce.
    • Its job runs ok and stays enabled.
    • Re-enabling the archived control's job pauses it with the "it was archived" notice.
  • Test-line budget: the new regression tests add 168 net test lines. config/test-lines-allocations/196297-automation-parent-retention.txt grants exactly that, as checks-fast-baseline-ratchets requires.
  • Crabbox AWS proof on 6b7c92c9. The final head 89097433 changes only the test-line allocation file; no runtime, test or doc file differs from the proven head:
    • Run run_94e3713e8a808a96b20bd63fbff0b901, lease cbx_c5d662ff7d0e (c7a.8xlarge, us-east-1). Exit 0; the lease is released.
    • All 21 changed and proof files on the box are sha256-identical to the head.
    • Command: crabbox run --provider aws -- bash proof.sh. The script runs the QA scenario, then the upgrade script.
    • QA scenario cron-automation-parent-retention (real Gateway, mock-openai, archiveDashboardAfter: 6s), 5/5 steps passed:
      • Automatic maintenance, triggered by a real turn in another chat, archives the idle chat with a disabled automation and the idle chat with none.
      • The idle chat with an enabled automation stays unarchived through that pass and through sessions.cleanup --enforce.
      • Its job then runs ok, reaches the model, and stays enabled.
      • Re-enabling the control's job pauses it: "it was archived".
    • Upgrade from v2026.11.2 (same state dir, doctor --fix, then the PR build with archiveDashboardAfter: 5s). All 8 checks passed, 0 failed:
      • Baseline on v2026.11.2: the idle chat with an enabled automation is archived. Stable has no archived-parent pause, so its job still runs.
      • On the PR build, chats and jobs created on stable before the upgrade, and chats and jobs created after it, behave the same:
        • The chat with an enabled automation is kept through automatic maintenance and enforce cleanup. Its job runs ok, reaches the model and stays enabled.
        • The chat with a disabled automation is archived (stale-dashboard). Its job, once re-enabled, pauses with the archived-parent notice, which shows the parent link survived the upgrade.
Upgrade proof results.jsonl (abridged)
{"check":"stable-control-chat-archived","pass":true}
{"check":"stable-enabled-automation-chat-kept","pass":true}
{"check":"post-upgrade-control-chat-archived","pass":true}
{"check":"post-upgrade-enabled-automation-chat-kept","pass":true}
{"check":"stable-protected-automation-still-runs","pass":true,"detail":{"run":{"status":"ok"},"enabledAfter":true}}
{"check":"stable-archived-control-pauses-when-reenabled","pass":true,"detail":{"status":"skipped"}}
{"check":"post-upgrade-protected-automation-still-runs","pass":true,"detail":{"run":{"status":"ok"},"enabledAfter":true}}
{"check":"post-upgrade-archived-control-pauses-when-reenabled","pass":true,"detail":{"status":"skipped"}}
{"observation":"automatic-maintenance-archived-controls-within-30s","detail":{"archived":true}}

@clawsweeper

clawsweeper Bot commented Nov 9, 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 size: S labels Nov 9, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 9, 2026
@clawsweeper

clawsweeper Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR protects conversations with enabled parent-linked automations from automatic archiving and defers archiving while automation protection loads.

Example: A dashboard conversation owns an enabled weekly report and remains idle for 8 days.

  • Before: Default 7-day maintenance archives the conversation, causing its automation to pause.
  • After: Maintenance preserves the conversation and the report continues running; disabling the automation releases protection.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-based repair with shipped-entry-point and latest-stable upgrade evidence, distinct regressions, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Published Gateway results exercise automatic maintenance, sessions cleanup enforcement, protected-job execution, and an archived control's pause through the real Gateway with mock-openai; the final head changes only the test-line allocation, and inspected historical screenshots establish earlier UI behavior rather than this retention fix.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Recurring reports, watchers, and reminders stop when automatic maintenance archives their idle creating conversation.
Reason: The maintainer-authored direction resolves the documented interaction using existing owners, without adding configuration or weakening explicit archive/delete behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a current-main retention gap, and the previous hot-reload finding is resolved; no actionable findings remain.

Priority: P2
Reviewed head: 8909743363dd1fe91689ac7e0bb581d0f80e960f

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway's cron owner supplies enabled jobs to session-maintenance preservation; the shared planner and commit checks use those facts to decide which session rows may be archived.

flowchart TD
  A[Cron job owner] --> B[Exact parent resolution]
  B --> C[Maintenance preservation snapshot]
  D[Cron loading state] --> C
  C --> E[Shared maintenance planner]
  E --> F[Live protection commit checks]
  F --> G[Session store]
Loading

Technical review

Best possible solution:

Merge the cron-owned preservation provider and shared loading deferral once the existing CI gates pass.

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

Current-main maintenance can archive an unprotected idle dashboard parent, and scheduled admission classifies that parent as archived and pauses its job; supplied Gateway evidence exercises the repaired flow, but this review ran no target code.

Is this the best way to solve the issue?

Preserving parents at the shared maintenance boundary fixes the cause while retaining explicit archive/delete pauses, existing retention settings, and occurrence authorization checks.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Josh Lehman: Raw commit 34c735e adds src/gateway/session-automation-index.ts:70 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 34c735e1ccb1; files: src/gateway/session-automation-index.ts)
  • Peter Steinberger: Raw commit 3d9b912 adds src/gateway/session-automation-index.ts:55 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3d9b912b8849; files: src/gateway/session-automation-index.ts)
  • Vyctor H. Brzezowski: Raw commit c4d5fdd adds src/config/sessions/store-maintenance-preserve.ts:107 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c4d5fddda138; files: src/config/sessions/store-maintenance-preserve.ts)

PR surface

Source +125, Tests +168, Docs 0, Other +2. Total +295 across 20 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 15 149 24 +125
Tests 2 172 4 +168
Docs 2 3 3 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 20 326 31 +295

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +149/-24 lines; tests +172/-4 lines Production growth carries protection through existing maintenance and lifecycle owners; regression growth covers three independent archive phases plus loading failure and reload transitions.

Root-cause cluster

Relationship: same_root_cause
Canonical: #187590
Summary: This PR implements the canonical report's requested protection for enabled automations' creating conversations.

Members:

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Automatic retention can silently stop recurring automations attached to idle conversations, with a focused repair and limited affected surface.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster 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 (4 earlier review cycles)
  • reviewed 2026-11-09T23:12:28.140Z sha 3ac99f4 :: blocked before merge. :: none
  • reviewed 2026-11-09T23:38:27.515Z sha 3ac99f4 :: blocked before merge. :: none
  • reviewed 2026-11-10T00:26:53.971Z sha fbb1ef1 :: needs changes before merge. :: [P2] Keep preservation pending across cron hot reloads
  • reviewed 2026-11-10T01:24:22.547Z sha 6b7c92c :: needs maintainer review before merge. :: none

Reviewed November 9, 2026, 8:41 PM ET / November 10, 2026, 01:41 UTC (Revision 5).

@jalehman

jalehman commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 9, 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 9, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 10, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Nov 10, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 10, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 10, 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 10, 2026
@jalehman
jalehman merged commit ac79724 into main Nov 10, 2026
140 of 141 checks passed
@jalehman
jalehman deleted the fix/187590-automation-parent-retention branch November 10, 2026 06:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 11, 2026
…atic archiving (openclaw#196297)

* fix(sessions): keep conversations with enabled automations from automatic archiving

* fix(sessions): defer automatic archiving until automations have loaded

* fix(sessions): warn once when a failed cron load pauses automatic archiving

* fix(sessions): keep automation parents protected across cron hot reloads

* fix(sessions): release archiving deferral when a reload disables cron

* chore(test): allocate test-line growth for automation parent retention
amittell pushed a commit to amittell/openclaw that referenced this pull request Nov 16, 2026
…atic archiving (openclaw#196297)

* fix(sessions): keep conversations with enabled automations from automatic archiving

* fix(sessions): defer automatic archiving until automations have loaded

* fix(sessions): warn once when a failed cron load pauses automatic archiving

* fix(sessions): keep automation parents protected across cron hot reloads

* fix(sessions): release archiving deferral when a reload disables cron

* chore(test): allocate test-line growth for automation parent retention

Carry adaptation for v2026.11.5-beta.4: the index keeps the carry's
resolveCronJobBoundSessionKeys (main renamed it resolveCronJobSessionBindings),
and the new maintenance test reads beta.4's one-argument
classifyScheduledParent(row), which returns a live row where main returns
"current".

(cherry picked from commit ac79724)
amittell added a commit to amittell/openclaw that referenced this pull request Nov 16, 2026
Alex, room openclaw#620. Of the 72 11.3..11.4 commits the census counted as
production changes, six main fixes are ported: openclaw#187499, openclaw#187653, openclaw#188023,
openclaw#195400, openclaw#196297 and openclaw#197960. PORTING-NOTES.md, "The 72 11.4 repairs
reviewed against the carry", records each deferral with its reason, the two
UNSURE outcomes, and the M4 qualification.
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…enclaw#196297)

Backport of ac79724.

Release adaptation: preserve existing display index binding API; adopt maintenance provider, pending-load lifecycle and commit revalidation. Exclude docs and allocation metadata. No schema or retention-policy redesign.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 877a25cd07c2a134b5e1aace6a5a139d734bfe56)
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Feature]: Don't let automatic session archiving pause a conversation's automations

1 participant