chatd

package
v2.33.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const RelaySourceHeader = "X-Coder-Relay-Source-Replica"

RelaySourceHeader marks replica-relayed stream requests.

Variables

This section is empty.

Functions

func NewMultiReplicaSubscribeFn

func NewMultiReplicaSubscribeFn(
	cfg MultiReplicaSubscribeConfig,
) osschatd.SubscribeFn

NewMultiReplicaSubscribeFn returns a SubscribeFn that manages relay connections to remote replicas and returns relay message_part events only. OSS handles pubsub subscription, message catch-up, queue updates, status forwarding, and local parts merging.

Types

type MultiReplicaSubscribeConfig

type MultiReplicaSubscribeConfig struct {
	ResolveReplicaAddress func(context.Context, uuid.UUID) (string, bool)
	ReplicaHTTPClient     *http.Client
	ReplicaIDFn           func() uuid.UUID
	DialerFn              func(
		ctx context.Context,
		chatID uuid.UUID,
		workerID uuid.UUID,
		requestHeader http.Header,
	) (
		snapshot []codersdk.ChatStreamEvent,
		parts <-chan codersdk.ChatStreamEvent,
		cancel func(),
		err error,
	)
	// Clock is used for creating timers. In production use
	// quartz.NewReal(); in tests use quartz.NewMock(t) to
	// control reconnect timing deterministically.
	Clock quartz.Clock
}

MultiReplicaSubscribeConfig holds the dependencies for multi-replica chat subscription. ReplicaIDFn is called lazily because the replica ID may not be known at construction time.

DialerFn, when set, overrides the default WebSocket relay dialer. This is used in tests to inject mock relay behavior without requiring real HTTP servers.

type RelayDialError added in v2.33.0

type RelayDialError struct {
	HTTPStatus int
	Err        error
}

RelayDialError wraps a failed relay handshake. HTTPStatus is 0 when the failure happened before a response (DNS, TCP, TLS, timeout, context cancel); otherwise it carries the peer's status code for the reconnect loop to classify.

func (*RelayDialError) Error added in v2.33.0

func (e *RelayDialError) Error() string

func (*RelayDialError) IsUnrecoverable added in v2.33.0

func (e *RelayDialError) IsUnrecoverable() bool

IsUnrecoverable reports whether retrying with the same captured session token is futile. Only 401/403 qualify - the token is dead or the peer won't authorize it. 5xx, 429, network, and context errors fall through to backoff.

func (*RelayDialError) Unwrap added in v2.33.0

func (e *RelayDialError) Unwrap() error

Jump to

Keyboard shortcuts

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