gitruntime

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxReadProcesses          = 8
	MaxWorkspaceCaptures      = 2
	MaxMutationProcesses      = 4
	MaxDestructiveScans       = 1
	MaxRequestDecodes         = 16
	MaxResponseBuilds         = 8
	MaxRPCStreams             = 4
	MaxConcurrentRPCRequests  = 4
	MaxQueuedRPCRequests      = 8
	MaxQueuedRPCNotifications = 4
	RequestReservation        = 8 << 20
	ResponseReservation       = 12 << 20
	StreamReservation         = 32 << 20
	CaptureReservation        = 8 << 20
	MaxRequestReservations    = MaxRequestDecodes * RequestReservation
	MaxResponseReservations   = MaxResponseBuilds * ResponseReservation
	MaxCaptureReservations    = MaxWorkspaceCaptures * CaptureReservation
	MaxRPCStreamReservations  = MaxRPCStreams * StreamReservation
	MaxPublishedSnapshotBytes = 128 << 20
	MaxRawRequestBytes        = 768 << 10
	MaxResponsePayload        = 768 << 10
	MaxSyntheticEnvelope      = 768 << 10
	MaxJSONDepth              = 32
	MaxJSONTokens             = 32_768
	MaxJSONRecords            = 8_192
	MaxJSONStringBytes        = 640 << 10
	MaxJSONTotalStringBytes   = 2 << 20
)
View Source
const (
	ErrorResponseBudget uint32 = 41305
	ErrorResourceLimit  uint32 = 41306
	ErrorRequestBudget  uint32 = 41307
)
View Source
const (
	MaxGitStdoutBytes = 1 << 20
	MaxGitStderrBytes = 64 << 10
)

Variables

View Source
var (
	ErrResourceLimit          = errors.New("git runtime resource limit")
	ErrRequestBudget          = errors.New("git request budget exceeded")
	ErrResponseBudget         = errors.New("git response budget exceeded")
	ErrContainmentUnavailable = errors.New("git subprocess containment unavailable")
)

Functions

func JSONEncodedSize

func JSONEncodedSize(value any, maxBytes int) (int, error)

JSONEncodedSize returns the exact encoding/json-compatible size of value while failing as soon as the output would exceed maxBytes. The closed encoder intentionally supports only the DTO shapes used by Git RPCs.

func MarshalJSONBounded

func MarshalJSONBounded(value any, maxBytes int) (json.RawMessage, error)

MarshalJSONBounded encodes value without allowing either the returned slice or an intermediate encoding buffer to grow beyond maxBytes.

func RegisterTyped

func RegisterTyped[TReq any, TResp any](
	router *sessionrpc.Router,
	typeID uint32,
	runtime *Runtime,
	spec RPCSpec[TReq, TResp],
	gate *accessgate.Gate,
	meta *session.Meta,
	policy accessgate.RPCAccessPolicy,
	handler func(context.Context, *TReq) (*TResp, error),
)

RegisterTyped applies the closed Git-domain request and response budgets. The decode reservation remains held until the handler and response guard finish, so the decoded DTO cannot outlive its admission.

Types

type Admission

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

Admission is an idempotently released runtime reservation.

func (*Admission) Release

func (a *Admission) Release()

type CommandError

type CommandError struct {
	ExitCode       int
	UnknownOutcome bool
	BudgetExceeded bool
	Cause          error
}

func (*CommandError) Error

func (e *CommandError) Error() string

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

type CommandKind

type CommandKind uint8
const (
	CommandRead CommandKind = iota
	CommandMutation
)

type CommandResult

type CommandResult struct {
	Stdout         []byte
	Stderr         []byte
	ExitCode       int
	UnknownOutcome bool
}

type Coordinator

type Coordinator interface {
	AcquireRead(context.Context, RepositoryIdentity) (Lease, error)
	AcquireMutation(context.Context, RepositoryIdentity) (Lease, error)
	Invalidate(RepositoryIdentity)
}

Coordinator is the narrow contract used by repository services.

type FilesystemEffect

type FilesystemEffect struct {
	Paths           []string
	ChangesTopology bool
}

FilesystemEffect describes the paths whose topology or content will change.

type FilesystemMutationCoordinator

type FilesystemMutationCoordinator interface {
	CoordinateFilesystemMutation(context.Context, FilesystemEffect, func() error) error
}

FilesystemMutationCoordinator is the only Git runtime contract exposed to the filesystem service.

type Lease

type Lease interface {
	Epoch() uint64
	Context(context.Context) context.Context
	Release()
}

Lease covers the topology and common-repository gates in their required acquisition order.

type RPCSpec

type RPCSpec[TReq any, TResp any] struct {
	Request  RequestSpec[TReq]
	Response ResponseSpec[TResp]
}

func DefaultRPCSpec

func DefaultRPCSpec[TReq any, TResp any]() RPCSpec[TReq, TResp]

type RepositoryIdentity

type RepositoryIdentity struct {
	CommonRepoKey string
	WorktreeKey   string
	WorktreeRoot  string
	CommonDir     string
	GitDir        string
}

RepositoryIdentity separates shared-ref coordination from worktree-local index and snapshot identity.

type RequestSpec

type RequestSpec[T any] struct {
	Validate func(*T) error
}

type ResponseSpec

type ResponseSpec[T any] struct {
	RetainedBytes func(*T) (int64, error)
}

type Runtime

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

func New

func New() *Runtime

func (*Runtime) AcquireCapture

func (r *Runtime) AcquireCapture(ctx context.Context) (*Admission, error)

func (*Runtime) AcquireDestructiveScan

func (r *Runtime) AcquireDestructiveScan(ctx context.Context) (*Admission, error)

func (*Runtime) AcquireMutation

func (r *Runtime) AcquireMutation(ctx context.Context, id RepositoryIdentity) (Lease, error)

func (*Runtime) AcquireRPCStream

func (r *Runtime) AcquireRPCStream(ctx context.Context) (*Admission, error)

func (*Runtime) AcquireRead

func (r *Runtime) AcquireRead(ctx context.Context, id RepositoryIdentity) (Lease, error)

func (*Runtime) AcquireRequestDecode

func (r *Runtime) AcquireRequestDecode(ctx context.Context) (*Admission, error)

func (*Runtime) AcquireResponseBuild

func (r *Runtime) AcquireResponseBuild(ctx context.Context) (*Admission, error)

func (*Runtime) CoordinateFilesystemMutation

func (r *Runtime) CoordinateFilesystemMutation(ctx context.Context, effect FilesystemEffect, fn func() error) error

CoordinateFilesystemMutation serializes a Files-owned effect with every registered worktree or Git metadata root that overlaps an effect path.

func (*Runtime) CoordinateTopologyMutation

func (r *Runtime) CoordinateTopologyMutation(ctx context.Context, effect FilesystemEffect, fn func(context.Context) error) error

CoordinateTopologyMutation owns the topology-exclusive/shared gate and every overlapping common-repository mutation gate through the supplied effect. The callback context may safely resolve repository identities without recursively acquiring the topology gate.

func (*Runtime) Invalidate

func (r *Runtime) Invalidate(id RepositoryIdentity)

func (*Runtime) NewSession

func (r *Runtime) NewSession() *Session

func (*Runtime) RepositoryIdentityCurrent

func (r *Runtime) RepositoryIdentityCurrent(id RepositoryIdentity) bool

RepositoryIdentityCurrent verifies that every filesystem object bound into an admitted repository identity still resolves to the same stable identity. Callers that already hold a topology lease may use this without reacquiring the topology gate.

func (*Runtime) ReservePublishedSnapshot

func (r *Runtime) ReservePublishedSnapshot(bytes int64) (*Admission, error)

ReservePublishedSnapshot accounts retained snapshot capacity across every direct-session cache. Cache eviction must release the returned admission.

func (*Runtime) ResolveRepositoryIdentity

func (r *Runtime) ResolveRepositoryIdentity(ctx context.Context, path string) (RepositoryIdentity, bool, error)

ResolveRepositoryIdentity resolves and admits an identity before exposing it. A successful identity remains in the bounded inactive registry after this call; operations and snapshots retain their own explicit leases.

func (*Runtime) RetainRepository

func (r *Runtime) RetainRepository(ctx context.Context, id RepositoryIdentity) (*Admission, error)

RetainRepository pins the registry entry and its common-repository epoch owner without holding a read/write gate. Published snapshots and in-flight singleflight generations must keep this admission until their references are released.

func (*Runtime) RunCapture

func (r *Runtime) RunCapture(ctx context.Context, repoRoot string, env []string, args ...string) (CommandResult, error)

func (*Runtime) RunMutation

func (r *Runtime) RunMutation(ctx context.Context, repoRoot string, env []string, args ...string) (CommandResult, error)

func (*Runtime) RunRead

func (r *Runtime) RunRead(ctx context.Context, repoRoot string, env []string, args ...string) (CommandResult, error)

func (*Runtime) RunReadAllowExitCodes

func (r *Runtime) RunReadAllowExitCodes(ctx context.Context, repoRoot string, env []string, allowedExitCodes []int, args ...string) (CommandResult, error)

func (*Runtime) StreamCapture

func (r *Runtime) StreamCapture(ctx context.Context, repoRoot string, env []string, consume func(io.Reader) error, args ...string) (CommandResult, error)

StreamCapture acquires the capture reservation in addition to read-process admission. Callers that retain the reservation through cache publication should acquire it explicitly and use StreamRead instead.

func (*Runtime) StreamRead

func (r *Runtime) StreamRead(ctx context.Context, repoRoot string, env []string, consume func(io.Reader) error, args ...string) (CommandResult, error)

StreamRead runs a read-only Git command with bounded process admission and containment while the caller incrementally consumes stdout.

func (*Runtime) TryAcquireRPCStream

func (r *Runtime) TryAcquireRPCStream() (*Admission, error)

type Session

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

Session owns one explicit reference for every worktree resolved by a direct session. Close releases all references; repeated resolves are deduplicated.

func (*Session) Close

func (s *Session) Close()

func (*Session) RetainRepository

func (s *Session) RetainRepository(ctx context.Context, id RepositoryIdentity) error

Jump to

Keyboard shortcuts

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