Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions evidence/indexer-255-20261029/patch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Candidate

Runtime candidate: commit `6da28494` on baseline `ab03f3ffb8f2e5bc02c304828c5c41890eef673e`.

`Bundle._manifest` / `_view` may reuse validated resource path/content hashes only within one Collect invocation. Keys contain the exact path and immutable bytes; metadata, required resources and dependency revisions are still validated for each bundle. Public manifest/view calls remain uncached. Default selection, ranking, limits, explicit identities and context resources are unchanged.

The same packaged library bytes were repeatedly validated and hashed for each generated skill owner. This removes repeated resource work, not corpus contents or provenance checks. No cross-request state is introduced. Tests exercise changed bytes at the same path, multiple owners, mutable metadata/dependencies, unsafe paths and request lifetime.

Tradeoff: the request-local memo retains distinct resource bytes/keys until that Collect call completes. It is not a cross-request cache, but memory overhead is nonzero. Peak memory is not measured in this campaign and no memory-improvement claim is made.

## Withheld from production

The final feature branch reverts the runtime change in `23e769ac`; production runtime matches the baseline. The candidate-specific regression tests are retained with the candidate, not active against baseline private APIs. This is evidence-only delivery, not promotion of an unaccepted optimization.

`candidate.patch` preserves the source/test delta. The 2.2KB `candidate.bundle` additionally preserves the **exact** original candidate commit so replication does not depend on a temporary branch surviving a squash merge. It requires the baseline commit already in this repository:

```sh
git bundle verify evidence/indexer-255-20261029/patch/candidate.bundle
git fetch evidence/indexer-255-20261029/patch/candidate.bundle \
refs/heads/issue255-indexer-evidence:refs/heads/reproduce-indexer-255-candidate
git worktree add /tmp/indexer-255-candidate 6da28494891b21cdc89f632d84d763bc997b7d15
```

Do not use the final evidence-only branch as the optimized arm. No more performance studies were run after the single prospective confirmation.
Binary file not shown.
165 changes: 165 additions & 0 deletions evidence/indexer-255-20261029/patch/candidate.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
From 6da28494891b21cdc89f632d84d763bc997b7d15 Mon Sep 17 00:00:00 2001
From: Codex <codex@openai.com>
Date: Thu, 29 Oct 2026 05:40:54 -0700
Subject: [PATCH] perf(indexer): reuse exact resource validation within collect
requests

Signed-off-by: Codex <codex@openai.com>
---
src/inferrsi/knowledge_operations.py | 29 +++++++++++--
tests/test_collect_resource_memo.py | 65 ++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 4 deletions(-)
create mode 100644 tests/test_collect_resource_memo.py

diff --git a/src/inferrsi/knowledge_operations.py b/src/inferrsi/knowledge_operations.py
index 63920c05..c582ea0a 100644
--- a/src/inferrsi/knowledge_operations.py
+++ b/src/inferrsi/knowledge_operations.py
@@ -126,6 +126,11 @@ class Bundle:
object.__setattr__(self, "metadata", _normalized(self.metadata, "metadata"))

def manifest(self) -> dict:
+ return self._manifest()
+
+ def _manifest(self, resources_seen: dict | None = None) -> dict:
+ # Only Collect shares this memo within one invocation. Keys include exact
+ # immutable bytes, never a mutable Bundle or a resource path alone.
record = self.metadata
if not isinstance(record.get("id"), str) or not re.fullmatch(IDENTITY, record["id"]):
raise ValueError("Invalid bundle identity")
@@ -149,10 +154,19 @@ class Bundle:
if not isinstance(record["sources"], list) or not record["sources"]:
raise ValueError("Bundle requires sources, including explicit unknown provenance")
_sources(record["sources"])
+ resources = {}
for path, data in self.content.items():
- safe_path(path)
if not isinstance(data, bytes):
+ safe_path(path)
raise ValueError("Bundle content must be bytes")
+ key = (path, data)
+ cached = resources_seen.get(key) if resources_seen is not None else None
+ if cached is None:
+ safe_path(path)
+ cached = _hash(data)
+ if resources_seen is not None:
+ resources_seen[key] = cached
+ resources[path] = cached
if record["entrypoint"] not in self.content:
raise ValueError("Missing entrypoint in complete bundle")
for required in record.get("required_resources", []):
@@ -161,7 +175,7 @@ class Bundle:
continue
if safe_path(required) not in self.content:
raise ValueError(f"Missing required resource: {required}")
- resources = {path: _hash(data) for path, data in sorted(self.content.items())}
+ resources = dict(sorted(resources.items()))
for dependency, revision in self.dependencies.items():
safe_path(dependency)
if not re.fullmatch(r"sha256:[0-9a-f]{64}", revision):
@@ -190,7 +204,10 @@ class Bundle:
return "sha256:" + _hash(_json(self.manifest()))

def view(self, *, material: bool = False) -> dict:
- manifest = self.manifest()
+ return self._view(material=material)
+
+ def _view(self, *, material: bool = False, resources_seen: dict | None = None) -> dict:
+ manifest = self._manifest(resources_seen)
result = {
**self.metadata,
"revision": "sha256:" + _hash(_json(manifest)),
@@ -557,6 +574,7 @@ class KnowledgeReader:

cases = self._cases() if kind else {}
selected, omitted, seen = [], [], set()
+ resources_seen: dict[tuple[str, bytes], str] = {}
used = 0
ranked, contexts, context_omissions = [], [], []
context_used = 0
@@ -614,7 +632,10 @@ class KnowledgeReader:
omitted.append({"id": reference, "reason": "filters"})
continue
bundle = self._read(qualified, pinned.get(qualified))
- view = {**bundle.view(material=material), "authority": authority, "ref": qualified}
+ view = {
+ **bundle._view(material=material, resources_seen=resources_seen),
+ "authority": authority, "ref": qualified,
+ }
entry = bundle.content[bundle.metadata["entrypoint"]]
haystack = (_json(bundle.metadata) + entry).decode("utf-8", "replace").casefold()
except IdentityError as exc:
diff --git a/tests/test_collect_resource_memo.py b/tests/test_collect_resource_memo.py
new file mode 100644
index 00000000..0c468e5d
--- /dev/null
+++ b/tests/test_collect_resource_memo.py
@@ -0,0 +1,65 @@
+"""Request-local resource reuse must not cache mutable Bundle validation."""
+import pytest
+
+from inferrsi.knowledge_operations import Bundle, KnowledgeReader, RevisionConflict, _hash
+
+CGROUP = "inferrsi.common.skills.cgroup_resource_controls"
+
+
+def small_bundle(data=b"original"):
+ return Bundle({"id": "example", "kind": "skill", "sources": [{"type": "unknown"}],
+ "applicability": {}, "state": "active", "limitations": [],
+ "attribution": {}, "entrypoint": "SKILL.md"}, {"SKILL.md": data}, {})
+
+
+def test_memo_keys_exact_bytes_not_path_or_mutable_bundle():
+ memo = {}
+ bundle = small_bundle()
+ original = bundle._view(resources_seen=memo)
+ assert bundle._view(resources_seen=memo) == original
+ other = small_bundle(b"other owner")
+ assert other._view(resources_seen=memo)["resources"]["SKILL.md"] == _hash(b"other owner")
+ bundle.content["SKILL.md"] = b"changed"
+ changed = bundle._view(resources_seen=memo)
+ assert changed["revision"] != original["revision"]
+ assert changed["resources"]["SKILL.md"] == _hash(b"changed")
+ assert bundle.view() == changed
+ bundle.metadata["limitations"].append("new limitation")
+ assert bundle._view(resources_seen=memo)["revision"] != changed["revision"]
+ bundle.metadata["id"] = "INVALID"
+ with pytest.raises(ValueError, match="identity"):
+ bundle._view(resources_seen=memo)
+
+
+def test_memo_does_not_skip_security_or_dependency_validation():
+ bundle, memo = small_bundle(), {}
+ bundle._view(resources_seen=memo)
+ bundle.dependencies["SKILL.md"] = "sha256:" + "0" * 64
+ with pytest.raises(RevisionConflict):
+ bundle._view(resources_seen=memo)
+ bundle.dependencies.clear()
+ bundle.content["../SKILL.md"] = b"original"
+ with pytest.raises(ValueError, match="Unsafe"):
+ bundle._view(resources_seen=memo)
+ del bundle.content["../SKILL.md"]
+ bundle.content["SKILL.md"] = bytearray(b"original")
+ with pytest.raises(ValueError, match="bytes"):
+ bundle._view(resources_seen=memo)
+
+
+def test_collect_resource_memo_is_not_retained_between_requests(monkeypatch):
+ reader = KnowledgeReader()
+ seen = []
+ original = Bundle._view
+
+ def capture(self, *, material=False, resources_seen=None):
+ seen.append(resources_seen)
+ return original(self, material=material, resources_seen=resources_seen)
+
+ monkeypatch.setattr(Bundle, "_view", capture)
+ one = reader.collect(ids=[CGROUP])
+ first = seen[-1]
+ two = reader.collect(ids=[CGROUP])
+ assert one == two
+ assert first is not seen[-1]
+ assert first and seen[-1]
--
2.52.0

21 changes: 21 additions & 0 deletions evidence/indexer-255-20261029/plan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Indexer #255: bounded CPU comparison and accuracy assessment

Owner: Dong1017. Scope and closure acceptance: [Issue #255](https://github.com/InferMatrixLab/InferRSI/issues/255). This is a harness-plane CPU retrieval campaign, not model or hardware efficacy evidence.

`protocol.json` is the frozen comparison contract. The exact baseline already includes the historical knowledge trim; this campaign does not repeat or claim that work. Candidate cap: one request-local resource-validation optimization. No paid services, new models, GPUs, synthetic corpus or ranking rewrite. Stop at one complete comparison; preserve any gate failures rather than revise gates to fit outcomes.

The source-only profile identified repeated Bundle resource validation and SHA-256 as the dominant controllable cost. A profiled reused-reader cgroup query took 1.767 seconds, with manifest 1.327 seconds, including approximately 47,278 SHA/path operations. Profile timings are diagnostic only, not the campaign result.

## Reproduce

First recover the preserved candidate commit using `../patch/README.md`. The final feature branch contains evidence only, not the optimized runtime. Use two clean worktrees at the baseline and candidate commits, the same Python executable, and dependencies recorded in `python-environment.txt`. Run sequentially without competing benchmark jobs:

```sh
python tools/evaluate_indexer.py \
--baseline /path/to/baseline --candidate /path/to/candidate \
--protocol evidence/indexer-255-20261029/plan/protocol.json \
--cases tests/fixtures/indexer/development.json tests/fixtures/indexer/heldout.json \
--output /path/to/new-results
```

A fresh reader is not a cold filesystem cache. Full CLI latency includes interpreter startup/output capture; JSON decoding is separately recorded. All 20 paired AB/BA groups and slow samples are retained. Bootstrap resamples the group statistic, not individual queries. Tail estimates from 20 samples are descriptive and noisy, not production SLOs.
33 changes: 33 additions & 0 deletions evidence/indexer-255-20261029/plan/confirmation-v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 2,
"purpose": "One prospective focused replication of unexplained full-CLI catalog-search tail; never replace or pool v1 FAIL",
"baseline_revision": "ab03f3ffb8f2e5bc02c304828c5c41890eef673e",
"candidate_revision": "6da28494891b21cdc89f632d84d763bc997b7d15",
"candidate_source_sha256": "16bbb0e523e4026dc4f189e81b96e79988c795b5e54b5abb66305d295a62bf31",
"frozen_v1_runner_sha256": "ea5b91ff17e80a422fd373621528dfe74ff144976bb55d6432501df452757ca5",
"command": "python -m inferrsi knowledge search cgroupv2 --limit 5 --json",
"timing": "Exactly v1 tools.evaluate_indexer.cli(mode=search): full subprocess including interpreter startup and stdout capture; JSON decode separately outside clock",
"warmup": "No explicit warmup; repeated process calls under existing OS cache, not cold cache",
"samples": 120,
"order": "60 AB and60 BA shuffled with random.Random(25502); paired successive subprocess calls; sequential only",
"negative_control": {
"pairs": 40,
"order": "20 AB and20 BA shuffled with random.Random(25503), both labels use baseline tree; after primary confirmation; diagnostic only, never pooled or acceptance substitute"
},
"gates": {
"p50_max_regression_percent": 10,
"p95_max_regression_percent": 20,
"output_parity": "Exact canonical output SHA-256 per pair; constant within both arms",
"identity": "Same exact baseline/candidate runtime/corpus as v1, source/corpus before/after unchanged",
"failure": "Any completed guard miss FAIL; missing/changed evidence INCONCLUSIVE. No trimming or pooling. Exactly one confirmation study regardless of outcome; do not repeat to obtain PASS."
},
"statistics": {
"p50": "median",
"p95": "nearest rank ceil(.95*n)",
"paired_bootstrap": "10000 paired group resamples random.Random(25504) for p50 and p95 relative change; percentile2.5/97.5 intervals descriptive, no extra posthoc acceptance rule"
},
"raw": "Every sample latency/decode_ns/outputhash/bytecount, pair index/order, UTC start and monotonic offsets; preserve failures/timeouts separately",
"budget": "One fixed study including40baseline-baselinepairs; CPU only, estimated3-5minutes, no install/model/GPU/service calls",
"coordination": "Start only after parent freeze receipt and otherworkers acknowledge no heavy CPU work; never edit source/runner/protocol mid-run",
"decision": "This study alone cannot turn v1 into PASS or authorize runtime merge; assess all evidence and uncertainty explicitly"
}
35 changes: 35 additions & 0 deletions evidence/indexer-255-20261029/plan/integrity-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"patch/README.md": "56b5d4a5e996d5d094ffdde2edbe27285be1dad98cd3ef19c939d62722376463",
"patch/candidate.bundle": "a3ab0986e7c5d39867ef8f2137f4a1c273c5f52daa95e571373ffa01435ad5c7",
"patch/candidate.patch": "a0c3e5230c489008525244af0bfe7c8ea483034c11ce5a835ef24a4b8a06669a",
"plan/README.md": "05a545d7e729c206df72aec1cf7715a7505c3ba6c6a4562f27f5899a318654cf",
"plan/confirmation-v2.json": "40de4eefba8712d3d07f2e48049b0899c831f94bfcfa252c1f8841525a337fa4",
"plan/protocol.json": "e4964329a20e6752b8149ab270733c0bbb258d0f948bdca9e86da6fe8f028956",
"plan/python-environment.txt": "e61e77e6b46a835af8b82e4fbc997d36b8ac9fbb415ab33cccc3b6f434874192",
"results/baseline-lint.txt": "f23163c00e3cd478afeb6fe5126d1758f9e94349e65067ffcec30aee311ecb58",
"results/baseline-smoke.json": "dd3f8876a759efbd733142838a797730be76cf956d6c3f39a40caaff900a4c00",
"results/confirmation-v2.json": "34d5b863c9f8dc75369d8bca4050019b3b33acf8e5bd26889ff0595850a65e26",
"results/final-evidence-tree-tests.txt": "d798e533b9e00ddacbdd77be63b15a1936f4853c3502c3010711093403006845",
"results/final-lint.txt": "f23163c00e3cd478afeb6fe5126d1758f9e94349e65067ffcec30aee311ecb58",
"results/focused-tests.txt": "c8f559b45ab7a92c5c94970cb03b7d481e9bede52082ced61b1f80ba5e09ef9d",
"results/full-suite-initial.txt": "e6332f13837daa4b5aa3389750fa2342472daec28dac3d465850d9c9e1870439",
"results/import-proof-baseline.json": "1e2e9d0e2b318c06582548995dc79614ce087cd946a5874da57b83d41b331736",
"results/import-proof-indexer-evidence.json": "1e2e9d0e2b318c06582548995dc79614ce087cd946a5874da57b83d41b331736",
"results/paired-run/A-mandatory-audit.json": "7fd24578d05007a916389e0080ad36ca24572a3f4a5598e7a99594cb52e6d869",
"results/paired-run/B-mandatory-audit.json": "cddaaa095a8b6645c75c3504cad70c4d30bd54bc9069f8c114006d784b892642",
"results/paired-run/timing.json": "588d37dfc6464c9894fd19a69d2db37f0635f8a9991c051e15131ca1f317a934",
"results/raw/3f3d873aaa65657ef4e3213e15847dbd90c9e30207621238fc2a35d2c9d5419f.json.gz": "7af84694f52243cf0433a7212af5d038c6dbca8a08e125ef8c0ef7fe2dae90a6",
"results/raw/517e374c3f13d9d22dafad37d51368d1f4e5669842f9bc0dadc1bb88cba3d968.json.gz": "0c070b69dcc6ea010a24c637a160b19ea8a7384eb40bb17636db0eaa42906a0a",
"results/raw/a35be36b859e6c4fd5bd7b7ec38920794f77adb322e9ae26498f31a9b4a91b6c.json.gz": "22a4ada0c2dab381ee9f8e3b342d0418d9e0668a16379fde069bae4b1eb0e9ad",
"results/raw/fbe219d8332596850e32d3d64ed4e4d566644d630c6e007338fd834af83fd2c0.json.gz": "0de101743d3cdb7a1eef38a7a398d71ce372bb19f9380b85000b45d052f3341c",
"results/raw-archives.json": "0f0ce2ed6da87046936b811b02930f1a9d0f6cc8d27c8c2077e6c08d65cd19d0",
"results/report.md": "38186030ae6cf8a94d202c4c1d6ae41bad8b19d9060f63dd350ae8c66896cb2a",
"results/targeted-env-final.txt": "dd2c815dfa55647cde1bace7510b74c4de3cca07ed800f2687acd150abfdabd8",
"results/targeted-env-initial.txt": "fedbef13168bf9473c9abd869cbf1830872e634601122b1f69b1b015d1828063",
"validator/README.md": "2217992077ac3fd5aee72cee23c2d90b8598bbde3cca634bccfa17cd263d0845",
"validator/confirm_cli_search.py": "b11b4cf08b6dceb43be447516d5abb740bb2de8c2fdfd7a9ee3f820a1174b55d",
"validator/frozen_evaluate_indexer.py": "ea5b91ff17e80a422fd373621528dfe74ff144976bb55d6432501df452757ca5",
"validator/label-review.md": "edf4946fef7485d968845407e3c4b8035e43fe634e56ecb0b32aa64f022f4262",
"validator/supplemental_required_audit.py": "ce1cf9b796ce8e029191220bf55e6924a7cb2b7a364f062db4631433a36568ff",
"validator/verify_raw_archives.py": "dc730ed4536278cf925e0663c99d6c703ab3fa0cfcbbb828b5bf1065e6aded44"
}
Loading
Loading