Skip to content

fix: keep bounded event consume runs alive after stdin EOF#1285

Merged
liangshuo-1 merged 5 commits into
mainfrom
fix/event-consume-stdin-eof
Jun 8, 2026
Merged

fix: keep bounded event consume runs alive after stdin EOF#1285
liangshuo-1 merged 5 commits into
mainfrom
fix/event-consume-stdin-eof

Conversation

@Emrys1105

@Emrys1105 Emrys1105 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

event consume armed its stdin-EOF shutdown watcher for every non-TTY session, so subprocess callers whose stdin is /dev/null (OpenCode, CI, bash -c) were cancelled at startup with Error: context canceled — even when --max-events/--timeout explicitly declared the run's lifecycle (#1131). This PR gates the watcher to non-TTY unbounded runs only, so bounded runs exit via their own bound, timeout, or SIGTERM. Supersedes #1183 (cherry-picked with author attribution preserved) and adds the documentation/contract sync it lacked.

Changes

  • Gate the stdin-EOF watcher with shouldWatchStdinEOF (non-TTY && maxEvents <= 0 && timeout <= 0) in cmd/event/consume.go — cherry-picked from fix(event): keep bounded consume alive after stdin EOF #1183 (author @jinhyuk9714)
  • Extend TestShouldWatchStdinEOF with combined / mixed-sign bound cases in cmd/event/consume_stdin_test.go (9 cases total)
  • Drop the now-misleading "or close stdin" stop hint for bounded runs in internal/event/consume/consume.go, with tests in internal/event/consume/listening_text_test.go
  • Sync skills/lark-event/SKILL.md: bounded-run stdin-EOF exemption and exit-reason table note
  • Append "Bounded runs ignore stdin EOF." to --max-events / --timeout flag help in cmd/event/consume.go

Behavior change: a bounded run no longer stops early when a piped stdin closes — it exits only via its bound, timeout, or SIGTERM. Residual (accepted): unbounded runs over /dev/null keep the documented legacy instant graceful exit (reason: signal); under a cold-start race this can surface as exit 1 context canceled (pre-existing, out of scope).

Test Plan

  • make unit-test passed (full unit + integration suite, via harness validate)
  • validate passed (build / vet / unit / integration / convention / security)
  • local-eval passed (E2E 2/2 passed + 1 fixture-gated skip backed by live manual evidence)
  • acceptance-reviewer passed (7/7 cases)
  • manual verification: lark-cli event consume im.message.receive_v1 --as bot --max-events 1 --timeout 10m < /dev/null in the sandbox container — stayed alive 5m07s on /dev/null stdin, received 1 real IM event, exited 0 with reason: limit

Related Issues

Closes #1131

Supersedes #1183 (commits cherry-picked with original authorship preserved).

@Emrys1105 Emrys1105 added bug Something isn't working domain/event Event subscription domain labels Jun 5, 2026
@CLAassistant

CLAassistant commented Jun 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added size/L Large or sensitive change across domains or core paths and removed domain/event Event subscription domain labels Jun 5, 2026
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refines stdin EOF shutdown behavior for the event consume command. A new shouldWatchStdinEOF predicate gates stdin-EOF watching to non-TTY unbounded runs only. Bounded runs (with --max-events or --timeout) now display guidance that omits "close stdin" instructions. Documentation is updated to clarify this conditional behavior.

Changes

Conditional stdin EOF watching for bounded event consumption runs

Layer / File(s) Summary
stdin EOF watching predicate and CLI wiring
cmd/event/consume.go, cmd/event/consume_stdin_test.go
shouldWatchStdinEOF(isTerminal, maxEvents, timeout) centralizes the logic that enables stdin-EOF shutdown only for non-TTY unbounded runs. The consume command wiring uses this predicate instead of a simple non-TTY check. The --max-events flag help text is extended to document that bounded runs ignore stdin-EOF shutdown.
Bounded run stop guidance updates
internal/event/consume/consume.go, internal/event/consume/listening_text_test.go
stopHintText now accepts Options and returns context-aware guidance: bounded runs instruct SIGTERM kill only, while unbounded runs include both SIGTERM and stdin-close instructions. Tests distinguish unbounded (includes stdin closure) from bounded (no stdin closure) behavior.
Documentation clarifications
skills/lark-event/SKILL.md
Top-level description now includes --as bot flag usage. Stdin EOF behavior clarifies that EOF is ignored for bounded runs. Exit code table specifies stdin EOF applies only to unbounded runs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through bounded time,
No stdin closing—quite sublime!
For unbounded hopes and dreams so free,
Close stdin or SIGTERM, take your key!
Thump thump goes the predicate gate,
Deciding when to shut down—no wait!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main behavior change: keeping bounded event consume runs alive after stdin EOF, directly addressing the core problem in #1131.
Linked Issues check ✅ Passed The PR fully addresses objective #1131 by gating the stdin-EOF watcher to non-TTY unbounded runs only, preventing premature shutdown for bounded runs with explicit --max-events/--timeout while maintaining the intended behavior for unbounded runs.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objectives: stdin-EOF watcher gating, bounded/unbounded run behavior differentiation, stop-hint text updates, and documentation synchronization. No extraneous modifications detected.
Description check ✅ Passed The pull request description is comprehensive and well-structured, covering all required template sections with detailed technical context.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/event-consume-stdin-eof

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@687a3b8b82485f2f1f46448f5f82c4ae89616e6b

🧩 Skill update

npx skills add larksuite/cli#fix/event-consume-stdin-eof -y -g

@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.43%. Comparing base (076f4d5) to head (37d2dc3).

Files with missing lines Patch % Lines
cmd/event/consume.go 80.00% 1 Missing ⚠️
internal/event/consume/consume.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1285   +/-   ##
=======================================
  Coverage   71.42%   71.43%           
=======================================
  Files         688      688           
  Lines       65313    65318    +5     
=======================================
+ Hits        46653    46658    +5     
  Misses      15021    15021           
  Partials     3639     3639           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Emrys1105
Emrys1105 requested a review from liuxinyanglxy June 8, 2026 07:23
@Emrys1105
Emrys1105 force-pushed the fix/event-consume-stdin-eof branch 2 times, most recently from 37d2dc3 to 687a3b8 Compare June 8, 2026 08:51
@liangshuo-1
liangshuo-1 merged commit ec2ffeb into main Jun 8, 2026
22 checks passed
@liangshuo-1
liangshuo-1 deleted the fix/event-consume-stdin-eof branch June 8, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode 中运行lark-event技能, 监听一个条消息, 然后自动回复

5 participants