Open-source research software · v0.1.0

Reason about code.
Before you change it.

A research prototype for coding agents: connect symbols to their dependencies and supporting evidence, retrieve relevant context, and inspect potential consequences before an edit.

By Dr. Abu Suraih Sakhri · Agent benefit has not been demonstrated in the current study.

Python ≥3.12 Apache-2.0 DOI 10.5281/zenodo.22923463
PRE-ACTION CONTEXTcanonical store
Proposed editchange Signer.sign(...) signature
↓ resolve
Mathematical Context ModelK = ⟨O,R,E,P,T⟩
objectsrelationsevidenceprovenancetime
↓ traverse + minimise
targetstable symbol identity
consequencecallers + dependencies
validationlinked tests + evidence
agent contextbounded support set
Archived release10.5281/zenodo.22923463
Evaluation suite10 repositories
Largest repoDjango · 2,932 files
Agent study23 tasks · inconclusive
01 / IDEA

A coding agent needs relevance and consequence.

Search is good at finding code that resembles a request. Editing safely also requires knowing what depends on the code being changed. MCM keeps those two problems distinct and lets them work together.

Semantic relevance

What code looks related to the task?

Vector and lexical retrieval are useful for locating definitions when names and wording are uncertain. MCM keeps these channels.

“Where is token validation implemented?”
Structural consequence

What code is connected to the thing I may change?

This needs explicit relations: calls, imports, tests, inheritance, evidence and time. MCM stores those relations rather than asking similarity to stand in for them.

“If I change this signature, which callers and tests matter?”

MCM is not a replacement for retrieval. It is a canonical context layer underneath retrieval and change analysis: typed objects and relations are primary; vector, lexical and graph indexes are rebuildable projections.

02 / FLOW

One proposed edit becomes a traceable context package.

The central workflow is pre-action: resolve the target, traverse what the change can reach, attach evidence, then assemble only the context the agent needs.

Proposed change Signer.sign(value, key=None) + algorithm="sha256"
  1. Resolve

    Map the request to a stable symbol identity rather than a line-number chunk.

  2. Propagate

    Walk typed relations from the target and attenuate confidence as paths get longer.

  3. Ground

    Keep the source bytes and provenance that justify every relation surfaced to the agent.

  4. Minimise

    Build a bounded context set that still reproduces the relevant closure and keeps its evidence.

  5. Act

    Expose the result through CLI, REST or MCP before the agent edits the repository.

03 / MODEL

The canonical store keeps meaning, evidence and time together

A repository is represented as objects, relations, evidence, provenance and temporal validity. Retrieval indexes and graph adjacency are derived from this store and can be rebuilt.

Definition 1: Canonical Semantic Store

A code repository is represented as a 5-tuple store $K$, where all symbols possess deterministic, line-independent qualname identities:

$$K = \langle \mathcal{O}, \mathcal{R}, \mathcal{E}, \mathcal{P}, \mathcal{T} \rangle$$ $$\text{id}(o) = \texttt{repo://} \parallel \text{relpath}(o) \parallel \texttt{\#} \parallel \tau_o \parallel \texttt{:} \parallel \text{qualname}(o)$$
Relation composition and confidence attenuation

Composing relational paths along the call graph attenuates confidence multiplicatively with path-decay factor $\delta$:

$$c(R_1 \circ R_2) = c(R_1) \cdot c(R_2) \cdot \delta(R_1, R_2)$$ $$C_{t+1} = \frac{C_t \cdot \alpha + s_{\text{observed}}}{\alpha + 1} \quad (\text{Bayesian Observation Update})$$
Context reduction must preserve support

A minimised context prompt package $C^*$ entails task query $Q$ ($C^* \models Q$) if and only if three independent formal clauses hold:

  • Replay Clause: Traversal over the relations in $C$ generates the identical deductive closure and confidence values as the full store $K$.
  • Presence Clause: Every object referenced in the transitive closure exists within $C$'s object set.
  • Traceability Clause: Every relation in $C$ retains at least one verifiable evidence record pointing to valid source artifacts.
Evidence status · September 2026 audit. These are previously reported results, not a new evaluation. Overall benchmark intervals resample tasks from shared commits independently; commit-clustered reanalysis is needed before interpreting separation as firm evidence. No detected difference does not establish equivalence. Read the audit.
04 / EVIDENCE

The latest evidence is useful, mixed and narrower than the architecture

The current evaluation separates three questions: how efficiently context is retrieved, how accurately impact is predicted, and whether giving that tool to an agent improves the agent’s work. Those questions do not have the same answer.

10repositories in the complete feature-hashing suite
4repository size tiers across six ecosystems
23cross-file agent tasks found from 520 candidate commits
0.28paired sign-flip p-value in the agent-in-the-loop experiment

Context efficiency: signal exists

With the default feature-hashing provider, MCM is ahead of vector RAG on 7/10 repositories and not separated on 3/10; against the hybrid baseline it is ahead on 7/10 and not separated on 3/10. In the trained-embedding sweep it is ahead of vector RAG on 5/8 and not separated on 3/8.

The effect is not uniform

requests is a counterexample in both sweeps, and python-dotenv falls behind the best baseline with the trained embedding. Repository size appears relevant, but the current data do not establish size as the causal explanation.

Impact predictions are selective

The evaluation reports 42 confirmed predictions out of 48 (rounded precision 0.88), among 685 testable observations across five repositories. The 7% firing rate applies to that testable subset; it is not a measure of reliability on arbitrary changes.

Agent benefit: not demonstrated

The separate agent study does not establish that access to mcm_impact improves file selection. The apparent gain on four informative tasks disappears under the obvious usage check: most winning trials never called the tool.

p = 0.28 23 paired task deltas

The agent study does not establish a benefit

Across 23 tasks, three trials per condition produced 138 trials, six of which errored. Treatment was better on 5 tasks, worse on 2 and tied on 16, with mean paired delta +0.072. A two-sided sign-flip permutation test gives p = 0.28. The current experiment therefore cannot show that supplying impact analysis makes the agent perform better.

Only 9 of the 23 tasks were downstream consequences of the target—the class of problem propagation is designed to predict. Eleven were upstream co-requirements and three had no recorded edge.

Complete Sweep A — feature hashing, 10 repositories
RepositoryTierFilesTasksMCM efficiencyBest baselineMargin
itsdangeroustiny15340.240vector-rag 0.130+0.110
python-dotenvtiny20340.088hybrid 0.082+0.006
requeststiny371300.029vector-rag 0.039-0.010
flasksmall831490.069vector-rag 0.057+0.012
clicksmall903060.099graph 0.082+0.017
richmedium2132340.079graph 0.071+0.008
pydanticmedium4493120.064graph 0.056+0.008
scrapymedium4913290.129graph 0.100+0.030
sqlalchemylarge6733140.100graph 0.039+0.061
djangolarge2,9321070.173hybrid 0.090+0.083
Sweep B — trained MiniLM embedding on GPU, 8 repositories
RepositoryTierFilesTasksMCM efficiencyBest baselineMargin
itsdangeroustiny15340.205hybrid 0.124+0.081
python-dotenvtiny20340.093vector-rag 0.102-0.008
requeststiny371300.031vector-rag 0.040-0.010
flasksmall831490.067vector-rag 0.063+0.004
clicksmall903060.100graph 0.082+0.018
richmedium2132340.086graph 0.071+0.015
pydanticmedium4493120.068hybrid 0.057+0.011
scrapymedium4913290.127hybrid 0.100+0.027

The large tier was not completed in this sweep because the 16 GB test machine could not hold the trained model plus the largest repositories concurrently. That is a hardware limitation of this run, not evidence about the method.

Key limitations that still bound the claims

One horizon per repository

Within-repository variance is not measured even though the evaluation now spans four size tiers and six ecosystems.

Fitted weights overfit

MCM’s seven-parameter fitted weights improve the tuning repository but buy nothing on held-out data.

Feature hashing is the default

The default embedding is not a trained sentence model. The paired provider experiments show that this choice changes the comparison materially.

Python only

The parser and extractors remain Python-specific, and dynamic behavior still requires the runtime observation channel.

The full methods, bootstrap rules, tuning protocol, provider ablations and limitations are maintained in docs/evaluation.md.

05 / RESEARCH LAB

Interact with the mechanisms, not the claims.

These browser exercises are fixed fixtures. They are here to make MCM’s representation and operations inspectable. They do not generate the empirical results reported later on the page; those come from repository-history benchmarks and the separate agent experiment.

Research lab · 01

Compare the retrieval strategies

Choose the same engineering task for each representation. This fixture shows what each approach is able to put in front of an agent; it is an explanatory demo, not benchmark evidence.

Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

1. Vector RAG

Heuristic
3 Chunks (1,840 toks)

Retrieves arbitrary text chunks via cosine similarity. Fractures AST hierarchy.

2. Graph memory

Untyped Graph
4 Nodes (780 toks)

Traverses syntax nodes without calibrated uncertainty or natural-language grounding.

3. MCM

Typed + evidence-backed
6 Objects (520 toks)

Walks typed relations from the change site, carrying a confidence that decays per hop, and checks the result replays against the full store.

Research lab · 02

Walk a change before writing it

Pick a symbol and a typed change. The model traverses dependency relations, attenuates confidence by path, and surfaces callers and tests that may need attention before the edit is made.

Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

0.85

Simulated Blast Radius ($K_{t+1}^{\text{pred}}$)

Calculated dynamically via algebraic backward-propagation:

Cascading Test Regressions

Tests requiring immediate re-execution before commit:
Illustrative, on a fixed fixture. Prediction quality is evaluated against real co-change history in docs/prediction.md, which also explains why a naive recall score understates it: co-change is symmetric and propagation is not, so an edit upstream of the change can never be reached by any downstream traversal.
Research lab · 03

Inspect the structural memory

This fixed itsdangerous fixture exposes the representation directly: stable symbols, typed edges, evidence-backed links, and confidence carried on the graph.

Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

Drag nodes to rearrange the illustration. Use the relationship list below for a text equivalent.
Read graph relationships
    Research lab · 04

    Spend a context budget deliberately

    Reduce the context package while preserving the objects, relations and evidence needed for the task. The point is not “fewer tokens” by itself; it is fewer irrelevant tokens without breaking support for the answer.

    Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

    Standard RAG / File Dump

    Wasteful
    18,450 tokens

    Full file inclusion dumps comments, utility helpers, and unrelated imports. Overflows small context windows and costs 5.2× more per API call.

    [Included] serializer.py (entire file: 412 lines)
    [Included] signer.py (entire file: 328 lines)
    [Included] timed.py (entire file: 215 lines)
    Contains 73% non-essential auxiliary tokens.

    MCM Minimal Package ($C^*$)

    Illustrative support check
    3,420 tokens

    Keeps only what the task entails, then checks three conditions on the result. The ratio below is a fixed assumption of this illustration, not a measured result — the measured context-efficiency numbers are in the benchmark section.

    Replay: Deduced closure identical to K
    Presence: 100% of symbols referenced exist
    Traceability: Active AST evidence attached
    Saved 15,030 tokens (81.4% reduction)
    Advanced lab · evidence

    Resolve conflicting claims

    Vary temporal overlap and source reliability to see how incompatible assertions are handled. This demonstrates the model’s separation of observation strength, provenance reliability and time.

    Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

    Assertion 1: Earlier / Established Claim

    Assertion 2: Incoming / New Claim

    Advanced lab · ranking

    See how retrieval channels trade off

    Adjust the five retrieval weights and watch the ranking move. The production tuner searches this simplex; the browser fixture makes the interaction visible.

    Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

    Ranked Code Candidates for Query: "Verify cryptographic token signature"

    Illustrative — fixed fixture, computed in-browser
    06 / USE IT

    Index locally, then expose MCM as an agent tool

    The default indexer and hashed embedding provider are local. The MCP server runs over stdio, so an agent can query the same store without a separate service.

    1. Create the index

    git clone https://github.com/abusuraihsakhri/mcm.git
    cd mcm
    python -m venv .venv
    pip install -e ".[dev,api]"
    
    mcm ingest /path/to/repo --db mcm.db
    mcm index --db mcm.db

    Current repository measurements report roughly 66 files/s; Django’s 2,932 Python files index in about 44 seconds on the test laptop.

    2. Connect your agent

    MCP toolWhat it gives the agent
    mcm_searchDefinitions ranked by semantic, lexical, structural, symbolic and provenance channels.
    mcm_impactPotential downstream consequences of a typed proposed change, before the edit.
    mcm_contextA bounded, evidence-backed context package for the current task.
    mcm_constraintsChecks against declared architectural constraints.
    mcm_ingestIndexes or refreshes a repository from the agent session.

    Use absolute paths for the MCP executable and database. Repository content stays in the local SQLite index unless you explicitly use external model-provider experiment scripts.

    Service interface

    The REST surface mirrors the same model

    The HTTP surface, for calling MCM from a service. If you want to use MCM from a coding agent, you want the MCP server above instead — these routes are not what an agent speaks. Payloads below match the real request models in mcm/api/app.py.

    Illustrative fixture. Values and outcomes below explain the mechanism; they are not measured performance or executed tests.

    {
      "status": "ready",
      "endpoint": "http://localhost:8000/impact",
      "headers": { "Content-Type": "application/json" },
      "payload": {
        "target_qualname": "itsdangerous.signer.Signer.sign",
        "change_kind": "SIGNATURE",
        "details": { "added_param": "algorithm", "default": "'sha256'" }
      }
    }
    07 / STATUS + CITATION

    What the repository currently establishes

    MCM is a v0.1.0 research prototype with a reproducible software release and an explicit distinction between architectural capability, benchmark evidence and unanswered questions.

    Softwarev0.1.0 · Python ≥3.12 · Apache-2.0
    Core claim

    A typed, evidence-backed context representation supports retrieval, dependency traversal, change-impact analysis and context minimisation in one store.

    Evidence

    Context-efficiency advantages appear across much of the repository suite, but are not universal; the original graph > vector-rag chain is not supported consistently.

    Agent effect

    Not demonstrated in the current 23-task agent experiment (paired sign-flip p = 0.28).

    Scope

    Python-specific research software. Browser labs are illustrative fixtures, not evaluation runs.

    Cite the archived software

    @software{sakhri2026mcm,
      author  = {Sakhri, Abu Suraih},
      title   = {Mathematical Context Model (MCM)},
      version = {0.1.0},
      year    = {2026},
      doi     = {10.5281/zenodo.22923463},
      url     = {https://doi.org/10.5281/zenodo.22923463}
    }

    No preprint identifier is asserted here. Use the Zenodo DOI for the current software release.