concurrency

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package concurrency computes the concurrency blast radius of a symbol: every module that affects or is affected by it via the contract's five concurrency edge types (spawns, sends_to, recvs_from, acquires_lock, accessed_under_lock), BFS in both directions over a store.Reader.

It backs the cks.context.concurrency_impact tool (R1' 00 C1, S1). cks calls Analyze in-process; the dev-only ckg MCP server may also expose it via pkg/mcphandlers.RegisterConcurrencyImpact.

Direction semantics on each returned Module:

"affected_by" — forward edge: seed -> ... -> module
"affects"     — reverse edge: module -> ... -> seed
"both"        — reached in both traversals

Design notes:

  • releases_lock is intentionally excluded. The unlock half of a lock pair adds no "what is affected" signal over acquires_lock.

  • store.Reader.NeighborhoodByQname is single-direction per call, so a FUNCTION seed reaches its own goroutine and the channel it writes, but NOT the peer goroutine across the channel (crossing a channel requires switching edge direction at the Channel node). To recover producer<->consumer or lock-sharing peers, seed a Channel / Mutex / Field node instead. This makes the byzantine-fairness query "what else touches this field/mutex under the same lock" (R1' 00 sec 4.3 L2) work by seeding the Field/Mutex node and reading "affects".

  • Channel and lock edges are usually INFERRED confidence; they are surfaced (not filtered to EXTRACTED), or concurrency impact would be empty on real Go code.

Index

Constants

View Source
const DepthCap = 5

DepthCap bounds BFS depth, mirroring pkg/impact.

Variables

ConcurrencyEdgeTypes is the contract's five concurrency edge types (R1' 00 C1, S1). releases_lock is intentionally excluded — see doc.go.

Functions

This section is empty.

Types

type Module

type Module struct {
	ID        string         `json:"id"`
	Type      types.NodeType `json:"type"`
	Name      string         `json:"name"`
	Qname     string         `json:"qname"`
	FilePath  string         `json:"file_path"`
	StartLine int            `json:"start_line"`
	Citation  string         `json:"citation,omitempty"` // "file:line" when both present
	Direction string         `json:"direction"`          // affects | affected_by | both
}

Module is one symbol reachable from the seed via a concurrency edge.

type Options

type Options struct {
	Depth    int // clamped to [1, DepthCap]; 0 -> defaultDepth
	MaxTotal int // 0 = unbounded; caps the returned Modules slice
}

Options bundles tunable knobs. The zero value resolves to documented defaults (Depth=2, MaxTotal=0=unbounded).

type Result

type Result struct {
	Seed     string         `json:"seed"`
	NotFound bool           `json:"not_found"`
	Depth    int            `json:"depth"`
	Modules  []Module       `json:"modules"`
	Edges    [][]any        `json:"edges"` // [src, dst, type, line] tuples, sorted
	Totals   map[string]any `json:"totals"`
}

Result is the payload cks's concurrency_impact tool consumes.

func Analyze

func Analyze(r store.Reader, symbol string, opt Options) (Result, error)

Analyze returns the concurrency blast radius of symbol: every module that affects or is affected by it via the five ConcurrencyEdgeTypes, BFS to depth in both directions, backed by store.Reader.NeighborhoodByQname.

Deterministic: modules are sorted by qname (tiebreak id), edges by (type, src, dst, line), so cks's prompt cache stays stable.

Jump to

Keyboard shortcuts

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