Skip to content

fix(cron): keep replies to delivered questions in the same idle session - #128845

Merged
steipete merged 15 commits into
openclaw:mainfrom
Thinkr1:fix/cron-delivery-mirror-idle-freshness
Oct 15, 2026
Merged

steipete merged 15 commits into
openclaw:mainfrom
Thinkr1:fix/cron-delivery-mirror-idle-freshness

Conversation

@Thinkr1

@Thinkr1 Thinkr1 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #128797

What Problem This Solves

A reply to a cron-delivered question can cross an idle reset and lose the question, even when the operator answers within minutes of delivery.

User Impact

A visible automation result newly appended to its destination conversation starts a fresh idle window. Silent runs, failed or uncertain deliveries, and retries of the same result do not refresh it. Recurring visible results can keep a destination idle-fresh; daily resets still use the session start time. No configuration or schema migration is needed.

Why This Change Was Made

Current main removed direct transcript mirrors in #168996 and now commits destination results through the canonical background-result writer. That writer still updates updatedAt, while idle expiry reads lastInteractionAt. Pass the message timestamp through its existing lifecycle patch so the guarded worker transaction commits the message and freshness together, only on a new append. This adds no parallel freshness writer or main-thread database access.

Original fix by @Thinkr1; maintainer cleanup moves the repair to the current owner and removes the obsolete six-file opt-in plumbing and QA scenario. The new regression uses a bare ok follow-up, addressing ClawSweeper's P2 finding that the old scenario repeated the question marker and could falsely report retained context. Main's current delivery, restart, and writer guards are preserved.

The background commit retains the admitted config-derived store path, agent/session identity, confirmed payload, and occurrence key. Existing producer/abort checks and session ID/lifecycle checks revalidate authority at the commit; the timestamp is captured after waiting for active work and preparing display content. No new deferred work or captured limits are introduced.

Evidence

Exact-head CI run 38812272070 passed: 37 successful jobs, 28 skipped, zero failures, on c247a03bd5eeb96df8d417e643ceb9cd32f07b00. This includes production/test typechecks, lint, build, UI checks, and the selected test shards.

  • Source/history confirmation on main f6c0408505eb32d25d794557df153bdc4738a85d: the background-result commit omitted lastInteractionAt, and evaluateSessionFreshness uses that field for idle expiry.
  • Regression: keeps the destination session for a reply to a delivered cron question in src/cron/isolated-agent/destination-completion.test.ts. It exercises cron dispatch, durable destination persistence, replay without a second freshness touch, and the next operator reply under a 180-minute idle policy. The previous human interaction is already 185 minutes old at delivery. The stored row is seeded as stale; no clock overrides, real timers, or sleeps are added.
  • Initial CI run 38805509290 caught a fixture bug: pinning only the test-thread clock to May made it disagree with the real SQLite delivery worker, so dispatch timed out before the freshness assertion. Removed the clock override and retained the production-path assertions. The next run passed delivery, freshness, and replay assertions, then exposed a missing inbound-finalization step in the reply fixture; it now uses the production finalizeInboundContext owner. The third run passed the runtime regression and all destination/background-result tests; its test typecheck caught the missing required commandAuthorized argument, now explicitly false for this ordinary reply. These were new fixture errors, not inherited failures; no CI reruns were requested.
  • Existing destination regressions cover NO_REPLY, failed/uncertain sends, session resets, and duplicate results. PR CI ran these tests through node --import tsx scripts/ci-run-node-test-shard.mts and supplied the typecheck gate. On head c247a03bd5eeb96df8d417e643ceb9cd32f07b00, changed-test job 116689168044 passed all 16 destination tests and 9 background-result tests. The new regression passed in 5.322 seconds. File wrapper wall times were 75.01 seconds and 25.74 seconds, respectively (including transforms/imports and worker setup). The destination integration uses real delivery/storage/reply-admission owners; no Gateway process or local test execution was used.
  • Changed-file oxfmt, core oxlint, and git diff --check passed. The borrowed install lacks the UI-only Solid lint dependency, so the static lint config omits only UI overrides; all applicable core rules are retained. No dependency installation or shared-install changes.
  • Codex autoreview, including the CI fixture correction: scoped-clean, no actionable P0–P2 findings. Review covered the diff and current writer/kernel/delivery owners; no project code was executed.
  • ClawSweeper revision 15 (reviewed head bc5b35fad377) reports no actionable code findings and confirms the earlier false-positive test was addressed. Its sole remaining request is live Gateway/Telegram proof; that proof-only request is intentionally not followed under the maintainer policy below. The final required-boolean fixture correction is covered by fresh autoreview and green exact-head CI.
  • Live Gateway/Telegram proof, leases, local typechecks, local test suites, and production-revert negative controls were intentionally skipped per maintainer policy. PR CI is the proof; earlier contributor live claims are not carried forward as evidence for this head.
  • Delta against main: production +1/-0, tests +89/-0, docs +4/-2. The one production line uses the existing lifecycle contract; unrelated deletion would not make this fix safer.

@clawsweeper

clawsweeper Bot commented Aug 24, 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.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Refresh destination idle freshness when a visible automation result is newly committed to its conversation.

Example: A Telegram conversation has been idle for 185 minutes under a 180-minute policy when an automation asks “Approve the scheduled transaction?”

  • Before: A subsequent “ok” triggers idle rollover and loses the scheduled question.
  • After: The delivered question starts a new idle window, so “ok” continues the conversation containing it.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and supported by green exact-head CI, but supplied evidence does not satisfy the required shipped-entry-point proof.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Replies to recently delivered automation questions can lose those questions across an idle reset.
Reason: The report establishes concrete user impact, and the maintainer repair commits adopt the narrow visible-result exception to system-event freshness policy.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it repairs a current session-context bug through the existing persistence owner, has maintainer engagement, and introduces no actionable code defect.

Priority: P1
Reviewed head: c247a03bd5eeb96df8d417e643ceb9cd32f07b00

Before merge

  • Add real behavior proof - The current body withdraws earlier live claims and supplies a passing production-owner integration test with mocked Telegram transport. Provide redacted Gateway/Telegram logs, live output, or a recording showing delivery after 185 idle minutes under a 180-minute policy, followed by a bare “ok” whose provider context contains the question exactly once, plus replay without another freshness refresh. Redact IPs, API keys, phone numbers, and non-public endpoints; then request re-review. The cited maintainer testing policy does not waive this external-PR proof gate. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: The shipped Gateway/Telegram idle-boundary flow remains unshown, and no executed base-fail/head-pass negative control is supplied for the new regression.
Agent review details

How this fits together

Cron delivery passes confirmed visible output to the canonical background-result writer, which atomically appends conversation history and updates session metadata consumed by inbound reply admission.

flowchart LR
  A[Cron result] --> B[Confirmed delivery]
  B --> C[Background result writer]
  C --> D[Transcript and freshness transaction]
  D --> E[Inbound reply admission]
  E --> F[Conversation context]
Loading

Technical review

Best possible solution:

Retain this focused repair in the canonical background-result transaction, preserving replay idempotency and daily-reset semantics.

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

The linked report supplies an official affected release and transcript evidence, and current source confirms that delivered results omit the timestamp used for idle expiry; no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

This is a focused root-cause repair using the existing atomic lifecycle patch, with no competing freshness writer or configuration surface.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Interaction freshness versus bookkeeping changes intended behavior with a stated reason (566d2d7: Separate session start and interaction timestamps from updatedAt so background bookkeeping cannot indefinitely postpone resets.)
  • Canonical background-result persistence keeps the original intent (133d5ff: Make the conversation own durable automation output through serialized, idempotent transcript persistence.)
  • Destination conversation ownership keeps the original intent (e63e209: Commit confirmed delivered content to its destination instead of maintaining competing transcript mirrors and awareness notes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned production change: The introduced diff adds lastInteractionAt to the existing lifecycle patch without adding another writer, configuration option, or storage format. (src/sessions/background-session-result.ts:171, c247a03bd5ee)
  • Current main still needs the repair: Current main's background-result writer touches updatedAt without setting lastInteractionAt; evaluateSessionFreshness uses lastInteractionAt for idle expiry, and inbound admission forwards that timestamp. (src/sessions/background-session-result.ts:170, 330c27ed6342)
  • Atomic update and replay behavior: The transcript kernel applies the lifecycle patch in the append transaction; this caller supplies no expectedSessionState, so an idempotent replay does not apply the freshness patch. (src/config/sessions/session-transcript-turn-state.ts:109, c247a03bd5ee)
  • Maintainer-adopted direction: The verified steipete repair commit explicitly adopts the canonical background-result lifecycle patch; the current description acknowledges that recurring visible results can keep destinations idle-fresh while daily resets retain session-start semantics. (src/sessions/background-session-result.ts:171, afadce351573)
  • Independent regression assertions: The regression dispatches a question, verifies persisted freshness and unchanged replay freshness, then admits a bare “ok” through finalizeInboundContext and initSessionState while independently checking the retained question. (src/cron/isolated-agent/destination-completion.test.ts:48, c247a03bd5ee)
  • Exact-head CI: GitHub confirms CI run 38812272070 succeeded on the reviewed head, including checks-node-changed-1 and openclaw/ci-gate; all 37 executed jobs succeeded and 28 were skipped. (c247a03bd5ee)

Likely related people:

  • Peter Steinberger: Raw commit ca77256 adds src/sessions/background-session-result.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ca77256127e6; files: src/sessions/background-session-result.ts)
  • Josh Lehman: Raw commit 133d5ff adds src/sessions/background-session-result.ts:115 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 133d5fff6c94; files: src/sessions/background-session-result.ts)
  • weiqinl: Raw commit bf7ccd6 adds src/sessions/background-session-result.ts:170 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: bf7ccd6f191f; files: src/sessions/background-session-result.ts)

PR surface

Source +1, Tests +89, Docs +2. Total +92 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 1 89 0 +89
Docs 2 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 94 2 +92

Review metrics

Metric Value Why it matters
Production versus regression code Production +1/-0; tests +89/-0 The production change reuses the existing transaction, while the integration regression protects delivery persistence, replay freshness, and subsequent reply admission.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: A timely operator reply can silently lose its scheduled question and be interpreted against unrelated conversation context.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Telegram can expose whether a terse reply retains a newly delivered scheduled question across the previously expired idle boundary.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the delivered-question, bare-reply, and replay evidence described in the proof assessment.

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 (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-25T12:02:10.988Z sha 66e013daf5895ed2f0aff603edaaae4c11547892 :: needs changes before merge. :: [P2] Describe custom-session freshness accurately
  • reviewed 2026-08-25T13:20:00.627Z sha 6d1ace2b3ef1f12932f03838e26a7b2d7e74b89a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-28T21:22:52.873Z sha 5b5a5091abbb8f533f4b6ec9b9ce8eba829b2e21 :: needs real behavior proof before merge. :: [P1] Pass the freshness flag to the active SQLite turn writer
  • reviewed 2026-08-29T20:21:20.764Z sha 96535ba :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T14:30:07.764Z sha 96535ba :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T14:40:25.681Z sha 96535ba :: blocked before merge. :: none
  • reviewed 2026-10-03T17:43:16.818Z sha 96535ba :: blocked before merge. :: [P2] [P2] Check cron context independently of the follow-up text
  • reviewed 2026-10-15T21:41:01.390Z sha bc5b35f :: needs real behavior proof before merge. :: none

Reviewed October 15, 2026, 6:10 PM ET / 22:10 UTC (Revision 16).

@Thinkr1

Thinkr1 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 24, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 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:

@Thinkr1
Thinkr1 force-pushed the fix/cron-delivery-mirror-idle-freshness branch from 64fc392 to 2c9d102 Compare August 25, 2026 08:52
@Thinkr1

Thinkr1 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 25, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 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 merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@clawsweeper clawsweeper Bot added proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 3, 2026
steipete and others added 2 commits October 15, 2026 13:49
Integrate current main and replace obsolete mirror-specific freshness plumbing with the canonical background-result lifecycle patch. Preserve replay semantics and cover the next operator reply without repeating the scheduled question.
@steipete steipete changed the title fix: cron delivery mirror renews channel session idle freshness fix(cron): keep replies to delivered questions in the same idle session Oct 15, 2026
@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. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Oct 15, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 9eb0dba into openclaw:main Oct 15, 2026
130 of 131 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…on (openclaw#128845)

* fix: renew idle freshness when cron delivery mirrors into channel session

operator-facing delivery mirrors now stamp lastInteractionAt alongside updatedAt so idle reset does not cut between the cron question and reply

fixes openclaw#128797

* test: use resolveSessionResetPolicy in cron mirror freshness regression

* fix: scope idle refresh to direct cron delivery mirrors

make touchLastInteractionAt an explicit opt-in from appendDirectCronDeliveryTranscriptMirror instead of enabling it for every appendExactAssistantMessageToSessionTranscript call; and add preservation coverage for generic assistant appends and update cron mirror expectations

* test: prove cron delivery session freshness end to end

* test: fix cron delivery freshness QA config

* docs: document cron delivery freshness behavior

* docs: clarify cron session freshness targets

* test(cron): preserve delivery worker clock in freshness regression

* test(cron): finalize operator reply context before session admission

* test(cron): specify command authority for the operator reply

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Thinkr1 <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S 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.

Cron delivery appended to a channel session does not refresh its idle freshness, so the reset cuts between the question and the operator's answer

2 participants