Skip to content

fix: keep older Run Now attempts from clearing newer runs - #2082

Closed
shanselman wants to merge 2 commits into
openclaw:mainfrom
shanselman:shanselman-cron-run-safety-timer-token
Closed

shanselman wants to merge 2 commits into
openclaw:mainfrom
shanselman:shanselman-cron-run-safety-timer-token

Conversation

@shanselman

@shanselman shanselman commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2076
Related: #2071

What Problem This Solves

Fixes: an earlier Run Now timeout or stale run-history entry can clear the running indicator for a later run of the same job.

User Impact

User impact: An earlier run cannot clear the running indicator for a newer Run Now. For a legacy accepted acknowledgement without a RunId, history cannot safely complete the indicator; the page waits for an independent job-list update or the token-owned safety timeout.

Why This Change Was Made

Each Run Now now has a distinct in-memory token. The 90-second continuation dispatches to the UI thread, verifies that its token is still current, and clears only that run. History completion requires an exact RunId match; runAtMs (execution start) and ts (completion/end record) do not identify an invocation. The timeout no longer requests an uncorrelated cron.list or cron.runs refresh. The separate remove/disabled-job behavior in #2032 is untouched.

Evidence

  • Current candidate: commit 079b18dce43b8fd07d4fffc52913d194a3b84c7c based on e70292487958be9e70170e2f3affe7afc42056e8; the candidate diff SHA-256 before commit was 02D60C7D14F095D7A7A6B23D7833A1DCBD0794B3B1BB90B0EA98F876E1DCE095 and the source fingerprint was unchanged across final validation.
  • Pre-fix-equivalent behavioral negative control: temporarily changed IsCurrentRun to the vulnerable job-only token-presence check, then ran dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --filter FullyQualifiedName~CronRunningLatchTests.StaleRunToken_DoesNotMatchNewerRunForSameJob. It failed at CronRunningLatchTests.cs:16: Assert.False() expected False, actual True (1 failed, 0 passed). Restored the per-run identity implementation; final focused CronRunningLatchTests and CronPageContractTests run passed 10/10. This is a pre-fix-equivalent mutation, not a run against the historical base checkout.
  • Shared autoreview: local candidate against that base, P0-P3, complete scoped-clean, no findings. Independent rubber-duck review: no blocking findings; verified the conservative RunId requirement and timestamp limitation.
  • The isolated fixture UI test passed for rejection recovery only. The A-completes/B-starts/stale-A-history/B-completes sequence remains Not verified: the fixture rejects cron.run with FIXTURE_READ_ONLY and does not implement cron.runs.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • windows-winui-interactive: the Run Now running-state ownership is user-visible; the fixture test covers rejection only, so current-head interactive A/B timeout/history proof is still required and is not claimed here.

Validation

  • Full build: .\build.ps1 - passed; all build targets succeeded.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --filter 'FullyQualifiedName~CronRunningLatchTests|FullyQualifiedName~CronPageContractTests' - 10 passed, 0 failed, 10 total.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore - 4,876 passed, 24 skipped, 4,900 total.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore - 5,300 passed, 0 failed, 5,300 total on the final rerun.
  • dotnet test .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj -c Debug -r win-x64 -p:Platform=x64 -p:DevBuild=false --no-restore --filter 'FullyQualifiedName~CronRunNow_FixtureRejectionRestoresTheRunAction' - 1 passed, 0 failed, 1 total.
  • An earlier full Tray attempt had one unrelated 10-second ActivationRouterTests.MigrationShutdown_UsesCurrentUserIpcWithoutCreatingADeepLinkRoute timeout. The exact test rerun passed 1/1, and the final full Tray rerun passed.
  • git diff --check - passed.

Real Behavior Proof

  • Environment tested: Windows worktree with the isolated synthetic Gateway fixture; no real Gateway or shared runtime.
  • PR head or commit tested: commit 079b18dce43b8fd07d4fffc52913d194a3b84c7c; the exact candidate source was validated before commit and its fingerprint remained unchanged.
  • Exact steps or command run: invoked Run Now on a fixture job; the fixture returned FIXTURE_READ_ONLY, then the test verified the Run Now button was enabled again.
  • Evidence after fix: focused UI test passed 1/1; registry and page-contract tests passed as part of the 5,300-test Tray suite.
  • Observed result: rejection recovery is verified; this is not stale-timeout ownership proof.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A
  • Not verified or blocked: the fixture rejects cron.run and does not implement cron.runs, so the live A/B completion/history/timeout sequence cannot run without fixture work outside this issue.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): Yes, the 90-second timeout no longer issues uncorrelated cron.list or cron.runs requests.
  • Command or tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any answer is Yes, explain the risk and mitigation: The change removes the uncorrelated timeout-triggered cron.list and cron.runs requests. It adds no network surface; the UI now clears only for the current per-run token or an exact RunId match, preventing a stale response from clearing a newer run.

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes, with legacy ID-less history intentionally not used to complete a run.
  • Config or environment changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

Give each Run Now attempt its own token and require matching run identity before a timeout or history entry clears the running state. Avoid timeout-triggered uncorrelated cron refreshes.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

🦞👀
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 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 priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR gives each Run Now attempt its own token so older callbacks and unrelated history cannot clear a newer run.

Example: Job job-1 starts run A at 0 seconds, finishes at 10 seconds, and starts run B at 20 seconds.

  • Before: A's 90-second timer clears B's running indicator, cancels its refresh loop, and enables its actions.
  • After: A's timer finds a different current token and leaves B's indicator and refresh loop intact.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused implementation appears correct, but the supplied runtime evidence does not establish the changed behavior.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An older manual run can make a newer run appear finished and enable its actions prematurely.
Reason: The collaborator-authored direction addresses a concrete source-owned race with a narrow repair and explicitly records its legacy acknowledgement tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this collaborator-authored PR addresses a source-confirmed race still present on main; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 079b18dce43b8fd07d4fffc52913d194a3b84c7c

Before merge

None.

Findings

None.

Tests

  • Low-value test tests/OpenClaw.Tray.Tests/CronPageContractTests.cs: Remove the added assertions that merely require the exact BeginRun and MatchesRunId call strings when behavioral callback coverage replaces them; those assertions pin implementation names without exercising stale completion.
  • Missing end-to-end proof: The accepted A/B lifecycle through CronPage, including stale timeout and history rejection followed by B's legitimate completion, is unverified; the supplied negative control mutates the new helper rather than running the historical base.
Agent review details

How this fits together

CronPage sends manual-run requests through OpenClawGatewayClient and combines acknowledgements, history, job-list updates, and timers to control running indicators and job actions.

flowchart TD
  A[Run Now button] --> B[CronPage]
  B --> C[Gateway client]
  C --> D[Gateway cron service]
  D --> E[Acknowledgements and history]
  E --> B
  F[Per-run token and timer] --> B
  B --> G[Running indicator and actions]
Loading

Technical review

Best possible solution:

Keep per-run identity and completion checks under CronPage's existing UI-thread ownership.

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

Current-main source establishes the A-completes/B-starts/A-times-out sequence; no live reproduction was run during this read-only review.

Is this the best way to solve the issue?

The focused token registry addresses stale callbacks directly, and exact RunId matching prevents timestamp-based miscorrelation; the author explicitly accepts the conservative ID-less fallback.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Safety timeout and asynchronous run acknowledgement keeps the original intent (61fcd39: The Cron page redesign introduced a persistent running indicator and a safety timeout so controls could recover if completion was not reported.)
  • History completion and timeout-triggered refresh changes intended behavior with a stated reason (638386e: Run-history UX work added polling and completion detection to keep manual runs and their controls responsive; this PR explains why uncorrelated refreshes and timestamp-only completion can affect newer attempts.)
  • Independent job-list latch clearing keeps the original intent (e01db9f: The existing predicate clears a scheduled-running latch when the Gateway reports idle and advances the next run; that predicate remains unchanged.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Régis Brid: Raw commit 638386e adds src/OpenClaw.Tray.WinUI/Pages/CronPage.xaml.cs:241 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 638386ed73ae; files: src/OpenClaw.Tray.WinUI/Pages/CronPage.xaml.cs)

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 and test delta Production +57/-14 lines; tests +127/-0 lines. The production growth provides invocation identity and correlation without introducing persistence or a new application service.

Labels

Label changes:

  • add P2: The race affects running indicators, refresh loops, and action availability for repeated manual cron runs, with no demonstrated loss of job execution.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The race affects running indicators, refresh loops, and action availability for repeated manual cron runs, with no demonstrated loss of job execution.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed November 8, 2026, 4:59 AM ET / 09:59 UTC.

@shanselman

Copy link
Copy Markdown
Collaborator Author

Hi @karkarl! I'm a Copilot triage bot posting for Scott (I'm not Scott). He asked me to assign this PR to you and see if you'd be up for reviewing it and merging it when you're happy with it.

This is one of five small fixes from the state machine audit in #2071 (Fix dangerous implicit state machines (audit lanes)). This one stops an older Run Now timeout or stale history entry from clearing the running indicator for a newer run of the same cron job.

CI note: all UI tests passed (653 passed, 7 allowed skips), but the job then failed on an HTTP 504 while downloading a compatibility archive. That looks like a temporary infrastructure hiccup, so a rerun will probably turn it green.

No rush at all, and please feel free to ask for changes or push back. Thank you so much!

@roboclaw-bot

Copy link
Copy Markdown
Contributor

PR cleanup review

Reviewed head: 079b18dce43b8fd07d4fffc52913d194a3b84c7c. Main comparison: e59374c064f43d68f5c72d070d4c89ef2d20ec3b.

Source cleanup review at 079b18d against main e59374c: the per-attempt token and server run-ID checks are not in main and address the stale-callback race without adding timeout polling. The failed CI job reached 653 passing UI cases and 82 passing fixture cases, then failed downloading the stable archive with HTTP 504, so a targeted rerun is justified. The remaining custom-proof gap is an accepted A/B overlap with stale A completion/timeout while B is running; the added native rejection case does not demonstrate that sequence.

Action in this cleanup pass: leaving this PR open. No branch changes or runtime-proof waiver. The findings above come from source, discussion and recorded-CI review; Windows validation was not rerun in this pass.

@shanselman

Copy link
Copy Markdown
Collaborator Author

Hi! I'm a Copilot triage agent posting for Scott (I'm not Scott). I was doing a landing pass and checked this PR against current main. I'm only leaving notes here: I haven't changed, closed or merged anything.

What I found

  • All five files this PR touches are gone or replaced on main. #1893 (feat(automations): native Automations page with web parity) deleted CronRunningLatch.cs, CronPageContractTests.cs, CronRunningLatchTests.cs and CronTimezoneUiTests.cs, and the Cron page itself was replaced by the new Automations page. So this branch can't be rebased as-is.
  • The behavior this PR protects looks like it is already covered by the new store. In src/OpenClaw.Shared/Cron/AutomationsStore.cs, RunNowAsync gives each run its own RunInvocation, refuses a second Run Now while one is still tracked, and every completion path (acknowledgement, history poll, safety timeout) is posted to the UI thread and guarded by OwnsRun / OwnsWatcher. History completion needs an exact RunId match, and a legacy acknowledgement without a RunId keeps only the owner-bound safety timeout. That is the same contract this PR describes.
  • Existing tests in tests/OpenClaw.Shared.Tests/AutomationsStoreConcurrencyTests.cs cover the neighbouring cases: SuccessiveRunsRequireTheAcceptedRunIdDespiteStaleHistoryAndListState, IndependentListTimestampsCannotCompleteIdentifiedOrIdlessLocalRuns and LateAcknowledgementCannotRetireOrReplaceANewerInvocation.

What I did not verify

  • I did not find a test that fires an older run's safety timeout after a newer run has started. By reading the code it should be a no-op (the old watcher is cancelled when the run clears, and the timeout is ownership-checked), but I didn't prove it by running it.
  • I did not drive the new Automations page by hand.

Suggestion for the owner (no pressure)

This looks superseded by #1893 (feat(automations): native Automations page with web parity). If you agree, this PR and its issue #2076 (Give the cron Run Now safety timer a per-run token; lane 5 of #2071, Fix dangerous implicit state machines (audit lanes)) could be closed as obsolete. If you'd like proof first, one small store test for the old-watcher timeout would settle it.

Retain the main AutomationsStore owner and its invocation identity guards. Port the distinct ID-less timeout and rejected Run Now regressions to the current test owners instead of restoring deleted CronPage logic.

Co-authored-by: bkudiess <[email protected]>
@bkudiess

Copy link
Copy Markdown
Collaborator

Closing this as superseded by #1893 (feat(automations): native Automations page with web parity).

The original fix (079b18dc) changed the old Cron page's Run Now handling and added a per-run token in CronRunningLatch. #1893 replaced that page with the native Automations page and moved Run Now handling into AutomationsStore. The store now gives each Run Now its own invocation and checks that a safety timeout still owns the job before clearing it. That is the same protection this PR added, so the bug from #2076 is already fixed on main.

After the latest merge from main, this PR only adds tests (AutomationsStoreConcurrencyTests and one AutomationsUiTests wait). It no longer changes app code.

Thanks @shanselman for the original fix and the regression case. Related: #2071.

@bkudiess bkudiess closed this Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

Give the cron Run Now safety timer a per-run token

4 participants