Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@JustYannicc
Copy link
Contributor

Summary

Skip heartbeat API calls when HEARTBEAT.md exists but contains no actionable content. Saves API costs when users keep an empty/template HEARTBEAT.md.

Closes #1534

Changes

Core logic

  • src/auto-reply/heartbeat.ts - New isHeartbeatContentEffectivelyEmpty() function that detects files with only:
    • Whitespace/empty lines
    • Markdown headers (# , ## , etc.) - note: requires space after # per ATX spec
    • Returns false for missing files (LLM decides) or actual content

Integration

  • src/infra/heartbeat-runner.ts - Check HEARTBEAT.md content before API call; emit skipped/empty-heartbeat-file event when skipping

Tests

  • src/auto-reply/heartbeat.test.ts - 11 new unit tests for isHeartbeatContentEffectivelyEmpty()
  • src/infra/heartbeat-runner.returns-default-unset.test.ts - Integration tests verifying skip behavior

Template

  • docs/reference/templates/HEARTBEAT.md - Updated to be effectively empty by default (header only)

Behavior Matrix

File Content isEmpty Action
Missing false RUN (LLM decides)
# HEARTBEAT.md true SKIP ✅
# Header\n## Section true SKIP ✅
- Check email false RUN
#TODO fix (no space) false RUN (not a valid header)

Testing

npm run test -- heartbeat
# 49 tests pass (11 new + 38 existing)

Real-world validation done on live Clawdbot instance.


AI Contribution Disclosure

  • AI-assisted: Built with Claude (Clawdbot)
  • Testing level: Fully tested - unit tests + integration tests + live validation
  • Understanding: Yes - simple regex-based content detection with careful handling of edge cases (ATX header spec compliance)

JustYannicc and others added 5 commits January 24, 2026 04:11
- Added isHeartbeatContentEffectivelyEmpty() to detect files with only headers/comments
- Modified runHeartbeatOnce() to check HEARTBEAT.md content before polling the LLM
- Returns early with 'empty-heartbeat-file' reason when no actionable tasks exist
- Preserves existing behavior when file is missing (lets LLM decide)
- Added comprehensive test coverage for empty file detection
- Saves API calls/costs when heartbeat file has no meaningful content
Changed instruction text to comment format so new workspaces benefit from
heartbeat optimization immediately. Users still get clear guidance on usage.
@steipete steipete force-pushed the feature/heartbeat-optimization branch from 865e84d to d0e2753 Compare January 24, 2026 04:18
@steipete steipete merged commit dd06028 into openclaw:main Jan 24, 2026
@steipete
Copy link
Contributor

Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: dd06028\n- Merge commit: dd06028\n\nThanks @JustYannicc!

@hkirat hkirat mentioned this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Skip heartbeat API calls when HEARTBEAT.md is effectively empty

2 participants