Skip to content

fix(event): keep bounded consume alive after stdin EOF#1183

Open
sjh9714 wants to merge 2 commits into
larksuite:mainfrom
sjh9714:fix-event-consume-bounded-stdin
Open

fix(event): keep bounded consume alive after stdin EOF#1183
sjh9714 wants to merge 2 commits into
larksuite:mainfrom
sjh9714:fix-event-consume-bounded-stdin

Conversation

@sjh9714
Copy link
Copy Markdown

@sjh9714 sjh9714 commented May 30, 2026

Summary

Fixes #1131.

event consume documented --max-events / --timeout as the way to run bounded non-interactive consumers, but the non-TTY stdin EOF watcher still canceled those runs immediately when a subprocess closed stdin. This keeps stdin EOF as the lifecycle signal only for unbounded non-TTY consumers, so bounded runs can exit by their own limit or timeout.

Changes

  • Gate the stdin EOF watcher on non-TTY and no bounded lifecycle flags.
  • Add regression coverage for terminal, unbounded non-terminal, --max-events, and --timeout cases.

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark-cli event consume flow works as expected; not run because this local environment is not configured with Lark app credentials.

Commands run:

  • go test ./cmd/event -run TestShouldWatchStdinEOF -count=1 (failed before the fix)
  • go test ./cmd/event -run 'TestShouldWatchStdinEOF|TestWatchStdinEOF' -count=1
  • go test ./cmd/event -count=1
  • make unit-test
  • go vet ./...
  • gofmt -l .
  • go mod tidy && git diff --exit-code -- go.mod go.sum
  • make build
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=origin/main
  • git diff --check
  • make test (unit/vet/examples stages passed; integration tests then failed because local lark-cli config is not configured, with error.type=config / message=not configured)

Note: I used Codex while preparing this change, and I reviewed the final diff and ran the listed checks locally.

Summary by CodeRabbit

  • Bug Fixes
    • The consume command no longer stops on stdin closure for bounded runs; stdin EOF is only observed for non-terminal sessions with no max-events or timeout set.
  • Tests
    • Added tests validating stdin-EOF behavior across terminal vs non-terminal and bounded vs unbounded run configurations.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 30, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10dcdf3c-b111-4d57-a972-55557941e108

📥 Commits

Reviewing files that changed from the base of the PR and between c6b7090 and db4a09c.

📒 Files selected for processing (2)
  • cmd/event/consume.go
  • cmd/event/consume_stdin_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/event/consume.go

📝 Walkthrough

Walkthrough

This PR refines the stdin EOF shutdown behavior in the event consumer. A new shouldWatchStdinEOF predicate restricts stdin EOF cancellation to non-TTY sessions without lifecycle bounds, replacing the previous non-TTY-only logic. Bounded runs now rely solely on --max-events or --timeout for lifecycle control.

Changes

Stdin EOF Shutdown Gating

Layer / File(s) Summary
Stdin EOF predicate and integration
cmd/event/consume.go, cmd/event/consume_stdin_test.go
Adds shouldWatchStdinEOF(isTerminal, maxEvents, timeout) helper that gates stdin EOF shutdown to non-TTY unbounded sessions. Updates runConsume to call the predicate. Table-driven tests verify behavior across terminal/non-terminal and bounded/unbounded scenarios.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A watchful hare refines the gates,

Stdin's EOF no longer waits—

Bounded runs claim their own reins,

While unbounded flows sustain their veins.

One predicate, four tests proclaim,

Lifecycle control, elegantly tamed. 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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 title clearly and specifically summarizes the main change: keeping bounded consume operations alive after stdin EOF, which is the core fix addressed in this PR.
Description check ✅ Passed The description includes a clear summary, specific changes, comprehensive test plan with commands run, and links the related issue. All key template sections are adequately covered.
Linked Issues check ✅ Passed The PR successfully addresses the requirements in #1131: stdin EOF watcher is now gated behind non-TTY and no bounded lifecycle flags, allowing --max-events/--timeout to complete without premature termination.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the stdin EOF watcher behavior for bounded consumers. No unrelated modifications or scope creep detected in the changeset.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 added the size/L Large or sensitive change across domains or core paths label May 30, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/event/consume.go`:
- Around line 375-377: The predicate shouldWatchStdinEOF currently uses strict
equality to zero for maxEvents and timeout which mismatches downstream semantics
where lifecycle bounds are active only when > 0; change the checks in
shouldWatchStdinEOF (the function determining whether to watch stdin EOF) to use
<= 0 for maxEvents and timeout so negative values are treated as unbounded like
consume.Options / listeningText / exitReason downstream, ensuring a consistent
decision about watching stdin EOF.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50b2fd9e-b363-40a6-88cf-520f0450a4db

📥 Commits

Reviewing files that changed from the base of the PR and between b1ecf2d and c6b7090.

📒 Files selected for processing (2)
  • cmd/event/consume.go
  • cmd/event/consume_stdin_test.go

Comment thread cmd/event/consume.go
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.92%. Comparing base (b1ecf2d) to head (db4a09c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/event/consume.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1183   +/-   ##
=======================================
  Coverage   68.92%   68.92%           
=======================================
  Files         629      629           
  Lines       58762    58764    +2     
=======================================
+ Hits        40503    40505    +2     
  Misses      14952    14952           
  Partials     3307     3307           

☔ View full report in Codecov by Sentry.
📢 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.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add sjh9714/cli#fix-event-consume-bounded-stdin -y -g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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技能, 监听一个条消息, 然后自动回复

2 participants