Live overlap detection
File claims stop two sessions from writing one file. Two sessions can still collide in different files. One session adds ParseInvoice in billing/parse.go while another adds ParseInvoice in api/invoice.go. Live overlap detection finds that while both sessions run, and tells both agents.
The coordinator compares what each session reports. An agent reports a plan before it starts, and the pre-commit hook reports a snapshot of the change at each commit. When two sessions overlap, the coordinator writes a notice to each session, and each agent reads it at the end of a later tool result.
Overlap notices are advisory. They grant or take no claim, so a false notice costs attention and nothing else.
How it works
Section titled “How it works”An agent calls zentri_submit_plan before it starts work, and again when the plan changes. A plan has these fields:
| Field | Limit |
|---|---|
summary |
Required. 1 to 2048 bytes. |
steps |
At most 30, each at most 500 bytes. |
files |
At most 200 paths. A path that ends in / names a directory. |
symbols |
At most 100 {kind, name} pairs, with no path. |
A plan never claims files. The coordinator compares it with other sessions’ claims, plans, and snapshots, and returns the overlaps in the result, most direct first:
| Reason | Matches when |
|---|---|
file |
A planned path equals another session’s path, or one of them is a directory that holds the other. |
symbol |
A planned symbol has the same kind and normalized name as another session’s symbol. |
similar_symbol |
A planned symbol has the same kind and a trigram similarity of at least 0.63. |
summary |
The cosine of the two plan summaries’ embeddings reaches the project’s partial_cosine. Both embeddings come from the same model. |
Each overlapping session gets one overlap_plan notice from the sender. A newer plan from the same sender replaces a notice that was not yet acknowledged. The result also carries plan_id, created_at, redacted, and summary_check. summary_check is skipped when the coordinator could not embed the summary, and done otherwise.
Snapshots from the pre-commit hook
Section titled “Snapshots from the pre-commit hook”At each commit in a session’s worktree, the kit’s pre-commit hook sends the coordinator a snapshot of the session’s change against its base commit. The hook runs git diff --cached --no-renames --no-ext-diff --no-textconv --no-color against the base commit, and reads file contents with one git cat-file --batch. It sends the parts in this order:
numstatlists each changed file with its added and deleted line counts.symbolslists the public symbols that the change adds or whose signature it changes.patchis the unified diff.patch_truncatedsays whether the hook cut it.
The hook has 5 seconds in all. It finishes the claim check by 2.5 seconds, stops parsing at 3.5 seconds, and sends the snapshot by 4.5 seconds, with the symbols it parsed so far. A commit in a nested repository sends no snapshot. When the send fails, the hook prints zentri: snapshot not sent: and the reason, and the commit goes on.
The coordinator compares the snapshot’s symbols with other sessions’ latest snapshots and current plans, notifies both sessions, and returns the overlaps. The hook prints at most 20 of them to the commit’s output, then zentri: and N more overlaps. scripts/e2e-m3.sh checks for this line:
zentri: overlap_symbol: your func ParseInvoice in billing/parse.go; @ana (session 6fce6c79) has func ParseInvoice in api/invoice.goA near match ends with (similarity 0.xx). When the other symbol comes from a plan, the line says plans instead of has.
The public symbol index
Section titled “The public symbol index”The hook finds symbols with pkg/symbols/parse on your machine. The coordinator never parses code. It checks each symbol and recomputes its normalized name instead of trusting the hook’s. The symbol kinds are func, type, component, route, table, and migration.
| Language | Extensions | How the hook reads it |
|---|---|---|
go |
.go |
go/parser. Exported functions, methods on exported types, exported types, and routes. |
typescript |
.ts, .mts, .cts |
Tree-sitter, through the pure-Go gotreesitter v0.58.0. The module’s exports. |
tsx, jsx |
.tsx, .jsx |
Tree-sitter. A capitalized function is a component. |
javascript |
.js, .mjs, .cjs |
Tree-sitter. The module’s exports. |
python |
.py, .pyi |
Tree-sitter. Names with no leading _, and names in __all__. |
sql |
.sql |
Regular expressions. Tables only. |
other |
Any other extension | No symbols. |
The path roles run before the language table. Test files and fixtures give no symbols, migration files give migration symbols, and Next.js route handlers give route symbols. A file over 1 MiB, or a parse that runs past 1.25 seconds, falls back to the language’s regular expressions.
Normalize in pkg/symbols splits a name into lowercase words joined by _. ParseHTTPRequest, parse_http_request, and Parse.HTTPRequest all become parse_http_request. A route becomes its lowercase method, a space, and its path with each parameter written as {}. A migration drops a leading version number.
Matching
Section titled “Matching”Two symbols match only when they have the same kind. The coordinator compares their normalized names with the Postgres pg_trgm function similarity(), and their doc comments as Doc comments explains.
| Notice kind | Match | The agent reads |
|---|---|---|
overlap_symbol |
The normalized names are equal. | @ana also changes func ParseInvoice (api/invoice.go). Agree on one version before you both ship it. |
symbol_near_duplicate |
The name similarity is at least 0.63, the constant NearDuplicateSimilarity, or the doc comments are close. |
@ana adds func InvoiceTotals (billing/total.go), close to your InvoiceTotal. Reuse one instead of keeping both. |
overlap_plan |
A plan matches by one of the reasons above. | @ana's plan overlaps yours: api/invoice.go. Agree who does what with a note. |
When the other symbol comes from a plan, the text says also plans or plans. One result reports at most 100 overlaps.
How 0.63 was chosen
Section titled “How 0.63 was chosen”zentri-server overlap calibrate scores labeled pairs of symbol names from examples/symbols with the same similarity() function. It sweeps thresholds from 0.30 to 0.95 in steps of 0.01 and picks the threshold that maximizes F0.5, which weighs precision above recall. A tie goes to the higher threshold. ADR-0007 first proposed 0.60, and the sweep moved it to 0.63. ADR-0007 records these runs, with 95% Wilson intervals in brackets:
| Pairs | Threshold | TP | FP | FN | TN | Precision | Recall | F0.5 |
|---|---|---|---|---|---|---|---|---|
| Tuning set, 240 | 0.63 | 78 | 34 | 42 | 86 | 0.696 [0.606, 0.774] | 0.650 [0.561, 0.729] | 0.687 |
| Tuning set, 240 | 0.60 | 0.664 | 0.742 | 0.678 | ||||
| Held-out set, 200 | 0.63 | 66 | 27 | 34 | 73 | 0.710 [0.611, 0.792] | 0.660 [0.563, 0.745] | 0.699 |
| Held-out set, 200 | 0.60 | 0.686 | 0.720 | 0.692 |
On the held-out set, about 3 in 10 pairs at or above 0.63 are not real near duplicates, and about a third of the real near duplicates score below 0.63. Trigrams compare spelling, not meaning. These pairs from ADR-0007 show the failure modes:
| Pair | Similarity | At 0.63 |
|---|---|---|
Customer and Client |
0.067 | Missed synonym |
ComputeTax and CalculateTax |
0.300 | Missed synonym |
LoadConfig and LoadCfg |
0.400 | Missed abbreviation |
serializeInvoice and deserializeInvoice |
0.727 | False notice |
ForecastModelV1 and ForecastModelV2 |
0.800 | False notice |
ParseID and ParseIP |
0.636 | False notice |
loanFromLender and lenderFromLoan |
1.0 | False notice |
Doc comments
Section titled “Doc comments”Names miss a near duplicate that is spelled differently, such as parseCSV and readCommaSeparated, but the two doc comments can still say the same thing. So two symbols of one kind whose names do not match still raise symbol_near_duplicate when the cosine of their doc comments reaches a threshold. The notice line then ends with (similar doc comments), the overlap carries doc_similarity beside similarity, and the pre-commit hook prints both scores.
The coordinator reads a doc after the secret scan. It drops a leading copy of the symbol’s own name, as in Go’s // ParseInvoice reads ..., and keeps at most 300 bytes. A doc with fewer than 3 content words, such as Get returns the value., takes no part. The scorer follows the coordinator’s embedder:
| Embedder | Doc scorer | Threshold | Where the doc text goes |
|---|---|---|---|
hash, the default |
doc-lexical-v1 |
0.47 | Nowhere |
Ollama with embeddinggemma:300m |
The model | 0.73 | The configured Ollama server |
Ollama with nomic-embed-text:v1.5 |
The model | 0.89 | The configured Ollama server |
| OpenAI, or any other Ollama model | doc-lexical-v1 |
0.47 | Nowhere |
doc-lexical-v1 runs inside the coordinator. It drops stop words, stems the rest, and hashes them into a vector, so the cosine of two docs is about the share of content words they have in common. It scores shared words, not meaning. Each scorer has its own threshold because each spreads cosines on its own scale: two unrelated docs score a median of 0.28 under embeddinggemma and 0.67 under nomic-embed-text.
A snapshot scores the docs of at most 200 symbols. It sends at most 32 new texts to a model and waits for it at most 2 seconds. Each vector is stored once per project and model, keyed by a hash of its text, never with the text. When the model fails, the snapshot still lands, and its docs match by the vectors already stored. The coordinator logs the count and the reason, never a doc.
zentri-server overlap calibrate-docs picked each threshold on 140 labeled pairs in examples/symbols/docs. It sweeps 0.30 to 0.99 in steps of 0.01, keeps the thresholds that flag at most 0.1% of the set’s unlabeled pairs, and picks the best F0.5. 120 held-out pairs were committed before any tuning and scored once. On them, with a pair flagged when its names or its docs match:
| Scorer | Threshold | Precision [95% CI] | Recall [95% CI] | F0.5 | Unlabeled pairs flagged |
|---|---|---|---|---|---|
| Names alone | 0.375 [0.185, 0.614] | 0.100 [0.047, 0.201] | 0.242 | ||
doc-lexical-v1 |
0.47 | 0.508 [0.386, 0.629] | 0.517 [0.393, 0.638] | 0.510 | 0.26% |
embeddinggemma:300m |
0.73 | 0.527 [0.398, 0.653] | 0.483 [0.362, 0.607] | 0.518 | 0.01% |
nomic-embed-text:v1.5 |
0.89 | 0.492 [0.368, 0.616] | 0.483 [0.362, 0.607] | 0.490 | 0.15% |
The doc sets are built from hard cases: synonyms, paraphrases, ports to another language, and versions, antonyms, and siblings whose docs mirror each other. That is why names alone do worse on them than on the name sets. Docs caught every copied doc and most ports. No scorer caught any of the 13 held-out paraphrases, and docs that mirror each other, such as those of encryptMedicalNote and decryptMedicalNote, raise a false notice. ADR-0017 has the full tables.
The notice digest
Section titled “The notice digest”The coordinator writes each notice to a session’s inbox. The agent reads notices in two ways:
- A digest at the end of hook output and MCP tool results. The digest shows the 3 most urgent undelivered notices under a
Zentri notices:header, one line each, at most 160 characters. A repeated notice ends with(xN). When more notices wait, a last line saysN more. Call zentri_check_inbox.The coordinator marks the shown notices delivered. zentri_check_inbox, which returns up to 20 notices, oldest first, and acknowledges them.
An MCP result is at most 32 KiB. The digest is a separate text block, and the coordinator never cuts it. This example digest uses the notice templates:
Zentri notices:- @ben also changes func ParseInvoice (billing/parse.go). Agree on one version before you both ship it.- @ben's plan overlaps yours: api/invoice.go; ParseInvoice. Agree who does what with a note.2 more. Call zentri_check_inbox.The digest ranks notice kinds in this order, most urgent first: unclaimed_edit, claim_conflict, question_answered, decision_decided, question_expired, note, overlap_symbol, overlap_plan, symbol_near_duplicate, intent_unblocked, intent_watcher, intent_escalated, decision_pending, question_escalated, and question_asked. Within one kind, the newest comes first.
An agent answers an overlap with zentri_post_note. The note’s text is 1 to 1024 bytes. The note goes to one session by session_id, or to the sessions that match any of up to 50 paths. A session matches when its live claim covers a path exactly, its current plan covers a path, or its latest snapshot changes a path. A note never reaches its sender, and the coordinator redacts secrets in it. The recipient reads Note from @ana: and the text.
Reading another session’s diff
Section titled “Reading another session’s diff”zentri_get_session_diff reads another session’s latest snapshot. It returns numstat, symbols, and a slice of the patch of at most 24 KiB, starting at offset. next_offset gives the start of the next slice, and it is absent on the last one. A path limits the patch to one file and leaves numstat and symbols whole. A session token needs the diff:read scope.
Use it
Section titled “Use it”Submit a plan before the agent starts. These are the zentri_submit_plan arguments. POST /v1/sessions/{session_id}/plans takes the same body. The HTTP API reference lists every endpoint.
{ "summary": "Parse carrier invoices into line items", "steps": ["Add ParseInvoice", "Call it from the invoice API"], "files": ["api/invoice.go", "billing/"], "symbols": [{ "kind": "func", "name": "ParseInvoice" }]}Commit as usual. The pre-commit hook sends the snapshot and prints any overlaps. Then read the other session’s change. These are the zentri_get_session_diff arguments, with the session ID from the notice or from zentri_list_active_sessions:
{ "session_id": "SESSION_ID", "path": "api/invoice.go" }To rerun the threshold calibration, point ZENTRI_DATABASE_URL at any Postgres with pg_trgm and run this command. scripts/calibrate-symbols.sh runs the same command.
zentri-server overlap calibrate --dataset examples/symbols/pairs.jsonl \ --heldout examples/symbols/heldout/pairs.jsonlTo rerun the doc calibration, run scripts/calibrate-symbol-docs.sh. With ZENTRI_EMBEDDER unset or hash, it measures doc-lexical-v1. With any other embedder, it measures that model reading the docs, so you can measure a model before the coordinator uses it.
The MCP tools reference lists every tool’s arguments, and the server CLI reference lists the calibrate flags.
Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Plans per session | 30 a minute, then 429 plan_rate_limited |
| Snapshots per session | 30 a minute, then 429 snapshot_rate_limited |
| Notes per session | 10 a minute, then 429 note_rate_limited |
| Snapshot body | 1 MiB |
Snapshot numstat entries and symbols |
5000 and 1000 |
Snapshot patch |
512 KiB |
| Symbol name, signature, and doc | 200 bytes, 200 characters, and 300 characters |
| Doc text a scorer reads | 300 bytes, from at most 200 symbols a snapshot |
| Doc texts sent to a model | 32 a snapshot, within 2 seconds |
| Overlaps in one result | 100 |
| Patch slice in one diff read | 24 KiB |
Limitations
Section titled “Limitations”- Trigram similarity misses synonyms and abbreviations, and it flags antonym prefixes, versions, and swapped word order. The calibration table above shows examples.
- Doc comments miss paraphrases that share few words, and they flag versions, antonyms, and siblings whose docs mirror each other. Two symbols with the same boilerplate doc score 1.0.
- On the held-out pairs, the offline lexical scorer flagged 0.26% of unrelated pairs, more than the 0.1% it was tuned to.
- OpenAI and Ollama models other than the two measured ones use the lexical scorer. Adding a model means running the doc calibration and changing the coordinator’s code.
- After the embedder changes, symbols from earlier snapshots match by name alone until their session commits again.
- A symbol with no doc comment, or one under 3 content words, matches by name alone.
- A change to a function body alone gives no symbol. Only an added symbol or a changed signature counts.
- A snapshot comes only from a commit. Work that the session has not committed is invisible to symbol matching.
- Parsing depends on time. On a slow machine, symbols past the 3.5-second parse deadline are left out, so two commits of the same change can send different symbols.
- The hook parses
vendor/andnode_modules/like any other directory. - A TypeScript overload keeps its first signature.
- An abandoned parse keeps a CPU busy until the hook exits.
- The
summaryreason reusespartial_cosinefrom intent dedup. That threshold was not calibrated for plans.
Related pages
Section titled “Related pages”- File claims covers claims, the pre-edit hook, and the pre-commit hook.
- The three catches places overlap detection next to the other two catches.
- Intents and dedup explains
partial_cosineand the embedding model. - Sessions and forks explains sessions and their states.
- Claude Code, Codex, OpenCode, and generic MCP describe how each kit passes on the digest.
- Two sessions runs two sessions on one project.
- The MCP tools reference and the server CLI reference list tools and commands.