Skip to content

fix(policy): stop watch promptly when interrupted - #186562

Merged
obviyus merged 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-policy-watch-cancel-20261028
Oct 28, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-policy-watch-cancel-20261028

Conversation

@Alix-007

@Alix-007 Alix-007 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

policy watch keeps its polling wait alive after an interrupt, delaying CLI cleanup until the next interval. Long intervals make an otherwise completed watch appear stuck.

User Impact

SIGINT/SIGTERM stop a waiting watch promptly with exit status 130/143. An already admitted evaluation still settles, but does not emit another report after interruption. --once, interval validation, findings, and attestation semantics remain unchanged.

Why This Change Was Made

Keep cancellation with the watch command: one private AbortController owns the polling wait and first signal result, while a finally removes both listeners. Existing evaluation and error owners remain intact; no new signal API, configuration, permission, or policy-enforcement behavior.

Evidence

Observed runtime capture.

Built CLI, Linux arm64, Node 24.22.1, isolated HOME/profile/config/state/workspace and a real authored policy.jsonc. Commands use policy watch --json --interval-ms 60000; signals arrive after the first report.

Signal Main, twice Candidate, twice
SIGINT Still alive after >5 seconds Natural exit 130 in 47.9/49.2 ms
SIGTERM Still alive after >5 seconds Natural exit 143 in 27.8/26.4 ms
  • No further report after candidate interruption. Baseline processes were explicitly killed for cleanup after the observation window.
  • Both refs retain --once success, invalid-interval rejection, and no-signal behavior.
  • A process-local gate pauses the actual policy-file read for the held-evaluation control only. After a signal the process remains alive until release; candidate then exits 130/143 without a late report. Primary idle-interrupt runs use no preload.
  • 42 focused tests passed, including signal precedence, admitted-evaluation joining, no-signal once, interval-cap/error NDJSON, and exact listener cleanup. The held-signal regressions fail on main while the no-signal control passes. Lint, formatting, and whitespace checks passed.
  • No Gateway, model, channel, or paid credential required.

Simplification: reused the existing Policy CLI harness and consolidated related watch/status/overlay tables, removing duplicate temp-directory, process, and output setup. All distinct cases remain; the contributor's public-helper import repair is retained. Production +43/-11, tests +103/-106 (net -3), docs +4. No ceiling raised.

Two-way door: reverting restores delayed interruption; no migrations or persisted format changes. Blast radius is Policy watch cancellation and cleanup, not policy enforcement or attestation contents.

@clawsweeper

clawsweeper Bot commented Oct 28, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR cancels Policy watch polling on SIGINT or SIGTERM while allowing an active evaluation to settle.

Example: Interrupt openclaw policy watch --json --interval-ms 60000 with SIGINT after its first report.

  • Before: The process remains alive in its polling wait.
  • After: The wait cancels promptly and the process exits 130 without another report.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, correct repair with supplied shipped-CLI proof and preserved regression coverage; broad CI is still running.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The inspected runtime capture exercises the built Policy watch CLI on isolated Linux arm64 with Node 24.22.1 and a real policy file, comparing base and matching candidate production bytes for SIGINT/SIGTERM during idle waits and held evaluations; candidate exits 130/143 after admitted work settles without a late report, while once, invalid-interval, and no-signal controls retain their behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Interrupting a waiting Policy watch leaves the process running instead of completing CLI cleanup.
Reason: The change repairs observed cancellation behavior within the existing command and adds no configuration, public API, or persistence contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current Policy watch cancellation bug without actionable findings; current-head CI remains pending.

Priority: P2
Reviewed head: 45fb14e4f4528349896f4ea7cca60ebaba8bcb97

Before merge

None.

Findings

None.

Agent review details

How this fits together

The bundled Policy plugin registers a CLI watch command that reads workspace policy evidence, evaluates conformance, and emits attestation drift reports between polling waits.

flowchart TD
  A[Policy watch CLI] --> B[Evaluate workspace evidence]
  B --> C[Emit drift report]
  C --> D[Abortable polling wait]
  D --> B
  E[SIGINT or SIGTERM] --> F[Command cancellation owner]
  F --> D
  F --> G[Join evaluation and exit]
Loading

Technical review

Best possible solution:

Land the command-owned abortable wait and evaluation-settlement repair after current-head CI passes.

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

Current-main source shows the uncancellable wait, and the supplied built-CLI comparison confirms both signal failures; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The smallest complete repair belongs in the existing watch command: cancel its wait, retain active evaluation settlement, suppress subsequent reports, and release listeners without changing shared evaluation or error owners.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Policy watch polling and attestation reporting keeps the original intent (a30ac3f: Provide repeated read-only accepted-attestation drift checks and a single-evaluation mode for supervisors and CI.)
  • Command-local ownership and report deduplication keeps the original intent (51ef4bc: Remove private forwarding layers while preserving CLI behavior; the later predicate simplification retained the same report decisions.)
  • Interval ceiling and streamed failure coverage keeps the original intent (7de09d5: Prevent oversized intervals from overflowing Node timers and causing rapid repeated evaluations.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Gio Della-Libera: Raw commit a30ac3f adds extensions/policy/src/cli.ts:300 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a30ac3f8d7cb; files: extensions/policy/src/cli.ts)
  • Peter Steinberger: Raw commit 94749b0 adds extensions/policy/src/cli.ts:312 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 94749b0a45ce; files: extensions/policy/src/cli.ts)
  • Krasimir Kralev: Raw commit 7de09d5 adds extensions/policy/src/cli.ts:414 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 7de09d5a2337; files: extensions/policy/src/cli.ts)

PR surface

Source +32, Tests -3, Docs +4. Total +33 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 43 11 +32
Tests 2 103 106 -3
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 150 117 +33

Review metrics

Metric Value Why it matters
Production versus test changes Production +43/-11 LOC; tests +103/-106 LOC The growth implements command-local cancellation and cleanup; shared test fixtures preserve distinct cases while reducing total test code.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Interrupted Policy watch processes remain alive, affecting a bounded advanced CLI workflow.
  • 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 (2 earlier review cycles)
  • reviewed 2026-10-28T05:56:40.871Z sha bcf83c3 :: needs changes before merge. :: [P2] Replace private root test-helper imports with SDK subpaths
  • reviewed 2026-10-28T06:21:46.628Z sha 330ca9d :: needs maintainer review before merge. :: none

Reviewed October 28, 2026, 4:57 AM ET / 08:57 UTC (Revision 3).

@Alix-007

Copy link
Copy Markdown
Contributor Author

Updated the lifecycle test to use the existing public SDK helper imports. The 49 focused/boundary tests and fresh built-CLI signal/control proof pass at 330ca9de2ba4f94898e64effab410ce7620130ee. Evidence is in the PR body.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 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. 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. 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. labels Oct 28, 2026
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Built CLI proof on Linux arm64, Node v24.22.1, with isolated profile/HOME/config/state/workspace and a real authored policy.jsonc.

Main d013384a7e94dad0e7bc16492b185a5e9d787743; candidate production bytes match 45fb14e4f4528349896f4ea7cca60ebaba8bcb97 (later changes consolidate tests and document cancellation).

openclaw --profile <isolated> policy watch --json --interval-ms 60000
(signal sent to the owned process group after its first report)

                 main #1 / #2                   candidate #1 / #2
SIGINT           alive after 5152 / 5019ms      natural exit130 after47.9 /49.2ms
SIGTERM          alive after 5006 / 5011ms      natural exit143 after27.8 /26.4ms

Candidate emitted no report after the interrupt. Baseline processes were force-stopped by the harness only after observing that they remained alive beyond five seconds.

Controls on both refs:

  • --once: natural exit0, one clean report.
  • Invalid intervals 0 and 500ms: exit2, no evaluation report, unchanged validation message.
  • No signal: watch remains alive with one initial report during the observation window.
  • Held evaluation: a process-local preload pauses the actual read of this task's policy file. After SIGINT/SIGTERM the process remains alive until release, proving admitted work is joined. Candidate then exits130/143 with no late report; main produces one late report. This gate is a control only; primary idle-interrupt runs have no preload.

All child groups were stopped/joined. No system-clock changes, Gateway, model, channel, or paid credentials.

42 focused tests passed after consolidation, including exact listener cleanup, first-signal precedence within the command, held evaluation, once/no-signal, interval cap and error NDJSON. On base the two held-signal regressions fail and the no-signal control passes. Test delta is -3 lines, no ceiling raised. Lint/format/whitespace checks passed.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus
obviyus merged commit eba63b9 into openclaw:main Oct 28, 2026
124 of 129 checks passed
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in eba63b9. Thanks @Alix-007. policy watch now stops promptly on Ctrl-C or a service stop.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for reviewing this and running the extra verification!

obviyus added a commit that referenced this pull request Oct 28, 2026
fix(voice-call): stop voicecall tail on Ctrl-C and SIGTERM

openclaw voicecall tail ignored SIGINT and SIGTERM while it followed the call log, so it kept running and printing records after Ctrl-C or a service stop. It now stops on the first signal and exits with the conventional status, following the pattern policy watch uses (#186562).

Evidence: built Linux CLI on Node 24.22.1. On main tail stayed alive and printed a later JSONL record after each signal (twice each); with this change it exited with 130 or 143 in 41 to 46 ms, with no later output (twice each). The SQLite-backed tail also exits correctly, and no-signal and finite-run controls pass. If stdout is never read, the process now stops through the launcher's SIGTERM after about 1.1 s; on main it never stops in that case. Details: #186691 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 28, 2026
fix(cron): stop cron run --wait on Ctrl-C and SIGTERM

cron run --wait (and the automations alias) ignored SIGINT and SIGTERM while it polled for the job result, so it kept polling after Ctrl-C or a service stop. It now stops on the first signal, exits with the conventional status and prints no final result. It doesn't cancel the job itself, matching policy watch (#186562) and voicecall tail (#186691).

Evidence: built CLI on Node 24.22.1 with both aliases (48 real processes). On main the waiter stayed alive more than 5 s after each signal and made 201 more polls in total (twice each); with this change it exited with 130 or 143 in 20 to 32 ms, with no later polls, no final-result output and no cancel RPC (twice each). Completed, deadline, no-wait and zero-wait controls behave the same on both refs. The Gateway side was a recorded WebSocket fixture. Details: #186750 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
fix(policy): stop policy watch promptly when interrupted

openclaw policy watch ignored SIGINT and SIGTERM while it waited for the next poll, so Ctrl-C or a service stop left it running until it was killed. The watch loop now ends on the first signal, waits for any in-flight policy read to finish, and exits with the conventional signal status.

Evidence: built CLI on Node 24.22.1. On main the watch stayed alive for more than 5 s after SIGINT or SIGTERM (twice each); with this change it exited with 130 or 143 within 26 to 49 ms (twice each). Single-shot, invalid-input and no-signal runs, plus a signal that arrives during a held policy read, behave correctly on both refs. Details: openclaw#186562 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
fix(voice-call): stop voicecall tail on Ctrl-C and SIGTERM

openclaw voicecall tail ignored SIGINT and SIGTERM while it followed the call log, so it kept running and printing records after Ctrl-C or a service stop. It now stops on the first signal and exits with the conventional status, following the pattern policy watch uses (openclaw#186562).

Evidence: built Linux CLI on Node 24.22.1. On main tail stayed alive and printed a later JSONL record after each signal (twice each); with this change it exited with 130 or 143 in 41 to 46 ms, with no later output (twice each). The SQLite-backed tail also exits correctly, and no-signal and finite-run controls pass. If stdout is never read, the process now stops through the launcher's SIGTERM after about 1.1 s; on main it never stops in that case. Details: openclaw#186691 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 29, 2026
…#186750)

fix(cron): stop cron run --wait on Ctrl-C and SIGTERM

cron run --wait (and the automations alias) ignored SIGINT and SIGTERM while it polled for the job result, so it kept polling after Ctrl-C or a service stop. It now stops on the first signal, exits with the conventional status and prints no final result. It doesn't cancel the job itself, matching policy watch (openclaw#186562) and voicecall tail (openclaw#186691).

Evidence: built CLI on Node 24.22.1 with both aliases (48 real processes). On main the waiter stayed alive more than 5 s after each signal and made 201 more polls in total (twice each); with this change it exited with 130 or 143 in 20 to 32 ms, with no later polls, no final-result output and no cancel RPC (twice each). Completed, deadline, no-wait and zero-wait controls behave the same on both refs. The Gateway side was a recorded WebSocket fixture. Details: openclaw#186750 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[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 extensions: policy 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.

2 participants