heartbeat

package
v0.7.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package heartbeat is a tiny idle-heartbeat helper for long blocking calls (an LLM stream between deltas, a single MCP tool call) that otherwise produce zero log output while waiting. Silence during a multi-minute wait is indistinguishable from a hang; a heartbeat every Interval turns that silence into an explicit "still waiting" signal.

Index

Constants

This section is empty.

Variables

View Source
var Interval = 30 * time.Second

Interval is how often an idle heartbeat fires while Touch hasn't been called. Mutable for testing (shrunk so a heartbeat test doesn't eat real wall-clock time), mirroring the connectTimeout / connectOuterGrace mutable-for-testing pattern in internal/pkg/mcp/manager.go.

Functions

This section is empty.

Types

type H

type H struct {
	// contains filtered or unexported fields
}

H ticks a background goroutine that logs a DEBUG "still waiting" line every Interval while the guarded call hasn't completed or produced activity. Touch resets the idle clock (call it on every unit of progress — a stream delta, a progress notification); Stop cancels the ticker goroutine cleanly. Safe for concurrent use: lastActivity is updated via atomic so the ticker goroutine reading it never races Touch's writer.

func Start

func Start(ctx context.Context, msg string, attrs ...any) *H

Start launches the idle-heartbeat goroutine, logging msg (plus attrs) via ctx's logger (scope.GetLogger) every Interval of inactivity. Stop must be called (typically deferred) once the guarded call returns, success or error, so the goroutine doesn't leak.

func (*H) Stop

func (h *H) Stop()

Stop cancels the ticker goroutine and waits for it to exit, so no goroutine leaks past the guarded call's return.

func (*H) Touch

func (h *H) Touch()

Touch resets the idle clock — call it on every unit of progress so the heartbeat only fires during genuinely idle stretches.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL