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
123 changes: 123 additions & 0 deletions research/t16-invoice-read-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Reuse JSON parses in the complete T16 invoice boundary replay

This opt-in adapter runs Tairitsu-Aya's complete 54-case
[T16 invoice boundary audit](../t16-invoice-boundary-audit/README.md) while
reusing the loaded invoice's JSON parses. Every predicate in that boundary
audit still runs. The complete reconstructed receipt must equal the unchanged
`EXPECTED.json`. No selected source, frozen archive or kappa changes.

Kumagi's [PR3009](https://github.com/CrocSwap/integer-mult-bounds/pull/3009)
already reduced fixture compression costs. Its remaining handoff identified
repeated JSON parsing. Profiling the current predecessor on this Linux host
with CPython 3.14 found 1,968 `json.raw_decode` calls taking 28.846 seconds of
a 166.859-second instrumented run. These are profile costs, not speedup data.

## Measured result

Four fresh CPython 3.12.15 processes on one shared Linux host ran in
baseline/cached/cached/baseline order. Every complete emitted receipt was
byte-identical to the original. [RESULT.json](RESULT.json) records exact commands,
environment, verifier hash, timing method and all observations.

| Mode | Wall seconds, in execution order | Peak RSS (KiB) |
| --- | --- | --- |
| Baseline | 179.276, 197.756 | 939892, 939804 |
| Cached | 170.213, 179.694 | 970392, 970320 |

Mean wall time fell from 188.516 to 174.954 seconds (7.19%); mean peak RSS rose
by 30,508 KiB (about 29.8 MiB). Each cached replay reused 488 of 628 reads across
12 paths, retaining 30,013,304 bytes of raw and serialized data. Timing ranges
overlap and the host was shared: these are local observations, not a confidence
interval or portable speed guarantee. No process reused another process's cache.

## Equivalence and invalidation

Only the loaded `invoice_allcold.read` function is replaced. Its frozen source
bytes remain unchanged. The adapter keeps one `(raw bytes, marshaled JSON)`
entry for the first successfully parsed contents of each path:

1. Read the current file bytes on **every** call. Size, modification time,
inode and a previously recorded digest are never freshness tests.
2. If the bytes differ, use the original `json.loads`/`gzip.decompress`
semantics. One-shot mutations are not serialized or added to the cache.
3. If the bytes agree, deserialize the private in-memory representation.
Every call returns a fresh mutable value, including nested lists/dictionaries.

A hit therefore returns the same JSON value as a fresh parse of the bytes just
read; a miss performs that parse. Mutating the return cannot change the cached
bytes. Malformed inputs and missing files still fail after a successful read.
Restoring a fixture is observed like any other change. `marshal` is used only
on this process's JSON values, never on input-controlled serialized bytes.
The predecessor already uses this representation for its mutation copies.
Keeping the first contents suits this audit's restored-fixture pattern. A file
that changes permanently will be reparsed on every subsequent read; this is
not intended as a general-purpose workload cache.

There is no persistent cache and no cached assertion or invoice result.
Each replay starts with an empty cache and
removes its extracted fixtures and private bytecode namespace on completion.

Source pins cover predecessor code, cases, expected receipt, manifests and all
nine transitive data/engine inputs. Archive-member checks, file hashes,
real-file mutations, the JSON assembly boundary, upstream controller checks,
the isolated driver predicate and final restored-fixture check remain active.
Predecessor harness sources are compiled directly; frozen imports use a fresh
bytecode namespace even for direct invocation. The replay refuses `-O`.

## Reproduce

From the repository root, standard-library Python 3.12:

```sh
python3.12 -B research/t16-invoice-read-cache/test_verify.py
python3.12 -B scripts/research_package.py --package research/t16-invoice-read-cache
```

Compare the same fixture with and without the adapter, using disposable paths:

```sh
python3.12 -B research/t16-invoice-read-cache/verify.py --baseline --receipt /tmp/t16-before.json
python3.12 -B research/t16-invoice-read-cache/verify.py --receipt /tmp/t16-after.json
cmp /tmp/t16-before.json /tmp/t16-after.json
cmp /tmp/t16-after.json research/t16-invoice-boundary-audit/EXPECTED.json
```

Both modes execute the same authenticated predecessor `run()` and compare its
complete result to the original receipt. Baseline mode leaves its reader
unchanged. Cases still give 28 invoice rejections and 26 acceptances; assembly
rejects 16 survivors and accepts ten, with the original further classifications.
The extra final cache-statistics line is not part of the receipt.

Ten focused controls cover plain/gzip types, byte changes with preserved timestamps,
repeated changed contents and restoration, cold/warm return mutation,
malformed/truncated data, missing paths, path/suffix separation, source tampering
and rejection of optimized replay. Local mutation experiments confirm that metadata-only
freshness and shared mutable returns fail these controls. The cache tests do
not replace any check of the predecessor's mathematical hypotheses.

## Scope and sources

Base: `463113d675af7410ac91d53a4fed51ec6494eb9a`, priority revision 6.
The [canonical claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/2051#discussioncomment-19001801)
continues the original audit's thread. `TASK.json` records scope and overlap.
This is verifier engineering. It neither runs the full selected cold chain nor
discharges any all-size supplier or multiplication theorem obligation.

## Open next questions

Does the improvement persist on another Python 3.12 host? Run the two modes in
alternating order, compare full receipts and report wall time and peak memory.
Interpreter and competing load affect timing; independent host measurements
remain outside this package's evidence.

## Credit

Credit Tairitsu-Aya for the audit, cases and expected receipt; Josie Elliston
for PR1959's handoff; Kumagi for PR3009 and the remaining parsing lead; and
jackmgaller for the predecessor's `marshal` copying technique. Original invoice,
controller, moment/outer and selected-construction contributors retain their
attribution in the predecessor. No predecessor package is copied or edited.

Prepared by thakrarsagar with substantial OpenAI Codex assistance, including
separate source inspection, regression-test implementation and code review.
Apache-2.0. No independent human or proof-assistant review is claimed.
158 changes: 158 additions & 0 deletions research/t16-invoice-read-cache/RESULT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"python": "3.12.15 (main, Oct 14 2026, 01:05:27) [Clang 23.1.3 ]",
"executable": "/tmp/imb-loop-9963-i01/python/cpython-3.12.15-linux-x86_64-gnu/bin/python3.12",
"platform": "Linux-7.0.0-38-generic-x86_64-with-glibc2.43",
"verifier_sha256": "6daf8299c4c9e9997b1c200d141a6a2ea9de3946a9a065f956dc977ba797f8cd",
"runs": [
{
"label": "1-baseline",
"argv": [
"/tmp/imb-loop-9963-i01/python/cpython-3.12.15-linux-x86_64-gnu/bin/python3.12",
"-B",
"/root/projects/imb-loop-9963/research/t16-invoice-read-cache/verify.py",
"--baseline",
"--receipt",
"/root/projects/imb-loop-9963/.scratch/iteration-01/1-baseline.json"
],
"wall_seconds": 179.27564533799887,
"user_seconds": 170.425319,
"system_seconds": 8.55583,
"peak_rss_kib": 939892,
"receipt_sha256": "e3c0e3c93fbbc6a63e43502dbb98b9e6556abe6c412e0c142f7a202f0e420541",
"cache": {
"baseline": true,
"hits": 0,
"misses": 0,
"paths": 0,
"retained_bytes": 0
}
},
{
"label": "2-cached",
"argv": [
"/tmp/imb-loop-9963-i01/python/cpython-3.12.15-linux-x86_64-gnu/bin/python3.12",
"-B",
"/root/projects/imb-loop-9963/research/t16-invoice-read-cache/verify.py",
"--receipt",
"/root/projects/imb-loop-9963/.scratch/iteration-01/2-cached.json"
],
"wall_seconds": 170.21300993097248,
"user_seconds": 160.368821,
"system_seconds": 9.004701,
"peak_rss_kib": 970392,
"receipt_sha256": "e3c0e3c93fbbc6a63e43502dbb98b9e6556abe6c412e0c142f7a202f0e420541",
"cache": {
"baseline": false,
"hits": 488,
"misses": 140,
"paths": 12,
"retained_bytes": 30013304
}
},
{
"label": "3-cached",
"argv": [
"/tmp/imb-loop-9963-i01/python/cpython-3.12.15-linux-x86_64-gnu/bin/python3.12",
"-B",
"/root/projects/imb-loop-9963/research/t16-invoice-read-cache/verify.py",
"--receipt",
"/root/projects/imb-loop-9963/.scratch/iteration-01/3-cached.json"
],
"wall_seconds": 179.69449680298567,
"user_seconds": 170.101426,
"system_seconds": 9.23581,
"peak_rss_kib": 970320,
"receipt_sha256": "e3c0e3c93fbbc6a63e43502dbb98b9e6556abe6c412e0c142f7a202f0e420541",
"cache": {
"baseline": false,
"hits": 488,
"misses": 140,
"paths": 12,
"retained_bytes": 30013304
}
},
{
"label": "4-baseline",
"argv": [
"/tmp/imb-loop-9963-i01/python/cpython-3.12.15-linux-x86_64-gnu/bin/python3.12",
"-B",
"/root/projects/imb-loop-9963/research/t16-invoice-read-cache/verify.py",
"--baseline",
"--receipt",
"/root/projects/imb-loop-9963/.scratch/iteration-01/4-baseline.json"
],
"wall_seconds": 197.75562528698356,
"user_seconds": 187.5488,
"system_seconds": 9.366797,
"peak_rss_kib": 939804,
"receipt_sha256": "e3c0e3c93fbbc6a63e43502dbb98b9e6556abe6c412e0c142f7a202f0e420541",
"cache": {
"baseline": true,
"hits": 0,
"misses": 0,
"paths": 0,
"retained_bytes": 0
}
}
],
"schema_version": 1,
"observed_on": "2026-10-17",
"base_commit": "463113d675af7410ac91d53a4fed51ec6494eb9a",
"cpu": "AMD EPYC-Genoa Processor; 4 logical CPUs available",
"evidence_scope": "Local observations on one shared Linux host; no confidence interval or portable speed guarantee.",
"measurement": {
"order": [
"baseline",
"cached",
"cached",
"baseline"
],
"method": "Sequential fresh subprocesses; time.perf_counter around spawn/wait for wall time and os.wait4 rusage for child user/system CPU and ru_maxrss (KiB on Linux); 600-second alarm per process. No concurrent replay in this worktree.",
"receipt_check": "Every emitted receipt was compared byte for byte with unchanged research/t16-invoice-boundary-audit/EXPECTED.json.",
"scratch": "Absolute executable and receipt paths are session observations, not required locations; use python3.12 and disposable receipt paths when reproducing. Session scratch is deleted after publication."
},
"aggregate": {
"baseline_mean_wall_seconds": 188.5156353124912,
"cached_mean_wall_seconds": 174.95375336697907,
"mean_wall_reduction_percent": 7.194035615683236,
"baseline_mean_peak_rss_kib": 939848,
"cached_mean_peak_rss_kib": 970356
},
"retained_coverage": {
"cases": 54,
"invoice_reject": 28,
"invoice_accept": 26,
"assembly_reject": 16,
"assembly_accept": 10,
"all_four_receipts_byte_identical": true
},
"focused_controls": {
"command": [
"python3.12",
"-B",
"research/t16-invoice-read-cache/test_verify.py"
],
"tests": 10,
"status": "PASS"
},
"obligations_not_run": [
"Complete selected cold composition replay",
"All-size supplier or integer multiplication theorem",
"Independent host timing replication"
],
"registered_replay": {
"command": [
"python3.12",
"-B",
"scripts/research_package.py",
"--package",
"research/t16-invoice-read-cache"
],
"completed_at": "2026-10-17T17:56:53Z",
"status": "PASS_REGISTERED_RESEARCH_PACKAGE research/t16-invoice-read-cache outcome=completed",
"focused_tests": 10,
"cases": 54,
"cache_hits": 488,
"cache_misses": 140
}
}
102 changes: 102 additions & 0 deletions research/t16-invoice-read-cache/SOURCES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"schema_version": 1,
"base_commit": "463113d675af7410ac91d53a4fed51ec6494eb9a",
"files": [
{
"path": "certificates/selected-result.json",
"usage": "provenance",
"git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81",
"sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129"
},
{
"path": "docs/research/agent-task-catalog.json",
"usage": "provenance",
"git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5",
"sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0"
},
{
"path": "research/t16-invoice-boundary-audit/EXPECTED.json",
"usage": "input",
"git_blob": "6cc1f4795640c09431738332b0a9e9c48b48f796",
"sha256": "e3c0e3c93fbbc6a63e43502dbb98b9e6556abe6c412e0c142f7a202f0e420541"
},
{
"path": "research/t16-invoice-boundary-audit/SOURCES.json",
"usage": "input",
"git_blob": "21c8fa5b9ee76819e40de3f1473077cd02f4dc7f",
"sha256": "ef816261008c212dbde2498722f66e37555944f206be061fa8c92dc72a22fb9d"
},
{
"path": "research/t16-invoice-boundary-audit/VERIFY.json",
"usage": "input",
"git_blob": "425dbc047d76503857973db43c0f6dce53a2d061",
"sha256": "aedf0434c96fb814b853e12ad4cfc7a05bd1a8b324da8666cf1b9e4d75228026"
},
{
"path": "research/t16-invoice-boundary-audit/cases.py",
"usage": "input",
"git_blob": "b0dfceedc6b14d5856b9d232d11aa022cd29b71e",
"sha256": "8f7a8a583b691adbc5f77fe5826c41e299d0d7bbab79bbf79122039a712c46fb"
},
{
"path": "research/t16-invoice-boundary-audit/verify.py",
"usage": "input",
"git_blob": "5669c919f7f26b2db3ef6140359fd13c99210c74",
"sha256": "fdd9c9f2800f4ea53f241e05bf816587faa4e812879b679d597b7734058d664b"
},
{
"path": "research/community-frontier1094-audit/selected-replay.tar.gz",
"usage": "input",
"git_blob": "c24daf067f9c543421d89ca2eeaa4eb78a57fb6f",
"sha256": "f1da80610bf33c58527f18ad63b4350d0b864e1d4486141ee17ac9bed4d529d6"
},
{
"path": "research/complex-k492-owner-repair/vendor/multicold/engines/base_two_moment.py",
"usage": "input",
"git_blob": "14a90fa0e788217856f070382c9e61bd7c603c61",
"sha256": "aee70c242a2f1d225528fabe2002e1564d1dc884797c07d28a831c7878ee9098"
},
{
"path": "research/complex-k492-owner-repair/vendor/multicold/engines/moment.py",
"usage": "input",
"git_blob": "7d697cb45203fe72d97037403d6da41f71f3b7fd",
"sha256": "81cbc864e106418fc7854322746f72180cb8110ff39f74450a3b8d55a82c1482"
},
{
"path": "research/complex-k492-owner-repair/vendor/multicold/engines/outer.py",
"usage": "input",
"git_blob": "43007488ad2c43187c77cc6798beff8b1cd76ad2",
"sha256": "c1ebb52163a7219504c728a5c2b098bf1e50bf20148a2879c5a74c3cadc7c03c"
},
{
"path": "research/complex-k492-owner-repair/vendor/multicold/vendor/pr558/vendor/pr552/complex-global/vendor531/evidence/audit/PREFIX-AND-INVOICE.json",
"usage": "input",
"git_blob": "a16bf40bccc81278a443e0d5f09b44495035de81",
"sha256": "ce1bfa49be88ae67a404f606a11db2232b7e1f2610d4418058e39749d86d8478"
},
{
"path": "research/complex-t16-rare-pattern-exchanges/data/OWNERS.json.gz",
"usage": "input",
"git_blob": "d3ba33d7e703a3229d9fb8a360f69d2f318bbb70",
"sha256": "87902c528dfab7d503dcf8a784260e3ab6fb7424c418a1820f7261f25be7b6bc"
},
{
"path": "research/complex-t16-rare-pattern-exchanges/data/PLAN.json",
"usage": "input",
"git_blob": "f1bec76e8e9b7a1f09c1e05cb6cce973b6e59f1b",
"sha256": "7bd786ba8e66408f02aa9ef446eaf20c1bfe981ea2e4dd1e5a929f0aa7767bc0"
},
{
"path": "research/complex-t16-rare-pattern-exchanges/data/SPEC.json",
"usage": "input",
"git_blob": "af013ccc2975d9d575d116f8a463cc947f220c8d",
"sha256": "8cb51f25a5da4a29d3783853025b73ff1f452429d4fdb30c599e598bcab0e71d"
},
{
"path": "research/complex-t16-rare-pattern-exchanges/upstream1087.tar.gz",
"usage": "input",
"git_blob": "2970ef79b0441e937449bed30f68f2e0558186ba",
"sha256": "d4acf04daef85d4514f80ec5fcd2492d0c60e5d6c49fa71b3e6523f8db2dea86"
}
]
}
Loading