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 ¶
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 ¶
Types ¶
type CommandFactory ¶
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.
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.
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.