Skip to content

fix(cli): stop session tail polling after a broken pipe - #197038

Merged
obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-sessions-tail-pipe-close-20261111
Nov 11, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
Alix-007:alix/fix-sessions-tail-pipe-close-20261111

Conversation

@Alix-007

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw sessions tail --follow keeps polling indefinitely after its downstream pipe closes and the next event encounters a broken pipe.

User Impact

User impact: piped session followers now release their polling work when output closes. Normal following and the existing SIGINT/SIGTERM exit statuses are preserved. No configuration, storage, protocol, or migration changes.

Why This Change Was Made

The shared console owner already cancels command work on EPIPE. Session tail now observes that cancellation during selection and following, and uses its existing single cleanup path to retire the timer and listeners. Output-close exit status remains owned by the shared console policy.

Evidence

Product head: 85ad3d9763ee5b9e81f844ba2db48760788cd068; acceptance-red base: 83872e599d5720c0bc97d313283a2bc245046699.

  • Real CLI / OS pipe / SQLite: the normal built openclaw.mjs sessions tail --store STORE --session-key KEY --tail 1 --follow reads synthetic canonical session events. After a consumer closes the actual output pipe, a second event is committed. BASE still has live launcher and CLI processes after 6000.22 ms; HEAD naturally exits 0 in 1067.28 ms, with 0 live owned processes before cleanup and no harness signal needed.
  • Controls: both versions deliver later events while the consumer remains connected, exit 130 on SIGINT / 143 on SIGTERM, and pass finite CLI readback of each second event. Configuration bytes stay unchanged. BASE cleanup is recorded separately from the natural HEAD exit.
  • Checks: node scripts/run-vitest.mjs src/commands/sessions-tail.test.ts --maxWorkers=1: 30 passed, 75.954 seconds wall time. Targeted types, lint, format, staged test-line budget, normal CLI build, and independent adversarial review pass; review findings: None. Both existing module mock factories and their ledger are unchanged. Full-repository mock checking is left to PR CI; the overbroad local scan was cancelled, not passed.

Inspectable receipts, raw streams, frozen collector, checks, and independent review. No evidence assets are committed to the product branch.

Replay and scope

Use the published collect.py and collect.mts together on normally built, clean checkouts:

python3 collect.py CHECKOUT NEW_OUTPUT NODE26 EXPECTATION

EXPECTATION=red on BASE and EXPECTATION=green on HEAD change only the expected outcome; the production entry, scenario, controls, and observation bounds are identical. Collector SHA-256: d871e72bb3c5759a2180b940043f1afed5eb6e38bc1f38e059faa9f9055ed4f2; fixture SHA-256: 4e653197156364d2420f1a31c2779c9aee4faf13e335ad7805d59b5242abd128.

Three files: production +22/-4, tests +40/-9 (net 31 LF) and an exact own-regression allocation. Selection cancellation, follow cancellation, raw-signal cleanup, read failures, and post-stop non-polling are covered. The canonical console cancellation owner and neighboring command observers were checked; no shared-console behavior or selector change is required.

Cleanup: only owned processes are retired; isolated fixture stores are retained in the collector output. No real sessions, providers, channels, or user data are used.

Not tested: Windows/macOS, remote Gateway selection against a live service, provider/channel traffic, and the full repository CI matrix. The native proof covers Linux / Node 26 local-store following.

@clawsweeper

clawsweeper Bot commented Nov 11, 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 commands Command implementations size: S labels Nov 11, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Stops session-tail polling when the shared CLI work scope is cancelled after output closes.

Example: A consumer closes the output of openclaw sessions tail --follow, then another session event arrives.

  • Before: The command encounters EPIPE but keeps its polling interval alive.
  • After: The command clears its interval and listeners and exits through the shared console cleanup policy.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A small, useful lifecycle repair with inspected shipped-entry-point proof, preserved signal behavior, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): Inspected contributor artifacts exercise the built openclaw.mjs session-tail command on Linux/Node 26 with canonical synthetic SQLite events and an actual OS pipe: the repaired command exits naturally after pipe closure, while connected following and SIGINT/SIGTERM controls remain correct. The proof predates the latest head, but its exercised follow implementation and shared cancellation owners remain intact.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A piped session follower remains running after its consumer closes and a later event encounters a broken pipe.
Reason: Releasing orphaned polling restores expected CLI cleanup without adding settings, changing stored data, or creating another lifecycle owner.

Merge readiness

✅ Ready for maintainer review

This PR repairs a current CLI cleanup bug with a focused change and convincing real-pipe evidence; no actionable defects found, with exact-head CI still pending.

Priority: P2
Reviewed head: 9f45e653943d06e6465000d14542e061efbf94ff

Before merge

None.

Findings

None.

Agent review details

How this fits together

The sessions CLI reads selected sessions' SQLite trajectory events and prints progress; the shared console owner turns broken output into cancellation that the follow loop must observe.

flowchart TD
  A[Sessions CLI] --> B[Session selection]
  B --> C[SQLite trajectory reader]
  C --> D[Progress output]
  D --> E[Console cancellation owner]
  E --> F[Async work signal]
  F --> G[Follow cleanup]
Loading

Technical review

Best possible solution:

Merge the focused cancellation repair once the required exact-head checks pass.

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

The supplied real-CLI base receipt demonstrates the failure, and current main retains the affected polling implementation; no target code was executed during this read-only review.

Is this the best way to solve the issue?

This is the smallest complete repair: the follow owner observes existing command cancellation, releases its timer and listeners through existing cleanup, and preserves shared exit policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Follow cleanup and signal exit statuses keeps the original intent (22a54d0: Return the terminal outcome after removing polling and listeners so the command boundary preserves conventional signal statuses.)
  • Follow-state ownership keeps the original intent (02aa587: Remove duplicate snapshot plumbing while preserving CLI behavior and keeping follow state with its existing owner.)
  • Lifecycle regression fixtures keeps the original intent (test(core,plugins): remove low-value tests (batch d504) #183075: Consolidate duplicated setup and assertions while preserving distinct lifecycle contracts; this PR extends the retained table with cancellation.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +10, Tests -1. Total +9 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 13 3 +10
Tests 1 7 8 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 20 11 +9

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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A broken downstream pipe leaves an advanced CLI follow invocation polling indefinitely, with impact limited to that command.
  • 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 (1 earlier review cycle)
  • reviewed 2026-11-11T05:25:25.365Z sha 85ad3d9 :: needs maintainer review before merge. :: none

Reviewed November 11, 2026, 1:26 AM ET / 06:26 UTC (Revision 2).

@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 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-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 11, 2026
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Proof for head 9f45e65 (main merged in; the review branch is otherwise unchanged).

What changed on top of the contributor commit:

  • Kept only the fix: the follow loop now stops when the command's existing abort signal fires. Dropped the extra abort checks in session selection (not needed for this bug).
  • Tests: one abort row in the existing follow test instead of new tests. Test lines net -1. Removed the test-lines allocation file.

Setup: secretless node:24.22.1 container, built CLI (pnpm build, node openclaw.mjs), a local stand-in OpenAI-compatible model, real openclaw agent --local turns to write session events. Main at 577da8a and the candidate were each run twice.

Pipe case: openclaw sessions tail --follow --tail 1 --session-key <key> | head -n 1, then one more agent turn, then ps 10 s later.

main run 1 main run 2 candidate run 1 candidate run 2
head printed 1 line and exited yes yes yes yes
openclaw sessions tail still running 10 s after next event yes yes no no
pipeline status (openclaw, head) still running (killed) still running (killed) 0 0 0 0

Controls (same on main and candidate, both runs):

  • --follow without a pipe keeps following and prints the new turn's events.
  • SIGINT exits 130, SIGTERM exits 143.
  • tail without --follow exits 0 with the expected lines.
  • No tail processes left over.

Candidate source: sessions-tail.test.ts passes (28 tests); oxlint clean on both files.

Run logs
== main-1
[06:06:22] lane=main run=1 commit=577da8a944e1f834f2920ec49f51fa0be5ada0fb
[06:06:54] agent turn 1 exit=0
[06:07:05] session key=agent:main:explicit:s197038
[06:07:13] A: head printed: 06:06:52Z session.ended    agent:main:explicit:s197038    success
[06:07:13] A: head running? no
[06:07:54] agent turn 2 exit=0
[06:08:04] A: 10s after next event, tail processes:
   4411 bash -c node openclaw.mjs sessions tail --follow --tail 1 --session-key 'agent:main:explicit:s197038' 2>/proof/out-main-1/A.stderr | head -n 1 > /proof/out-main-1/A.head; echo "${PIPESTATUS[*]}" > /proof/out-main-1/A.status
   4413 node openclaw.mjs sessions tail --follow --tail 1 --session-key agent:main:explicit:s197038
[06:08:04] A: pipeline status (openclaw head): still-running
[06:08:04] A: stderr: 
[06:08:49] agent turn INT exit=0
[06:08:53] INT: still following? yes; lines=8
[06:08:53] INT: exit=130
[06:09:59] agent turn TERM exit=0
[06:10:03] TERM: still following? yes; lines=8
[06:10:03] TERM: exit=143
[06:10:20] D: no-follow exit=0 lines=3
[06:10:20] leftover tail processes: 0
== main-2
[06:10:26] lane=main run=2 commit=577da8a944e1f834f2920ec49f51fa0be5ada0fb
[06:11:28] agent turn 1 exit=0
[06:11:39] session key=agent:main:explicit:s197038
[06:11:47] A: head printed: 06:11:25Z session.ended    agent:main:explicit:s197038    success
[06:11:47] A: head running? no
[06:12:18] agent turn 2 exit=0
[06:12:29] A: 10s after next event, tail processes:
   6778 bash -c node openclaw.mjs sessions tail --follow --tail 1 --session-key 'agent:main:explicit:s197038' 2>/proof/out-main-2/A.stderr | head -n 1 > /proof/out-main-2/A.head; echo "${PIPESTATUS[*]}" > /proof/out-main-2/A.status
   6781 node openclaw.mjs sessions tail --follow --tail 1 --session-key agent:main:explicit:s197038
[06:12:29] A: pipeline status (openclaw head): still-running
[06:12:29] A: stderr: 
[06:13:22] agent turn INT exit=0
[06:13:26] INT: still following? yes; lines=8
[06:13:26] INT: exit=130
[06:14:34] agent turn TERM exit=0
[06:14:38] TERM: still following? yes; lines=8
[06:14:38] TERM: exit=143
[06:14:47] D: no-follow exit=0 lines=3
[06:14:47] leftover tail processes: 0
== cand-1
[06:25:54] lane=cand run=1 commit=4ff9a2e67b4e470062f9c466c3b618d41c023663
[06:26:18] agent turn 1 exit=0
[06:26:24] session key=agent:main:explicit:s197038
[06:26:29] A: head printed: 06:26:15Z session.ended    agent:main:explicit:s197038    success
[06:26:29] A: head running? no
[06:26:54] agent turn 2 exit=0
[06:27:04] A: 10s after next event, tail processes:
[06:27:04] A: pipeline status (openclaw head): 0 0
[06:27:04] A: stderr: 
[06:27:38] agent turn INT exit=0
[06:27:42] INT: still following? yes; lines=8
[06:27:42] INT: exit=130
[06:28:11] agent turn TERM exit=0
[06:28:15] TERM: still following? yes; lines=8
[06:28:15] TERM: exit=143
[06:28:18] D: no-follow exit=0 lines=3
[06:28:18] leftover tail processes: 0
== cand-2
[06:28:20] lane=cand run=2 commit=4ff9a2e67b4e470062f9c466c3b618d41c023663
[06:29:07] agent turn 1 exit=0
[06:29:11] session key=agent:main:explicit:s197038
[06:29:15] A: head printed: 06:28:46Z session.ended    agent:main:explicit:s197038    success
[06:29:15] A: head running? no
[06:29:32] agent turn 2 exit=0
[06:29:42] A: 10s after next event, tail processes:
[06:29:42] A: pipeline status (openclaw head): 0 0
[06:29:42] A: stderr: 
[06:30:10] agent turn INT exit=0
[06:30:14] INT: still following? yes; lines=8
[06:30:14] INT: exit=130
[06:30:39] agent turn TERM exit=0
[06:30:43] TERM: still following? yes; lines=8
[06:30:43] TERM: exit=143
[06:30:46] D: no-follow exit=0 lines=3
[06:30:46] leftover tail processes: 0

@obviyus
obviyus merged commit e04e7ee into openclaw:main Nov 11, 2026
115 of 116 checks passed
@obviyus

obviyus commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Landed in e04e7ee. Thanks @Alix-007.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for tightening the follow-loop fix, simplifying the tests, and checking it with real agent turns!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
)

fix(sessions): stop sessions tail --follow when its output pipe closes

When the reader of openclaw sessions tail --follow closed, for example | head -n 1, the next write hit a broken pipe but the follow loop never saw the command's abort signal, so the CLI kept polling forever. The follow loop now receives the command's existing abort signal and stops once the output closes. No text changes.

Evidence: the built CLI in a secretless node:24.22.1 container with a local stand-in model and real agent --local turns writing session events, two runs each. On main, after head -n 1 exited and the next turn landed, openclaw sessions tail was still running 10 s later. With this change it exits 0 within that time with nothing left running. --follow without a pipe keeps following, SIGINT exits 130, SIGTERM exits 143 and tail without --follow exits 0 on both. One abort row in the existing follow test replaces the new tests, at -1 net test lines. Details: openclaw#197038 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
)

fix(sessions): stop sessions tail --follow when its output pipe closes

When the reader of openclaw sessions tail --follow closed, for example | head -n 1, the next write hit a broken pipe but the follow loop never saw the command's abort signal, so the CLI kept polling forever. The follow loop now receives the command's existing abort signal and stops once the output closes. No text changes.

Evidence: the built CLI in a secretless node:24.22.1 container with a local stand-in model and real agent --local turns writing session events, two runs each. On main, after head -n 1 exited and the next turn landed, openclaw sessions tail was still running 10 s later. With this change it exits 0 within that time with nothing left running. --follow without a pipe keeps following, SIGINT exits 130, SIGTERM exits 143 and tail without --follow exits 0 on both. One abort row in the existing follow test replaces the new tests, at -1 net test lines. Details: openclaw#197038 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit e04e7ee)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit b7941684be7db537856dcea5bb6877d84075c20d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations 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: XS 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