---
title: governance | CodeWeaver Docs
description: API reference for codeweaver.engine.chunker.governance
url: "https://docs.knitli.com/api/engine/chunker/governance"
type: static
generatedAt: "2026-04-17T17:21:08.421Z"
---

# governance
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/engine/chunker/governance.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F&text=governance)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F&text=governance)[Share on Bluesky](https://bsky.app/intent/compose?text=governance%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F&title=governance)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F&t=governance)[Share on Email](mailto:?subject=governance&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F)[Share on WhatsApp](https://wa.me/?text=governance%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fengine%2Fchunker%2Fgovernance%2F&text=governance)
# `codeweaver.engine.chunker.governance`
[Section titled “codeweaver.engine.chunker.governance”](#codeweaverenginechunkergovernance)
Resource governance for chunking operations.

This module provides resource limit enforcement during chunking operations to prevent resource exhaustion and ensure responsive operation across large codebases. The ResourceGovernor enforces timeouts and chunk count limits through a context manager protocol.

## Class: `PerformanceSettings`
[Section titled “Class: PerformanceSettings”](#class-performancesettings)
Protocol for performance settings configuration.

## Class: `ResourceGovernor`
[Section titled “Class: ResourceGovernor”](#class-resourcegovernor)
Enforces resource limits during chunking operations.

This context manager tracks operation timing and chunk counts to prevent resource exhaustion. It enforces two critical limits:

 1. **Timeout limit**: Maximum time allowed for chunking a single file
 1. **Chunk count limit**: Maximum chunks that can be generated per file

The governor uses a context manager protocol to automatically initialize and clean up resource tracking. All resource checks are thread-safe through the use of instance-local state with no shared mutable data.

Usage:


**

```
with ResourceGovernor(settings) as governor:    for node in nodes:        governor.check_timeout()  # Verify not timed out        chunk = create_chunk(node)        governor.register_chunk()  # Track and check limits
```

Attributes: settings: Performance configuration containing timeout and limit values _start_time: Timestamp when context manager was entered (None when inactive) _chunk_count: Number of chunks registered in current operation

Raises: ChunkingTimeoutError: When operation exceeds configured timeout ChunkLimitExceededError: When chunk count exceeds configured maximum

### Method: `check_chunk_limit`
[Section titled “Method: check_chunk_limit”](#method-check_chunk_limit)

**

```
check_chunk_limit()
```

Check if chunk count has exceeded configured limit.

Compares current chunk count against maximum allowed per file. This prevents memory exhaustion and index bloat from pathological input.

Raises: ChunkLimitExceededError: When chunk count exceeds maximum

### Method: `check_timeout`
[Section titled “Method: check_timeout”](#method-check_timeout)

**

```
check_timeout()
```

Check if operation has exceeded timeout limit.

Compares elapsed time against configured timeout threshold. Safe to call even if context manager is not active (no-op).

Raises: ChunkingTimeoutError: When elapsed time exceeds timeout_seconds

### Method: `register_chunk`
[Section titled “Method: register_chunk”](#method-register_chunk)

**

```
register_chunk()
```

Register a new chunk and enforce all resource limits.

Increments the chunk counter and checks both timeout and chunk limits. This is the primary method to call after creating each chunk.

Call this after successfully creating each chunk to maintain accurate resource tracking and enforcement.

Raises: ChunkingTimeoutError: If timeout limit exceeded ChunkLimitExceededError: If chunk count limit exceeded