Skip to content

fix: narrow agentEntry type to avoid TS2339 on heartbeat access#30010

Closed
thomasxm wants to merge 0 commit intoopenclaw:mainfrom
thomasxm:fix/cron-heartbeat-type-narrowing
Closed

fix: narrow agentEntry type to avoid TS2339 on heartbeat access#30010
thomasxm wants to merge 0 commit intoopenclaw:mainfrom
thomasxm:fix/cron-heartbeat-type-narrowing

Conversation

@thomasxm
Copy link

Summary

  • The && short-circuit from Array.isArray(runtimeConfig.agents?.list) && .find(...) produces false | AgentConfig, causing TypeScript to reject .heartbeat access with TS2339 even with optional chaining
  • Coerce with || undefined so the type narrows to AgentConfig | undefined

This is a one-line fix for a CI-blocking type error on main.

Test plan

  • pnpm build passes (no TS2339)
  • pnpm check passes

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime size: XS labels Feb 28, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 28, 2026

Greptile Summary

Fixes TypeScript TS2339 error by narrowing the type of agentEntry from false | AgentConfig | undefined to AgentConfig | undefined. The || undefined coercion ensures that when Array.isArray() returns false, the result is undefined rather than false, allowing safe optional chaining on .heartbeat.

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Type-only fix with zero runtime behavior changes - simply narrows the type to enable proper TypeScript compilation
  • No files require special attention

Last reviewed commit: 3d3fff2

thomasxm pushed a commit to thomasxm/openclaw that referenced this pull request Feb 28, 2026
Cherry-pick from fix/cron-heartbeat-type-narrowing (PR openclaw#30010) to unblock
CI on this branch. The pre-existing bug on main causes `pnpm check` to fail
with TS2339 because `Array.isArray(...) && .find(...)` short-circuits to
`false | AgentConfig` instead of `AgentConfig | undefined`.
Copy link

@nikolasdehor nikolasdehor left a comment

Choose a reason for hiding this comment

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

Clean minimal fix. The || undefined coercion at the declaration site is the right approach — fixes the type narrowing once. Note: PR #30021 touches this exact line with a different approach; this PR's fix is more idiomatic and should take precedence. LGTM.

@openclaw-barnacle
Copy link

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle bot added the stale Marked as stale due to inactivity label Mar 6, 2026
@thomasxm thomasxm closed this Mar 6, 2026
@thomasxm thomasxm force-pushed the fix/cron-heartbeat-type-narrowing branch from 3d3fff2 to b02a076 Compare March 6, 2026 09:17
@thomasxm
Copy link
Author

thomasxm commented Mar 6, 2026

Closing this — the TS2339 type-narrowing issue on agentEntry.heartbeat was already fixed on main in the cron delivery refactor. That commit introduced an intermediate agentHeartbeat variable with an explicit type guard (agentEntry && typeof agentEntry === "object" ? agentEntry.heartbeat : undefined), which eliminates the false | AgentConfig union that caused the original error. This PR's || undefined coercion is no longer needed.

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

Labels

gateway Gateway runtime size: XS stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants