isolate

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package isolate runs tree-sitter extraction in supervised worker processes so a crashing or hanging file is skipped and reported instead of taking the whole indexer (and the MCP server around it) down.

Modelled on upstream codebase-memory-mcp 9b9638e1 / fb334f78 / e242ce1e, adapted to this Go pipeline: instead of supervising the whole index run and re-running it with the culprit quarantined, a small pool of long-lived worker processes each extract one file at a time over a gob stream. When a worker dies mid-request the in-flight file is recorded as a crash skip and the worker is replaced; when a request exceeds the per-file quiet timeout the worker is killed, the file is recorded as a timeout skip, and the worker is replaced. Everything else continues.

Recursion is prevented structurally: workers run RunWorker and never the pipeline, and the parent selects worker mode by argv, not by an ambient environment variable.

Index

Constants

View Source
const (
	EnvTestCrashOn = "CBM_TEST_CRASH_ON"
	EnvTestHangOn  = "CBM_TEST_HANG_ON"
)

Test-only fault injection, honoured only inside a worker process. A relPath containing CBM_TEST_CRASH_ON aborts the worker; one containing CBM_TEST_HANG_ON never answers. Both are checked by the supervisor tests so the guard is exercised against a real fault, never a fixture that may stop faulting (upstream's reasoning in 9b9638e1).

Variables

This section is empty.

Functions

func RunWorker

func RunWorker(r io.Reader, w io.Writer) error

RunWorker serves extraction requests from r to w until EOF. It is the body of the hidden `code-graph cbm-extract-worker` subcommand.

Types

type CommandFactory

type CommandFactory func() *exec.Cmd

CommandFactory builds the worker command. Production uses the running binary with the `cbm-extract-worker` argument; tests substitute the test binary.

func DefaultCommandFactory

func DefaultCommandFactory() (CommandFactory, error)

DefaultCommandFactory launches the current executable in worker mode.

type Pool

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

Pool supervises N worker processes.

func NewPool

func NewPool(size int, timeout time.Duration, factory CommandFactory) *Pool

NewPool creates a pool of size workers. Workers are spawned lazily.

func (*Pool) Close

func (p *Pool) Close()

Close terminates all workers. Extract calls after Close fail.

func (*Pool) Extract

func (p *Pool) Extract(ctx context.Context, req Request) (*cbm.FileResult, error)

Extract runs one file through a worker. It returns *SkipError when the worker crashed or exceeded the quiet timeout on this file; other errors are ordinary extraction errors reported by the worker.

func (*Pool) Stats

func (p *Pool) Stats() Stats

Stats returns a snapshot of the supervisor counters.

type Request

type Request struct {
	Source   []byte
	Language lang.Language
	Project  string
	RelPath  string
}

Request is one extraction job sent to a worker.

type Response

type Response struct {
	Result *cbm.FileResult
	Err    string
}

Response is the worker's answer. Err is the extraction error text, if any.

type SkipError

type SkipError struct {
	Reason SkipReason
	Detail string
}

SkipError is returned by Pool.Extract when the file could not be extracted because the worker crashed or hung on it.

func (*SkipError) Error

func (e *SkipError) Error() string

type SkipReason

type SkipReason string

SkipReason classifies why a file was skipped by the supervisor.

const (
	SkipCrash   SkipReason = "crash"
	SkipTimeout SkipReason = "timeout"
)

func IsSkip

func IsSkip(err error) (SkipReason, bool)

IsSkip reports whether err is a supervisor skip and returns its reason.

type Stats

type Stats struct {
	Extracted int
	Crashes   int
	Timeouts  int
	Respawns  int
}

Stats counts supervisor outcomes since the pool was created.

Jump to

Keyboard shortcuts

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