MCPcopy Index your code
hub / github.com/coder/coder / ContextWithRun

Function ContextWithRun

coderd/x/chatd/chatdebug/context.go:29–42  ·  view source on GitHub ↗

ContextWithRun stores rc in ctx. Step counter cleanup is reference-counted per RunID: each live RunContext increments a counter and runtime.AddCleanup decrements it when the struct is garbage collected. Shared state (step counters) is only deleted when the last RunContext for a given RunID becomes

(ctx context.Context, rc *RunContext)

Source from the content-addressed store, hash-verified

27// RunID becomes unreachable, preventing premature cleanup when
28// multiple RunContext instances share the same RunID.
29func ContextWithRun(ctx context.Context, rc *RunContext) context.Context {
30 if rc == nil {
31 panic("chatdebug: nil RunContext")
32 }
33
34 enriched := context.WithValue(ctx, runContextKey{}, rc)
35 if rc.RunID != uuid.Nil {
36 trackRunRef(rc.RunID)
37 runtime.AddCleanup(rc, func(id uuid.UUID) {
38 releaseRunRef(id)
39 }, rc.RunID)
40 }
41 return enriched
42}
43
44// RunFromContext returns the debug run context stored in ctx.
45func RunFromContext(ctx context.Context) (*RunContext, bool) {

Calls 2

trackRunRefFunction · 0.85
releaseRunRefFunction · 0.85