Compare commits

...
Author SHA1 Message Date
65f2f9a22b chore(experiment): checkpoint shared native byte reads
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 04:31:39 +00:00
2dc3820b69 chore(experiment): refresh main before byte batch work
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 04:10:35 +00:00
90fee8aee5 fix(experiment): report retained string source scope explicitly
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 04:09:59 +00:00
dd6c1db523 test(experiment): record matched LLVM native query model outcomes
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 04:08:34 +00:00
6bc4ea2839 feat(experiment): project native string queries before serialization
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 04:01:39 +00:00
c8469c844c chore(experiment): refresh main before native string trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 03:51:50 +00:00
ededbd7f24 perf(experiment): reuse proven native source refusals
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:51:37 +00:00
b88c75df82 test(experiment): record streamed inventory model outcomes
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:31:29 +00:00
35d93e21f2 fix(experiment): discover trial tools from the registered catalog
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:26:50 +00:00
0c8b7c29a4 feat(experiment): stream bounded native string evidence
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:24:24 +00:00
8488f82366 chore(experiment): refresh main before inventory scaling tests
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:05:22 +00:00
5d4c2638ae test(experiment): record bounded large-string model outcomes
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 02:04:14 +00:00
185bf90c41 feat(experiment): select string fields before bounded transport encoding
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 01:53:59 +00:00
b2a2ab29cf chore(experiment): refresh main before capacity trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 01:10:29 +00:00
985dcc4156 test(experiment): verify model use of precise string facts
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 01:09:38 +00:00
04e0959de4 fix(experiment): preserve precise native string facts
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 01:04:22 +00:00
ba0ded9a7b chore(experiment): refresh main before string precision trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 00:52:01 +00:00
f161952ffd test(experiment): record pooled-string agent comparison
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 00:51:04 +00:00
4158e8a050 feat(experiment): compose bounded incoming reference spans
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 00:34:36 +00:00
391be63177 chore(experiment): bound configurable build memory headroom
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-17 00:33:07 +00:00
bde56bc2bc docs(experiment): update capability coverage after return fixes
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 23:34:49 +00:00
c8d8319367 chore(experiment): refresh main before cross-function trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 23:26:03 +00:00
ef60791750 docs(experiment): record corrected-provider agent comparison
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 23:24:59 +00:00
bf9d3a6e47 fix(experiment): preserve returning and unknown control-flow paths
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 23:09:16 +00:00
cda262bfc4 fix(experiment): preserve AArch64 PLT entry identity
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 22:57:37 +00:00
d3443521d4 chore(experiment): refresh main before PLT boundary trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 22:48:05 +00:00
e4153bc268 docs(experiment): record three-way AArch64 agent comparison
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 22:44:48 +00:00
5eede35c97 fix(experiment): compose AArch64 PC-relative references
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 22:22:39 +00:00
4aee0afc21 chore(experiment): refresh main before cross-architecture trials
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 21:37:14 +00:00
d4b615e2b9 docs(experiment): record real-agent storage composition results
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 21:35:50 +00:00
577ca5a0ae feat(experiment): compose native architecture storage facts
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 21:23:04 +00:00
bfe439d990 chore(experiment): refresh main before storage-description exploration
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 20:55:19 +00:00
8416f4d3e3 docs(experiment): record real-agent function-boundary composition
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 20:51:43 +00:00
e70f2df61e fix(experiment): isolate malformed native facet failures
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 20:51:43 +00:00
5ca00675b7 feat(experiment): expose recovered function prototype entries
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 20:22:37 +00:00
9a769cbefe chore(experiment): refresh main before function-boundary exploration
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 19:56:35 +00:00
1565461809 docs(experiment): record real-agent path-query comparison
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 19:55:22 +00:00
e990feeb7c feat(experiment): compose bounded recovered CFG path witnesses
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 19:43:14 +00:00
e23f540445 chore(experiment): refresh main before path-query exploration
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 19:36:31 +00:00
7259ea1dee docs(experiment): retain mixed discovery repeat results
Both real-model answers satisfy the unchanged oracle. Record the smaller actual help path, all task costs, and the unexplained 189-second gap between completed client executions without removing it from elapsed time.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 19:32:32 +00:00
65b701df54 perf(experiment): separate discovery summaries from full contracts
Return explicit method intents in reference indexes while preserving all full contracts, topic matching and complete MCP catalogs. Separate provider-free contracts from session admission and defer native loading until open.

Validate 82 related tests, exact SDK/MCP full-contract parity, real zlib CLI/SDK reads and native/inspection cleanup retries. Freeze the unchanged two-level question for an order-reversed real-model repeat.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 18:57:16 +00:00
3e4c0d8b59 docs(experiment): report two-level control model trials
Both real-model answers satisfy the frozen controller, SSA identity, path-witness and machine-evidence oracle. Code Mode reduces cumulative input while increasing uncached input and runtime costs in this sample; preserve the complete mixed result and native-work confounds.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 18:40:12 +00:00
8d13c67e7e fix(experiment): preserve CFG query scope and reuse control indexes
Distinguish unretained blocks from empty relations and page generated control dependencies over one lazy snapshot index. Verify all 2,845 SQLite triples through both real MCP adapters and an independent finite-path oracle; 82 related tests pass.

Record equivalent core-query and process-family costs. Freeze the shared two-level controller question and oracle before real-model launches.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 18:25:47 +00:00
d7d95c7dcc chore(experiment): refresh main before control study
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 18:02:56 +00:00
7a76e0b9ba fix(experiment): align native reads with refreshed main
Retain inspection file owners before a target lease exists and gate replacement on cleanup. Reuse the streaming string inventory owner and the same installation adapter in native profiling.

Validate 80 related tests, real SSH value/source parity in both MCP adapters, injected descriptor/native cleanup retries, zlib SDK immutability and native profiling. Keep historical model costs pinned to their measured runtime.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 18:01:04 +00:00
8e0aa73db2 chore(experiment): refresh main baseline
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 17:52:38 +00:00
bd27ab7422 docs(experiment): report stripped SSH workflow comparison
Record correct real-model answers through complete atomic and corrected traditional native toolsets. Preserve the under-equipped initial baseline separately, full task costs, provenance, resource evidence and profile/strategy limits.

The direct model answers with machine facts alone; server Code Mode uses the new value queries but performs extra analysis. No inherent Code Mode or broad complex-software superiority is established.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 17:45:41 +00:00
1aaa21296f fix(experiment): exhaust native baseline catalog pages
Derive missing-tool coverage only after all catalog pages are examined, reject cursor loops and omit unused result schemas in name-only generation while honoring explicit caller settings.

The final actual MCP generator preserves the measured 16-tool selection and verifies owned cleanup under the resource bounds.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 17:45:41 +00:00
3e08a6aeaf fix(experiment): derive complete native baseline toolsets
Match the actual MCP catalog to the compiled Kuna capability owner and shared session/view contracts. Fail if declared native operations lack named tools, and preserve existing output artifacts.

The actual MCP generator reproduces the corrected 16-tool SSH baseline with verified cleanup. This prevents another evaluator allowlist from hiding function discovery.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 17:40:05 +00:00
09677946cb test(experiment): freeze stripped SSH warning comparison
Use one machine-supported oracle for traditional, direct atomic and server Code Mode workflows. Include pointer/stack passing, local strict-checking routing and return-width limits without requiring native-only identities.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 17:03:05 +00:00
4a067b335b feat(experiment): query value locations and use occurrences
Share exact coordinate selection across retained graph, projection and call-boundary values. Index inverse operand occurrences for values without requiring defining operations; preserve PHI slots, unknown spaces, partial scope and evidence.

Verify 250 OpenSSH SSA versions and 369 uses through both real MCP adapters. An equivalent retained-source task takes six core reads instead of 244; model costs and native speedups remain unproved. Pass 78 shared tests and actual catalog checks.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:59:12 +00:00
9f576495a0 docs(experiment): retain immutable wait-trial runtime
Preserve the observed benchmark revision under a fixed tag while correcting co-author trailer formatting on the experiment branch. Runtime trees and recorded trial identities stay unchanged.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:25:48 +00:00
499fe56a62 docs(experiment): map verified primitive coverage
Separate task sufficiency, patched-engine requirements and remaining unknowns. Explain identity and relation grain without claiming universal RE completeness or provider parity.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:22:38 +00:00
782132cb58 fix(experiment): publish shared execution resource policy
Use one policy for executor defaults, MCP admission and help. Make timeout default/maximum explicit, omit Code Mode limits from direct help, and describe the independent switch facet.

Validate 73 shared tests, both actual MCP catalogs, rejection recovery, and real zlib Evidence access after bounded guest failures. Model results remain pinned to earlier discovery contracts.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:22:38 +00:00
f521ec72f5 docs(experiment): report paired long-wait results
Both models retain correct selected-case answers and use one client wait. Record complete costs, timeout/output-budget recovery and mixed adapter outcomes without attributing a causal speedup.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:12:11 +00:00
b5259d82a4 test(experiment): freeze client wait guidance diagnostic
Keep identical analysis contracts, question, engine and complete catalogs. Test common opt-in wait guidance while retaining polling and native latency in whole-task costs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 16:02:44 +00:00
3348688579 docs(experiment): record real-agent selected-case results
Report both correct answers and complete task costs. Preserve the native latency and client polling confounds; no general Code Mode advantage is established.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 15:58:53 +00:00
f44dca9c37 feat(experiment): expose native case-to-edge facts
Share exact jump-table metadata and paged case relationships across CLI,
MCP and Code Mode. Keep labels, row identities, recovered edges and machine
defaults separate; reclaim independent facts under output capacity.

Verify all 182 SQLite table targets against ELF bytes through both MCP
adapters and retain cases/calls when a real 2 MiB native budget omits IR.
Freeze the next analyst question and oracle before real-model trials.

[AUTOMATED] Experimental native patch; no upstream integration or PR.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 15:32:12 +00:00
29e0472812 test(experiment): measure queued and repeated native reads
Compare sequential and overlapping requests through both real MCP adapters
with the same preserved engine, selected instruction windows and full graph.
Retain the unexplained model-run anomaly without claiming a speed fix.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 14:25:22 +00:00
4882f6b5dc docs(experiment): retain guided model comparisons and limits
Verify both repeated answers and exact discovery calls against unchanged
source facts. Record complete task costs, overlapping requests, unexplained
capture-time variation and the client executor available to both lanes.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 14:14:27 +00:00
7a7c4a6d7a docs(experiment): record real-agent control-flow evidence
Review both complete answers against the precommitted oracle and independent
ELF instruction bytes. Retain all costs, validation retries, discovery noise
and the limits of this single observational pair.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 14:01:07 +00:00
e2205313a5 feat(experiment): expose bounded full recovered graphs
Preserve complete graph facts with a bounded lossless native wire codec and
shared paged Evidence views. Verify both MCP adapters and retained legacy
records, then freeze a control/data-flow question and oracle for real agents.

[AUTOMATED] Exploratory native patch; no upstream integration or PR.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 13:47:33 +00:00
7d0da075e7 perf(experiment): measure native analysis phase costs
[AUTOMATED] Add a gated diagnostic overlay and production-owner profiling runner. Preserve actual phase/resource results, disabled-output control and lossless full-graph encoding feasibility without claiming a public codec or model speedup.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 12:41:35 +00:00
4986b8644f docs(experiment): record indexed discovery model costs
Retain both correctness-equal wide-PHI pairs, complete discovery costs and the remaining whole-function native computation boundary.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 12:22:02 +00:00
a440049026 feat(experiment): expose a schema-free method index
Discover declared methods through the shared reference owner before requesting named contracts; preserve the existing default and runtime capability semantics.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 12:15:10 +00:00
e678be3f9d docs(experiment): record selected operand model results
Both adapters satisfy the fixed wide-PHI oracle with one capture and selected slots. Preserve mixed timing/token costs and the observed discovery overhead rather than inferring a Code Mode advantage.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 12:12:09 +00:00
e38a4c4394 feat(experiment): page native SSA operand relationships
Keep operation and slice defaults compact; preserve exact input slots and phi edges, distinguish unretained seeds, and align advertised relation schemas with runtime validation. Pin a seeded wide-PHI model task after real public MCP verification.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 12:05:15 +00:00
a225d7c552 fix(experiment): retain direct analysis failures in trial ledgers
Record the second PHI model pair, including the native timeout and successful retry; keep adapter conclusions limited to observed whole-task costs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 11:57:25 +00:00
14bc2bca21 fix(experiment): align named reference lookup with input contracts
Share displayed method names with direct registration, support explicit multi-name selection and unmatched terms, and cache immutable schema conversions by schema identity. Export input-side schemas so defaulted fields stay optional; verify both actual MCP catalogs and named contracts before repeating the unchanged model task.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 11:41:48 +00:00
71be07de42 docs(experiment): record real-model phi projection results
Both answers satisfy the fixed four-alternative oracle with one VM capture and scoped facts. Preserve whole-task costs and source checks, including the direct reference-name lookup miss that needs a shared discovery fix.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 11:30:18 +00:00
8114bd675e feat(experiment): expose bounded call-rooted definition facts
Share native membership and operand ownership across full and projected facts. Preserve exact phi bindings and definition frontiers when the full graph is unavailable, keep CFG/use coverage explicit, and expose selected reads through the same CLI/SDK/MCP contracts. Verify real SQLite/zlib fidelity, encoded fallback, bounded metadata, and cache reuse; pin the next real-model question and oracle.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 11:16:26 +00:00
4d7fccbce6 docs(experiment): measure bounded native definition projections
Preserve a diagnostic-only patch and reproducible lossless encoding/projection probe. The real VM graph exceeds several public capacities; selected SSA neighborhoods are much smaller, with explicit frontiers. Record actual resource costs and keep public engine/API limits unchanged.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 10:30:19 +00:00
af53e0fbe5 fix(experiment): retain ownership after tagged cleanup failures
Check the native cleanup Result before clearing the lease and preserve cleanup resources through the MCP error adapter. Reproduce the old false success, then verify real SDK close/replacement ownership and both MCP retry paths with explicit fault injection.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 10:25:17 +00:00
f08c191ed3 docs(experiment): compare compact call counts in real model tasks
Retain the successful answer and source checks from both adapters and all measured task costs. Both avoid call-set paging; direct beats Code Mode in the new sample and before/after effects remain mixed.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 10:07:36 +00:00
da6f5470be perf(experiment): summarize retained calls before paging
Expose a compact call distribution in snapshot metadata through the shared validated owner. Preserve coverage, unknown targets, dead rows, immutable selected reads, and empty versus unavailable semantics. Retain the same boundary question and oracle for paired real-model comparison.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 10:00:04 +00:00
fb9adbf384 docs(experiment): record real-model call boundary results
Both lanes satisfy the pre-pinned SQLite task with one retained VM analysis. Record full answer/source review, actual model and resource counters, and mixed context costs without a general efficiency claim.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 09:53:53 +00:00
f9f9dc209d feat(experiment): retain call facts beyond full graph capacity
Separate native call and boundary-value ownership from the bounded recovered graph. Validate facets independently and preserve shared identities, source evidence, and explicit partial coverage. Pin the SQLite boundary task and oracle before paired real-model trials.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 09:46:42 +00:00
04c081fc61 experiment(re): verify model reference aggregation against machine calls
Record both completed model workflows, whole-task costs and source/identity checks. Compare every VM direct-call pair with independent disassembly, preserve indirect-call limits, verify unpatched stock through the shared CLI/API, and retain failed/partial research costs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 09:01:54 +00:00
3aa685db39 feat(experiment): compose shallow outgoing references with explicit scope
Share one native parser for both directions, preserve occurrence identity and unknown function applicability, push kind filters to Kuna and reuse sources across fields/pages/scopes. Verify real SQLite machine references independently, including calls omitted from optimized IR and VM queries beyond graph capacity. Pin the aggregate model task before its paired runs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 08:48:24 +00:00
56182b2217 experiment(re): verify cross-function model answers and mixed adapter costs
Record the pre-pinned explicit-return-path pair with source and identity validation. Both models complete the context-flow task; Code Mode has fewer MCP requests without a demonstrated overall efficiency advantage. Preserve large-function and shallow-reference coverage limits.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 08:20:24 +00:00
e9348df0c3 experiment(re): align cross-function question with pinned return-path oracle
Retain both initial real-model answers and whole-task costs. Both prove the core context connection but omit the oracle-required return-code distinctions; clarify that requirement before the next pair without changing the oracle or supplying addresses.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 08:10:41 +00:00
01e5c59551 fix(experiment): validate native engine pins before model trials
Preserve the rejected cross-function launch caused by a non-embedded Cargo test build replacing the mutable CLI. Check explicit engine identity before profile creation and after the task; use an independent executable copy for measured runs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 08:03:30 +00:00
33c4282b8a feat(experiment): expose structured native call and argument relations
Keep recovered callee identities separate from fspec annotations and SSA argument values separate from passing storage. Add selected calls and function-input reads through the shared fact owner, with real SQLite MCP coverage and a pre-pinned cross-function model task.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 07:58:01 +00:00
f34425dc24 fix(experiment): enforce Code Mode payload budgets on guest errors
Reject oversized error delivery with explicit omission metadata, account for JSON escaping, and retain source observations and their lookup after failure. Reproduce and verify the real MCP path without claiming model-token savings from byte counts.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 07:33:09 +00:00
dad0228df8 experiment(re): verify model composition of class and dispatch tables
Record matching six-byte table oracles, real byte-tool use, model response counts and whole-task costs without generalizing a single paired observation.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 07:23:40 +00:00
73db4fad54 feat(experiment): compose bounded native byte windows with RE facts
Add shared SDK/CLI/MCP byte reads over the existing Kuna data protocol, preserve partial batches and exact u64 ranges, and retain complete source Evidence. Reuse named read lifecycles, bound aggregate hex expansion, and verify stock/native/direct MCP paths plus a shipped-file byte oracle before pinning a table-dispatch model task.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 07:17:18 +00:00
c53c2a9b90 experiment(re): record equal-coverage model use of retained Pragma code
Keep actual response/MCP counts, whole-task token usage and resource receipts separate. Both adapters complete the local task with explicit missing IR; no general speedup is inferred.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:58:46 +00:00
9e1b39358a experiment(re): pin a model task over recovered Pragma code
Exercise the restored code facet with a question fixed before trial and independent instruction anchors, using identical envelope guidance in both atomic calling modes.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:52:03 +00:00
1346e97dca fix(experiment): preserve code when encoded native graphs exceed capacity
Bound compact native JSON with the existing writer, keep a valid code facet when the graph cannot fit, and pass the supervised byte budget explicitly. Verify real SQLite Parser/Pragma captures, exact preserved C/mappings/graph facts and public MCP reads. Keep string inventory parsing/projection under its own owner.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:50:20 +00:00
dc022bcd0f experiment(re): separate model rounds from MCP requests in fair trials
Validate per-response usage totals, retain the negative large-VM comparison and qualify the client executor, cache and investigation-depth differences. Add optional common envelope/stopping guidance without relabeling historical runs.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:29:26 +00:00
5aa78c873e experiment(re): pin coverage criteria for a large SQLite VM task
Record independent machine-code anchors before model trials, separate cache regimes and incomplete answers, and exercise real recovered-IR capacity failure without hiding retained code.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:09:46 +00:00
15d75ea1ea fix(experiment): preserve cached fact ownership for SDK callers
Freeze parsed inventories once at their owning boundary and share the rule with native IR and function views. Verify the real SDK mutation regression and retain corrected equal-depth SQLite model costs, including persistent-cache limitations.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 06:07:46 +00:00
e9b9a8dd0e experiment(re): describe direct atomic trials without a Code Mode tool
Keep the direct adapter benchmark instructions consistent with its actual registered tools; retain historical trial profiles unchanged.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 05:48:57 +00:00
f3f209d03f experiment(re)!: preserve partial captures and resolve function entries
Keep validated code available when native graph extraction is unavailable, bind output to the actual input/entry, preserve cancellation observations, and share batch source/error semantics. Add filtered function/alias reads and slice field selection across adapters.

Verified 38 focused tests, targeted lint, real stock/native MCP workflows, large SQLite graph-capacity fallback, and real cold/warm MCP reuse. Retain actual model costs and unequal-depth/selection limitations instead of claiming general superiority.

BREAKING CHANGE: Experimental native snapshots may succeed with readable code and an unavailable recovered_ir facet. Inspect facets before graph reads; unavailable graph counts are null/unknown.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 05:48:03 +00:00
4f13bd6733 experiment(re)!: separate IR origins from machine instruction facts
A real model conflated an optimized CFG edge with the bytes at its instruction origin. Make provenance explicit and add bounded, batched instruction windows from the existing Kuna CLI, preserving exact bytes, per-window failures and Evidence. Record the task-cost comparison without treating the incomplete machine-path answer as an equal-quality win.

Verified 33 focused tests, targeted lint, real stock/patched MCP decoding with mixed success, and a real 4096-row capacity run under the resource observer.

BREAKING CHANGE: Experimental operation.address/addresses and block.start become origin_address/origin_addresses and origin_start. Printed CFG target_address becomes target_origin; historical source captures are unchanged.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 04:51:55 +00:00
f2f029c5dd experiment(re): retain native model trace and task-cost limits
The real model uses recovered controllers and indexed phi/value relations, but the first native-IR trial still does not beat the traditional local-question workflow. Record actual whole-task usage and prepare value-origin and small-function counterexamples.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 04:33:55 +00:00
a7e9f8843b experiment(re): expose native CFG and value identities for composition
[AUTOMATED] Preserve the opt-in pinned Kuna exporter as a reproducible source patch. Share typed graph/value reads and derived control dependence through the SDK, CLI and MCP adapters, retaining unknown runtime and memory semantics.

Validated 29 focused tests, lint, actual diagnostic/native MCP workflows and a real zlib CLI composition. C and line mappings match the prior stock capture. Full upstream corpus/workspace gates and revised real-model costs remain unverified.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 04:28:22 +00:00
fcfc87b2b4 experiment(re): record actual three-way model task costs
Retain failed attempts, cached input accounting and payload-exit process-family counters. The first comparison favors the traditional workflow; keep the negative finding explicit.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 04:00:19 +00:00
c5cefd622b experiment(re): refine composition contracts from a real model trace
Record genuine Code Mode use and full model usage rather than response-only estimates. Describe return shapes, permit byte-budgeted internal C reads, separate guest CPU from analysis deadlines, and move subsequent model profiles outside the source tree. Verify lease, admission, cleanup-retry and cancellation semantics.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 03:28:30 +00:00
5aa1c5c64f experiment(re): expose shared atomic facts through isolated Code Mode
Add a compact rea-codemode MCP server, bounded QuickJS execution and shared SDK/direct adapters. Reuse native target and process owners; retain evidence and lease-scoped snapshots. Extend the real-model trial runner with an isolated experimental MCP registration. Capability and evaluation work remains in progress.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 03:17:05 +00:00
2e11fc23fd experiment(re): validate guard slices and record token tradeoffs
Verify three repaired zlib mappings, a SQLite call guard and all ordinary 16-bit header values against retained native evidence. Record producer omissions, failed-run costs and the small-function context counterexample. Preserve existing capture outputs with exclusive writes.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:46 +00:00
fd79a273f3 experiment(re): compose native SSA uses and branch dependencies
Retain bounded native snapshots and public MCP evidence, then query explicit SSA relations without interpreting reconstructed C. Preserve unknown flow, cloned block identity and dependency frontiers.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:46 +00:00
d711c55aed experiment(re): distinguish point facts from object selectors
Apply the interior-reference counterexample to the facade: label exact-address scope and emit location endpoints while preserving caller selectors separately. Carry canonical target-content provenance through experimental MCP replies and verify it on the real client. Keep original measurements pinned to the v1 response shape. Nine experiment checks and real Kuna lifecycle/context checks pass.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:46 +00:00
72b24433ea experiment(re): record native sharing and composition counterexamples
Measure twelve equivalent MCP navigation workflows, native reference plans on SQLite/zlib, a compiled interior-reference oracle and a failed exact code-mapping composition. Preserve failed attempts and measurement limits, including unavailable live-agent effectiveness evidence. Add bounded native probes and deterministic mapping tests. All 191 Kuna cases pass serially; nine experiment tests and one-checker typecheck pass.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:46 +00:00
2e19ece025 experiment(kuna): preserve typed reference facts at their owner
Expose source-owned reference kind, endpoints, function identities and instruction text for experiments. Keep the existing address-only public result and retained-cache shape; materialize richer facts only when explicitly requested. Record prior art, composition rules and the distinction between fact, transport and compute units. Verified 18 producer boundary cases and an independently checked native interior-reference example.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:46 +00:00
27f981352d experiment(re): compare fact granularity through real MCP
Add a non-shipping MCP facade over the existing admitted analysis port, real-provider comparison runner and offline token accounting. Keep the full catalog, source Evidence and per-input failures. Separate verification runs from equivalent-work timings. Kuna zlib comparisons pass; broader comparisons remain in progress.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:45 +00:00
0d99e8c5c5 experiment(re): define composable facts and context boundaries
Start a non-integrating experiment around fact identity, per-input outcomes, paging and shared primitive composition. Include deterministic boundary checks; real-provider comparisons remain in progress.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-16 02:59:45 +00:00
240 changed files with 39360 additions and 152 deletions

No files matched your search

+119 -12
View File
@@ -4,6 +4,7 @@ import argparse
import hashlib
import json
import os
import re
from pathlib import Path
import shutil
import signal
@@ -22,7 +23,31 @@ def file_digest(path):
return digest.hexdigest()
def runtime_fingerprint(root):
def pinned_experimental_engine(settings):
expected = settings.get('REA_ATOMIC_NATIVE_IR_ENGINE_SHA256')
if expected is None:
return None
if not re.fullmatch(r'[0-9a-f]{64}', expected):
raise ValueError('Experimental native engine pin must be a SHA-256')
path = Path(settings.get('REA_KUNA_COMMAND', ''))
if not path.is_absolute() or not path.is_file() or not os.access(path, os.X_OK):
raise ValueError('Pinned experimental engine requires an absolute executable file')
actual = file_digest(path)
if actual != expected:
raise ValueError('Experimental engine digest differs from its pin; use a preserved build artifact')
return {'path': str(path), 'sha256': actual}
def experimental_engine_unchanged(receipt):
if receipt is None:
return None
try:
return file_digest(Path(receipt['path'])) == receipt['sha256']
except OSError:
return False
def runtime_fingerprint(root, entrypoint=None):
files = []
for name in ['dist', 'bridge']:
for path in sorted((root / name).rglob('*')):
@@ -30,6 +55,18 @@ def runtime_fingerprint(root):
raise ValueError('Runtime fingerprint does not follow symlinks')
if path.is_file():
files.append({'path': path.relative_to(root).as_posix(), 'sha256': file_digest(path)})
if entrypoint is not None:
# Include the experimental modules and their installed QuickJS JS/WASM,
# plus the shared fact owner; the entrypoint alone does not pin them.
for directory in [entrypoint.parent, root / 'experiments/atomic-re-tools']:
for path in sorted(directory.rglob('*')):
if path.suffix not in {'.mjs', '.cjs', '.js', '.wasm'} and path.name not in {'package.json', 'package-lock.json'}:
continue
if path.is_symlink():
raise ValueError('Experimental runtime fingerprint does not follow symlinks')
if path.is_file():
label = path.relative_to(root).as_posix() if path.is_relative_to(root) else path.as_posix()
files.append({'path': label, 'sha256': file_digest(path)})
files.sort(key=lambda row: row['path'])
text = json.dumps(files, separators=(',', ':'), ensure_ascii=False)
return files, hashlib.sha256(text.encode()).hexdigest()
@@ -39,6 +76,12 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--mode', choices=['direct', 'client-code'], default='direct')
parser.add_argument('--runtime-root', type=Path, required=True)
parser.add_argument('--mcp-entrypoint', type=Path,
help='Caller-selected experimental stdio MCP entrypoint; leaves production dispatcher unchanged')
parser.add_argument('--server-name', default='rea')
parser.add_argument('--protocol-profile', choices=['canonical', 'atomic', 'atomic-direct'], default='canonical')
parser.add_argument('--profile-parent', type=Path,
help='Absolute parent outside the repository for the isolated model workspace')
parser.add_argument('--revision', required=True)
parser.add_argument('--prompt', type=Path, required=True)
parser.add_argument('--artifact-path', help='Replace {{artifact_path}} in a question template')
@@ -54,6 +97,10 @@ def main():
help='Retain owned tool/usage items; excludes account/ambient state')
parser.add_argument('--guide-enabled-tools', action='store_true',
help='Opt-in exact-name discovery guidance for selected REA tools')
parser.add_argument('--normalize-mcp-guidance', action='store_true',
help='Opt-in common envelope/stopping guidance, identical across protocol lanes')
parser.add_argument('--guide-long-waits', action='store_true',
help='Opt-in common client wait guidance; does not change analysis contracts or deadlines')
args = parser.parse_args()
if args.guide_enabled_tools and args.enabled_tools is None:
parser.error('--guide-enabled-tools requires --enabled-tools')
@@ -94,13 +141,19 @@ def main():
if undeclared:
raise ValueError('Declare inherited provider settings explicitly in --providers: '
+ ', '.join(undeclared) + '. Values are not logged.')
# Fail before copying credentials or spending model tokens. Cargo test/build
# can replace a mutable target/release path with a different feature build.
experimental_engine = pinned_experimental_engine(provider_env)
source_auth_home = (Path(os.environ['CODEX_HOME']) if 'CODEX_HOME' in os.environ
else Path.home() / '.codex')
source_auth = source_auth_home / 'auth.json'
args.output.mkdir(parents=True, exist_ok=False, mode=0o700)
runtime_files, runtime_digest = runtime_fingerprint(repository)
runtime_files, runtime_digest = runtime_fingerprint(repository, args.mcp_entrypoint)
(args.output / 'runtime-files.json').write_text(json.dumps(runtime_files))
profile = Path(tempfile.mkdtemp(prefix='profile-', dir=args.output))
if args.profile_parent and (not args.profile_parent.is_absolute()
or args.profile_parent.resolve().is_relative_to(repository.resolve())):
raise ValueError('profile-parent must be an absolute directory outside runtime-root')
profile = Path(tempfile.mkdtemp(prefix='rea-model-profile-', dir=args.profile_parent or args.output))
trial_codex_home = profile / 'codex'
account = profile / 'account'
workspace = profile / 'workspace'
@@ -119,7 +172,12 @@ def main():
'NODE_OPTIONS': '--max-old-space-size=512',
})
target_digest = file_digest(Path(args.artifact_path)) if args.artifact_path else None
command_args = [str(repository / 'scripts/rea.mjs'), 'mcp']
if not args.server_name.replace('-', '').replace('_', '').isalnum():
raise ValueError('server-name must contain only letters, digits, hyphens or underscores')
if args.mcp_entrypoint and not args.mcp_entrypoint.is_absolute():
raise ValueError('mcp-entrypoint must be absolute')
command_args = ([str(args.mcp_entrypoint)] if args.mcp_entrypoint
else [str(repository / 'scripts/rea.mjs'), 'mcp'])
instruction = (
'Use the registered REA MCP server for this investigation. Static analysis '
'only: do not execute target code, fetch URLs, launch a GUI, or modify targets. '
@@ -132,6 +190,23 @@ def main():
'Prefer summary/focused views where appropriate. Do not invent successful facts '
'after a tool error. No other agents. Stop once the requested facts are supported.'
)
if args.protocol_profile in {'atomic', 'atomic-direct'}:
instruction = (
'Use the registered ' + args.server_name + ' MCP server for this static binary investigation. '
'Call reference to inspect API contracts, then compose the supported analysis calls. '
'Do not execute target code, fetch URLs, launch a GUI, modify targets, use shell/file tools, '
'or use other agents. API methods return {ok,context,data} or {ok:false,error}; '
'execute_javascript returns the script value, with script-derived authority. '
'Preserve real evidence_id values, artifact digest, uncertainty and traversal boundaries. '
'Check failures before reading data. Do not infer absence from partial coverage. '
'Do not return complete inventories or source reports when a focused answer suffices. '
'Close the binary when finished. No precomputed answer is available to you.'
)
if args.protocol_profile == 'atomic-direct':
instruction = instruction.replace(
'execute_javascript returns the script value, with script-derived authority. ',
'Call the registered facts_* tools directly; no JavaScript execution tool is registered. '
)
if args.authority == 'browser':
instruction = (
'Use the registered REA tools for the explicitly selected public browser scenario. '
@@ -147,14 +222,31 @@ def main():
'possible and select the requested normalized_result fields before returning '
'intermediate output to model context. Keep real Evidence IDs and limitations.'
)
if args.normalize_mcp_guidance:
instruction += (
' MCP calls return transport envelopes: prefer structuredContent when present; '
'otherwise parse the text content JSON. Do not print both duplicate encodings. '
'Apply the same rule to every tool. Stop once the requested facts are supported, '
'state missing coverage explicitly, and close the binary when finished.'
)
if args.guide_enabled_tools:
instruction += (
' Configured REA tool function names for this trial: '
+ json.dumps(['mcp__rea__' + name for name in enabled_tools])
+ '. For discovery select only these exact names from ALL_TOOLS and '
'return only their metadata. Preserve the original analyst question, '
' Configured REA server label: ' + json.dumps(args.server_name)
+ '. Enabled tool base names for this trial: ' + json.dumps(enabled_tools)
+ '. Discover their actual registered callable names from ALL_TOOLS metadata; '
'do not construct a namespace from the server label. Select only matching '
'enabled base names and return only their metadata. Preserve the original analyst question, '
'dependency order and source Evidence.'
)
if args.guide_long_waits:
instruction += (
' When the client executor reports a running cell during a long analysis, '
'resume that same cell with wait and yield_time_ms:30000, within the '
'advertised tool schema, rather than repeated one-second polls. '
'The wait may return early when the result is ready. Do not sleep or '
'start duplicate analysis calls just to check completion. Keep the '
'original analysis dependencies, evidence and stopping requirements.'
)
quote = json.dumps
config = '\n'.join([
'approval_policy = "never"', 'sandbox_mode = "read-only"',
@@ -166,16 +258,16 @@ def main():
'code_mode = ' + ('true' if args.mode == 'client-code' else 'false'),
'code_mode_only = ' + ('true' if args.mode == 'client-code' else 'false'),
'[history]', 'persistence = "none"',
'[mcp_servers.rea]', 'command = ' + quote(node),
'[mcp_servers.' + args.server_name + ']', 'command = ' + quote(node),
'args = ' + quote(command_args), 'startup_timeout_sec = 60',
'tool_timeout_sec = 600',
*([] if enabled_tools is None else ['enabled_tools = ' + quote(enabled_tools)]),
'[mcp_servers.rea.env]',
'[mcp_servers.' + args.server_name + '.env]',
*[key + ' = ' + quote(value) for key, value in provider_env.items()],
]) + '\n'
# MCP read-only hints cover normal static tools. Explicitly authorize only
# the session-opening primitive needed by the requested native tasks.
config += '[mcp_servers.rea.tools.open_binary]\napproval_mode = "approve"\n'
config += '[mcp_servers.' + args.server_name + '.tools.open_binary]\napproval_mode = "approve"\n'
for tool in ['analyze_javascript_application', 'inspect_analysis_view',
'inspect_android_package', 'search_android_classes',
'inspect_android_class', 'inspect_android_method',
@@ -189,7 +281,7 @@ def main():
'inspect_evm_interface', 'get_evidence_bundle', 'export_evidence_bundle',
'capture_browser_scenario',
'resolve_containing_procedure', 'analyze_function', 'close_binary']:
config += '[mcp_servers.rea.tools.' + tool + ']\napproval_mode = "approve"\n'
config += '[mcp_servers.' + args.server_name + '.tools.' + tool + ']\napproval_mode = "approve"\n'
try:
if source_auth.exists():
shutil.copyfile(source_auth, auth)
@@ -209,10 +301,17 @@ def main():
'mode': args.mode, 'model': args.model, 'reasoning': args.reasoning,
'capture_tool_context': args.capture_tool_context,
'guide_enabled_tools': args.guide_enabled_tools,
'normalize_mcp_guidance': args.normalize_mcp_guidance,
'guide_long_waits': args.guide_long_waits,
'driver_commit': subprocess.check_output(
['git', 'rev-parse', 'HEAD'], cwd=driver_repository, text=True).strip(),
'runtime_revision': args.revision,
'runtime_root': str(repository),
'mcp_server_name': args.server_name,
'protocol_profile': args.protocol_profile,
'isolated_profile_parent': str(args.profile_parent) if args.profile_parent else str(args.output),
'mcp_entrypoint': str(args.mcp_entrypoint) if args.mcp_entrypoint else None,
'mcp_entrypoint_sha256': file_digest(args.mcp_entrypoint) if args.mcp_entrypoint else None,
'selected_artifact_path': args.artifact_path,
'selected_artifact_sha256_before': target_digest,
'enabled_tools': enabled_tools,
@@ -230,6 +329,7 @@ def main():
'question_template_sha256': template_digest,
'provider_settings_sha256': hashlib.sha256(
json.dumps(provider_env, sort_keys=True).encode()).hexdigest(),
'experimental_engine': experimental_engine,
'provider_search_path_sha256': hashlib.sha256(
provider_env.get('PATH', os.environ.get('PATH', '')).encode()).hexdigest(),
'provider_environment_policy_sha256': hashlib.sha256(
@@ -282,6 +382,9 @@ def main():
summary = {
'mode': args.mode, 'requested_model': args.model, 'reasoning': args.reasoning,
'runtime_revision': args.revision,
'runtime_inputs_unchanged': runtime_fingerprint(repository, args.mcp_entrypoint)[1] == runtime_digest,
'experimental_engine': experimental_engine,
'experimental_engine_unchanged': experimental_engine_unchanged(experimental_engine),
'capture_tool_context_requested': args.capture_tool_context,
'selected_artifact_sha256_before': target_digest,
'selected_artifact_sha256_after': final_target_digest,
@@ -296,6 +399,10 @@ def main():
}
(args.output / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
print(json.dumps(summary))
if not summary['runtime_inputs_unchanged']:
raise RuntimeError('Runtime inputs changed during the trial; retain costs but reject the comparison')
if summary['experimental_engine_unchanged'] is False:
raise RuntimeError('Experimental engine changed during the trial; retain costs but reject the comparison')
finally:
try:
if args.capture_tool_context:
@@ -68,10 +68,15 @@ def stop_owned_scope(unit, process, group):
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--task-ceiling', type=int, default=192)
parser.add_argument('--early-stop-mib', type=int, default=3072,
help='Memory pre-stop threshold; hard cap remains 4 GiB (default 3072 MiB)')
parser.add_argument('--observe-payload-exit', action='store_true',
help='Observe payload-exit counters before the cgroup observer exits')
parser.add_argument('command', nargs=argparse.REMAINDER)
options = parser.parse_args()
if not 1 <= options.early_stop_mib <= 3584:
parser.error('--early-stop-mib must leave at least 512 MiB below the 4 GiB hard cap')
early_stop_bytes = options.early_stop_mib * 1024 * 1024
if options.task_ceiling <= 0:
parser.error('--task-ceiling must be positive')
if options.observe_payload_exit and options.task_ceiling < 2:
@@ -95,7 +100,7 @@ def main():
]
command = [
'systemd-run', '--user', '--scope', '--unit=' + unit,
'-p', 'MemoryMax=4G', '-p', 'MemoryHigh=3G', '-p', 'MemorySwapMax=0',
'-p', 'MemoryMax=4G', '-p', f'MemoryHigh={early_stop_bytes}', '-p', 'MemorySwapMax=0',
'-p', 'CPUQuota=100%', '-p', 'TasksMax=' + str(options.task_ceiling),
'taskset', '-c', str(cpu), *payload,
]
@@ -158,7 +163,7 @@ def main():
except FileNotFoundError:
# A completed transient scope can disappear between reads.
pass
if peak > 3 * gib:
if peak > early_stop_bytes:
abort = 'scope_memory_early_stop'
elif available_bytes() < 4 * gib:
abort = 'host_available_memory_early_stop'
@@ -184,7 +189,7 @@ def main():
'resource_scope': unit, 'peak_cgroup_bytes_sampled': peak,
'elapsed_seconds': round(time.monotonic() - started, 3),
'abort': abort, 'hard_memory_bytes': 4 * gib,
'early_stop_bytes': 3 * gib, 'cpu_quota_percent': 100,
'early_stop_bytes': early_stop_bytes, 'cpu_quota_percent': 100,
'cpu_affinity': [cpu],
'task_ceiling': options.task_ceiling, 'peak_tasks_sampled': peak_tasks,
'resource_events_last_observed': events,
@@ -0,0 +1,88 @@
// Generate a complete declared-native baseline; do not infer tools from ordering.
import assert from "node:assert/strict";
import { readFile, writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { KUNA_OPERATIONS } from "../../dist/kuna/KunaProviderCapabilities.js";
import {
createVerifierRun,
completeVerifierRun,
assertVerifierCleanupComplete,
} from "../../scripts/lib/verifier-run.mjs";
const [output] = process.argv.slice(2);
assert.ok(output, "Usage: node select-kuna-tools.mjs NEW_OUTPUT_JSON");
assert.equal(process.versions.node, (await readFile(".nvmrc", "utf8")).trim());
const desired = new Set([
...KUNA_OPERATIONS,
"open_binary",
"close_binary",
"inspect_analysis_view",
]);
const run = createVerifierRun(),
failures = [];
const client = new Client({
name: "rea-kuna-baseline-catalog",
version: "0.1.0",
});
const transport = new StdioClientTransport({
command: process.execPath,
args: [resolve("scripts/rea.mjs"), "mcp"],
env: {
...process.env,
// This pass needs tool identities, not large result schemas. Keep any
// explicit caller profile; the measured runner already selects off.
REA_MCP_OUTPUT_SCHEMA_PROFILE:
process.env.REA_MCP_OUTPUT_SCHEMA_PROFILE ?? "off",
},
stderr: "pipe",
});
let names;
try {
await client.connect(transport);
names = [];
const cursors = new Set();
let cursor;
do {
assert.ok(!cursors.has(cursor), "Catalog pagination did not advance");
cursors.add(cursor);
const page = await client.listTools(cursor === undefined ? {} : { cursor });
names.push(
...page.tools
.filter((tool) => desired.has(tool.name))
.map((tool) => tool.name),
);
cursor = page.nextCursor;
} while (cursor !== undefined);
assert.equal(
new Set(names).size,
names.length,
"Ambiguous duplicate catalog names",
);
assert.deepEqual(
[...desired].filter((name) => !names.includes(name)),
[],
"Declared native operation lacks a named MCP tool",
);
} catch (error) {
failures.push(error.stack ?? String(error));
} finally {
await client.close();
await transport.close();
}
const lifecycle = await completeVerifierRun(run);
assertVerifierCleanupComplete(lifecycle.process_lineage);
assert.deepEqual(failures, []);
// Caller-selected artifact only; never replace an existing configuration/record.
await writeFile(output, JSON.stringify(names, null, 2) + "\n", { flag: "wx" });
console.log(
JSON.stringify({
provider: "kuna",
selection: "complete declared native operations plus session/views",
names,
lifecycle,
scope:
"Actual registered catalog matched by name to the compiled provider capability owner. No target opened; declared coverage does not prove live provider availability.",
}),
);
@@ -0,0 +1,46 @@
import hashlib
import importlib.util
from pathlib import Path
import tempfile
import unittest
spec = importlib.util.spec_from_file_location('agent_trial', Path(__file__).with_name('agent-trial.py'))
trial = importlib.util.module_from_spec(spec)
spec.loader.exec_module(trial)
class ExperimentalEnginePinTests(unittest.TestCase):
def test_missing_pin_preserves_other_provider_trials(self):
self.assertIsNone(trial.pinned_experimental_engine({}))
self.assertIsNone(trial.experimental_engine_unchanged(None))
def test_feature_build_replacement_and_removal_invalidate_pinned_engine(self):
with tempfile.TemporaryDirectory() as directory:
engine = Path(directory) / 'kuna'
engine.write_bytes(b'embedded-spec-build')
engine.chmod(0o755)
settings = {'REA_KUNA_COMMAND': str(engine),
'REA_ATOMIC_NATIVE_IR_ENGINE_SHA256': hashlib.sha256(engine.read_bytes()).hexdigest()}
receipt = trial.pinned_experimental_engine(settings)
self.assertTrue(trial.experimental_engine_unchanged(receipt))
engine.write_bytes(b'non-embedded-test-build')
with self.assertRaisesRegex(ValueError, 'differs from its pin'):
trial.pinned_experimental_engine(settings)
self.assertFalse(trial.experimental_engine_unchanged(receipt))
engine.unlink()
self.assertFalse(trial.experimental_engine_unchanged(receipt))
with self.assertRaisesRegex(ValueError, 'absolute executable'):
trial.pinned_experimental_engine(settings)
def test_malformed_pin_and_relative_command_are_rejected(self):
for settings in [
{'REA_ATOMIC_NATIVE_IR_ENGINE_SHA256': 'bad'},
{'REA_ATOMIC_NATIVE_IR_ENGINE_SHA256': '0' * 64, 'REA_KUNA_COMMAND': './kuna'},
]:
with self.assertRaises(ValueError):
trial.pinned_experimental_engine(settings)
if __name__ == '__main__':
unittest.main()
@@ -29,13 +29,16 @@ class PayloadObservationTests(unittest.TestCase):
spec = importlib.util.spec_from_file_location('resource_run', Path(__file__).with_name('resource-run.py'))
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
arguments = ['resource-run.py', '--observe-payload-exit', '--task-ceiling', '1', '--', 'payload']
with patch.object(sys, 'argv', arguments), patch.object(sys, 'stderr', io.StringIO()), \
patch.object(module.subprocess, 'Popen') as spawn:
with self.assertRaises(SystemExit) as failure:
module.main()
self.assertEqual(failure.exception.code, 2)
spawn.assert_not_called()
for flags in [['--observe-payload-exit', '--task-ceiling', '1'],
['--early-stop-mib', '0'], ['--early-stop-mib', '3585']]:
with self.subTest(flags=flags), \
patch.object(sys, 'argv', ['resource-run.py', *flags, '--', 'payload']), \
patch.object(sys, 'stderr', io.StringIO()), \
patch.object(module.subprocess, 'Popen') as spawn:
with self.assertRaises(SystemExit) as failure:
module.main()
self.assertEqual(failure.exception.code, 2)
spawn.assert_not_called()
def test_preserves_nonzero_status_kernel_peak_and_nonzero_events(self):
with tempfile.TemporaryDirectory() as directory:
+451
View File
@@ -0,0 +1,451 @@
# Atomic RE through Code Mode
This is an **in-progress experiment**, not an integrated provider release. Branch
`experiment/atomic-codemode-20261016` starts at main
`42fc6c53ae188978deb3bedfe88287b6b316ba22` and carries the previous atomic-facts
prototype. Historical measurements in `../atomic-re-tools/` retain their original
baselines. No PR or merge is intended.
The branch was subsequently [refreshed from main `60bf10245`](main-refresh-study.md).
Shared installation/file cleanup and string parsing now follow that main's
owners. Historical model measurements retain their original frozen runtimes;
the refresh has separate real-provider verification and resource receipts.
The goal is a real model completing reverse-engineering questions through
composable facts, with Code Mode as the calling adapter. A configured feature flag,
a scripted verifier or a small response does not prove that goal.
The [capability map](capability-map.md) distinguishes verified task coverage,
experimental exporter requirements and remaining unknowns before interpreting
adapter comparisons.
The [string-span study](string-span-study.md) adds paged incoming occurrence
queries for encoded object spans and independently verifies pooled suffix
references on real SQLite. The same native sparse range index serves Kuna's
existing string aggregates. Equivalent cold occurrence retrieval falls from
48.1 to 1.8 seconds; this is shared analysis reuse, not a Code Mode result.
The subsequent frozen real-model runs all answer the selected task correctly:
traditional takes 315.6 seconds, Direct 102.3 and Code Mode 93.6. Code Mode uses
less cumulative input but more uncached input and peak memory than Direct.
Traditional's full inventory is truncated by the client; one original cited
payload remains only partially auditable. The study preserves that limitation.
The [string-fact precision study](string-facts-study.md) preserves native NUL
termination as true/false/unknown through the shared domain and public output
contract. Real canonical MCP, SDK, Direct, Code Mode and CLI checks retain both
NUL-terminated strings and a nonterminated printable run without length-based
agent inference. The old coarse descriptor remains compatible.
Both fresh real models complete the same frozen task after this repair: Direct
takes 95.2 seconds, Code Mode 90.9. Code Mode lowers cumulative input and peak
memory but increases uncached input and CPU. The results do not isolate the
metadata change's performance effect; all source and usage checks are recorded.
The [large-result study](large-result-study.md) verifies that paging alone does
not bound a large field. String metadata can now be selected without text, while
SDK full reads remain available. Shared pre-allocation JSON checks preserve
context and Evidence on transport refusal, including in-program Code Mode
recovery. The synthetic fixture tests capacity; it does not establish real-app
analysis quality. Real SQLite/SSH regressions are reported separately.
The subsequent real Code Mode model passes the frozen capacity task. Direct
retrieves correct data but labels two 17-byte prefixes as 16, failing the exact
reporting criterion. Both use metadata selection without sending full blobs.
Code Mode uses less input but more wall time; the differing correctness and byte
window choices prevent a matched-quality efficiency ranking. All runs remain.
The [streamed inventory study](streamed-inventory-study.md) then restores real
FFmpeg queries whose complete native source exceeds 8 MiB, using the production
streaming parser and bounded retained files. Real SDK/MCP lanes pass; LLVM and
Node still exceed the existing 64 MiB budget. Those failures remain explicit.
Both real models now complete the FFmpeg task with all cited raw captures
verified. Code Mode uses less cumulative input but more uncached input and time.
The study also retains two evaluator namespace failures and their full costs;
the corrected pair uses actual registered tool discovery.
The [refusal-cache study](capacity-refusal-study.md) then avoids repeated native
work for proven immutable source-budget failures. Real SDK and both MCP adapters
verify reuse and readable partial Evidence; cancellation/cleanup uncertainty
remain uncached. The first Code Mode precondition failure and its cost remain in
the record. Larger-target inventory coverage is still unresolved.
The later [native query study](native-string-query-study.md) makes selected LLVM
and Node string queries answerable without retaining a whole oversized inventory.
Both frozen LLVM model answers pass; Code Mode uses fewer input tokens in that
pair, with only a modest wall-time difference. The [shared byte checkpoint](byte-batch-study.md)
then batches missing byte windows through one native program while retaining
per-window facts and Evidence. A same-engine SDK toggle reduces ten-window cold
retrieval from about 94.3 to 8.5 seconds. Real provider preflight passes; new model
trials for this byte change were not run because the user cleared the goal.
The [AArch64 reference study](aarch64-xref-study.md) finds and fixes missing
ADRP-based string and memory references before the next model comparison.
Real SDK and traditional MCP preflights now agree with independent machine
evidence; the shared bounded producer preserves space/width and uncertainty.
All three real models now complete the behavior-level task. Code Mode takes
151.3 seconds / 388,365 cumulative input tokens, Direct 164.9 / 515,929 and
traditional 345.7 / 681,613. Code has more uncached input than traditional and
more memory than Direct. These are the earlier pinned measurements.
The [return-coverage study](aarch64-return-study.md) subsequently fixes two
independent producer defects: BTI import-entry identity and false no-return
promotion that erased the post-warning path. All three fresh model answers pass
the same selected task. Direct uses 351,157 cumulative input tokens / 139.0
seconds, Code Mode 371,571 / 166.8, and traditional 662,683 / 263.1. Code Mode
reduces MCP requests but adds model responses in this sample; correct primitives
and fewer RPCs do not establish a stable adapter advantage.
The [architecture storage study](storage-study.md) adds exact native register-name
and address-space queries, sharing one bounded immutable capture per lease.
It separates coordinates, widths and native map misses from hardware absence,
SSA equality or alias claims. Both real SSH models complete the extended task;
Code Mode uses 307,888 versus 415,450 cumulative input tokens and 142.2 versus
158.1 seconds, but more local CPU. This single pair does not establish a stable
advantage; the full typecheck gate remains resource-limited.
The [function-boundary study](function-boundary-study.md) adds independent native
prototype entries and return descriptors, separated from raw input varnodes.
Both real SSH models correctly distinguish these inventories and compose the
selected caller/parameter/helper transfer. Direct uses 331,674 cumulative input
tokens / 118.4 seconds; Code Mode uses 359,789 / 125.7, with lower uncached input
but mixed overall costs. Native and real-provider checks are recorded there.
The [path-query study](path-query-study.md) adds a shared, bounded recovered-CFG
witness query with exclusions and paging. Both actual MCP adapters verify the
same four real SQLite witnesses without requiring the model to fetch the entire
graph. This establishes graph-relative facts; predicate feasibility stays unknown.
Both real models now use the query and answer correctly on the same frozen
controller task: direct takes 200.8 seconds / 495,895 cumulative input tokens;
Code Mode takes 203.3 seconds / 554,477. Code Mode has lower uncached input,
but no stable overall advantage is established. All prior pairs stay reported.
The [control-query study](control-query-study.md) verifies every derived control
triple on the real SQLite VM, fixes unknown CFG seeds and reuses a lazy
postdominator index. Its [two-level investigation](controller-oracle.md) is
frozen before model runs and separates alternative path predicates, SSA identity
and finite recovered-edge witnesses from runtime claims. Both real-model answers
now pass: Code Mode reduces cumulative input but increases uncached input, time,
CPU and memory in this pair. Correct facts support both calling strategies;
the query-cache improvement is separate from those mixed whole-task costs.
The [discovery-summary study](discovery-summary-study.md) addresses repeated
metadata from that pair. The complete method index now uses owned intent
summaries; all full contracts and advertised tools remain available. Contracts
and session admission have separate owners, with native loading deferred to open.
Its repeat uses the same frozen control question and retains the earlier results.
That completed repeat again answers correctly in both lanes. The smaller index
does not establish an overall task improvement: actual help use adds a Code Mode
call, and cumulative/uncached tokens, local resources and end-to-end time have
mixed changes. A large observed inter-call gap remains charged and unexplained.
The [exact-value query study](value-query-study.md) adds location-to-value and
value-to-operand-use queries, including inputs/constants without defining operations.
Real stripped OpenSSH checks preserve all 250 SSA versions / 369 occurrences at
one selected policy location while reducing an equivalent core read task from
244 queries to six. A subsequent [real-agent OpenSSH comparison](ssh-warning-study.md)
completes the same machine-supported task through all three interfaces, after
correcting an incomplete traditional evaluator toolset. Atomic direct has the
lowest measured costs in this sample, using machine facts without decompilation;
Code Mode uses the new queries but takes extra analysis steps. General efficiency
claims still require broader evidence.
The reference is [Hex-Rays IDA MCP](https://github.com/HexRaysSA/ida-mcp/blob/df6de7985b534a964c125d5a86e41b26b17b14f6/ida_mcp/mcp.py):
an on-demand `reference` lookup and an execution entrypoint over a richer analysis
API. This experiment uses JavaScript and a QuickJS WASM environment rather than
Python in the host process. It exposes only declared static analysis capabilities.
It does not add target execution, patching or GUI control.
Three boundaries own the implementation:
- `provider.mjs`, `native-ir.mjs`: existing REA native target/process owners and parsed Kuna
string/reference/SSA facts, retained sources, freshness and cleanup.
- `api.mjs`: named, validated fact/relationship contracts and their intent summaries.
`session.mjs` owns shared admission and lease/file cleanup, loading the native
provider only on open. SDK callers, CLI scripts and both MCP adapters use these
same contracts and application owner.
- `executor.mjs`, `server.mjs`, `cli.mjs`: bounded JavaScript composition and
presentation. No analysis is reimplemented in the execution environment.
The complete Code Mode MCP catalog is `open_binary`, `reference`,
`execute_javascript`, `close_binary`. Setting `REA_ATOMIC_ADAPTER=direct` exposes
the same fact API as `facts_*` MCP operations for comparison. This is a distinct
experimental server; the production REA catalog is not filtered or replaced.
Use the pinned Node, an existing REA build and a caller-supplied Kuna 1.833:
```sh
npm ci --prefix experiments/atomic-codemode --ignore-scripts
node --test experiments/atomic-codemode/*.test.mjs
REA_KUNA_COMMAND=/absolute/path/to/kuna node experiments/atomic-codemode/server.mjs
```
The local MCP registration for real model trials is named `rea-codemode`.
`agent-trial.py --mcp-entrypoint /absolute/path/to/server.mjs
--server-name rea-codemode --protocol-profile atomic --profile-parent /tmp` creates an isolated
configuration, home and empty working directory for the model. Shell/file tools,
web search and delegation are disabled. No repository or oracle is placed in that
workspace. The copied authentication file is removed with the isolated profile.
Model output, actual MCP calls, original errors and usage remain in the trial
directory. `REA_ATOMIC_TRACE` and `REA_ATOMIC_EVIDENCE_DIR` retain actual API calls
and complete sources outside the model workspace when explicitly selected by the
evaluator. The ambient environment and credentials are not logged.
Current bounds: 64 MiB guest heap, 32 KiB code and script value/error payloads, 64 host calls per execution,
120 seconds wall deadline and 2 seconds of guest synchronous execution. Native
requests use existing supervision and a 1 GiB function-memory limit. Buffered
formats and diagnostics keep an 8 MiB bound; string inventories stream through
the production reader into the existing 64 MiB per-target source budget, without
an aggregate stdout string. Two resident function indexes each derive from at
most 2 MiB diagnostic or 8 MiB native wire source. Compressed native graphs admit at most 32 MiB decoded
JSON plus independent row/text/relationship bounds. One decoded Evidence text view
up to 32 MiB is also retained per lease; these source bounds are not parsed-heap
size guarantees. Sources are
content-digested and retained until close; explicit evaluator copies survive
close. Capacity failures are explicit, not clipped facts. Leases and snapshot
handles prevent cross-session joins.
The current experimental MCP profile also caps encoded tool-result bodies at
1 MiB, including text escaping and metadata; JSON-RPC/client framing is separate.
`reference.transport_limits` advertises this policy in both modes. The QuickJS
bridge remains 2 MiB. CLI/SDK transports have their own bounds; SDK full selected
string values remain available. Prefer `strings({query,fields:[]})` for metadata.
Invocation context and observed source IDs are additional bounded receipt
metadata; the script payload bound is not a 32 KiB whole-MCP-wire limit. A real
MCP probe found that a 40,000-byte guest exception bypassed that payload policy
and produced a 40,183-byte response. Oversized errors now return explicit
`output_budget` with omission metadata. Escaping expansion is checked too;
ordinary smaller errors remain intact. `verify-executor.mjs` confirms real MCP
delivery and continued access to source Evidence collected before the exception.
It measures response bytes, not model tokens or an analysis speedup. Targeted JS
tests at this stage totaled 42, alongside the separate real-provider and native-writer checks.
The diagnostic SSA format still has incomplete CFG and phi predecessor coverage.
The opt-in [native recovered IR experiment](native-engine.md) adds full recovered
CFG edges, exact value/operand identities, phi incoming-edge bindings, selected
`values`/`blocks` reads and derived control dependence. It requires an explicitly
pinned patched engine; stock Kuna does not gain those capabilities from a wrapper.
Runtime successors, memory aliases and machine-semantic equivalence remain
unknown. Other providers are not yet wired to this experimental service.
The initial [actual model comparison](trials.md) favors the focused traditional
workflow. The seeded value-origin task has lower cumulative input and wall time
through Code Mode, but initially exposes an IR-to-machine-path error. The revised
trial correctly explains that machine path with lower observed task costs;
broader claims still require more than this single seeded task.
The large SQLite VM diagnostic task also completes when its native graph exceeds
capacity. Atomic direct beats Code Mode on cumulative input and wall time in
that sample, and a traditional reused-project run is fastest. The actual CLI
client already exposes JavaScript dispatch in every lane, regardless of requested
feature flags. MCP request counts therefore do not establish fewer model rounds;
the ledger now records actual model responses and client dispatch/wait calls.
`instructions` reads selected machine byte/decode windows through the same
owner. Recovered operations use `origin_address` and blocks `origin_start`;
these locations cannot be substituted for machine branch destinations. The
value-origin trial demonstrates why this boundary matters. The experiment
now has nineteen fact methods, still behind the same four-tool Code Mode
catalog.
`calls` connects recovered call operations to native target specifications and
separates argument SSA values from passing storage. `values(is_input:true)`
selects retained callee inputs for exact storage comparisons. These candidate
links preserve snapshot identities, missing specifications, unknown storage and
runtime-binding limits. The [cross-function task and oracle](call-oracle.md)
are fixed before its real-model trials; the graph wire format is version 3, with independent version-1 call facts.
`references` now selects incoming exact-address references or outgoing
instruction/function references, with native kind filtering, field selection and
paging. Source Evidence plus `source_row` identifies an occurrence. Function
applicability, excluded/unattributed rows, indirect targets and discovery stay
explicit. `fields:[]` requests only the always-retained identity columns across
projection contracts. The [reference question and independent oracle](reference-oracle.md)
cover real SQLite VM aggregates and a machine call omitted from optimized IR.
`bytes` reads explicit virtual-address ranges as native loaded-image hex without
decoding them as instructions. Batched reads preserve short reads and individual
failures, with 64 KiB aggregate selected-byte capacity to bound hex/bridge growth.
Complete hexdumps remain in Evidence. The original-file-offset mapping and live
runtime memory remain unknown. This closes a direct byte-reading contract gap
for data tables; it does not establish arbitrary memory-alias analysis.
`functions` provides selected name/alias/entry reads. Native snapshots report
code and recovered-IR facets separately, preserving readable code when graph
extraction is unavailable. Real capacity and cold/warm MCP checks are documented
in [native-engine.md](native-engine.md). Whole-model costs and unequal-depth
comparisons remain separate in the trial report.
The corrected SQLite comparison reaches the formatter implementation in all
three interfaces. Code Mode uses fewer calls than atomic direct in that sample;
a traditional run reusing its persistent whole-project cache is faster than
Code Mode's fresh lease. Cache state, completed-answer coverage and actual
uncached tokens must therefore accompany any cost comparison.
SDK views share immutable parsed inventories with their owner. A real SDK probe
initially changed a returned string and made the next query disappear under the
same Evidence ID. Freezing at the cache boundary fixes that producing rule,
without copying or parsing the entire inventory for each read. `verify-sdk.mjs`
checks the real provider's string/metadata/function views and complete retained
source digest. The fixed probe passes under the bounded runner (1.328 seconds,
1.144 family CPU seconds, 110.6 MiB kernel family peak, zero OOM kills and verified
payload cleanup); it is a correctness check, not a model-cost measurement.
Encoded size is another real coverage boundary: two SQLite functions initially
lose even their C because pretty JSON exceeds transport capacity. The native
patch now uses bounded compact serialization and a graph-only failure when
needed. Parser's full graph fits; Pragma retains identical C with an explicit
missing graph. The 8 MiB bound remains. See the exact sizes, rebuilt engine digest
and verification scope in [native-engine.md](native-engine.md).
Completion requires actual model Code Mode use, independently checked task
answers, shared atomic/direct/Code Mode semantics, needed relation coverage,
failure/cancellation/identity tests, and equivalent completed-task measurements
including discovery/retries, actual model usage, cold/warm analysis, CPU and
process-family peak memory. Negative cases such as the small SQLite function
must remain in the comparison.
The outgoing-reference real-model pair now completes with identical required
facts and explicit coverage limits. In its single sample, Code Mode uses 264,680
cumulative input / 93.837 seconds versus direct's 285,086 / 106.183. The shared
CLI/API also verifies the VM aggregates on unpatched stock Kuna 1.833. These are
scoped positive results alongside the earlier mixed adapter comparisons, not
proof of general superiority. Details and retained failed/partial attempts are
in [trials.md](trials.md).
Recovered calls and their boundary values now survive full-graph capacity
failure. The real VM capture preserves 416 call operations and 1,294 boundary
values while its graph remains unavailable. Values clearly state their partial
scope; definition IDs do not imply readable defining operations. See the
[boundary question and oracle](boundary-oracle.md) and its completed real-model
pair in [trials.md](trials.md). Both answers pass, using one VM capture each.
Code Mode's single-sample latency is lower, with mixed context costs; broader
efficiency remains unproven. The focused JS suite at that stage passes 49 tests.
Available snapshot call facets now include `by_opcode` known/unknown-target
counts and their own coverage. The owner derives them once from the same
validated immutable calls used by selected reads, including dead operations;
target knowledge is independent of opcode. Empty available facets report zeros,
while unavailable facets omit counts. This small aggregate addresses an observed
cost in the real boundary pair: paging the entire call set just to count it.
Both subsequent real-model answers satisfy the unchanged question/oracle without
that paging. In the new sample direct is faster and lower on cumulative/uncached
input than Code Mode, reversing the preceding latency ordering. Whole-task
effects remain mixed; see [the complete results](trials.md). This aggregate is a
shared fact-layer improvement, available to either adapter.
The shared owner also checks the native cleanup `Result` before releasing its
lease or clearing retained state. A tagged cleanup failure now stays retryable;
MCP errors retain the lease context and reported resources. The real SDK
failure-injection verifier first reproduces the old false success, then verifies
both close and target replacement retain the staged file/owner until a successful
retry. Both public MCP adapters preserve that error and retry successfully.
These use an injected tagged failure, not an observed engine cleanup incident;
native reads and subsequent cleanup use the real provider. See the recorded
scope and resource receipts in [native-engine.md](native-engine.md).
A [subsequent diagnostic probe](projection-experiment.md) measures the VM's full
17 MB recovered graph and much smaller selected definition neighborhoods. It
supports trying a bounded operation/value facet, while preserving unresolved
definitions and unavailable CFG. The following implementation now makes that
facet callable; the original diagnostic remains separate from public results.
`snapshot.facets.operations` distinguishes a complete recovered graph from a
bounded call-rooted definition projection. `operations`, `values`, selected
definition/use `relations` and `slice` share the same parsed operation owner in
either case. Projection coverage preserves unexpanded definition counts and
selected slice frontier reasons; CFG/controller reads remain unavailable.
Native operation reads retain `is_dead` and literal operand/value identities.
Coverage returns compact counts and bounded issue text, with complete native
details retained in Evidence. [The new question/oracle](projection-oracle.md)
are fixed before real-model trials of the PHI format alternatives.
Both first PHI-format model answers pass the full oracle using one VM analysis
and a six-operation selected trace, with the global graph/use limits intact.
The trace reveals two format sources at each shared call, verified against byte
and machine evidence. [Costs and source review](trials.md) also record a direct
documentation-lookup miss; named discovery needs fixing before rerunning the
same task. No general adapter speedup follows from that first pair.
Named reference lookup now accepts canonical IDs or exact displayed names,
including space/comma-separated lists. One presentation map supplies direct
registration and documentation names; unmatched terms remain explicit. Selected
schemas come from named contracts, use input semantics (defaulted fields stay
optional), and are cached immutably by Zod schema identity for the process.
Validation stays in the API registry; documentation has its own module. Both
actual MCP catalogs and all fourteen reference schemas validate. The unchanged
PHI question/oracle were rerun: both answers pass again, but direct has a native
timeout followed by a successful retry. Complete costs and the unknown timeout
cause remain in [trials.md](trials.md); this does not isolate an adapter speedup.
The next observed atom boundary is a wide PHI. One real VM operation has 156
inputs; its old default single-node slice is about 44 KB and exceeds the guest's
32 KiB result budget. Native operation/slice defaults now return opcode, output
and exact input/definition/constant counts. Explicit detailed fields still work.
`relations({kind:"operands",seeds:[id],input_indices:[0,105,155]})` reads selected
slots; omitting the selector pages all slots. Each slot retains value/definition
and phi predecessor/edge identity, including null values and definition-free
constants/inputs. Counts concern recovered facts, not source function arity.
Full and projected native operations use the same owner. Relationship paging
counts existing groups before materializing only the requested page; identity
reads deduplicate requested IDs in caller order. Diagnostic SSA explicitly lacks
native operand relations. The discriminated relation schema advertises the same
seed types and selector applicability enforced at runtime. The fourteen-method
API and both adapters remain shared; no new engine or output-budget increase is
needed. The [seeded wide-operand task/oracle](operands-oracle.md) is separate from
the earlier PHI-format question and is pinned before model trials.
Both actual wide-operand model answers now pass that fixed oracle, including
distinct edges sharing a value and absent-slot versus unretained-seed semantics.
Each performs one native analysis and reads only selected slots, distinct values
and their immediate definitions. Code Mode takes 95.699 seconds versus direct's
91.817, with nearly equal cumulative input and lower uncached input. Its four
discovery lookups prevent fewer MCP requests from becoming fewer model responses.
These [mixed costs](trials.md#selected-wide-phi-input-relationships) validate the
fact boundary while leaving broad efficiency unproven. The current shared JS
suite passes 57 tests; the Python cost-ledger suite passes three.
Discovery now also offers `reference({view:"index"})`: the complete fourteen
method names and descriptions, without schemas or return contracts. Follow with
`view:"contracts"` and exact names for only the needed inputs. The default
contract view and named/topic lookup stay compatible. Both views use the same
registry and presentation map; index access never constructs unrequested schemas.
The index describes declared methods, while `snapshot` remains the live coverage
authority. This addresses observed blind discovery without inventing aliases or
changing analysis facts; its whole-task effect must be measured on the unchanged
wide-operand question.
The identical question now completes correctly through both indexed adapters.
Code Mode uses the intended index plus one named lookup; discovery drops from
four calls to two, without changing the seven fact reads. The new pair takes
about 98.8 seconds each; cumulative input favors direct, uncached input favors
Code Mode. All four wide-operand answers pass, with no retry or OOM. Costs remain
mixed. A selected-slot read still incurs whole-function native decompilation on
a fresh lease; phase profiling is the next computation question, separate from
the now finer fact/query boundary.
The [native phase study](native-compute-study.md) now measures the VM drive at
about 34 seconds, C rendering at 0.22 seconds and projection at 0.03 seconds.
Repeated new native processes do not gain the API owner's warm result reuse.
Its subsequent [bounded codec implementation](native-graph-transport-study.md)
now returns the complete 21,349-operation VM graph in about 3.79 MB, inside the
unchanged 8 MiB wire budget. Selected definitions/CFG reads and decoded Evidence
work through both real MCP adapters; all graph fields and ordinary C/calls match
the prior complete golden. Same-lease reuse is about 67 ms after a 39.7-second
fresh capture, with resource limits and no OOM. The [next question/oracle](savepoint-control-oracle.md)
start from names/error messages and exercise the new condition/CFG coverage.
Two [real-model pairs](savepoint-control-study.md), including a discovery-guided
repeat, answer both local guards correctly without a whole-report fetch. Code
Mode uses fewer MCP requests, but whole-task costs are mixed and a large capture
time variation remains unexplained. Both clients already provide JavaScript
orchestration. Source fidelity is not machine equivalence, provider parity or a
general speedup. The [native switch experiment](switch-study.md) now exports and independently checks
182 labels over those 149 targets, exposes selected case-to-edge relations and
keeps them readable when a 2 MiB native output budget omits the full graph.
Both real models now answer the selected-case/default question correctly using
one retained capture and focused case/byte reads. Code Mode uses fewer tokens
in this pair, but unequal native capture time and extra client polling confound
the comparison. Whole-task costs and limits are in the same study; a general
efficiency advantage remains unproved. A common
[long-wait repeat](client-wait-study.md) reduces polling to one wait per lane;
both answers remain correct, but direct wins cumulative input and wall time
while Code Mode uses less uncached input. Runtime correctness, discovery,
composition choices and waiting all matter to the completed task.
@@ -0,0 +1,251 @@
# AArch64 import entries and return coverage
Two independent producer defects are corrected: BTI import-entry identity and
false no-return promotion that erased a post-warning path. A fresh three-way
model run passes the selected task oracle with all interfaces. Direct atomic
reads use less cumulative and uncached input and finish sooner than Code Mode
in this sample, despite more MCP requests. Correct primitive facts are useful;
the extra Code Mode layer does not automatically improve a completed task.
This continues the [three-way warning investigation](aarch64-xref-study.md),
where all three interfaces encountered the same dropped post-warning path.
## PLT entry checkpoint
The actual Debian arm64 SSH fixture remains SHA-256
`de352e4ace7028d9816fd0ee9d22936bc1b5622c400d5b0b7df660df3426b068`,
1,051,744 bytes, extracted and never executed. The independent
[machine verifier](verify-aarch64-machine.py) checks the warning epilogue's
restored LR/SP, tail branch `0x25858 → 0xbad0`, BTI at that entry, ADRP at
`0xbad4`, loaded GOT slot `0x10f390`, and its `free@GLIBC_2.17` JUMP_SLOT
relocation. GNU objdump's neighbouring synthetic PLT label is not authoritative
symbol identity. Actual runtime binding, pointer authentication and path
feasibility remain unknown.
The old loader recognizes an ADRP/LDR pair and names the ADRP address. The
resulting inventory splits `sub_bad0` (4 bytes) from `free` at `0xbad4` (20).
The corrected owner recognizes the complete standard veneer, optional immediate
BTI c prefix and optional AUTIA1716. It uses the ADRP's own PC and exact
relocation slot, without assuming a PLT stride. Complete load/add/branch
agreement is required before consuming a relocation. Truncated/corrupt sequences,
ordinary preceding instructions, missing slots, misalignment and overflowing
instruction ranges cannot manufacture an entry.
The AArch64 decoder and its tests move into `loader/elf_plt/aarch64.rs`;
section and PT_DYNAMIC paths call that single owner. The parent still owns GOT
name correlation and deduplication. These supported sequences follow Arm's
[System V ABI examples](https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst#sample-plt-sequences).
Other veneer forms stay unrecognized. This experiment does not establish full
Ghidra loader/analyzer parity.
REA refreshed main through `d5be402fb3dbfc56ac9854c27b5538df20cc2437`
(merge `d3443521d`); native upstream stays
`fe01d6294eb0d1053ce343c8943646df88e143fc`. The PLT-only overlay hash is
`ec660ee463d46e95bc76a9c80e0889ee65443748f1196ad61c4464352dfc8c19`.
Copied immutable embed-specs/opt1 engine SHA-256:
`646c49341f9f55147ce9363d8f3e33b69860a830dbd1b88beea339db88ff2fe9`.
The previous engine is `e43185ff11e74c18753e8755c7757ef6ede415c87a1dac9f04bb39856de87f43`.
Six new test groups first ran against the old decoder: five failed, one passed.
All 13 PLT decoder tests then passed, including seven AArch64 groups and the
other architectures' retained cases. The real public SDK inventory now places
`free` at `0xbad0` and `_exit` at `0xbdd0`; their former ADRP-body entries disappear.
The warning's recovered tail call names `free`. The real native CLI
[loader verifier](verify-aarch64-plt.py) checks both the original ELF section
path and PT_DYNAMIC fallback using a separately hashed derived copy with only
ELF section-header coordinates zeroed. Both produce the corrected entries.
Neither input is executed. Both patch application directions pass.
The original and sectionless inventories contain 1713 and 518 entries; this
check compares selected imports, not whole-inventory completeness. PAC coverage
uses synthetic byte fixtures; the real SSH checks exercise the BTI form.
| Executed check | Family wall s | Family CPU s | Kernel family peak MiB |
| ------------------------------------------------------------------------- | ------------- | ------------ | ---------------------- |
| Refreshed REA runtime build | 34.141 | 32.976667 | 3039.0 |
| Six new groups against old decoder, expected failure | 123.335 | 122.063494 | 1031.2 |
| All 13 PLT tests after correction, including compile | 68.475 | 68.217534 | 887.9 |
| Corrected native CLI build | 102.486 | 102.098492 | 625.3 |
| Old-engine SDK inventory/references/two captures/full source verification | 14.314 | 14.060418 | 389.6 |
| PLT-only engine, equivalent SDK workflow | 14.312 | 14.080485 | 388.5 |
| Real CLI, both loader paths | 4.045 | 3.744119 | 101.9 |
All listed scopes verify payload cleanup, observed OOM 0, one CPU and the existing
4 GiB hard/3 GiB early-stop memory guard. Peaks include charged file cache and
are not RSS; verified payload-exit counters are not final whole-scope counters.
SDK sessions use fresh retained-evidence stores; OS cache state is uncontrolled.
The single equivalent SDK pair does not establish a performance improvement.
No new model/token measurement or broad repository typecheck is claimed here.
The PLT-only correction **does not** restore the caller's strict diagnostic:
its recovered call facet still omits `0x2854c`, and C still marks the warning
call at `0x2841c` no-return. This controlled result separates the import-entry
defect from the no-return defect. The discovered-no-return pass has a weaker
terminal-call promotion than the existing propagation walk: it observes a
terminal call somewhere and absence of RET, without rejecting an escaping tail
transfer to possibly returning code. Causality and the structural correction
require their own checks; the entry fix alone is not claimed to solve it.
## No-return ownership checkpoint
With the PLT-only engine unchanged, disabling only `noreturn_disc` restores the
caller call at `0x2854c` and removes the false no-return annotation from the
warning call at `0x2841c`. That native CLI counterfactual takes 5.052 s wall,
4.813974 s local family CPU, 175.6 MiB kernel family peak, with verified cleanup
and observed OOM 0. It isolates the discovered pass; it is not the final fix or
the configuration supplied to model evaluators.
The discovered pass's duplicate promotion scanned a whole function span for
any terminal call and no RET. An alternative tail transfer to a returning
import therefore failed to protect the caller's continuation. The correction
removes that interpretation and shares the propagation pass's conservative
reachable-path walk. Known terminal transfers stop a path; returning tails,
missing successors, unresolved indirect jumps and escaping branches cannot
prove the whole function no-return. A dead, unreachable RET no longer prevents
legitimate promotion. Existing call-site threshold and strict-successor options
remain, but an absent local successor contributes no new vote: it is compatible
with a returning tail call. The inspected
[Ghidra analyzer](https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/FindNoReturnFunctionsAnalyzer.java)
also skips calls without fall-through when looking for new indicators; this is
source comparison, not a real-Ghidra runtime verification.
The shared entry first checks for any terminal-transfer candidate before
allocating a body map or visiting its CFG. That necessary-condition check also
applies to the existing propagation consumer. Terminal sets still grow during
the bounded fixpoint, so false results are not cached across changing sets.
There is no added long-lived graph cache or duplicate adapter interpretation.
Five new semantic test groups cover the fatal/returning-tail alternative,
four different unknown exits, genuine terminal paths with a dead RET, a
transitive wrapper fixpoint, and missing versus positively identified
successors. Against the old rule, four groups fail and the wrapper group passes
(the two pre-existing smoke tests also pass). After the correction, all 39
no-return-related tests pass, including those groups. Expected-failure run:
68.371 s wall / 68.147478 s CPU / 889.2 MiB peak. Passing run including compile:
73.808 s / 72.914925 s / 892.6 MiB. Both have verified cleanup and observed OOM 0.
An earlier syntax-error attempt is not counted as a semantic regression run.
The final overlay SHA-256 is
`597b5236c42b214b88da39afe0f2b2b1cd7c5ff82e512e91d6a3249bfef565f1`;
the immutable engine SHA-256 is
`0969be0c9c3ace9357acce1f802f12e8595bc57445da32937933de543ca77672`.
Forward-index and reverse-worktree application checks pass. The public
[SDK verifier](verify-aarch64-returns.mjs) now finds the strict call at
`0x2854c`, removes the false warning-call annotation, retains the genuine fatal
call annotation, verifies canonical import ownership and byte identity, hashes
all retained sources, and checks complete C/source fidelity and warm reuse.
Warm captures retain identical handles/facts: warning 0.770 ms / 0.000797 CPU s;
caller 0.702 ms / 0.000761 CPU s. Cold captures take 2033.6 / 5857.3 ms and
2.023671 / 5.835244 CPU s respectively. These are lease cache observations, not
OS-cold or model-task measurements.
| Executed check after no-return correction | Family wall s | Family CPU s | Kernel family peak MiB |
| --------------------------------------------------------------------- | ------------- | ------------ | ---------------------- |
| Native CLI build | 212.756 | 166.409933 | 629.8 |
| New SDK return/source verifier | 13.606 | 13.381336 | 421.9 |
| Equivalent earlier SDK inventory/references/two captures/full sources | 15.632 | 15.370816 | 415.7 |
| Existing AArch64 xrefs/GOT reads/source regression | 13.309 | 13.018756 | 206.9 |
| Complete old x86 function/prototype fidelity through MCP | 9.080 | 8.790274 | 308.5 |
| All 87 experimental JS tests | 5.355 | 5.055786 | 83.8 |
| Both actual catalogs and converted schemas | 1.936 | 1.712823 | 136.3 |
| Both real native ELF loader paths | 4.047 | 3.799690 | 101.1 |
All these successful scopes verify cleanup and observed OOM 0 under the same
resource bounds. Wall/CPU divergence occurred during compilation; attribution
between host contention and changed compilation is unmeasured. The equivalent
SDK task is slower than the PLT-only 14.312 s / 14.080485 CPU s / 388.5 MiB
sample, while retaining the previously missing path. This single sequential
pair does not establish a general performance delta. Changed-file JS lint,
format and Python compilation checks pass. Broad repository type checking
retains the previously disclosed resource-limited gap.
## Fresh real-model comparison after both corrections
All three trials freeze REA runtime
`bf9d3a6e47de1e16a7eefb58bf385dfbe093fdb9`, the final engine above, the same
target and the unchanged [question](aarch64-warning-question.txt). Trial prefixes
are `arm-return-{direct,codemode,traditional}-v1` under the ignored local cache.
Execution order is Direct, Code Mode, traditional. Each uses a fresh isolated
Codex profile; traditional gets a new project-cache directory and the atomic
modes get new evidence stores. Each requests `gpt-6.1-sol` with high
reasoning through Codex 0.161.0, and receives its actual advertised tools:
22 Direct, 4 Code Mode, or all 16 Kuna-supported traditional tools. Discovery
and SDK-converted schema verification precede these runs. No runtime or engine
mutation occurs during the three trials.
| Whole-task observation | Traditional | Code Mode | Direct atomic |
| -------------------------------------------- | ----------: | --------: | ------------: |
| Cumulative input tokens | 662,683 | 371,571 | 351,157 |
| Cached input, included above | 570,368 | 323,968 | 310,912 |
| Uncached input | 92,315 | 47,603 | 40,245 |
| Output tokens | 5,304 | 6,069 | 5,402 |
| Reasoning tokens, included in output | 1,181 | 1,586 | 1,379 |
| Model responses | 20 | 14 | 12 |
| Client executor calls / waits | 15 / 4 | 13 / 0 | 11 / 0 |
| MCP attempts | 20 | 13 | 25 |
| Rejected MCP attempts | 2 | 0 | 0 |
| Reference-document requests, included in MCP | — | 3 | 1 |
| Shared fact API calls | — | 23 | 22 |
| Model wall seconds | 263.085 | 166.756 | 139.033 |
| Family wall seconds | 263.580 | 167.258 | 139.587 |
| Local family CPU seconds | 166.299552 | 41.040445 | 34.362879 |
| Kernel family peak MiB | 1279.4 | 617.0 | 625.2 |
The unique per-response usage sums match each runner total. Cache writes are
zero. All three runs preserve runtime/engine/target fingerprints, close the
target, remove their isolated profiles, verify payload cleanup and observe OOM 0. Whole-scope final counters remain unavailable; family CPU/memory use verified
payload-exit observations. Memory includes charged file cache, not just RSS.
Remote compute, resolved service model build, OS cache state and host contention
are unmeasured. Fresh local profiles do not imply cold OS or remote model caches.
Code Mode executes its 23 fact calls inside eight `execute_javascript` requests;
Direct issues 22 `facts_*` requests. Each mode retains the same two complete
native function documents, verified equal, including restored strict call
`0x2854c`, the selected pointer bindings, and the warning's named `free` tail.
Code Mode requests three snapshots but captures only two distinct sources; a
repeat uses the existing lease cache. Different queries/field selections and
model response counts are part of the measured workflows, not equal instruction
traces. Both modes, and traditional, also have the same client-side JavaScript
executor available. This compares MCP/API surfaces, not JavaScript versus its
absence.
The traditional run first passes xref instruction addresses `0x25750` and
`0x2853c` to an exact-entry analysis operation; both are correctly rejected. It
recovers with `list_procedures`. Traditional `xrefs` normalizes these results to
address strings; the atomic response also supplies native owning-function
facts. Those navigation differences and retries are counted. Its two successful
function dossiers share the same ready project-export key
`dbfd828b95d9c1a2981707728a9e31b4c38688162e851a904c3808fd911c79eb`.
Higher CPU is not evidence of a broken project cache. Traditional project export
and per-function atomic export remain different native analysis profiles; the
comparison does not isolate transport or schema cost from analysis scope.
All complete answers were read and passed agent review against the frozen
question, independent file/GNU oracle, selected additional GNU checks and their
actual delivered Evidence. Each identifies both functions, proves the selected
pointer transfer and first helper target, verifies format formation/passing,
the four-byte test and actual zero/nonzero successors, conditional cleanup
return, and the necessary runtime/logging/alias limitations. This is selected
task correctness, not human readiness or general analysis completeness.
Every cited source is verified: 11 traditional, 14 Code Mode and 14 Direct IDs.
Traditional projected views correctly have their own provider and null engine
profile; their explicit parent-Evidence links trace to the pinned engine. An
initial audit incorrectly required a native engine profile on each projection;
the corrected audit follows that provenance chain and passes. Atomic retained
source byte counts/digests, target/engine contexts, selected native call/value
bindings, restored strict call and complete selected-function equality pass.
Answer SHA-256 values are:
- Traditional: `655877f07ce8819e7f086c584b49fb6d63dd2a7319c792deb09a721092eb7c5b`
- Code Mode: `35d96912940a3a51704093d08ab228aea3e40fbdc80085d8137385f0d9199f61`
- Direct: `24b1f3954397c3c30686a199189d0a37b61bc6ce74dfc49cfc061e79fe5c7fa9`
The local `return-model-costs.json`, `return-answer-checks.json` and
`return-answer-review.json` retain the detailed receipts/review; raw model and
native captures remain ignored. The earlier Code Mode advantage does not repeat:
this sample uses 5.8% more cumulative input, 18.3% more uncached input and 19.9%
more model wall time than Direct. Its memory peak is slightly lower. One
sequential sample with different model choices cannot establish a stable winner
or attribute the change solely to the fixes. It supplies a concrete counterexample
to treating fewer RPCs as proof of fewer tokens or faster completed analysis.
Broader complex-software effectiveness remains unproved.
@@ -0,0 +1,92 @@
# AArch64 OpenSSH warning oracle
Freeze the question, oracle, source runtime, immutable engine and complete
catalogs before real models. This is a behavior/machine question, without
native-only SSA or prototype-count requirements. The traditional native
Kuna workflow is a valid comparison when its complete tools and evidence
can answer the same question. No question addresses or answers are supplied
to the isolated model workspaces.
Target: extracted Debian `openssh-client_10.0p1-7+deb13u4_arm64.deb`, never
installed or executed. ELF size 1,051,744, SHA-256
`de352e4ace7028d9816fd0ee9d22936bc1b5622c400d5b0b7df660df3426b068`.
Package/provenance and signature-verification limits are in [the storage study](storage-study.md).
All lanes use immutable embed-specs/opt1 engine SHA-256
`e43185ff11e74c18753e8755c7757ef6ede415c87a1dac9f04bb39856de87f43`.
The backend xref correction benefits every lane; old engines with missing
AArch64 facts are not used as a scored traditional baseline.
Independent GNU AArch64 disassembly and FDEs identify banner function
`0x256c0..0x25888`, selected caller `0x27848..0x297d4`. The public
[file/machine verifier](verify-aarch64-machine.py) checks selected ELF words,
ADRP/ADD math, direct/conditional branch targets, the GOT slot/relocation and
GNU unwind ranges without consuming Kuna output. Native SDK/source fidelity
is checked separately. GNU nearest-export labels are not original function names.
Required facts and interpretations:
- Banner format is `0xb0468`: `ADRP X6,0xb0000` at `0x2574c`, then
`ADD X6,X6,0x468` at `0x25750`, then `BL 0x5ae04` at `0x25754`.
The incoming data-reference site is the completing ADD, owned by `0x256c0`.
X6 holds the format pointer at the call. No banner-format stack slot or
original source argument ordinal should be invented from the x86 study.
- Strict format is `0xb1330`: `ADRP X6,0xb1000` at `0x28534`, unrelated
`MOV X5,0` at `0x28538`, completing `ADD X6,X6,0x330` at `0x2853c`,
and `BL 0x5ae04` at `0x2854c`. Reference owner is `0x27848`.
- Banner function has selected incoming calls `0x2841c` from `0x27848` and
`0x29ccc` from `0x297e0`. Select the caller by the strict diagnostic and
corroboration, not by address/name ordering or an original source-name guess.
- Selected pointer setup is `MOV X0,X27` at `0x28414`, then
`BL 0x256c0` at `0x2841c`. In the callee `MOV X23,X0` at `0x256e8`
preserves the incoming pointer; X0 is not rewritten before the first helper
`BL 0x3d108` at `0x256f0`. Matching native passing/input tuples, if used,
remain snapshot-scoped correlations and not global SSA/alias equality.
- Local decision loads **four bytes**: `LDR W0,[X25,0x88]` at `0x2851c`.
`CBZ W0,0x28554` at `0x28524` takes the zero successor `0x28554`;
nonzero falls through to `0x28528`, which prepares the strict diagnostic.
The normalized static model names the tested global `dat_1104f8`.
- The address recovery is corroborated by `ADRP X25,0x10f000` at `0x27904`
and `LDR X25,[X25,0xf20]` at `0x27908`: slot `0x10ff20`, initial/model
bytes `7004110000000000` = `0x110470`, plus field offset `0x88` gives
static image coordinate `0x1104f8`. Independent ELF relocation is
`R_AARCH64_RELATIVE` with addend `0x110470`. An ABI-conforming initial
relocation uses load bias plus addend; this is not a captured live pointer
or a read of the tested runtime value. Across calls, interpreting X25 as
preserved relies on the ordinary callee-save model, not a proved runtime path.
See [Arm ELF relocation semantics](https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#dynamic-relocations)
and [AAPCS64 registers](https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#general-purpose-registers).
- After the strict logging call, `B 0x281c0` at `0x28550` enters cleanup.
Its selected returning route sets `W0=0xffffffff` at `0x281f4` and reaches
`RET X30` at `0x28264`; intervening calls, the stack-check branch at
`0x28214` and pointer authentication can prevent runtime return. Report low
32 bits `0xffffffff` (signed 32-bit -1), without inventing the original return type.
- The banner call precedes this policy test. It alone is not proof of rejection.
Zero enters more checks at `0x28554`, not proof of acceptance/login. The
static initial global/pointer is not a runtime value, alias or binding proof.
Score complete final answers against owner/caller, both address formations,
selected pointer/helper transfer, tested storage/width and zero/nonzero machine
successors, cleanup/low return bits, Evidence/target identities, necessary
unknowns and close. Accept native C/model recovery corroborated by machine
addressing for the static global, or selected loaded-image bytes plus instruction
arithmetic; do not require an unavailable native-only representation. Explicitly
label weaker/missing coverage rather than treating missing facts as completion.
Preflight confirms both strings/xrefs, both selected C/assembly dossiers and
the correct artifact through the real traditional MCP. It resolves the same
static `dat_1104f8`. Its 95.291-second first dossier waits for whole-program
export; later reads reuse that cache. This preflight is not a model trial.
Both atomic catalogs are complete (twenty-two direct / four Code tools), and
the baseline includes all thirteen declared Kuna native operations plus
open/close/retained views (sixteen tools), generated from the capability owner
and actual catalog. Use the same question, requested gpt-6.1-sol/high, fresh
isolated profiles/private caches, common envelope/discovery/stopping/wait
guidance and one-CPU / 4 GiB hard / 3 GiB early-stop bounds. Planned order is
traditional → Code Mode → direct, pinned before launch. Charge every attempt,
whole-task cumulative/cached/uncached input, output/reasoning, responses,
calls/retries/waits, elapsed/CPU and kernel family peak memory. Existing client
JavaScript dispatch is present in every lane. Native profiles differ: selected
atomic windows/functions versus traditional whole-program export. This is a
workflow comparison, not an isolated dispatch-only or same-native-work ablation.
Remote build/compute, OS/model caches and host contention remain unknown.
@@ -0,0 +1,30 @@
Analyze {{artifact_path}} statically, starting from these observed formats:
- REMOTE HOST IDENTIFICATION HAS CHANGED
- Host key for %.200s has changed and you have requested strict checking.
Find the function that supplies the banner format to a formatting/logging call,
and the caller that owns the second diagnostic. Establish both from references
and corroborating function facts; do not guess original source names. Show the
selected direct call from that caller into the warning function. Trace its
passed pointer into the warning function's first helper-call use, including
machine passing locations and call targets. If using SSA, keep the snapshots'
value identities separate; matching storage is not a general alias proof.
Show how the banner format pointer is formed and passed to its formatting/
logging call. Verify the essential address formation, register or stack passing
location and transfer against selected machine instructions. Recovered origins
or operand slots alone do not establish machine addresses or source ordinals.
In the selected caller, after the warning call returns, identify the local test
that chooses the strict-checking diagnostic versus continuation. Report the
tested storage and width, both actual machine successors with zero/nonzero
behavior, and the selected failure-cleanup path's low 32-bit return value.
Distinguish machine addressing from any static model's global-address recovery;
do not present an initial/model pointer as observed live memory. Does selecting
the banner alone prove rejection? Does zero prove a connection will be accepted?
Give a focused answer with function/instruction addresses, real Evidence IDs,
target digest and necessary coverage. Prefer selected facts/windows; do not
return full reports or inventories to model context. Preserve unknown runtime
values, relocation/binding state, aliases, logging behavior, other paths and
runtime feasibility. Do not execute the target. Close the target lease.
@@ -0,0 +1,230 @@
# Composable AArch64 address references
The AArch64 OpenSSH check exposed a real completeness gap before another model
comparison: both warning strings were present, but Kuna returned zero incoming
references for either. Native observations had unknown discovery coverage;
zero was not proof that the strings were unused. Independent GNU decoding
showed ADRP plus ADD at `0x2574c/0x25750` and `0x28534/0x2853c`.
The query scanner read one instruction's p-code at a time. The existing ARM
pool-displacement tracker supplied the relevant bounded value-flow owner, but
did not carry AArch64 page bases. The experiment extends that owner rather than
introducing another interpreter or postprocessing disassembly text. SLEIGH's
mnemonic licenses ADRP, and its exact constant COPY supplies the coordinate;
COPY/ADD/SUB then propagate the value. Machine operand text and hardcoded
register-offset tables are not reparsed. Possible page copies alone, such as
ordinary MOV-immediate instructions, do not establish PC provenance.
The same calculation produces Data for materialized register addresses, or
Read/Write for a LOAD/STORE through a composed default-data-space byte address.
The accessed cell is identified; its mutable/GOT contents are not propagated
as a live value. This also covers the selected GOT slot, which an intermediate
address-only fix still missed. Space-selector constants and stored values are
not mistaken for access pointers.
The directly related refactor renames the former private pool-only module to
`kuna_pc_relative`, moves its tests out of the implementation and retains one
value lookup for arithmetic and memory accesses. Keys preserve native space
identity, offset and width. Partial overwrites invalidate overlaps; copies can
carry a known value into a different register. Calls/jumps/returns stop carry,
instruction-local predicates do not execute both arms sequentially, a pool
load overwritten later in the same instruction cannot seed a stale value,
unsupported widths remain unknown and interval checks include the final u64
byte without overflow. Empty/failed assembly rendering cannot license ADRP.
State remains function-local, follows fall-through addresses and keeps the
existing eight-hop/eight-value bounds. It is not a complete fixed-point,
cross-call, alias, runtime-value or feasible-path analysis. Unknown discovery
and indirect-target coverage remain explicit through the shared parser and
SDK/CLI/MCP views. Both experimental adapters and the traditional Kuna provider
consume the corrected native producer; no special advantage is injected into
one evaluator lane. Stock Kuna is not silently upgraded.
## Pins and real artifacts
REA refreshed main through `0d2247428` before this work. The native upstream is
`fe01d6294eb0d1053ce343c8943646df88e143fc`, overlay SHA-256
`62cb9d9386d110ca1301d4f7d541d0d1ee676f17ca888163cf7d69d8a9d07c53`.
The copied immutable embed-specs/opt1 engine SHA-256 is
`e43185ff11e74c18753e8755c7757ef6ede415c87a1dac9f04bb39856de87f43`.
Default forward-index and reverse-worktree patch checks pass. New analysis
patch sections use Git-supported unprefixed empty context lines, preserving
line counts/source bytes without whitespace-only lines in the patch artifact.
The target is extracted Debian arm64 OpenSSH, SHA-256
`de352e4ace7028d9816fd0ee9d22936bc1b5622c400d5b0b7df660df3426b068`.
The [storage study](storage-study.md) records its package URL, digest and
unverified package-signature scope. It was neither installed nor executed.
The [independent machine oracle](verify-aarch64-machine.py) reads checked
file-backed ELF ranges, validates selected instruction/branch math and GNU FDEs,
and confirms the selected RELATIVE relocation. It does not read Kuna output.
The oracle refuses optimized Python rather than silently disabling assertions.
The real SDK verifier returns one reference for `0xb0468`, from `0x25750`,
owned by `0x256c0`; and one for `0xb1330`, from `0x2853c`, owned by `0x27848`.
It also verifies both direct caller sites and 77 reads of GOT slot `0x10ff20`,
including `0x256d0`, `0x27908`, `0x27dcc` and `0x28eb8`. The slot's selected
loaded-image bytes agree with the independent file read, while runtime memory
remains not-observed. Full retained source digests are verified. A warm repeat
uses the same Evidence IDs and identical facts.
## Executed checks and costs before model trials
| Check | Family wall s | Family CPU s | Kernel family peak MiB |
| ------------------------------------------------------------- | ------------- | ------------ | ---------------------- |
| Refreshed REA runtime build | 36.660 | 35.931222 | 2989.1 |
| 17 final PC-relative tests, including compile | 69.090 | 68.844945 | 885.1 |
| All 125 Listing tests, including those 17 | 0.524 | 0.349058 | 59.2 |
| Final native CLI build | 104.525 | 104.240617 | 630.2 |
| Real AArch64 SDK/source verifier | 13.109 | 12.857963 | 203.1 |
| Old x86 complete-function/prototype fidelity through real MCP | 8.779 | 8.516305 | 302.0 |
| Both actual atomic catalogs and converted schemas | 1.932 | 1.689159 | 139.3 |
| All 87 experimental JS tests | 5.060 | 4.890171 | 78.8 |
| Complete traditional capability/catalog selection | 4.148 | 3.761593 | 443.2 |
| Actual traditional MCP target/C/assembly preflight | 103.002 | 102.596202 | 872.3 |
The independent machine verifier, changed-file lint/format checks and patch
application checks also pass; their CPU/memory costs were not separately measured.
All measured successful runs have observed OOM 0 and verified payload cleanup.
Resource scopes use one CPU, 4 GiB hard/3 GiB early-stop memory, TasksMax192 and
swap disabled. Peaks include charged file cache and are not RSS. Final
whole-scope counters are unavailable; table values use verified payload-exit
observations. Broad repository type checking retains the previously reported
resource-limited gap; no passing full typecheck/native corpus gate is claimed.
The 17 PC-relative tests include the retained pool-displacement cases and new
page/copy/space/width/clobber/predicate/access cases; they are included in the
125 Listing tests, not additional independent executions. An intermediate run
passed 16/17: its obsolete assertion expected no reference when a composed
temporary was dereferenced. The intended extension now identifies that actual
cell Read while retaining the negative assertion against a register address-taken
claim. The test was updated to require exactly that stronger typed outcome.
All failed/intermediate receipts remain local; they are not model attempts.
The AArch64 two-address reference batch takes 3,548.3 ms wall / 3.535213 CPU s
on a fresh lease, versus 1.54 ms / 0.001539 s for the same-lease repeat. This
shows retained-source reuse, not faster native discovery. Old engine c48ad957
returned incorrect zero results; its costs are not an equivalent completed-task
performance baseline for those new facts.
A separate equivalent x86 task requests the same three exact-address reference
sets before/after. Every normalized fact and coverage field agrees (counts
1/1/2), using fresh leases/private caches. Its old/new cold phase is
4,028.3/4,082.2 ms wall and 3.993216/4.031850 CPU s; warm is 3.30/2.38 ms.
Whole-run wall is 4.852/4.852 s, CPU 4.554857/4.580338 s, peak 155.3/157.4 MiB.
This single lookup repeat shows no material observed regression for that case;
it is not a model-token measurement or a general speed guarantee. OS/cache and
host variation remain uncontrolled.
## Frozen model task
The [question](aarch64-warning-question.txt) and [oracle](aarch64-warning-oracle.md)
ask the same behavior-level warning/pointer/guard/cleanup question through
three complete interfaces. Native SSA identities are optional. Traditional
preflight supplies the same strings, actual references, both C/assembly dossiers,
and recovered static `dat_1104f8`, with target/engine digests verified. Its first
dossier costs 95.291 s waiting for whole-program export; later assembly/dossier
reads reuse that cache. Atomic selected-native profiles differ, so the planned
comparison is a full workflow comparison, not a dispatch-only ablation.
The runtime/question/oracle are frozen at
`5eede35c978c76ff9215443ed0a0d5980bfbdfe1`. Execution order is traditional →
Code Mode → direct. All request gpt-6.1-sol/high via Codex 0.161.0, with fresh
isolated profiles/private caches and the same task. Both atomic catalogs are
complete (22/4 tools); the traditional set contains every declared Kuna native
operation and session/views (16 tools). Each client actually has JavaScript
dispatch. This compares MCP workflows inside that common client surface.
All three complete answers pass agent review against the frozen oracle. They
identify both owners, the X27→X0 pointer/helper transfer, banner ADRP/ADD into
X6, four-byte field/CBZ successors, static versus live pointer knowledge,
cleanup/low return bits, Evidence/target identities, unknowns and close. The
traditional answer uses native C recovery plus machine addressing for the static
global; both atomic answers also read the selected loaded-image pointer bytes.
No native-only representation is required to pass.
Separate scripted checks verify all seven traditional, fifteen Code and fourteen
Direct cited sources against delivered responses/traces and target/engine
identities. Atomic retained source hashes/lengths agree; complete selected native
function documents are identical between the two atomic lanes. Selected native
argument/value/passing tuples and the PHI/input distinction match the delivered
graphs/call facets. The independent ELF/GNU oracle checks the machine facts.
Supplementary GNU checks corroborate the traditional answer's added logging
wrapper call at `0x5ae6c → 0x5abb0`, with X6 unchanged. Source/fidelity checks
are separate from agent review of the entire natural-language answers; neither
constitutes human readiness or global machine-equivalence verification.
| Whole completed task | Traditional | Code Mode | Direct atomic |
| ----------------------------------------------------- | ----------- | ----------------------------- | --------------- |
| Required answer | pass | pass | pass |
| Cumulative input tokens | 681,613 | 388,365 | 515,929 |
| Cached input, included above | 639,360 | 336,000 | 436,224 |
| Uncached input | 42,253 | 52,365 | 79,705 |
| Output tokens | 5,423 | 5,755 | 6,529 |
| Reasoning, included in output | 1,324 | 1,137 | 1,934 |
| Unique model responses | 23 | 13 | 15 |
| Client executor / wait calls | 16 / 6 | 12 / 0 | 14 / 0 |
| MCP attempts, including failures/discovery/open/close | 13 | 12 | 31 |
| Rejected MCP attempts | 2 | 0 | 0 |
| Atomic fact reads | n/a | 25 inner reads | 25 direct reads |
| Native function dossiers / snapshot requests | 4 dossiers | 3 requests, 2 unique captures | 2 captures |
| Model wall seconds | 345.676 | 151.264 | 164.942 |
| Family wall seconds | 346.217 | 151.834 | 165.421 |
| Local family CPU seconds | 186.786767 | 41.152525 | 43.116751 |
| Kernel family peak MiB | 973.1 | 695.7 | 600.4 |
Both traditional rejections are instruction-interior addresses passed to exact
procedure lookup. The inventory was available, the model used it and completed;
this is not the earlier under-equipped baseline. All four traditional dossiers
report the same ready project-export key, so the observation does not establish
a broken project cache. Its extra logging-wrapper investigations and native
profile add work beyond the two selected atomic captures. All attempts remain
charged; failed/intermediate development checks are separate from model trials.
Code uses 24.7% less cumulative input and less wall/CPU time than Direct in
this pair, but more peak memory. Compared with traditional it uses 43.0% less
cumulative input and less wall/CPU/memory, but **23.9% more uncached input** and
more output. There are only two fewer model responses than Direct, despite
nineteen fewer MCP requests. Same fact-read counts do not mean identical native
work. This is one new architecture/version sample with uncontrolled OS/model
caches, host contention, service build and remote compute, not a stable Code
Mode advantage, a price claim or broad complex-software superiority.
Unique per-response usage sums match the task totals. All target, engine and
runtime fingerprints remain unchanged. All three profiles are removed; verified
payload-exit observations show OOM 0 and descendant cleanup. The same resource
bounds and kernel-memory interpretation as above apply.
Raw model records are `arm-warning-{traditional,codemode,direct}-v1/` with sibling
resource logs/configs; atomic traces and explicitly retained sources have matching
prefixes. Derived records are `arm-model-costs.json`, `arm-answer-checks.json`,
`arm-answer-review.json` and `arm-traditional-delivered-evidence.json`. Reviewed
answer SHA-256 values are:
- Traditional: `5312aa0757b35b8a28b8d1c60af652760e445b0463117eb41def1e2eeb5031eb`
- Code: `e331df37f53e58a85bea61f37b5e3b7c6a6848af78a0225383df0d9a481121a7`
- Direct: `792b613d25e9c5dfec4e4dd03c13d265f24937e0eafc817931bd5a563e496408`
## Remaining native identity/control-flow question
All answers detect the recovered caller's no-return treatment of the warning
call and use machine instructions for the requested conditional post-call path.
The recovered call facet omits the strict call. Complete recovered-graph coverage
therefore does not establish a complete machine graph or a correct no-return
inference. This is a concrete remaining backend/identity investigation.
Supplementary static observations identify a suspicious boundary: the warning
epilogue restores LR/SP and branches at `0x25858` to `0xbad0`. That address
starts with BTI, followed by ADRP at `0xbad4` and a slot load at `0xbad8` from
`0x10f390`. ELF `R_AARCH64_JUMP_SLOT` names that slot `free@GLIBC_2.17`.
The native inventory instead exposes `sub_bad0` with size bound 4 and `free`
at `0xbad4` with bound 20. GNU's synthetic PLT label at `0xbad0` says closedir,
which the actual slot relocation contradicts; it must not be used as symbol
identity. Whether the native BTI/veneer split causes the no-return propagation
still needs a producing-boundary investigation and regression proof. No such
fix or rerun is attributed to the frozen comparison above.
Raw receipts live under `.cache/atomic-codemode/` as `arm-*`: initial missing
xrefs, intermediate/final native test/build logs, SDK/source records, x86 fidelity
and equivalent-query costs, actual catalogs and traditional preflight. Binaries,
native projects and raw captures remain uncommitted.
@@ -0,0 +1,24 @@
// Shared named contract and selection vocabulary; no engine or adapter code.
import { z } from "zod";
export const hex = z.string().regex(/^0x(?:0|[1-9a-f][0-9a-f]{0,15})$/u);
export const valueLocation = z.strictObject({
space: z.string(),
offset: hex,
size_bytes: z.number().int().positive(),
});
export const page = {
offset: z.number().int().nonnegative().default(0),
limit: z.number().int().min(1).max(128).default(20),
};
export const definition = (
{ summary, description },
input,
method,
example,
) => ({
summary,
description,
input: z.strictObject(input),
method,
example,
});
+424
View File
@@ -0,0 +1,424 @@
// One named contract registry shared by SDK, CLI, direct MCP and Code Mode.
import { z } from "zod";
import { MAX_BYTE_BATCH_BYTES, MAX_BYTE_WINDOWS } from "./limits.mjs";
import { MAX_GRAPH_BLOCKS } from "./graph-limits.mjs";
import { createReference } from "./reference.mjs";
import { definition, hex, page, valueLocation } from "./api-contracts.mjs";
import { storageMethods } from "./storage-contracts.mjs";
import { referencesMethod } from "./reference-contracts.mjs";
const snapshot = z.string().startsWith("snap_");
const byteWindow = z.strictObject({
address: hex,
length: z.number().int().min(1).max(MAX_BYTE_BATCH_BYTES).default(256),
});
const kinds = z.enum([
"value",
"load",
"store",
"phi",
"call",
"branch",
"switch",
"return",
]);
const fields = z
.array(
z.enum([
"kind",
"statement",
"definitions",
"constants",
"opcode",
"inputs",
"output",
"is_dead",
"input_count",
"definition_count",
"constant_count",
]),
)
.optional();
const identitySeeds = z.array(z.string()).min(1).max(128);
const relationInput = z.discriminatedUnion("kind", [
z.strictObject({
snapshot,
kind: z.literal("cases"),
seeds: identitySeeds,
case_values: z.array(hex).max(128).optional(),
case_indices: z.array(z.number().int().nonnegative()).max(128).optional(),
...page,
}),
z.strictObject({
snapshot,
kind: z.literal("operands"),
seeds: identitySeeds,
input_indices: z.array(z.number().int().nonnegative()).max(128).optional(),
...page,
}),
z.strictObject({
snapshot,
kind: z.enum(["definitions", "uses", "value_uses"]),
seeds: identitySeeds,
...page,
}),
z.strictObject({
snapshot,
kind: z.enum(["incoming", "outgoing", "controllers"]),
seeds: z.array(z.number().int().nonnegative()).min(1).max(128),
...page,
}),
]);
export const methods = {
...storageMethods,
switches: definition(
{
summary:
"Select recovered switches/table metadata; fetch cases separately. Native defaults may differ from machine guards.",
description:
"Inspect recovered indirect branches and their independent native jump-table metadata, without returning all case rows. Selector is the current recovered BRANCHIND input, which may be normalized rather than the machine jump address. Native consumed mask and signed rendering hint are not complete runtime/signedness proofs. Null tables/defaults stay unknown. The native model default out-edge is separate from any machine out-of-range guard destination. Use relations kind:cases for selected raw table rows, labels and their native mapping to recovered edges; row/edge ordinals are not case values. Available even when the full graph is unavailable if this independent facet was captured.",
},
{
snapshot,
ids: z.array(z.string()).max(128).optional(),
origin_addresses: z.array(hex).max(128).optional(),
fields: z.array(z.enum(["selector", "table"])).optional(),
...page,
},
"switches",
'await rea.switches({snapshot:s,origin_addresses:["0x1000"]})',
),
functions: definition(
{
summary:
"Select callable entries and aliases, preserving ambiguous names; reported sizes are bounds, not assured extents.",
description:
"Search retained native callable entries by literal name/alias, exact name, or entry addresses. Names can match several entries, including PLT/import stubs and implementations; preserve all matches and select by address. A name does not establish runtime symbol binding.",
},
{
query: z.string().default(""),
exact: z.boolean().default(false),
case_sensitive: z.boolean().default(true),
addresses: z.array(hex).max(128).optional(),
fields: z.array(z.enum(["name", "aliases", "size"])).optional(),
...page,
},
"functions",
'await rea.functions({query:"format_error",exact:true})',
),
strings: definition(
{
summary:
"Search native string candidates by literal text; discovery and reference attribution remain unknown.",
description:
"Search native string candidates by literal text (JavaScript UTF16 includes semantics, no regex). Address and encoding identify an object within the artifact; fields:[] omits display text. Select value, provider_value or decoding only when needed. Encoded byte lengths and provider-reported NUL termination are preserved when known; omitted NUL status is unknown. A false NUL status makes no claim about bytes outside that span. Coverage.source_scope distinguishes a retained whole inventory from a selected query report; source IDs need not be shared between queries/pages/detail views. source_row, when present, is the canonical candidate ordinal under the declared native scan settings. Paging and native selection completeness do not establish artifact discovery completeness. Complete captured source remains readable through evidence.",
},
{
query: z.string(),
fields: z
.array(z.enum(["value", "provider_value", "decoding"]))
.optional(),
...page,
},
"strings",
'await rea.strings({query:"incorrect header check",fields:[]})',
),
references: referencesMethod,
snapshot: definition(
{
summary:
"Capture one function's analysis; return a snapshot, retained Evidence, facet availability and scoped counts.",
description:
"Analyze an explicit function entry once; return a retained capture handle, facets and coverage. Reuses the source within this target lease. Code, recovered calls and values remain independently available when full recovered IR exceeds capacity. A bounded call-rooted operation/definition projection may also be available; inspect facets.operations and coverage before reads. CFG queries still require the complete recovered graph. Available calls include compact by_opcode counts of known/unknown targets over the whole retained call facet; no paging is needed for these counts. Selected calls and complete Evidence remain readable.",
},
{ entry: hex },
"snapshot",
'await rea.snapshot({entry:"0x1000"})',
),
bytes: definition(
{
summary:
"Read batched static loaded-image byte ranges with source identity and per-window partial outcomes.",
description:
"Read selected native loaded-image bytes without instruction decoding. Batch up to 16 exact virtual-address windows and 64 KiB total selected bytes; hex uses twice that space before provenance. Short reads remain partial. A shared source can contain several windows; source_row, when present, identifies its zero-based native window row. Repeated exact ranges can reuse that source. These are not live process memory or an original-file-offset mapping. Global code discovery is not performed.",
},
{
windows: z.array(byteWindow).min(1).max(MAX_BYTE_WINDOWS),
},
"bytes",
'await rea.bytes({windows:[{address:"0x2000",length:32}]})',
),
instructions: definition(
{
summary:
"Decode selected static machine-byte windows, distinct from optimized IR edges and runtime execution.",
description:
"Batch selected machine instruction windows. Read exact bytes and native disassembly to verify actual control transfers; optimized recovered CFG edges can bypass machine blocks. Address+size with the artifact context identifies the byte range. A caller-selected decode start does not prove execution/alignment.",
},
{
windows: z
.array(
z.strictObject({
address: hex,
count: z.number().int().min(1).max(4096).default(16),
}),
)
.min(1)
.max(16),
fields: z
.array(z.enum(["bytes", "text", "mnemonic", "operands"]))
.optional(),
},
"instructions",
'await rea.instructions({windows:[{address:"0x1000",count:8}],fields:["bytes","text"]})',
),
operations: definition(
{
summary:
"Select snapshot-local IR operations by identity, origin, constant or kind, with native/projection scope.",
description:
"Select SSA operations by IDs, source instruction origins, block IDs, constant literal or kind. Native default rows are compact summaries: opcode/kind/output and input/definition/constant counts; request detailed fields explicitly or page input slots via relations kind:operands. Filters intersect; identities and native is_dead are retained. Availability may be a complete recovered graph or a bounded call-rooted projection; inspect coverage before inferring absence. A literal match is not object identity. origin_addresses selects optimized recovered IR origins; use instructions for actual machine control transfers.",
},
{
snapshot,
ids: z.array(z.string()).max(128).optional(),
origin_addresses: z.array(hex).max(128).optional(),
block_ids: z.array(z.number().int().nonnegative()).max(128).optional(),
constant: hex.optional(),
kind: kinds.optional(),
fields,
...page,
},
"operations",
'await rea.operations({snapshot:s,constant:"0x2000",fields:["statement"]})',
),
relations: {
summary:
"Read typed SSA operands/def-use, CFG/controllers or switch cases by identities; preserve unknown/partial scope.",
description:
"Read native operand occurrences, operation definitions/uses, value_uses or case rows. value_uses takes value-ID seeds and returns exact operation/input-slot occurrences, including function inputs and constants without defining operations; null definition stays explicit, not a missing use. Uses cover retained operations, not runtime or memory aliases. Other data-flow/case seeds are operation IDs; incoming/outgoing CFG edges or derived controllers for block IDs. Native CFG/controller reads deduplicate seeds and report unretained_seeds; an unknown block is not a retained block with no relations. Incoming/outgoing rows keep caller seed then native edge order; controllers keep native controller/edge then postdominator order. cases pages one relation per case/out-edge, with a stable case_id; an unmapped case has one explicit unknown-edge row. total counts relations, not table rows. cases filters optional case_values (native labels tagged value) and case_indices (original row ordinals); both filters intersect and paging spans deduplicated seeds in caller order. Rows preserve missing/no-label status, original recovered target, and separate recovered edges. Partial/unavailable tables and unmapped rows are explicit; no runtime feasibility claim. operands pages every selected input slot, including constants, function inputs and null slots; input_indices optionally selects slots in caller order. Identity is snapshot + operation + input_index; value_id/definition and exact phi predecessor/edge bindings remain separate. Out-of-range slots of retained operations are absent; unretained_seeds remain unknown. A bounded call-rooted projection supports operands/definitions/uses but no CFG; uses cover retained selected operations only. Diagnostic SSA lacks native operands and has partial CFG/printed occurrences. controllers requires a complete recovered graph and concerns finite paths to recovered exits, not runtime feasibility.",
input: relationInput,
method: "relations",
example:
'await rea.relations({snapshot:s,kind:"operands",seeds:[op.id],input_indices:[0,2]})',
},
values: definition(
{
summary:
"Select SSA values by ID or exact space/offset/width; keep versions, inputs and constants distinct, without alias inference.",
description:
"Read native SSA values by IDs or exact locations [{space,offset,size_bytes}], with width required. Locations match retained metadata, including const/unique spaces, not pointee contents, aliases or live memory. Filters intersect; IDs retain caller order, otherwise locations retain caller order and values retain native order per location. Empty IDs/locations select none. Null-space values cannot resolve a location and stay explicit in location_coverage; unretained_locations means no known retained coordinate match, not absent machine storage. Scope may be a full graph, bounded call-rooted definition projection, or call-boundary values only; is_input filters the raw native input flag, which can also mark globals or stack values; it is not formal-parameter membership. Use parameters for the separate native recovered prototype, which also does not prove an original source signature. Offset is an address-space offset, not a computed arbitrary-width value. Width, constants, function inputs, annotation status and defining operation are separate facts. Requires the pinned native exporter.",
},
{
snapshot,
ids: z.array(z.string()).max(128).optional(),
is_input: z.boolean().optional(),
locations: z.array(valueLocation).max(128).optional(),
fields: z
.array(
z.enum([
"space",
"offset",
"size_bytes",
"is_constant",
"is_input",
"is_annotation",
"definition",
"type_name",
]),
)
.optional(),
...page,
},
"values",
"await rea.values({snapshot:s,ids:op.inputs.map(i=>i.value_id).filter(Boolean)})",
),
calls: definition(
{
summary:
"Read recovered calls, target knowledge, arguments and passing storage; signatures and runtime binding remain uncertain.",
description:
"Select structured recovered call sites and argument bindings. Target comes from native call specifications, never the fspec annotation offset or display text. Each argument separates its SSA value from its passing storage. Calls and their boundary values survive full graph capacity failure. target_value_id retains input zero independently of target resolution; it may be an fspec annotation or an unresolved indirect target value. A null output describes this recovered operation, not proof of a void source signature. Input slots are not original source parameter ordinals; missing storage and indirect/runtime targets remain unknown. To investigate across functions, snapshot the selected callee and select values with is_input:true, comparing exact space/offset/width. Requires the pinned native exporter.",
},
{
snapshot,
ids: z.array(z.string()).max(128).optional(),
origin_addresses: z.array(hex).max(128).optional(),
fields: z
.array(
z.enum([
"target",
"target_name",
"arguments",
"output",
"prototype",
"stack_offset",
"target_value_id",
"is_dead",
]),
)
.optional(),
...page,
},
"calls",
'await rea.calls({snapshot:s,origin_addresses:["0x1100"]})',
),
blocks: definition(
{
summary:
"Select recovered CFG blocks and edges; origin addresses are provenance, not machine block extents.",
description:
"Read native recovered blocks by stable snapshot-local ID, with ordered predecessors, successor edges and member operation IDs. origin_start describes optimized IR provenance, not a machine block extent. Requires an available native recovered IR graph. Runtime successors remain unknown.",
},
{
snapshot,
ids: z.array(z.number().int().nonnegative()).max(128).optional(),
fields: z
.array(
z.enum(["origin_start", "operations", "predecessors", "successors"]),
)
.optional(),
...page,
},
"blocks",
"await rea.blocks({snapshot:s,ids:[op.block]})",
),
parameters: definition(
{
summary:
"Select native recovered formal parameter and return storage, convention and recovery flags; raw input varnodes are not formals.",
description:
"Read the captured native function prototype: paged parameter entries, return descriptor, native convention label, locks, variadic and recovery-error flags. IDs/indices belong to this snapshot's recovered prototype, not proven source parameter ordinals or original signature. Native is_input also marks stack/global input varnodes; it is not formal membership. Select indices in caller order and optional fields; defaults omit display names/type strings. Output uses the same field selection. Null storage/type stays unknown; explicit is_void is independent of storage absence. Storage matches across snapshots require exact artifact/callee identity and ABI reasoning; stack rebasing, aliases, split/join storage, runtime binding and source signatures remain unproved. Requires a captured parameters facet, independently of full CFG/calls. Older experimental captures explicitly report not-captured; no synthetic empty signature.",
},
{
snapshot,
indices: z.array(z.number().int().nonnegative()).max(128).optional(),
fields: z
.array(
z.enum([
"name",
"type_name",
"size_bytes",
"is_void",
"storage",
"type_locked",
"name_locked",
"size_locked",
"this_pointer",
"indirect_storage",
"hidden_return",
]),
)
.optional(),
...page,
},
"parameters",
'await rea.parameters({snapshot:s,indices:[0],fields:["storage","size_bytes","is_void","type_name"]})',
),
path: definition(
{
summary:
"Find one shortest recovered CFG path to a block or exit, with exclusions and paged native edges; feasibility stays unknown.",
description:
"Find one shortest edge-count witness in the complete recovered CFG from a numeric block ID to a block or any zero-successor recovered exit, excluding avoid IDs. Ties follow native successor order. Return paged native edges with a separate step_index; index remains the original successor ordinal. A found zero-edge path is distinct from not-found. Unknown start/target/avoid identities produce status unknown and unretained_blocks, never absence. Not-found applies only to this recovered graph under the requested exclusions; exits, termination, machine flow and branch-predicate feasibility remain unproved. Requires the full recovered_ir facet, not a call-rooted projection. Search state is bounded by the admitted graph; one last-query cache per resident immutable graph expires with eviction/lease close. The avoid selection is bounded by the maximum admitted graph block count.",
},
{
snapshot,
from: z.number().int().nonnegative(),
target: z.discriminatedUnion("kind", [
z.strictObject({
kind: z.literal("block"),
id: z.number().int().nonnegative(),
}),
z.strictObject({ kind: z.literal("exit") }),
]),
avoid: z
.array(z.number().int().nonnegative())
.max(MAX_GRAPH_BLOCKS)
.default([]),
...page,
},
"path",
'await rea.path({snapshot:s,from:block,target:{kind:"exit"},avoid:[join]})',
),
slice: definition(
{
summary:
"Trace bounded backward definitions with explicit LOAD/PHI/frontier cutoffs; memory aliases remain unknown.",
description:
"Compose a bounded backward definition traversal from explicit operation IDs. Native default operation rows are compact summaries; request detailed fields or use paged operand relations for wide nodes. Available over a complete recovered graph or bounded call-rooted projection. Missing defining bodies retain frontier reasons; complete use sets and CFG are unavailable for a projection. Default load/phi cutoffs keep boundaries visible; choose stop_kinds:[] to traverse beyond them. Complete reachability and memory aliases remain unknown.",
},
{
snapshot,
seeds: z.array(z.string()).min(1).max(64),
max_operations: z.number().int().min(1).max(256).default(48),
stop_at: z.array(z.string()).max(128).default([]),
stop_kinds: z.array(kinds).default(["phi", "load"]),
fields,
},
"slice",
'await rea.slice({snapshot:s,seeds:callIds,stop_kinds:["load"],fields:["opcode","inputs","output","constants"]})',
),
code: definition(
{
summary:
"Read selected lines of retained reconstructed code, including when graph capture is unavailable.",
description:
"Read reconstructed code from the same retained function capture, even when its graph facet is unavailable. offset is zero-based. A large limit reads the complete code inside Code Mode for local filtering. The bridge byte budget bounds the result. No additional decompilation.",
},
{
snapshot,
offset: page.offset,
limit: z.number().int().positive().default(64),
},
"code",
"await rea.code({snapshot:s,offset:100,limit:64})",
),
evidence: definition(
{
summary:
"Page complete retained source or decoded graph Evidence with source/view identities and freshness checks.",
description:
"Read complete retained native source in UTF-16-code-unit pages by evidence_id; no reanalysis. component:source preserves exact original wire JSON. component:recovered_ir reads the decoded graph source, including lossless compressed graphs; source hash remains the original capture and view has its own hash/byte count. This is source inspection, not a claim that malformed graph facts are valid. Available until close_binary.",
},
{
evidence_id: z.string().startsWith("ev_"),
component: z.enum(["source", "recovered_ir"]).default("source"),
offset: page.offset,
limit: z.number().int().min(1).max(16384).default(4096),
},
"evidence",
"await rea.evidence({evidence_id:id,offset:0,limit:4096})",
),
};
methods.bytes.input = methods.bytes.input.superRefine((value, context) => {
// Pattern failures need not prevent object refinements from running in Zod.
// Only the named window contract may admit values to exact u64 arithmetic.
const windows = value.windows.flatMap((window) => {
const parsed = byteWindow.safeParse(window);
return parsed.success ? [parsed.data] : [];
});
if (
windows.reduce((sum, window) => sum + window.length, 0) >
MAX_BYTE_BATCH_BYTES
)
context.addIssue({
code: "custom",
path: ["windows"],
message:
"Select at most 64 KiB of bytes per batch; use additional windows/pages in later calls",
});
if (
windows.some(
(window) =>
BigInt(window.address) + BigInt(window.length) > 0xffffffffffffffffn,
)
)
context.addIssue({
code: "custom",
path: ["windows"],
message: "Byte range end exceeds the native u64 address format",
});
});
export const reference = createReference(methods);
+231
View File
@@ -0,0 +1,231 @@
import assert from "node:assert/strict";
import test from "node:test";
import Ajv2020 from "ajv/dist/2020.js";
import { methods, reference } from "./api.mjs";
import { AtomicSession } from "./session.mjs";
const factory = () => {
let sequence = 0;
const calls = [];
const create = async (path) => ({
context: { lease: `lease-${++sequence}`, selected_path: path },
close: async () => {
calls.push("close");
},
cancel: () => {
calls.push("cancel");
},
strings: async (input) => {
calls.push(input);
return { items: [], source: { evidence_id: "ev_real-owner" } };
},
});
return { create, calls };
};
test("path selectors agree in runtime and JSON Schema, without inferred target or string identities", () => {
const validate = new Ajv2020({ strict: false }).compile(
reference("path").methods[0].input_schema,
);
for (const [request, valid] of [
[{ from: 0, target: { kind: "exit" } }, true],
[
{
from: 0,
target: { kind: "block", id: 1 },
avoid: [2, 2],
offset: 1,
limit: 1,
},
true,
],
[{ from: "0", target: { kind: "exit" } }, false],
[{ from: 0, target: { kind: "block" } }, false],
[{ from: 0, target: { kind: "exit", id: 1 } }, false],
[{ from: 0, target: { kind: "exit" }, avoid: [-1] }, false],
[{ from: 0, target: { kind: "exit" }, limit: 129 }, false],
]) {
const input = { snapshot: "snap_test", ...request };
assert.equal(methods.path.input.safeParse(input).success, valid);
assert.equal(validate(input), valid, JSON.stringify(validate.errors));
}
});
test("relation identity and operand-only selectors agree in runtime and advertised schemas", () => {
const validate = new Ajv2020({ strict: false }).compile(
reference("relations").methods[0].input_schema,
);
for (const [request, valid] of [
[{ kind: "operands", seeds: ["0x1:0"], input_indices: [0, 155] }, true],
[{ kind: "operands", seeds: ["0x1:0"], input_indices: [] }, true],
[{ kind: "uses", seeds: ["0x1:0"] }, true],
[
{
kind: "cases",
seeds: ["0x1:0"],
case_values: ["0xffffffffffffffff"],
case_indices: [0, 155],
},
true,
],
[{ kind: "cases", seeds: [0] }, false],
[{ kind: "cases", seeds: ["0x1:0"], case_values: ["0X1"] }, false],
[{ kind: "incoming", seeds: [0] }, true],
[{ kind: "incoming", seeds: ["0"] }, false],
[{ kind: "operands", seeds: [0] }, false],
[{ kind: "uses", seeds: ["0x1:0"], input_indices: [0] }, false],
[{ kind: "operands", seeds: ["0x1:0"], input_indices: [-1] }, false],
]) {
const input = { snapshot: "snap_test", ...request };
assert.equal(methods.relations.input.safeParse(input).success, valid);
assert.equal(validate(input), valid, JSON.stringify(validate.errors));
}
});
test("named contracts reject extra keys and stale leases before provider admission", async () => {
const provider = factory();
const session = new AtomicSession(provider.create);
await session.open("first");
const lease = session.context.lease;
const invalid = await session.call("strings", { query: "x", guessed: true });
assert.equal(invalid.error.code, "invalid_input");
const wrongIdentity = await session.call("relations", {
snapshot: "snap_test",
kind: "incoming",
seeds: ["0"],
});
assert.equal(wrongIdentity.error.code, "invalid_input");
assert.equal(provider.calls.length, 0);
await session.open("second");
const stale = await session.call("strings", { query: "x" }, undefined, lease);
assert.equal(stale.error.code, "stale_context");
assert.deepEqual(provider.calls, ["close"]);
await session.close();
});
test("cancellation after a completed read retains observations under a cancelled outcome", async () => {
const controller = new AbortController();
const session = new AtomicSession(async () => ({
context: { lease: "late-cancel" },
close: async () => {},
strings: async () => {
controller.abort();
return {
source: { evidence_id: "ev_observed" },
items: [{ value: "retained" }],
};
},
}));
await session.open("target");
const result = await session.call(
"strings",
{ query: "x" },
controller.signal,
);
assert.equal(result.ok, false);
assert.equal(result.error.code, "cancelled");
assert.equal(
result.error.details.partial_observation.items[0].value,
"retained",
);
assert.equal(result.context.lease, "late-cancel");
await session.close();
});
test("close drains admitted reads and a failed cleanup retains ownership for retry", async () => {
let release;
let reads = 0;
let closes = 0;
const session = new AtomicSession(async () => ({
context: { lease: "owned" },
strings: () => {
reads++;
return new Promise((resolve) => {
release = resolve;
});
},
close: () => {
if (++closes === 1) throw new Error("cleanup failed");
},
cancel() {},
}));
await session.open("target");
const read = session.call("strings", { query: "x" });
await new Promise((resolve) => setImmediate(resolve));
const close = session.close();
assert.equal(closes, 0);
assert.equal(reads, 1);
release({ items: [] });
assert.equal((await read).ok, true);
await assert.rejects(close, /cleanup failed/u);
assert.equal(session.context.lease, "owned");
await session.close();
assert.equal(session.context, null);
});
for (const action of ["close", "replace"])
test(`failed open retains session file owners through ${action} and cleanup retry`, async () => {
let acquisitions = 0,
cleanupAttempts = 0,
releasable = false;
const primary = new Error(
"Engine inspection failed after acquiring a file",
);
const session = new AtomicSession(async (path, { fileResources }) => {
acquisitions++;
if (acquisitions === 1)
return fileResources.run(async () => {
fileResources.retain({
kind: "lease",
resource: "/selected/engine",
lease: {
release: async () => {
cleanupAttempts++;
if (!releasable) throw new Error("Descriptor remains open");
},
},
});
throw primary;
});
return {
context: { lease: "recovered", selected_path: path },
close: async () => {},
};
});
await assert.rejects(session.open("first"), (error) => error === primary);
assert.equal(session.context, null);
assert.equal(
(await session.call("strings", { query: "x" })).error.code,
"no_target",
);
const retry = () =>
action === "close" ? session.close() : session.open("second");
await assert.rejects(
retry(),
(error) =>
error.code === "cleanup_incomplete" &&
error.details.resources.length === 1 &&
error.details.resources[0] === "/selected/engine",
);
assert.equal(acquisitions, 1, "Unresolved owners block replacement");
assert.equal(cleanupAttempts, 1);
releasable = true;
assert.equal((await retry()).ok, true);
assert.equal(cleanupAttempts, 2);
if (action === "close") {
assert.equal(session.context, null);
assert.equal((await session.open("second")).ok, true);
}
assert.equal(acquisitions, 2);
assert.equal(session.context.lease, "recovered");
await session.close();
assert.equal(cleanupAttempts, 2, "Released owners are not retried");
});
test("cancellation before admission makes no provider query; advertised reference schemas compile", async () => {
const provider = factory();
const session = new AtomicSession(provider.create);
await session.open("target");
const stop = new AbortController();
stop.abort();
const cancelled = await session.call("strings", { query: "x" }, stop.signal);
assert.equal(cancelled.error.code, "cancelled");
assert.deepEqual(provider.calls, []);
const ajv = new Ajv2020({ strict: false });
for (const method of reference().methods) ajv.compile(method.input_schema);
await session.close();
});
@@ -0,0 +1,53 @@
# Calls and values surviving full-graph capacity
The question is `sqlite-boundary-question.txt`. Fix it and this acceptance oracle
before either real-model run. Both lanes use the same complete fourteen-method
API, preserved engine, model/effort request, common guidance and resource limits.
This task requires VM decompilation once per fresh lease; it is different work
from the earlier shallow-reference question. Do not compare their task times as
an adapter speedup. Actual client JavaScript dispatch is available in both lanes.
Artifact: Debian `libsqlite3-0:amd64` version `3.40.1-2+deb12u2`,
`libsqlite3.so.0.8.6`, SHA-256
`2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8`.
The selected VM implementation entry is `0xea6d0`, not its same-name PLT entry.
Pre-model public MCP capture with the new exporter establishes:
- Code is available. Full graph is unavailable with `atomic operation capacity
exceeded`. Calls remain available: 416 retained block-member operations,
consisting of 395 CALL and 21 CALLIND. The 395 direct targets are known, all
21 indirect targets remain unknown. Call-boundary values are available (1,294),
covering targets, arguments and outputs only, with 21,349 operations scanned
over 1,229 recovered blocks. These do not supply a complete definition/use graph.
- At `0xf115c`, recovered call ID `0xf115c:6a84` targets `ram:0x296c0`.
Input zero is `v1000118d6`, `fspec:0x102f4`, annotation true, width 8.
Three recovered inputs use passing storage `register:0x38/8`, `0x30/8`,
`0x10/8` (RDI, RSI, RDX in this verified x86-64 lane).
- At `0xf238b`, call ID `0xf238b:7130` has the same resolved target.
Input zero is `v100012a80`, `fspec:0x1030c`, annotation true, width 8.
Two recovered inputs use passing storage `register:0x38/8`, `0x30/8`.
- Both first arguments are the same snapshot-local SSA value `v30000004b`,
`register:0x38/8`, `is_input:true`, definition null. Other retained argument
values have defining operation IDs outside this boundary view. Exact SSA
identity is supported; source parameter ordinals and general aliases are not.
Independent GNU objdump decoding from the exported VM entry verifies the two
machine CALL targets and register setup. The earlier complete direct-call pair
oracle contains both. Of the 396 physical direct immediate calls, the only one
absent from the recovered 395 is `0xf2493 -> 0x29370` (stack check failure).
The question does not require rediscovering this extra call; the recovered-call
count must not be claimed as complete machine/runtime coverage.
Required final facts: correct selected entry and facet availability/scope; both
call-count groups and target-unknown distinction; both resolved targets separated
from annotation offsets; argument slots/locations; shared first-input identity;
selected machine checks; explicit unreadable definition/use and alias/runtime
limits; real Evidence and subject digest. Do not require the model to report
every additional native metadata counter. Check that its API source arguments
show only one VM analysis and all relevant reads reuse its snapshot/Evidence.
Raw public verification is retained as `facets-v3-mcp.json` and its Evidence
directory under `.cache/atomic-codemode/`. The ordinary VM record (C, mappings,
variables and other ordinary metadata) equals the prior captured engine output.
The independent oracle and precomputed answer are absent from the model workspace.
@@ -0,0 +1,26 @@
# Frozen shared-byte model task
Use the unchanged `native-string-query-question.txt` and all exact target/string/
byte facts in `native-string-query-oracle.md`. The target digest and 4+1 string
objects are unchanged. This phase's pinned engine is `bce4dc97fda99a028aca6b2b40a0a593c87b5224ac9e03221a69313faba2d3e8`,
with both `REA_ATOMIC_NATIVE_STRING_QUERY=1` and `REA_ATOMIC_NATIVE_BYTE_BATCH=1`.
The earlier oracle's engine digest describes its earlier frozen runtime only.
Both query reports remain distinct and each covers 602,544 candidates. A native
byte report may now contain several requested windows with one shared source ID;
source_row identifies a native window row, not the caller's ordinal after reuse.
Repeated or reordered ranges may refer to the same original row. Fewer distinct
byte Evidence IDs are valid when the cited source actually covers every claimed
window. Counts/hex and provenance must remain exact. Focused covering reads are
still allowed. Do not require ten commands or unique source IDs per window.
Grade complete original answers, all cited source hashes/contexts, raw byte
payloads and actual source-window reads. Keep failed calls and all costs, with no
answer repair or winning retry. Direct and Code Mode use the same 19 methods,
question, model/reasoning, static authority and resource controls; actual Code
Mode MCP execution must be observed. Report cumulative tokens, cached/uncached
input, output/reasoning, schemas/help/calls/retries, wall, local CPU and kernel
family peak. Actual clients have common JavaScript dispatch. Remote costs and
resolved model builds are unmeasured. One run per lane does not establish broad
RE superiority; historical model results use a different pinned runtime, while
the SDK acquisition-toggle comparison uses the same current engine and code.
@@ -0,0 +1,99 @@
# Shared native byte reads: checkpoint
The user cleared the active goal after implementation and real preflight.
Work stopped before new model trials. No PR or merge into main is requested.
Main was refreshed to `5112fe07a` in `2dc3820b6`. LeanToken returned not_indexed
for this experimental path; scoped native reads were used instead.
Opt in with `REA_ATOMIC_NATIVE_BYTE_BATCH=1` and an exact experimental native
engine pin. Unset/0 preserves single-window acquisition. The 19 shared methods,
22 Direct tools and four Code Mode tools are unchanged. The byte batch reads
only selected static loaded-image ranges; no target execution or modification.
`disassemble/kuna_batch.rs` shares one existing ConsoleProgram load, range
resolution, mapped-end clipping and data renderer across at most 16 windows /
64 KiB selected bytes. It rejects ignored options and bounds encoded output
against the existing 8 MiB capture ceiling. Each native row retains its exact
request, ordinal and success or window_unavailable error. Global load or report
encoding failure fails explicitly. The old read path can initialize again when
a bounded anonymous region lacks a name; this is source-derived reasoning, not
a measured count of internal translator initialization.
`NativeByteBatchReads` caches validated exact address/length facts for this target
lease, deduplicates missing ranges, batches only missing work and preserves caller
order. Source + source_row identify a window in retained raw Evidence; duplicates
or reordered calls can share that row. Partial reads remain partial. Successful
siblings survive bad per-row data; global failures preserve cached facts. Transient
capture failures are not cached here. Close clears the cache. Its retained entries
are bounded by source admission (128 sources times at most 16 windows); no global
cache or live-memory freshness claim is added.
Old and new byte reports use one normalization owner. Exact JSON numeric tokens
preserve u64 aliases and reject rounded fractional counters, with shared KunaJson
support; alias disagreements fail instead of publishing contradictory facts.
Original-file mapping and runtime memory remain unknown/not-observed.
## Executed evidence
- Native disassemble tests: 15 passed, including the two new protocol/budget tests.
- Runtime build passed; final experimental JS tests: 128 passed.
- Kuna reference files/ranges boundary tests: 27 passed.
- Changed-file lint/format, module boundaries, affected-source typecheck and
converted actual MCP schema/catalog checks passed.
- Real SDK, Direct and Code Mode LLVM checks passed all prior five literal-query
goldens, paging, projection, exact ten independent byte windows and 13 complete
retained source hashes per lane.
- Both actual MCP adapters passed SQLite mixed success/error, short reads,
repeated exact windows and the full 64 KiB request.
- Same-engine SDK comparison passed reordered/duplicate reuse, mixed cached/new
windows, all raw hashes and stale Evidence rejection after reopen.
- Actual producer cancellation preserved cached facts in partial_observation,
allowed a fresh retry and completed owned cleanup. Target bytes were unchanged.
The existing full repository typecheck memory refusal is not a pass. No full
check:fast/check:pr, full native workspace gate, new architecture/provider parity,
or new real-model result is claimed for this phase. Earlier model outcomes retain
their own immutable revisions. The prepared byte-batch oracle is unexecuted by models.
## Same-engine acquisition comparison
Both runs use engine `bce4dc97fda99a028aca6b2b40a0a593c87b5224ac9e03221a69313faba2d3e8`, the same LLVM artifact and independent
file oracle. Only acquisition is toggled between 0 and 1. Cold means a new lease,
not dropped OS caches. These are single scripted observations with no model tokens.
| Phase | Single-window ms / CPU s | Batched ms / CPU s |
| --------------------------- | -----------------------: | ------------------: |
| cold_ten_windows | 94269.834 / 94.110456 | 8505.789 / 8.488729 |
| warm_reordered_duplicates | 2.598 / 0.002657 | 10.494 / 0.010407 |
| mixed_cached_and_new_window | 6385.777 / 6.374731 | 6446.780 / 6.438594 |
Cold ten-window retrieval drops from about 94.3 to 8.5 seconds. The warm sample
is slower in the batch run; it is retained without claiming a warm speedup.
New unseen windows still incur program initialization. The old workflow retains
11 native sources for the completed task; batching retains two.
| Whole task | Wall s | Local family CPU s | Kernel family peak MiB |
| ------------ | ------: | -----------------: | ---------------------: |
| before | 102.304 | 101.898599 | 861.9 |
| after | 16.533 | 16.327818 | 858.1 |
| cancellation | 15.324 | 15.107833 | 862.8 |
Counters are verified at payload exit while the observer lives, not final whole-
scope counters. Memory includes charged file cache. Heavy work was serial, one
CPU, hard 4 GiB/no swap, with early stopping at 3 GiB (3.25 GiB for builds).
The first compiled native version was replaced before real provider verification
to distinguish request_address_hex from numeric native address aliases; original
builds/logs remain. No failed run was relabeled as passing.
## Reproduction anchors
The canonical native patch targets Kuna `fe01d6294eb0d1053ce343c8943646df88e143fc`.
Binaries, captures and explicit provider settings remain ignored. Source patch
SHA-256: `56d2cd197bfcab9566c055c32ee0aece4805c7708f0a0117a8fa06a768969055`.
- `native-byte-batch-before-v1.json`: `ec7c9ab21ef91ff6f965d8e6efc9da97c4a6593d19fde660ba5cb2b1c4459dcb`.
- `native-byte-batch-after-v1.json`: `9737291a03ad7c12700bf124134c4c06d4ef5beb8c31dda102eaa5ae0752aa47`.
- `native-byte-batch-cancellation-v1.json`: `6dd58baed164df0747573b143c31f01d12d5d697ca7c3ff4813b545c355d0d18`.
- `native-byte-batch-llvm-sdk-v1.json`: `04d2ee586f376c41d86d1e9c4508c6b84fcb04d71b7ce2aab6b2580169367a1e`.
- `native-byte-batch-llvm-direct-v1.json`: `53be8d5e5ce0f70d015be98d7ac0b500702fb414bd7a0b41be023a660717eff0`.
- `native-byte-batch-llvm-codemode-v1.json`: `d94e171953fcc86a09b38e730564fae0d42068e1d2ac59b5547bd3c4837d5d42`.
+141
View File
@@ -0,0 +1,141 @@
// Native loaded-image data is not instruction decoding or original-file mapping.
import { z } from "zod";
import { FactFailure } from "./fact-error.mjs";
import { MAX_BYTE_BATCH_BYTES, NATIVE_OUTPUT_BYTES } from "./limits.mjs";
import { parseKunaJson } from "../../dist/kuna/KunaJson.js";
const hex = z.string().regex(/^0x(?:0|[1-9a-f][0-9a-f]{0,15})$/u);
const payload = z.string().regex(/^(?:[0-9a-f]{2})*$/u);
const header = z.object({
binary: z.string(),
kind: z.literal("data"),
start_hex: hex,
end_hex: hex,
start: hex.optional(),
end: hex.optional(),
target: z.object({ address: hex, address_hex: hex }).optional(),
count: z
.number()
.int()
.nonnegative()
.max(MAX_BYTE_BATCH_BYTES / 16),
bytes: z.number().int().nonnegative().max(MAX_BYTE_BATCH_BYTES),
hex: payload,
truncated: z.boolean(),
notes: z.array(z.string()),
});
const row = z.object({
address: hex.optional(),
address_hex: hex,
size: z.number().int().min(1).max(16),
bytes: payload,
});
const requireFact = (valid, message) => {
if (!valid) throw new FactFailure("invalid_provider_output", message);
};
export function parseByteFacts(text, inputPath, request) {
try {
requireFact(
Buffer.byteLength(text) <= NATIVE_OUTPUT_BYTES,
"Byte source exceeds capture capacity",
);
return normalizeByteFacts(parseByteSourceJson(text), inputPath, request);
} catch (error) {
throw byteFailure(error);
}
}
export function parseByteSourceJson(text, integerKeys = []) {
return parseKunaJson(
text,
NATIVE_OUTPUT_BYTES,
new Set(["start", "end", "address"]),
new Set(["count", "bytes", "size", ...integerKeys]),
);
}
export function normalizeByteFacts(raw, inputPath, request) {
try {
requireFact(
Array.isArray(raw?.rows) && raw.rows.length <= MAX_BYTE_BATCH_BYTES / 16,
"Byte rows exceed capacity or have invalid shape",
);
const doc = header.parse(raw);
requireFact(
(doc.start === undefined || doc.start === doc.start_hex) &&
(doc.end === undefined || doc.end === doc.end_hex) &&
(doc.target === undefined ||
(doc.target.address === doc.start_hex &&
doc.target.address_hex === doc.start_hex)),
"Byte address aliases disagree",
);
requireFact(
doc.binary === inputPath && doc.start_hex === request.address,
"Byte source names a different target/window",
);
requireFact(
doc.bytes <= request.length && doc.count === raw.rows.length,
"Byte source exceeds the request or disagrees with row count",
);
let end = BigInt(request.address);
const pieces = raw.rows.map((value, index) => {
const item = row.parse(value);
requireFact(
item.address === undefined || item.address === item.address_hex,
"Byte row address aliases disagree",
);
requireFact(
BigInt(item.address_hex) === end && item.bytes.length === item.size * 2,
"Byte row address/length is inconsistent",
);
requireFact(
index === raw.rows.length - 1 || item.size === 16,
"Nonfinal byte row is not the declared native width",
);
end += BigInt(item.size);
return item.bytes;
});
requireFact(
end === BigInt(doc.end_hex) &&
end - BigInt(request.address) === BigInt(doc.bytes) &&
pieces.join("") === doc.hex &&
doc.hex.length === doc.bytes * 2,
"Byte rows, payload and extent disagree",
);
return {
hex: doc.hex,
returned_bytes: doc.bytes,
end_address: doc.end_hex,
coverage: {
authority: "native loaded-image bytes",
requested_bytes: request.length,
status:
doc.bytes === request.length
? "complete-for-requested-range"
: "partial",
provider_truncated: doc.truncated,
notes: doc.notes,
original_file_mapping: "unknown",
runtime_memory: "not-observed",
},
};
} catch (error) {
throw byteFailure(error);
}
}
function byteFailure(error) {
return error instanceof FactFailure
? error
: new FactFailure(
"invalid_provider_output",
"Native byte window does not match the declared format",
{
reason:
error instanceof z.ZodError
? error.issues[0]?.message.slice(0, 256)
: String(error.message).slice(0, 256),
},
);
}
@@ -0,0 +1,128 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseByteFacts } from "./byte-facts.mjs";
import { AtomicSession } from "./session.mjs";
const make = () => ({
binary: "/input",
kind: "data",
start_hex: "0x20000000000001",
end_hex: "0x20000000000005",
count: 1,
bytes: 4,
hex: "00417fff",
truncated: false,
notes: [],
rows: [
{
address_hex: "0x20000000000001",
size: 4,
bytes: "00417fff",
},
],
});
const request = { address: "0x20000000000001", length: 4 };
test("byte facts keep exact u64 extents, null/nontext bytes and loaded-image authority", () => {
const facts = parseByteFacts(JSON.stringify(make()), "/input", request);
assert.equal(facts.hex, "00417fff");
assert.equal(facts.end_address, "0x20000000000005");
assert.equal(facts.coverage.status, "complete-for-requested-range");
assert.equal(facts.coverage.original_file_mapping, "unknown");
assert.equal(facts.coverage.runtime_memory, "not-observed");
const clipped = parseByteFacts(JSON.stringify(make()), "/input", {
...request,
length: 5,
});
assert.equal(clipped.coverage.status, "partial");
const flagged = make();
flagged.truncated = true;
assert.equal(
parseByteFacts(JSON.stringify(flagged), "/input", request).coverage.status,
"complete-for-requested-range",
);
});
test("wrong byte subject, contradictory duplicated payload, gaps and counts fail before publishing facts", () => {
for (const mutate of [
(d) => (d.binary = "/other"),
(d) => (d.kind = "code"),
(d) => (d.hex = "00417f00"),
(d) => (d.rows[0].address_hex = "0x20000000000000"),
(d) => (d.rows[0].size = 3),
(d) => (d.end_hex = "0x20000000000006"),
(d) => (d.count = 2),
(d) => (d.rows = Array(4097).fill(null)),
]) {
const document = make();
mutate(document);
assert.throws(
() => parseByteFacts(JSON.stringify(document), "/input", request),
{ code: "invalid_provider_output" },
);
}
const empty = make();
Object.assign(empty, {
hex: "",
rows: [],
count: 0,
bytes: 0,
end_hex: request.address,
});
assert.equal(
parseByteFacts(JSON.stringify(empty), "/input", request).coverage.status,
"partial",
);
});
test("byte input capacity, malformed addresses and u64 end overflow reject before native admission", async () => {
let reads = 0;
const session = new AtomicSession(async () => ({
context: { lease: "bytes" },
bytes: () => {
reads += 1;
},
close: () => {},
}));
await session.open("/input");
try {
for (const windows of [
[{ address: "invalid", length: 1 }],
[{ address: "0xffffffffffffffff", length: 1 }],
[
{ address: "0x1000", length: 65536 },
{ address: "0x2000", length: 1 },
],
[{ address: "0x1000", length: 0 }],
]) {
const result = await session.call("bytes", { windows });
assert.equal(result.error.code, "invalid_input", JSON.stringify(result));
}
assert.equal(reads, 0);
} finally {
await session.close();
}
});
test("byte aliases and kept counters are validated from exact numeric source tokens", () => {
const raw = JSON.stringify({
...make(),
start: "9007199254740993",
end: "9007199254740997",
target: { address: "9007199254740993", address_hex: request.address },
rows: [{ ...make().rows[0], address: "9007199254740993" }],
})
.replaceAll('"9007199254740993"', "9007199254740993")
.replaceAll('"9007199254740997"', "9007199254740997");
assert.equal(parseByteFacts(raw, "/input", request).returned_bytes, 4);
for (const invalid of [
raw.replace('"count":1', '"count":1.0000000000000000001'),
raw.replace('"bytes":4', '"bytes":4e0'),
raw.replace('"size":4', '"size":4.0000000000000000001'),
raw.replace('"start":9007199254740993', '"start":9007199254740992'),
raw.replace('"end":9007199254740997', '"end":9007199254740996'),
raw.replace('"address":9007199254740993', '"address":9007199254740992'),
])
assert.throws(() => parseByteFacts(invalid, "/input", request), {
code: "invalid_provider_output",
});
});
@@ -0,0 +1,64 @@
# Cross-function context experiment: pinned question and oracle
This is an experiment acceptance oracle, unavailable to the isolated model.
The question is `sqlite-call-question.txt`. Fix this question and the required
facts before launching either model lane. Both adapters expose the same complete
fourteen-method fact API; Code Mode has four MCP tools, direct has seventeen.
Use the same pinned engine, artifact, model request, reasoning effort, common
envelope guidance, fresh target leases and resource limits. Do not change runtime
sources or HEAD during the model batch. One sample per lane cannot establish a
general advantage, and the client itself already offers JavaScript dispatch in
both lanes. This comparison isolates the server calling adapter, not all forms of
composition or a traditional provider workflow.
The artifact is the local Debian ELF `libsqlite3.so.0.8.6`, SHA-256
`2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8`.
Independent GNU objdump decoding from the function entries covers `0x64060`
through `0x65400`; existing earlier captures independently pin the same flow.
No target execution or source-code answer is used.
Required facts for an equal completed answer:
- Wrapper entry `0x65180`; direct machine CALL `0x65211` targets internal helper
`0x64060`. The recovered call operation has an fspec annotation as input zero;
that annotation's offset is not the target address.
- Caller LEA `0x65201` passes post-prologue `RSP+0x20` in RDI. Structured passing
storage is `register:0x38`, width 8. The SSA argument and the callee's retained
input are separate snapshot-local identities; matching their storage supplies a
candidate connection. The direct machine transfer and pointer setup support
this particular connection. Do not globally infer source parameter ordinal,
alias completeness or runtime binding from a slot number or a name.
- The helper preserves the input context pointer in RBP. Its 32-bit field at
context offset `0x30` is incremented at `0x64693`/`0x64696`/`0x64699` for an
opening parenthesis and decremented at `0x64c92` for a closing parenthesis.
The parser's token/branch context must support the parenthesis interpretation;
an ADD/SUB instruction alone does not identify the meaning of a field.
- In the wrapper this is `[RSP+0x50]`, initialized to zero with the other context
tail fields. After helper return zero, LOAD `0x65268` and TEST/JZ
`0x65270`/`0x65272` check it. Zero skips the malformed block; nonzero frees the
expression at `0x65274`, clears its output pointer at `0x65279`, then reaches
the malformed diagnostic at `0x65281` through formatter call `0x65290`.
- Return-code-one errors can also reach the malformed block, via
`0x65239`/`0x6523c`; return code 18 selects a separate depth-limit diagnostic
at `0x65330`. No demonstrated runtime-feasibility or full memory-alias claim.
The producer verifier additionally checks two formatter call targets:
`0x5f031 -> 0x2adc0` (free PLT) and `0x5f062 -> 0x27e50` (vmprintf PLT), whereas
their input-zero fspec offsets are `0x10000`/`0x10001`. Resolving these PLT entries
to runtime implementations is outside this task.
Native producer fidelity is checked against previously retained captures of all
three functions: C, ordinary metadata/line mappings, blocks, operations, values
and coverage are identical. Only schema version and structured call records are
added. Older sources used pretty JSON; their smaller/newer encoded sizes must
not be attributed to the call exporter. The earlier compact-writer change is a
separate experiment. Unsupported old schema graphs remain unavailable with valid
C retained, rather than acquiring guessed call records.
The first paired question runs at `01e5c5955` both explain the primary state flow
correctly but omit the oracle's separate return-1/return-18 distinctions. Because
the initial question did not explicitly enumerate those codes, the next round
clarifies that requirement in `sqlite-call-question.txt` before either lane
starts. The required facts and independent oracle stay unchanged. Earlier
questions and costs remain pinned to their original commits; neither incomplete
sample is counted as a full-oracle success.
@@ -0,0 +1,141 @@
# Capability and comparison scope
The experiment has nineteen fact methods behind a shared SDK/CLI owner, exposed
as twenty-two direct MCP tools or four Code Mode tools. The structured IR/call/
projection/switch facts require the explicitly pinned experimental Kuna patch;
they are not capabilities added to stock Kuna or integrated REA by registration
alone. Other providers are not wired to this experimental service.
A fair completed-task comparison first needs sufficient facts on both paths,
with a common correctness oracle. A complete universal RE interface is not
established here. The selected-case question requires native row/edge identities,
so it compares the two atomic adapters; no traditional-provider result for that
question is invented. Earlier traditional comparisons retain their own questions,
engine profiles and limitations in [the trial record](trials.md).
| Analyst question | Composable facts/relations | Executed evidence and limits |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Which implementation owns an observed message? | Callable entries/aliases, encoded strings, exact-address xrefs with occurrence identity and function attribution | Both recent SQLite tasks select the owner before capture. Name equality alone is insufficient; discovery/unattributed coverage remains explicit. |
| Which local condition controls a selected value/call? | Snapshot-local operations, SSA values, indexed operands, definitions/uses with PHI predecessor edges, recovered CFG edges | [Four real control-task runs](savepoint-control-study.md) verify the selected guards and machine instructions. [Full graph transport checks](native-graph-transport-study.md) establish producer fidelity, not global machine equivalence. |
| What crosses a call boundary? | Native call specifications, argument values and separate passing storage; selected callee inputs and bounded definition projections | Earlier pinned [call/boundary trials](trials.md) exercise these relations. Storage matches are candidates, not proof of runtime binding or complete ABI/memory effects; a new exporter hash alone is not a repeated cross-function model trial. |
| Which cases map to a recovered edge? | Original case identity/label/address, independent native default, flattened case/out-edge relations | [All 182 SQLite original targets](switch-study.md) match independent ELF table bytes. Four real models answer selected cases and distinguish the native default from the machine range guard. No complete case inventory is needed in model context. |
| What machine bytes support the interpretation? | Batched loaded-image bytes and selected linear instruction windows, each with source/coverage | The case models independently derive signed relative targets. These windows do not establish runtime execution/alignment, a complete machine CFG, live memory or arbitrary file-offset mappings. |
| Can the answer be audited without returning the report? | Snapshot/source identity, selected fields, batch reads, paging and retained raw/decoded Evidence | Real CLI/MCP checks verify source access and capacity fallbacks. Scope/partial/unknown survive composition; a guest-derived answer keeps its own authority. |
The [string-span experiment](string-span-study.md) extends exact xrefs with
batched incoming target-coordinate spans. It preserves all eleven selected
SQLite data occurrences, including nine pooled suffix pointers, with individual
endpoints/owners and raw source rows. Kuna already had aggregate string-span
counts; the new occurrence query shares its sparse index. Range membership alone
does not establish whole-string use, access overlap or runtime behavior.
Three real models complete the pooled-string task. The traditional original
inventory has a partial source audit after client truncation; atomic source
captures are fully checked. Code Mode's cumulative input/time improve in this
sample, while uncached input and memory exceed Direct. This remains task evidence,
not provider parity or a stable adapter advantage.
The useful grain so far is an identified object plus a relation with its exact
qualifiers: an operand needs its slot and PHI binding; a case/out-edge pair needs
both identities; an address needs its artifact/address space; an optimized
operation needs its snapshot and representation. One small JSON row is not
automatically one independently meaningful fact. Machine instructions and
normalized operations also cannot substitute for each other.
An identified object may still contain a huge field. The [capacity study](large-result-study.md)
adds string metadata selection and pre-allocation transport accounting with
recoverable source handles. Real SDK/MCP checks cover both escaping layers and
in-program recovery. In the frozen model pair, Code Mode passes; Direct reports
17-byte prefixes as 16 despite correct provider data. Preserve that failure;
the pair cannot rank efficiency at matched correctness. Native capture still
reads the complete bounded inventory, so small replies alone do not establish
scalable producer work. The [streamed inventory experiment](streamed-inventory-study.md)
restores FFmpeg queries over a 16.8 MB source with bounded files and the production
parser. Both corrected real-model answers pass with all sources checked; setup
failures remain in the ledger. Costs are mixed, and LLVM/Node still exceed the
unchanged 64 MiB retained-source ceiling.
Selection, projection, batching, paging and bounded traversal compose those
facts. The analysis owner derives/validates relations; Code Mode selects and
combines them. A query can be fine-grained even when its fresh native capture
still computes a whole function. Same-lease reuse is measured separately from
that work and does not establish a cross-session cache or native acceleration.
The [control-query study](control-query-study.md) independently verifies all
2,845 control-dependence triples in the real SQLite VM through both MCP adapters.
Two real models also complete a two-level controller/SSA/path-witness task and
distinguish alternative predicates from conjunction. Unknown CFG seeds are
explicit, and the snapshot owner reuses a bounded lazy postdominator index.
Code Mode has lower cumulative input but higher uncached input and runtime costs
in that pair; precise derived facts do not imply a preferred calling adapter.
The [OpenSSH value-query study](value-query-study.md) adds exact location lookup
and inverse operand occurrences for value identities, including inputs/constants
without definitions. It checks every retained selected version/use against the
complete source graph; this is separate from machine-byte evidence and does not
turn SSA occurrences into a memory-alias proof.
The [stripped OpenSSH model comparison](ssh-warning-study.md) also verifies a
common warning/caller/stack/guard question through the two atomic adapters and
the traditional Kuna workflow. Exact machine facts suffice for the direct
answer; extra SSA capture is not required by every RE question. The corrected
traditional baseline has its complete declared native toolset. This expands
the completed-task evidence while retaining the local scope and cost confounds.
Memory alias dependencies, full machine-flow recovery, indirect runtime binding,
feasible paths and nontermination remain unknown. The current evidence does
not establish provider parity, broad complex-software superiority or a stable
Code Mode cost advantage. The [wait repeat](client-wait-study.md) shows why fewer
MCP requests or polls cannot replace correct answers and whole-task costs.
The [path query](path-query-study.md) composes selected recovered edges into one
paged witness under explicit exclusions, with zero-edge/not-found/unknown
outcomes. Both real SQLite MCP lanes preserve every original edge field; complete
native function fidelity is checked. This removes an observed graph-reading
burden without establishing feasible runtime paths or an adapter cost advantage.
The completed path-query pair answers the unchanged two-level task correctly in
both actual models; each uses four path reads and three selected block reads,
without a complete graph inventory in model context. Direct and Code Mode have
similar wall time with mixed token/resource costs. Stock 1.833 explicitly rejects
the unsupported path query while preserving readable Evidence/code in a real SDK
check. These are scoped observations, not stock-provider parity or complete
runtime reachability coverage.
The [function-boundary study](function-boundary-study.md) adds independent native
prototype entries/return descriptors. On real stripped SSH, prototype counts
4/10 differ from raw input counts 3/44; both actual models preserve that distinction,
all exact matches/missing tuples and the selected caller-to-callee/helper transfer.
Call-passing storage is separate from the caller value's own coordinate. Native
model labels and recovered entries do not prove original source arity/ABI.
Complete old function fidelity is preserved except for the new facet. Actual
old-native/stock checks return explicit unavailability with readable Evidence.
The two completed model tasks have mixed token/time/resource costs; no stable
Code Mode advantage or provider parity follows.
The [storage study](storage-study.md) exposes native address-space descriptors
and exact varnode_xref names without function decompilation. Width-qualified
coordinates compose with prototype/value/passing-storage facts. Real x86-64
and AArch64 OpenSSH catalog checks do not establish big-endian, alias, runtime
or full provider parity coverage.
Both real models complete the extended native storage/prototype/call task.
Code Mode reduces cumulative/uncached input and wall time in that pair but uses
more local CPU and more inner fact reads. The shared metadata capability is
verified separately from this adapter observation; earlier mixed pairs remain.
The [AArch64 reference study](aarch64-xref-study.md) corrects an observed native
ADRP+ADD/LOAD/STORE gap through the shared PC-relative value owner. Real arm64
SSH checks verify both warning owners, callers, selected machine words and
77 GOT-slot reads. Coverage stays bounded and does not propagate live GOT
contents. Traditional C/assembly preflight can answer the same new behavior-level
question, avoiding a baseline missing necessary facts. All three real models
complete it, while token/time/resource tradeoffs remain mixed. That pinned run
preserves the recovered no-return disagreement and uses machine facts for the
post-call path.
The [return-coverage study](aarch64-return-study.md) fixes the BTI entry split
and a separate false no-return promotion through the native owners. The fresh
three-way task passes with the strict call restored in both atomic captures;
their complete selected function documents agree. Direct has lower input,
time and CPU than Code Mode in this sample. Memory, analysis-profile differences,
the common client executor and n=1 sampling prevent a universal adapter claim.
@@ -0,0 +1,132 @@
# Reuse proven native source refusals
After the streamed-inventory model pair, main was fetched again and remained
`150e996a8`. Baseline runtime is `b88c75df8`. Native engine remains
`2e398e7229e30b6d2387a802db8a0050764119a6b457020d334855e36e69d6c5`.
This is an experimental follow-up, with no PR or integration into main.
## Observed redundant work
Two identical real LLVM string queries in one target lease first hit the 64 MiB
source ceiling after 8.363 seconds. The second still runs native analysis for
3.024 seconds / 3.021736 CPU seconds, retaining another partial prefix and
reporting cleanup uncertainty. The provider discarded every failed work entry,
even a proven output-size refusal for the identical immutable native capture.
The source budget cannot grow within that lease. Neither query produces valid
string facts; absence must remain unknown.
The same two-request probe after the change takes 7.603 seconds for the first
refusal and 1.528 ms / 0.001567 CPU seconds for reuse. Only one partial source is
captured, with the same readable Evidence handle on both errors. The added
`cached_observation:{kind:"source_budget_refusal",scope:"target_lease"}` labels
the original observation being reused; it does not report a fresh native run or
current process status. Cold-time variation is not a causal speed claim.
| Same two-request diagnostic probe | Wall s | Local family CPU s | Kernel family peak MiB |
| --------------------------------- | -----: | -----------------: | ---------------------: |
| Before | 12.406 | 12.192070 | 1,745.6 |
| After | 8.579 | 8.364375 | 1,492.5 |
This compares the same diagnostic intent, not successful LLVM analysis. The
second original attempt adds a cleanup-uncertainty failure, whereas reuse keeps
the original proven resource refusal without starting another process. Different
cold costs and transient ownership observations prevent a pure latency ratio or
general memory/speedup claim. The decisive signal is avoided native work.
## Cache ownership and invalidation
`NativeCaptureCache` owns pending/completed native work in one provider lease.
It replaces the old map wrapper. It retains a refusal only for the understood
`FactFailure` resource code, native-source scope, positive safe byte limit and
observed lower bound above that limit, with a retained partial source ID and
only the six understood refusal fields. Secondary file-cleanup uncertainty and
unexamined metadata also prevent reuse. Classification copies own data properties without
invoking getters; unknown/primitive failures retain their original identity.
Cancellation, I/O, cleanup uncertainty, other resources and unproven constraints
remain uncached. The cache never turns an unknown primary cleanup outcome into
resource success. Error views are separate from the immutable retained refusal,
so editing an SDK error cannot alter later Evidence IDs or limits. At most the
existing 128-source policy's number of work entries is memoized. When that table
is full, new producer results still return without adding retention; the shared
application owner continues to bound native admission. This also bounds any future source/key aliases. No additional source budget is introduced.
Keys keep the existing native request inputs, with target/engine/profile fixed
by the owner instance. Catalog selectors do not change native capture arguments.
Cache validity follows the immutable artifact capture and nonincreasing source
budget, not live state. Successful captures retain the previous reuse semantics;
close clears the cache after confirmed resource cleanup. A new lease gets a new
owner. No cross-session negative cache is claimed.
## Actual adapters, failures and verification scope
Real LLVM SDK and Direct MCP checks pass refusal reuse, unchanged target/lease,
identical refusal details except the explicit reuse label, one raw source,
readable partial Evidence and exact full raw digest. SDK warm latency is 2.282 ms
/ 0.001675 CPU seconds; Direct is 6.412 ms / 0.005566 CPU seconds. Their fresh
first calls take 7.350 / 7.756 seconds respectively.
The first scripted Code Mode check fails its cache-hit precondition because the
first call reports `cleanup_incomplete`. It correctly does not reuse that
uncertain failure, and the second native attempt takes about 2.905 seconds.
Both partial raw captures independently validate target/engine/hash/length. The
original verifier recorded phases/stack but placed the complete API observation
after its assertions, so the failed API payload is not fully auditable. Preserve
that limitation and the original failed receipt; do not relabel it a pass.
The verifier now records replies before assertions and stops if cleanup is
uncertain. One fresh scripted coverage repeat then reaches the proven-refusal
path. In one actual MCP execution, the guest calls strings twice and Evidence
once: the second call is 3 ms by guest `Date.now` (millisecond precision, separate
warm CPU unmeasured), with the same handle and exactly one raw source. The full
8.126-second program uses 8.119767 local CPU seconds. The two error results remain
errors; successful composition does not establish successful LLVM analysis.
This is a scripted coverage repeat after a verifier correction, not another
model answer or a replacement for the failed observation.
| Whole verifier | Wall s | Local family CPU s | Kernel family peak MiB | Result |
| ---------------------------------------- | -----: | -----------------: | ---------------------: | ---------------------------------- |
| SDK refusal + reuse + Evidence | 9.092 | 8.908659 | 1,516.8 | pass |
| Direct MCP same task | 9.886 | 9.666791 | 1,635.9 | pass |
| First Code Mode attempt | 12.909 | 12.680445 | 1,939.9 | cache-hit precondition unavailable |
| Corrected Code Mode coverage repeat | 10.088 | 9.885309 | 1,698.8 | pass |
| Capacity + partial source + cancellation | 9.885 | 9.632806 | 1,487.4 | pass |
Both Code Mode attempts cost 22.997 family-wall seconds / 22.565754 CPU seconds;
peak across them is 1,939.9 MiB, not the sum of peaks. These receipts are not a
matched adapter performance ranking: verifier work and failure paths differ.
All are one-CPU, 3 GiB early-stop / 4 GiB hard-limit, no-swap runs; payload-exit
observers verify cleanup and OOM=0, including the failed attempt. Final exited-
cgroup counters are unavailable. Kernel family memory includes file cache.
All 116 experimental JS tests pass, including in-flight reuse, invalidation,
mutable caller views, zero/false/null/unknown errors, noncacheable cleanup,
accessor avoidance and bounded memo admission. Real FFmpeg selected facts,
Evidence, bytes and stale-handle checks pass in SDK/Direct/Code Mode after the
cache change. Cancellation/owned cleanup checks pass. Changed-file lint and
format checks pass. After tightening the sealed-source/secondary-cleanup eligibility guard, the full
116-test suite passes again, and captured SDK/Direct/Code Mode refusal DTOs all
pass through that sealed contract in replay. That replay is a production-boundary
check, not another live-provider or model run. Existing full-suite/resource-gate
limitations from the
[streaming study](streamed-inventory-study.md) remain. No new model trial was
performed for this cache change; the earlier fixed-runtime model costs remain
attached to that earlier runtime. Scripted probes consume no model tokens.
LLVM and Node inventories still exceed the source budget. This optimization
makes known refusal cheap; producer-side selective computation remains the next
coverage/computation question. It does not improve provider parity or prove
complex reverse-engineering superiority.
Local artifact SHA-256 (raw documents remain uncommitted):
- `capacity-cache-before.json`: `68fbd4444c81b4a4435a8d300f8b1ea7365f140078ab3cc322bde140be74db24`
- `capacity-cache-after.json`: `66491d37d85c3748578022e0f7e0f8013c2bf19ecec6d0c73db33d2246c7485e`
- `capacity-cache-before.log`: `d57684ede8f9d01bf9750b78f400b4bb529e2d7a23b84195d79d6d729cba6190`
- `capacity-cache-after.log`: `30039f832930680a8cc128c8a372c0018be08c88ac84e4db03d2cc15e4623b38`
- `capacity-cache-final-sdk.json`: `95326d584a88ca5130e79e116b5c0a14bdbaa0a6016342d58010515e8a6c22f9`
- `capacity-cache-final-direct.json`: `ead7e2c5976e13876d1d34cd336e88f62a2e9bba4b3812bc012efbc64d272473`
- `capacity-cache-final-codemode.json`: `8bb64217d52bdbd1771968b9274d6ae04a6ea3b0ae1e5a09d0510bf180320e7b`
- `capacity-cache-final2-codemode.json`: `4ccf81f282a2f62db00638b6a94feaf80992aacc8096ea15d3fc419f0d2789a3`
- `capacity-cache-js-precommit.log`: `d22b3e948baf2a36ae262786d470af0fc3d631ddd79d88a879ac9f2103352792`
- `capacity-cache-js-sealed.log`: `004ffeac2994612f1608fd5904eff15c41ea059d4ad91644abce8532669a5ea0`
+123
View File
@@ -0,0 +1,123 @@
import { freezeFacts as freeze } from "./fact-reads.mjs";
import { nativePage } from "./native-reads.mjs";
function search(outgoing, from, target, avoid) {
const blocked = new Set(avoid);
if (blocked.has(from) || (target.kind === "block" && blocked.has(target.id)))
return {
status: "not-found",
end: null,
items: [],
examined_blocks: 0,
examined_edges: 0,
search: "excluded-endpoint",
};
const queue = [from],
predecessor = new Map([[from, null]]);
let examined_blocks = 0,
examined_edges = 0;
for (let cursor = 0; cursor < queue.length; cursor++) {
const current = queue[cursor],
edges = outgoing.get(current) ?? [];
examined_blocks++;
if (target.kind === "block" ? current === target.id : edges.length === 0) {
const path = [];
for (let at = current; predecessor.get(at) !== null;) {
const edge = predecessor.get(at);
path.push(edge);
at = edge.from;
}
path.reverse();
return {
status: "found",
end: current,
items: path.map((edge, step_index) => freeze({ ...edge, step_index })),
examined_blocks,
examined_edges,
search: "shortest-witness",
};
}
for (const edge of edges) {
examined_edges++;
if (!blocked.has(edge.to) && !predecessor.has(edge.to)) {
predecessor.set(edge.to, edge);
queue.push(edge.to);
}
}
}
return {
status: "not-found",
end: null,
items: [],
examined_blocks,
examined_edges,
search: "reachable-subgraph-exhausted",
};
}
// Consume validated identities/edges, never provider text or machine predicates.
// A resident immutable graph owns at most one cached query and O(V) search state.
export function createGraphPathReader(blocks, outgoing) {
let last;
return (input) => {
const avoid = [...new Set(input.avoid ?? [])];
const selected = [
input.from,
...(input.target.kind === "block" ? [input.target.id] : []),
...avoid,
];
const unretained_blocks = [...new Set(selected)].filter(
(id) => !blocks.has(id),
);
let result;
if (unretained_blocks.length) {
result = {
status: "unknown",
end: null,
items: [],
examined_blocks: 0,
examined_edges: 0,
search: "unretained-selection",
};
} else {
const key = JSON.stringify([
input.from,
input.target.kind,
input.target.kind === "block" ? input.target.id : null,
[...avoid].sort((a, b) => a - b),
]);
if (last?.key !== key)
last = {
key,
result: freeze(search(outgoing, input.from, input.target, avoid)),
};
result = last.result;
}
const {
items,
examined_blocks,
examined_edges,
search: scope,
...outcome
} = result;
return {
...outcome,
from: input.from,
target: { ...input.target },
avoid,
...nativePage(items, input),
total: outcome.status === "unknown" ? null : items.length,
unretained_blocks,
path_coverage: {
scope:
"recovered CFG under requested exclusions; one shortest edge-count witness in native edge order",
search: scope,
examined_blocks,
examined_edges,
branch_predicate_feasibility: "unknown",
machine_semantic_equivalence: "unknown",
runtime_reachability: "unknown",
},
};
};
}
@@ -0,0 +1,190 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createGraphPathReader } from "./cfg-path.mjs";
import { MAX_GRAPH_BLOCKS } from "./graph-limits.mjs";
const graph = (successors) => {
const blocks = new Map(successors.map((_, id) => [id, { id }]));
const outgoing = new Map(
successors.map((targets, from) => [
from,
targets.map((to, index) =>
Object.freeze({
id: `${from}:${index}`,
from,
to,
target: to,
index,
operation: `op${from}`,
polarity: null,
condition_value: null,
condition_test: null,
}),
),
]),
);
return { blocks, outgoing, read: createGraphPathReader(blocks, outgoing) };
};
function floydDistances(successors, allowed) {
const distances = Array.from({ length: 3 }, (_, from) =>
Array.from({ length: 3 }, (_, to) =>
!allowed(from) || !allowed(to)
? Infinity
: from === to
? 0
: successors[from].includes(to)
? 1
: Infinity,
),
);
for (let k = 0; k < 3; k++)
for (let i = 0; i < 3; i++)
for (let j = 0; j < 3; j++)
distances[i][j] = Math.min(
distances[i][j],
distances[i][k] + distances[k][j],
);
return distances;
}
function assertWitness(result, { distance, ends, from, outgoing, allowed }) {
assert.equal(result.status, distance === Infinity ? "not-found" : "found");
assert.equal(result.total, distance === Infinity ? 0 : distance);
if (result.status !== "found") return;
assert.ok(ends.includes(result.end));
let at = from;
for (const [step, edge] of result.items.entries()) {
assert.equal(edge.step_index, step);
assert.equal(edge.from, at);
assert.equal(outgoing.get(at)[edge.index].id, edge.id);
assert.equal(outgoing.get(at)[edge.index].to, edge.to);
assert.ok(allowed(edge.to));
at = edge.to;
}
assert.equal(at, result.end);
}
test("all three-node digraphs and exclusions agree with independent Floyd-Warshall distances", () => {
for (let mask = 0; mask < 512; mask++) {
const successors = Array.from({ length: 3 }, (_, from) =>
[0, 1, 2].filter((to) => mask & (1 << (from * 3 + to))),
);
const { read, outgoing } = graph(successors);
for (let exclusions = 0; exclusions < 8; exclusions++) {
const avoid = [0, 1, 2].filter((id) => exclusions & (1 << id));
const allowed = (id) => !avoid.includes(id);
const distances = floydDistances(successors, allowed);
const queries = [0, 1, 2].flatMap((from) =>
[
{ kind: "exit" },
...[0, 1, 2].map((id) => ({ kind: "block", id })),
].map((target) => ({ from, target })),
);
for (const { from, target } of queries) {
const ends =
target.kind === "block"
? [target.id]
: [0, 1, 2].filter((id) => successors[id].length === 0);
const distance = Math.min(...ends.map((to) => distances[from][to]));
assertWitness(read({ from, target, avoid }), {
distance,
ends,
from,
outgoing,
allowed,
});
}
}
}
});
test("paging retains original edge ordinal, source fields and full-path outcome", () => {
const { read } = graph([[0, 1, 1], [2], []]);
const request = { from: 0, target: { kind: "exit" } };
const first = read({ ...request, limit: 1 });
assert.equal(first.status, "found");
assert.equal(first.total, 2);
assert.equal(first.end, 2);
assert.equal(first.next_offset, 1);
assert.equal(first.items[0].id, "0:1");
assert.equal(first.items[0].index, 1);
assert.equal(first.items[0].step_index, 0);
assert.equal(first.items[0].operation, "op0");
assert.throws(() => {
first.items[0].to = 999;
}, TypeError);
const second = read({ ...request, offset: 1, limit: 1 });
assert.equal(second.items[0].step_index, 1);
assert.equal(second.next_offset, null);
const beyond = read({ ...request, offset: 9 });
assert.equal(beyond.status, "found");
assert.equal(beyond.total, 2);
assert.equal(beyond.end, 2);
assert.deepEqual(beyond.items, []);
});
test("unknown selections, duplicates and excluded endpoints stay explicit", () => {
const { read } = graph([[1], []]);
for (const input of [
{ from: 9, target: { kind: "exit" } },
{ from: 0, target: { kind: "block", id: 9 } },
{ from: 0, target: { kind: "exit" }, avoid: [9, 9] },
]) {
const result = read(input);
assert.equal(result.status, "unknown");
assert.equal(result.total, null);
assert.equal(result.end, null);
assert.deepEqual(result.unretained_blocks, [9]);
}
assert.equal(
read({ from: 0, target: { kind: "block", id: 0 }, avoid: [0] }).status,
"not-found",
);
const zero = read({ from: 1, target: { kind: "exit" } });
assert.equal(zero.status, "found");
assert.equal(zero.total, 0);
assert.equal(zero.end, 1);
assert.equal(zero.path_coverage.runtime_reachability, "unknown");
});
test("one graph-owned cache covers paging and normalized exclusions, replaces on input change", () => {
const { blocks, outgoing } = graph([[1], [2], [], []]);
let reads = 0;
const observed = {
get(id) {
reads++;
return outgoing.get(id);
},
};
const read = createGraphPathReader(blocks, observed);
const request = { from: 0, target: { kind: "exit" }, avoid: [3, 3] };
read(request);
const initial = reads;
read({ ...request, avoid: [3], offset: 1, limit: 1 });
assert.equal(reads, initial);
read({ ...request, avoid: [99] });
read(request);
assert.equal(reads, initial);
read({ from: 0, target: { kind: "block", id: 1 }, avoid: [3] });
assert.ok(reads > initial);
const changed = reads;
read(request);
assert.ok(reads > changed);
const other = createGraphPathReader(blocks, observed);
const before = reads;
other(request);
assert.ok(reads > before, "fresh owner must not share the cache");
});
test("maximum admitted chain is iterative, paged and does not expand caller output", () => {
const { read } = graph(
Array.from({ length: MAX_GRAPH_BLOCKS }, (_, i) =>
i + 1 < MAX_GRAPH_BLOCKS ? [i + 1] : [],
),
);
const result = read({ from: 0, target: { kind: "exit" }, limit: 1 });
assert.equal(result.total, MAX_GRAPH_BLOCKS - 1);
assert.equal(result.items.length, 1);
assert.equal(result.end, MAX_GRAPH_BLOCKS - 1);
assert.equal(result.path_coverage.examined_blocks, MAX_GRAPH_BLOCKS);
});
+20
View File
@@ -0,0 +1,20 @@
import { readFile } from "node:fs/promises";
import { AtomicSession } from "./session.mjs";
import { executeJavaScript } from "./executor.mjs";
const [binary, script] = process.argv.slice(2);
if (!binary || !script)
throw new Error("Usage: node cli.mjs BINARY JAVASCRIPT_FILE");
const session = new AtomicSession();
try {
await session.open(binary);
const result = await executeJavaScript(
session,
await readFile(script, "utf8"),
);
console.log(JSON.stringify(result));
process.exitCode = result.ok ? 0 : 1;
} finally {
session.abort();
await session.close();
}
@@ -0,0 +1,135 @@
# Client waiting and whole-task cost
The [selected-case pair](switch-study.md) exposes one-second client polls after
the snapshot execution yields. Direct makes six waits (three one-second then
three ten-second requests); Code Mode makes three one-second requests. Five
direct and two Code Mode wait responses still report a running cell. Initial
execution yields after about 31 seconds in both lanes. This is observed client
behavior, separate from MCP attempts and native source-capture time.
Native latency remains variable, including in sequential scripted MCP runs
without models. The [overlap canary](overlap-study.md) did not establish a cause.
No analysis acceleration or cache invalidation change is proposed here.
## Frozen diagnostic
The opt-in runner flag `--guide-long-waits` appends exactly the same client wait
policy in both lanes: resume an already-running cell with a 30,000 ms wait,
respect the advertised schema, and do not sleep or duplicate analysis merely
to check progress. It changes neither the initial execution yield policy nor
the provider/Code Mode deadlines. It supplies no analysis facts. The policy,
flag and instruction digest are recorded in each trial's settings. Older runs
without this flag remain a separate stratum.
Run Code Mode first, then direct, with the unchanged
[question](sqlite-switch-question.txt) and [oracle](switch-oracle.md), final
`a9ca8a8a...` engine, complete four/eighteen-tool catalogs and the same exact
discovery/envelope guidance as the first pair. Use fresh leases and isolated
model workspaces, requested `gpt-6.1-sol/high`, Codex 0.161.0 and the same one-CPU,
4 GiB hard / 3 GiB early-stop resource policy. No runtime edits during the pair.
Local records use `sqlite-switch-{codemode,direct}-v2*`.
Review complete answers against the frozen independent machine oracle and
retained source, including selector widths, all requested cases, signed target
arithmetic, case/edge identities, native default versus machine out-of-range
guard, provenance and unknown runtime behavior. Require one VM capture and
focused reads; a lower token count without a correct answer is not a win.
Record actual wait arguments and running/completed responses, model responses,
all input/cached/uncached/output/reasoning tokens, MCP/API attempts, wall time,
family CPU, kernel family peak, native source-capture time, identity/freshness
and cleanup/OOM status. Count discovery, guidance and unsuccessful waits in
whole-task usage. Fewer polls would establish adherence in this client, not
causally lower tokens or native latency. A before/after pair remains subject to
model choices, prompt caches, host contention and run order; do not subtract
native or polling intervals to manufacture an adapter speedup.
The [official Codex CLI reference](https://learn.chatgpt.com/docs/cli/reference)
documents client configuration but does not establish the `wait` contract used
here. The actual captured client calls and subsequent run establish behavior;
no configuration feature flag is treated as proof of the available surface.
The native/API contracts are unchanged.
## Executed repeat
Both runs pin `790cdfdef`, with Code Mode first and direct second. Their shared
frozen runtime is preserved by tag
[`experiment/atomic-codemode-wait-runtime-20261016`](https://github.com/morluto/rea/tree/experiment/atomic-codemode-wait-runtime-20261016),
which retains the original revision before commit-attribution metadata cleanup.
Both complete answers again pass the frozen oracle: format ownership before capture, selector
widths, all five selected case identities/edges/targets, signed table arithmetic,
the absent explicit `0xb6` case and distinct native-default/machine-guard
destinations. Direct cites eleven observed source IDs; Code Mode cites ten.
Each has one VM source, equal to the full prior graph/ordinary-field golden,
and no complete case/C/graph fetch. Both close the lease and retain the stated
static/alias/runtime limits. Source fidelity does not prove global equivalence.
| Whole-task measure | Direct atomic | Code Mode |
| ------------------------------ | ------------: | --------: |
| Cumulative input tokens | 280,035 | 372,288 |
| Included cached input | 221,312 | 343,168 |
| Uncached input | 58,723 | 29,120 |
| Output tokens | 4,648 | 5,384 |
| Included reasoning output | 1,122 | 862 |
| Observed model responses | 12 | 16 |
| Client execution / wait calls | 10 / 1 | 14 / 1 |
| MCP attempts, including reject | 17 | 15 |
| Successful atomic fact reads | 14 | 19 |
| Model wall seconds | 175.908 | 196.640 |
| Family wall seconds | 176.382 | 197.767 |
| Family CPU seconds | 66.735 | 56.081 |
| Kernel process-family peak MiB | 786.6 | 870.3 |
| VM source-capture wall seconds | 47.010 | 39.828 |
Both request `yield_time_ms:30000` once, resuming their pending snapshot cell;
the waits return completed results after 16.5 seconds direct and 6.5 Code Mode.
Neither adds an unsuccessful running-cell poll. This establishes adherence,
and reduces waits from six/three to one/one in these samples. It does not
establish a causal token/latency reduction: native capture times and subsequent
investigation choices differ, and the Code Mode repeat makes more fact reads.
Code Mode's attempts include a schema-rejected `timeout_ms:200000` (maximum
120,000), then a valid retry. Later a script returns complete input arrays from
operations at a PHI-heavy origin and exceeds the 32 KiB result budget. Its three
host reads succeed and source Evidence survives; the next script returns a
smaller projection successfully. Both costs stay in the ledger. Direct has no
failed attempts. The timeout mistake also occurred in the earlier control task:
the next interface check should make the default/maximum explicit in discovery,
using the execution owner's policy rather than another copied constant.
Within this repeat, Code Mode uses 32.9% more cumulative input, 15.8% more output
and 11.8% more model wall time, while using 50.4% less uncached input and less
family CPU. Relative to the first pair, direct cumulative input falls but its
uncached input rises; Code Mode cumulative and uncached input both rise despite
fewer waits. There is no stable whole-task winner across these strata.
Per-response usage matches the ledger; guidance is included in token usage.
Runtime, engine and target fingerprints remain unchanged. OOM is zero and
payload/profile cleanup is verified. Resource/model settings and the cold-lease,
uncontrolled-cache/host and unmeasured-remote-compute limitations remain as above.
Kernel peaks include charged file cache, not RSS. Both clients already provide
JavaScript composition. Full records use the declared `-v2` local paths; the
unchanged summarizer reconstructs actual usage but does not grade correctness.
## Discovery follow-up
The execution owner, MCP admission schema and Code Mode help now use one frozen
policy in `limits.mjs`. Both the execution description and detailed reference
state that omitting `timeout_ms` uses the 120,000 ms default/maximum; the separate
2,000 ms guest CPU budget remains explicit. Heap, stack, host-call, source and
result budgets are unchanged. The direct adapter omits Code Mode execution
limits/notes. Snapshot documentation also names the optional independent switch
facet, avoiding a stale return description after the new exporter.
All 73 shared JS tests pass (4.349 family wall / 4.114 CPU seconds, 79.6 MiB
kernel peak). The actual SDK catalogs and named references validate in both
lanes. The Code Mode MCP check rejects the observed 200,000 ms parameter, then
successfully executes a defaulted request with zero host calls (final catalog
check: 5.086 family wall / 4.111 CPU seconds, 142.2 MiB kernel peak).
A real zlib MCP check also verifies bounded
ordinary/oversized guest errors and retained source access after failure
(1.530 wall / 1.338 CPU seconds, 136.6 MiB). All have OOM 0 and verified cleanup;
focused lint has no warnings and formatting passes. No native rebuild or full
repository gate ran for this discovery change. No new model pair has measured
whether it reduces mistakes or whole-task cost; earlier results retain their
original runtime pins.
@@ -0,0 +1,92 @@
// Stream a complete legacy native inventory; retain only small expected query pages.
import assert from "node:assert/strict";
import { createReadStream } from "node:fs";
import { readFile, writeFile } from "node:fs/promises";
import { createHash } from "node:crypto";
import { createGunzip } from "node:zlib";
import { Transform } from "node:stream";
import chain from "stream-chain";
import { parser } from "stream-json";
import { pick } from "stream-json/filters/pick.js";
import { streamArray } from "stream-json/streamers/stream-array.js";
import { join } from "node:path";
const [directory, output] = process.argv.slice(2);
assert(directory && output);
const manifest = JSON.parse(
await readFile(join(directory, "manifest.json"), "utf8"),
);
const queries = [
"undefined symbol",
"Invalid bitcode signature",
"",
"\ud800",
"a.b+",
].map((query) => ({ query, total: 0, sample: [] }));
const rawHash = createHash("sha256");
let bytes = 0,
total = 0,
group = [],
previous = -1;
const emit = () => {
group.sort((a, b) => a.encoding.localeCompare(b.encoding, "en"));
for (const row of group) {
for (const selection of queries)
if (row.text.includes(selection.query)) {
selection.total++;
if (selection.sample.length < 16)
selection.sample.push({ ...row, source_row: total });
}
total++;
}
group = [];
};
const stream = chain([
createReadStream(join(directory, "inventory.json.gz")),
createGunzip(),
new Transform({
transform(chunk, _encoding, done) {
rawHash.update(chunk);
bytes += chunk.length;
done(null, chunk);
},
}),
parser(),
pick({ filter: "strings" }),
streamArray(),
]);
for await (const { value } of stream) {
assert(Number.isSafeInteger(value.address) && typeof value.text === "string");
assert.equal(value.address_hex, "0x" + value.address.toString(16));
assert(value.address >= previous);
if (value.address !== previous) {
emit();
previous = value.address;
}
group.push(value);
}
emit();
assert.equal(rawHash.digest("hex"), manifest.raw_sha256);
assert.equal(bytes, manifest.raw_bytes);
await writeFile(
output,
JSON.stringify(
{
manifest,
total,
queries,
scope:
"Complete legacy producer comparison; query matches use JavaScript UTF16 includes, only first 16 per query retained. Not an independent proof of all string recognition.",
},
null,
2,
),
{ flag: "wx" },
);
console.log(
JSON.stringify({
total,
bytes,
queries: queries.map(({ query, total }) => ({ query, total })),
}),
);
@@ -0,0 +1,144 @@
// Immediate postdominators on the reversed recovered CFG, using linear retained
// state. Control dependence is derived for finite paths to recovered exits.
import { FactFailure } from "./fact-error.mjs";
import { freezeFacts } from "./fact-reads.mjs";
const workBudget = (limit) => {
let work = 0;
return () => {
if (++work > limit)
throw new FactFailure(
"capacity",
"Control-dependence work budget exceeded",
);
};
};
// Retain one linear-size index per resident graph. Selected rows are generated
// per read, so paging does not retain a potentially quadratic relation set.
export function createControlDependenceIndex(
blocks,
{ workLimit = 2_000_000 } = {},
) {
const exit = Symbol("recovered-exit");
const successors = new Map(
blocks.map((block) => [
block.id,
block.successors.map((edge) => edge.target),
]),
);
const reverse = new Map([
[exit, []],
...blocks.map((block) => [block.id, []]),
]);
const tick = workBudget(workLimit);
for (const [from, targets] of successors) {
if (!targets.length) targets.push(exit);
for (const to of targets) reverse.get(to).push(from);
}
const { parent, visited } = postdominatorParents(
exit,
successors,
reverse,
tick,
);
const coverage = freezeFacts({
scope:
"derived control dependence in the recovered graph; zero-successor blocks treated as exits; finite paths only",
status:
visited.size === blocks.length + 1
? "complete-for-recovered-finite-exit-paths"
: "partial",
exit_unreachable_blocks: blocks
.filter((block) => !visited.has(block.id))
.map((block) => block.id),
nontermination: "unknown",
runtime_reachability: "unknown",
});
function* relations(dependents) {
const tick = workBudget(workLimit);
for (const block of blocks) {
if (!parent.has(block.id)) continue;
for (const edge of block.successors) {
let runner = edge.target;
while (
parent.has(runner) &&
runner !== parent.get(block.id) &&
runner !== exit
) {
tick();
if (!dependents || dependents.has(runner))
yield { controller: block.id, dependent: runner, edge };
runner = parent.get(runner);
}
}
}
}
return Object.freeze({
relations,
coverage,
read: ({ seeds, offset = 0, limit = 20 }) => {
const selected = new Set(seeds),
items = [];
let total = 0;
// Exhaust for a truthful total, retaining only the requested page.
for (const row of relations(selected)) {
if (total >= offset && items.length < limit) items.push(row);
total++;
}
return {
items,
total,
next_offset: offset + limit < total ? offset + limit : null,
relation_coverage: coverage,
};
},
});
}
function postdominatorParents(exit, successors, reverse, tick) {
const visited = new Set([exit]);
const stack = [[exit, 0]],
postorder = [];
while (stack.length) {
tick();
const frame = stack.at(-1),
children = reverse.get(frame[0]);
if (frame[1] < children.length) {
const child = children[frame[1]++];
if (!visited.has(child)) {
visited.add(child);
stack.push([child, 0]);
}
} else {
postorder.push(frame[0]);
stack.pop();
}
}
const order = postorder.reverse();
const position = new Map(order.map((id, i) => [id, i]));
const parent = new Map([[exit, exit]]);
const intersect = (a, b) => {
while (a !== b) {
tick();
if (position.get(a) > position.get(b)) a = parent.get(a);
else b = parent.get(b);
}
return a;
};
let changed = true;
while (changed) {
changed = false;
for (const node of order.slice(1)) {
tick();
const known = successors.get(node).filter((id) => parent.has(id));
if (!known.length) continue;
const next = known.slice(1).reduce(intersect, known[0]);
if (parent.get(node) !== next) {
parent.set(node, next);
changed = true;
}
}
}
return { parent, visited };
}
@@ -0,0 +1,43 @@
// Test/evaluator oracle only. Removing a node and searching for exits is
// independent of the runtime's immediate-postdominator algorithm.
export function finiteExitControlOracle(blocks) {
const reverse = new Map(blocks.map((block) => [block.id, []]));
for (const block of blocks)
for (const edge of block.successors)
reverse.get(edge.target).push(block.id);
const exits = blocks
.filter((block) => !block.successors.length)
.map((b) => b.id);
const reachesExitWithout = (forbidden) => {
const seen = new Set(exits.filter((id) => id !== forbidden));
const queue = [...seen];
for (let i = 0; i < queue.length; i++)
for (const previous of reverse.get(queue[i]))
if (previous !== forbidden && !seen.has(previous)) {
seen.add(previous);
queue.push(previous);
}
return seen;
};
const active = reachesExitWithout(undefined),
relations = [];
for (const dependent of active) {
const avoiding = reachesExitWithout(dependent);
const postdominates = (node) => active.has(node) && !avoiding.has(node);
for (const block of blocks) {
if (!active.has(block.id)) continue;
// Strict postdominance excludes the node itself, preserving loop
// self-dependence when a recovered edge leads back to its controller.
if (block.id !== dependent && postdominates(block.id)) continue;
for (const edge of block.successors)
if (postdominates(edge.target))
relations.push({ controller: block.id, dependent, edge_id: edge.id });
}
}
return {
relations,
exit_unreachable_blocks: blocks
.filter((b) => !active.has(b.id))
.map((b) => b.id),
};
}
@@ -0,0 +1,152 @@
# Correct and reusable control queries
Retained-source inspection exposed a correctness gap: a nonexistent CFG seed
returned an empty set without saying that the block was unretained. Source-wide
control coverage could be mistaken for proof that the requested block had no
controllers. Incoming/outgoing queries shared this selection boundary. They now
deduplicate seeds and return `unretained_seeds`, distinguishing a retained block
with no relations. Incoming/outgoing order follows caller seeds then native
edges; controller order stays native controller/edge then postdominator ancestor.
`createControlDependenceIndex` replaces the one-shot implementation. The native
graph owner constructs it lazily and retains it only with that resident snapshot.
It holds linear-size postdominator/coverage state, without query keys or a
potentially quadratic complete relation set. Page reads generate relations,
count the entire selected set and retain only the requested page. Construction
and each relation walk have separate two-million-step budgets; capacity failure
is explicit. Coverage/edges are immutable; fresh reply row containers cannot
change subsequent reads. The index follows the existing two-resident-model
lifetime. CLI, SDK and both adapters use this owner; no native rebuild or new
public method is required.
Semantics remain finite paths to recovered zero-successor exits. Loop
self-dependence is possible; exit-unreachable blocks are explicit. Runtime
feasibility, memory aliases and nontermination remain unknown.
## Independent verification
The test/evaluator-only `control-path-oracle.mjs` removes each candidate node
and searches backward from exits. It independently verifies all 512 three-node
directed graphs, including cycles, alongside the existing 64 four-node DAGs,
multiple exits, unreachable regions and work-capacity checks. Single-row paging,
unknown/duplicate seeds and immutable coverage/edges pass. The related suite
passes 82 tests; the final added edge-mutation assertion also passes its focused
ten-test suite. Experiment lint has no warnings; formatting passes.
The real Debian SQLite VM has 1,229 blocks, 2,061 edges and 2,845 derived control
triples. Both actual MCP adapters page every triple and match the independent
oracle, including exact native edge metadata. Each executes 52 MCP requests.
Full graph, ordinary function/call records and Evidence views equal the earlier
golden; former projection frontiers remain readable. All three CFG relation
kinds correctly report unknown-only and mixed/duplicate seeds. Target and
preserved `a9ca8a8a...` engine match the [switch study](switch-study.md). No target
execution or modification occurs.
## Executed costs
| Scope | Family wall s | Family CPU s | Kernel peak MiB |
| --------------------------- | ------------: | -----------: | --------------: |
| Related 82 tests | 20.342 | 13.857 | 93.5 |
| Real Code Mode MCP | 103.417 | 78.642 | 713.2 |
| Real direct MCP | 42.702 | 42.301 | 725.4 |
| Equivalent-query diagnostic | 2.636 | 2.482 | 309.0 |
One CPU, 4 GiB hard / 3 GiB early-stop bounds apply. All have OOM/kill 0 and
verified payload cleanup. Kernel family peak includes charged file cache, not
RSS. Code Mode's fresh native capture takes 95.068 wall / 72.758 CPU seconds;
direct's takes 39.432 / 39.408. This native/host variation is not a dispatch
measurement. The first selected eight-row query takes 61.2 ms / 0.0616 CPU
seconds Code Mode, 15.0 ms / 0.0157 direct. The identical same-lease warm query
takes 3.2 ms / 0.00384 and 1.8 ms / 0.00242. Paging all triples takes 274.9/224.2
ms. Cumulative peaks only upper-bound warm memory. Private native caches are
fresh; OS caches and host contention are uncontrolled. Receipts remain local
as `controls-{code,direct}-v1*`.
`profile-controls.mjs` compares baseline
`d7d95c7dcc824cc90f63de7a8e2efa2237c53d8f` with the current owner on the same
validated retained graph. The complete task returns eight relations for blocks
1154/1159 in four two-row pages. Both return identical facts:
| Core task | Reads | Elapsed ms | Process CPU s |
| ----------------------------- | ----: | ---------: | ------------: |
| Previous implementation | 4 | 75.33 | 0.0751 |
| First indexed task | 4 | 23.33 | 0.0233 |
| Identical complete task, warm | 4 | 1.27 | 0.0013 |
| Previous, 50 complete tasks | 200 | 420.03 | 0.4174 |
| Indexed, 50 complete tasks | 200 | 60.27 | 0.0603 |
Parsing/validation separately takes 1,013.4 ms / 1.0127 CPU seconds. Order,
JIT and caches are uncontrolled within the shared process. This diagnostic
excludes fresh native work, MCP discovery/serialization and model tokens;
it does not establish a whole-agent speedup or fewer reads/tokens. Source/module
hashes and facts are retained in `controls-profile-v1.json`.
## Real-agent two-level investigation
The [question and oracle](controller-oracle.md) and runtime were frozen at
`8d13c67e7` before either model launch, Code Mode first and direct second.
Both complete answers pass the frozen oracle/source review: format ownership,
PHI/call binding, both complete controller levels, all four Boolean guards and
operand widths/LOADs, exact shared/distinct SSA identities, alternative predicates,
valid recovered witnesses, machine corroboration and explicit limits. Both close
the lease. The relation list is correctly distinguished from a conjunction.
Direct chooses longer bypass witnesses than the oracle examples. Every reported
edge is valid; both paths end at zero-successor block 1207 and avoid block 1159.
Including the initial controller edge, direct uses nine/twelve edges, Code Mode
six/six; shortest paths were not required. Both full native function records equal
the earlier golden. All thirteen Code Mode and ten direct cited source IDs exist
with matching artifact/engine identities. Code Mode's extra pointer/spill facts
also match the retained IR and selected GNU decoding. The cost summarizer does
not automatically grade natural language.
| Whole-task measure | Direct atomic | Code Mode |
| ------------------------------ | ------------: | --------: |
| Cumulative input tokens | 935,185 | 503,113 |
| Included cached input | 878,592 | 436,736 |
| Uncached input | 56,593 | 66,377 |
| Output tokens | 7,320 | 7,450 |
| Included reasoning output | 757 | 835 |
| Observed model responses | 24 | 17 |
| Client executions / waits | 22 / 1 | 15 / 1 |
| MCP attempts | 36 | 15 |
| Rejected MCP / inner API reads | 0 / 0 | 0 / 0 |
| Successful atomic fact reads | 32 | 33 |
| Model wall seconds | 230.280 | 246.479 |
| Family wall seconds | 230.755 | 248.500 |
| Family CPU seconds | 52.458 | 72.837 |
| Kernel process-family peak MiB | 876.5 | 944.3 |
| Native source-capture wall s | 37.852 | 52.471 |
Both request `gpt-6.1-sol/high` via Codex 0.161.0, with complete 18/4-tool catalogs
and common exact-name/envelope/stopping/long-wait guidance. Actual client calls
use JavaScript `exec`/`wait` in both lanes despite false client Code Mode flags.
This compares server Code Mode with direct atomic MCP on that host, not
composition against its absence. Resolved service build and remote compute are
unknown. Per-response usage sums match the ledger; cached input is included in
input, reasoning in output. Discovery, schemas, waits and all calls are charged.
Runtime, target and engine remain unchanged; both profiles/payloads have verified
cleanup, OOM/kill 0 and no resource abort under the same one-CPU / 4 GiB / 3 GiB
bounds. No new warm real-agent task was run.
Both actually query `controllers` at both levels. Neither uses the C tool or
fetches the complete raw IR report. Code Mode reads the complete block-successor
inventory internally for path search and does extra pointer/spill analysis:
fourteen block, six operation and three instruction API reads. Direct uses ten
block, five operation, two instruction reads, two bounded slices and more selected
CFG reads. Different strategies and native capture times remain confounds;
source-capture time is not an isolated native-drive interval and must not be
subtracted to manufacture a dispatch-only effect.
In this single pair, Code Mode reduces cumulative input by about 46% and uses
fewer model rounds, but increases uncached input, output, elapsed time, CPU and
peak memory. The index's core-query improvement does not establish a causal
whole-agent benefit. Correct composable facts support both strategies; there is
still no stable overall Code Mode advantage or broad complex-software superiority
claim. No traditional-provider cell is invented for this native-identity question.
Local records: `sqlite-controller-{direct,codemode}-v1*`,
`controller-matrix-costs.json` and `controller-answer-checks.json` under
`.cache/atomic-codemode/`. `summarize-trials.py` reconstructs costs. Fresh leases
and private native caches do not control OS/model-service caches; kernel peaks
include charged file cache, not RSS. Scripted warm/core results stay separate.
@@ -0,0 +1,108 @@
# Two-level recovered controller oracle
Freeze this oracle and [question](sqlite-controller-question.txt) before model
launches. Both lanes get the same question without addresses, native IDs or
precomputed paths; this oracle stays outside their isolated workspace. Complete
catalogs are eighteen direct tools or four Code Mode tools over the same API.
The question requires native identities/derived relations absent from the
traditional catalog, so there is no traditional-provider cell or parity claim.
Both clients already expose JavaScript dispatch.
Target: Debian SQLite `3.40.1-2+deb12u2` amd64
`/usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6`, SHA-256
`2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8`.
Engine SHA-256:
`a9ca8a8ac224936afb08a9d4be9c1225feb69473ad9f35764e8d1c4f04875b5b`.
REA was refreshed from main `4838f444939677107902549c59b73439e14d3ae9`
before this work. Freeze runtime/HEAD during both runs. Request
`gpt-6.1-sol/high`, Codex 0.161.0, common exact-name/envelope/stopping/long-wait
guidance, fresh leases/private caches, one CPU and 4 GiB hard / 3 GiB early-stop
bounds. Charge all discovery, retries, waits and actual model usage. Preserve
native timing variation and incomplete attempts.
## Formats and first-level controllers
References select VM entry `0xea6d0`, rather than same-name stub `0x288f0`.
Open format `0x12c500` is produced by `0xf2381:712c` in block 1142; release
format `0x12c538` by `0xf2437:753c` in block 1158. PHI `0xf238b:ceb7`, output
`v100033f25`, binds slots 0/1 to incoming edges `1142:0`/`1158:0`. Shared CALL
`0xf238b:7130` in block 1159 takes this format at input 2, with eight-byte
`register:0x30` (RSI) passing storage. Target `ram:0x296c0`, native label
`sqlite3VdbeError`, does not establish a complete source signature or runtime
binding.
The complete direct controller set of block 1159 is exactly:
- Block 1141, CBRANCH `0xedc01:7065`: selected `1141:1 -> 1142`, true/ne-zero;
other `1141:0 -> 1143`, false/ne-zero. One-byte condition `v100012864` is
defined by `0xedc01:7064 INT_SLESS`: slot 0 four-byte zero `v30001285f`,
slot 1 four-byte `v100012840` from LOAD `0xedbf8:7056`. Guard: signed loaded32 > 0.
- Block 1157, CBRANCH `0xf0389:71b8`: selected `1157:1 -> 1158`, true/ne-zero;
other `1157:0 -> 1161`, false/ne-zero. One-byte condition `v100012bd9` is
`0xf0384:71b3 INT_EQUAL`: slot 0 four-byte `v10001280a` from LOAD
`0xedbe5:7041`, slot 1 four-byte one `v3000393a3`. Guard: loaded32 == 1.
## Exactly one further level
- The complete direct set for 1141 is block 1140, CBRANCH `0xedbf2:7054`.
Selected `1140:0 -> 1141`, false/ne-zero; other `1140:1 -> 1149`, true/ne-zero.
One-byte `v10001282b` is `0xedbf0:704e INT_NOTEQUAL`: slot 0 four-byte
`v10001280a`, LOAD `0xedbe5:7041`, slot 1 four-byte zero `v10001282d`.
The selected edge negates NOTEQUAL: loaded32 == 0.
- The complete direct set for 1157 is block 1156, CBRANCH `0xf0382:71ab`.
Selected `1156:1 -> 1157`, true/ne-zero; other `1156:0 -> 1161`, false/ne-zero.
One-byte `v100012bc0` is `0xf0382:71aa INT_SLESSEQUAL`: slot 0 four-byte
one `v500038ab1`, slot 1 four-byte `v100012b9e`, LOAD `0xf0378:719d`.
Guard: signed loaded32 >= 1.
Open outer and release inner comparisons share exactly `v10001280a` (P).
Conjoining their selected predicates would require P == 0 and P == 1. These
are alternatives, not simultaneous prerequisites. Locally open combines
P == 0 with signed S > 0; release combines signed T >= 1 with P == 1.
These are not complete VM-entry path conditions or a demonstrated SQL trigger.
P, S (`v100012840`) and T (`v100012b9e`) all have unique-space coordinate
`0x23d00`/4 but are distinct SSA values. S/T have separate LOAD definitions,
even though machine code reads `[R13+0xd8]` in each path. Matching coordinates
or memory expressions do not equate contents across reads/paths or solve aliases.
## Graph witnesses
Accept any edge-valid witnesses with the required endpoints and omitted block,
not only these shortest examples:
- Selected: `1142 -> 1159`, edge `1142:0`; `1158 -> 1159`, edge `1158:0`.
- Open alternative avoiding 1159:
`1143 -> 1144 -> 1201 -> 1204 -> 1205 -> 1207`, edges
`1143:0, 1144:0, 1201:0, 1204:0, 1205:1`.
- Release alternative avoiding 1159:
`1161 -> 1162 -> 1163 -> 1164 -> 1205 -> 1207`, edges
`1161:1, 1162:1, 1163:1, 1164:0, 1205:1`.
1207 has zero successors. Check every edge against the retained graph. These
finite recovered paths establish neither machine paths, feasible predicates nor
termination.
## Independent machine checks and grading
ELF64LE PT_LOAD/file reads verify sixteen instruction sites and eight relative
targets; GNU decoding corroborates them. Receipt: `controller-machine-oracle.json`
locally. Earlier sites are in the [savepoint oracle](savepoint-control-oracle.md).
Additional facts:
- `0xedbf0 85f6` TESTs ESI; `0xedbf2 0f8548270000` is JNE `0xf0340`,
zero falls through to `0xedbf8`. Native successor origins are separate metadata.
- `0xf0378 458b9dd8000000` loads R11D from `[R13+0xd8]`; `0xf037f 4585db`
TESTs it; `0xf0382 7e0b` is signed JLE `0xf038f`, positive falls through
to `0xf0384`. Native true/ne-zero here is not machine JLE-taken.
- Other guards remain signed JG `0xedc01 -> 0xf2372` and equality JE
`0xf0389 -> 0xf242d`; format setups and shared CALL bytes are unchanged.
The full graph has 21,349 operations, 35,755 values, 1,229 blocks and 2,061 edges.
Both actual MCP adapters match all 2,845 control triples against the independent
node-removal/exit-reachability oracle, with source fidelity and exact native edge
metadata. This is not global machine/IR equivalence. Grade the complete answer
and actual calls: both controller levels, all four conditions, shared/distinct
SSA identities, valid witnesses, selected machine corroboration, real source
IDs/digest and explicit recovered/alias/machine/nontermination/runtime limits.
A cheap incomplete/incorrect answer is not an efficiency success. Close the lease.
@@ -0,0 +1,58 @@
"""Create bounded static ELF payloads with installed binutils; never execute them."""
import argparse
import hashlib
import json
from pathlib import Path
import subprocess
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('directory', type=Path, help='New output directory; must not exist')
args = parser.parse_args()
root = args.directory.resolve()
root.mkdir(mode=0o700)
cases = [
('plain', 'REA_CAPACITY_PLAIN:', 2 * 1024 * 1024 + 4096, b'A'),
('escaped', 'REA_CAPACITY_ESCAPED:', 1024 * 1024 + 4096, b'\\'),
]
assembly = [
'.text', '.global _start', '.type _start,@function', '_start:',
'ret', '.size _start,.-_start', '.section .rodata',
]
for name, prefix, size, fill in cases:
(root / (name + '.bin')).write_bytes(
prefix.encode() + fill * (size - len(prefix)) + b'\0')
assembly.extend([
'.global capacity_' + name, '.type capacity_' + name + ',@object',
'capacity_' + name + ':', '.incbin "' + name + '.bin"',
'.size capacity_' + name + ',.-capacity_' + name,
])
(root / 'fixture.s').write_text('\n'.join(assembly) + '\n')
subprocess.run(['as', '--64', '-o', 'fixture.o', 'fixture.s'], cwd=root, check=True)
subprocess.run(['ld', '-o', 'fixture.elf', 'fixture.o'], cwd=root, check=True)
binary = root / 'fixture.elf'
binary.chmod(0o444)
symbols = {}
for line in subprocess.check_output(['nm', '--format=posix', str(binary)], text=True).splitlines():
name, _, address, *_ = line.split()
if name.startswith('capacity_'):
symbols[name] = int(address, 16)
manifest = {
'binary': str(binary), 'sha256': hashlib.sha256(binary.read_bytes()).hexdigest(),
'output_directory_argument': str(args.directory),
'cases': [
{'name': name, 'query': prefix, 'address': hex(symbols['capacity_' + name]),
'text_bytes': size, 'encoded_span_bytes': size + 1,
'nul_terminated': True, 'fill_byte': fill[0]}
for name, prefix, size, fill in cases
],
'scope': 'Synthetic static ELF; never executed. Capacity/escaping behavior, '
'not real-application analysis quality.',
}
(root / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
print(json.dumps(manifest))
if __name__ == '__main__':
main()
@@ -0,0 +1,164 @@
# Intent discovery without duplicated full contracts
The [two-level control pair](control-query-study.md) exposed a concrete metadata
cost. Code Mode first received a 9,890-byte method index, then 26,614 bytes of
selected contracts; the index already repeated substantial full descriptions.
Its uncached input exceeded direct's despite lower cumulative input. Metadata
bytes alone cannot explain that token difference: selected contracts, returned
facts and analysis choices also differed.
The shared registry now owns an explicit intent summary beside each full
method description. `reference(view:"index")` returns those summaries and every
matching method/name, without schemas or return contracts. It labels the result
as intent discovery, not complete semantics or live availability. Full contracts
remain on demand, including an explicit all-contracts request. Topic matching
still searches the full descriptions, so a detail omitted from a summary remains
searchable. No automatic sentence cutting, schema truncation or catalog filtering
is introduced. Caller selection/order and unmatched queries remain explicit.
The definition helper takes named summary/description metadata. `api.mjs` owns
contracts; `session.mjs` owns shared application admission and file/lease cleanup.
The default session factory imports the native provider only on open. All known
consumers now import `AtomicSession` from `session.mjs`; no compatibility wrapper
or second analysis implementation remains. CLI, SDK and both MCP adapters share
that owner. This changes metadata/loading, not native arguments, analysis caching
or retained-fact semantics.
## Actual contract and runtime checks
The complete SDK reference object is deeply equal to the saved before object:
all fifteen input schemas, full descriptions, return contracts, examples, limits
and notes match. Both actual MCP lanes preserve their selected full contracts
exactly. Every advertised schema compiles against Draft 2020-12; named handlers
match their contract identities. Actual catalogs still contain all eighteen
direct tools or four Code Mode tools. Topic/all/named selection, unknown queries,
caller order and timeout rejection/recovery pass.
| Actual MCP lane | Previous index bytes | Intent index bytes | Full-contract bytes, unchanged |
| --------------- | -------------------: | -----------------: | -----------------------------: |
| Code Mode | 9,890 | 2,849 | 31,804 |
| Direct | 9,920 | 2,879 | 30,116 |
Those are serialized JSON bytes, not model tokens. No token improvement follows
from that table alone. The all-contract size difference between lanes is their
existing naming/examples/execution presentation, not missing methods.
The related 82 tests pass after the module split. Real zlib SDK reads preserve
immutable cached strings/aliases and the complete source digest. The real CLI
composes function/string reads through the moved application owner. SDK cleanup
and replacement retry pass on SSH. Both MCP adapters retain and retry failed
engine-inspection descriptors and native-close owners. The faults are injected,
not observed OS/engine failures; native reads and successful cleanup use real
providers. Lint reports no warnings and formatting passes.
| Executed scope | Family wall s | Family CPU s | Kernel peak MiB |
| ----------------------------------------------- | ------------: | -----------: | --------------: |
| Before actual metadata verification, both lanes | 2.032 | 1.869 | 141.3 |
| Final actual metadata verification, both lanes | 1.831 | 1.592 | 130.0 |
| Final related 82 tests | 3.948 | 3.788 | 82.9 |
| Real zlib SDK | 1.528 | 1.297 | 124.6 |
| Real zlib CLI | 1.629 | 1.365 | 122.1 |
| SDK cleanup/replacement retry | 1.731 | 1.551 | 120.4 |
| Engine descriptor retry, Code Mode | 1.932 | 1.717 | 199.1 |
| Engine descriptor retry, direct | 1.831 | 1.645 | 191.4 |
| Native close retry, Code Mode | 1.832 | 1.610 | 187.8 |
| Native close retry, direct | 1.730 | 1.566 | 181.4 |
All run with one CPU, 4 GiB hard / 3 GiB early-stop memory, OOM/kill 0 and verified
payload cleanup. Kernel family peaks include charged file cache, not RSS. An
intermediate metadata check costs 1.731 wall / 1.503 CPU seconds and 129.5 MiB;
the preliminary 82-test run before module separation costs 19.536 / 13.950
seconds and 90.9 MiB. These are implementation/check stages with uncontrolled
host/JIT/cache conditions, not a causal analysis-speed benchmark. Raw receipts
remain local as `discovery-summary-*` under `.cache/atomic-codemode/`.
## Real-model repeat protocol
Reuse the unchanged [question and oracle](controller-oracle.md), frozen at
`8d13c67e7`, and its same pinned SQLite artifact and `a9ca8a8a...` engine. The
interface revision is a separate stratum; preserve both earlier completed answers
and all costs. Freeze runtime/HEAD before running, with the same complete tool
manifests, model/client/settings and common discovery/envelope/stopping/wait
guidance. Reverse the prior order: direct first, Code Mode second. Use fresh
isolated leases/private caches; OS/model caches and host contention remain
uncontrolled. Review complete answers and paths before comparing whole-task
usage, CPU and family memory. Module loading and model choices also change, so
the result cannot isolate a pure byte-count effect.
## Completed real-model repeat
Runtime was frozen at `65b701df5`; the question/oracle remain byte-unchanged from
`8d13c67e7`. Both complete answers again pass the frozen source/oracle review:
ownership, PHI/call binding, both controller levels, four guards and widths,
exact shared/distinct SSA identities, valid avoidance witnesses, selected machine
checks and explicit unknowns. Both use one retained VM capture and close the
lease. Direct factors a longer common path suffix; every expanded edge is valid.
Code Mode gives the shorter witnesses. Each cites ten observed source IDs with
matching target/engine identity; both complete native function records equal the
prior golden. The cost summarizer does not perform natural-language grading.
| Whole-task measure | Direct atomic v2 | Code Mode v2 |
| ------------------------------ | ---------------: | -----------: |
| Cumulative input tokens | 834,800 | 546,797 |
| Included cached input | 768,000 | 482,560 |
| Uncached input | 66,800 | 64,237 |
| Output tokens | 7,782 | 7,917 |
| Included reasoning output | 1,002 | 1,322 |
| Observed model responses | 25 | 19 |
| Client executions / waits | 23 / 1 | 17 / 1 |
| MCP attempts | 38 | 18 |
| Rejected MCP / inner API reads | 0 / 0 | 0 / 0 |
| Successful atomic fact reads | 35 | 32 |
| Model wall seconds | 251.325 | 422.804 |
| Family wall seconds | 251.925 | 423.457 |
| Family CPU seconds | 51.979 | 54.169 |
| Kernel process-family peak MiB | 922.7 | 937.3 |
| Native source-capture wall s | 37.061 | 36.472 |
Both request `gpt-6.1-sol/high` through Codex 0.161.0 with the unchanged complete
18/4-tool manifests and common guidance. Both actually use client JavaScript
`exec`/`wait`; feature flags do not establish absence of that surface. Per-response
usage sums agree. Cached input is included in input, reasoning in output.
Runtime, engine and artifact fingerprints remain unchanged. Both profiles and
payloads have verified cleanup, OOM/kill 0 and no resource abort under the same
bounds. Resolved service build, remote compute and OS/model cache effects remain
unknown. These are fresh leases/private native caches, not warm task results.
Actual help use matters. Direct v2 skips the index and reads selected complete
contracts once (24,238 bytes), versus two calls/24,733 bytes in v1. Code Mode v2
uses the 2,849-byte index, then two contract calls: three help calls/30,520 bytes
total, versus two/36,504 in v1. Thus the complete Code Mode help path shrinks by
about 16%, with one extra call; the index's 71% byte reduction is not a 71%
whole-task token reduction.
Compared with its own v1 run, Code Mode v2 has slightly lower uncached input
(66,377 to 64,237), but higher cumulative input (503,113 to 546,797), output and
elapsed time. Direct v2 has lower cumulative input but higher uncached input and
elapsed time than direct v1. Neither before/after pair proves a consistent overall
benefit. Different model choices, module loading, reversed order and uncontrolled
service/host/cache behavior prevent attributing changes solely to summaries.
Captured client call/output timestamps locate a 189.366-second Code Mode gap
between two executions that both report `Script completed`; the executions
themselves last approximately 0.171/0.154 seconds. Matched client-tool interval
unions are 45.909 seconds direct and 50.383 Code Mode. Such intervals are not pure
native work, network or model latency, and gaps after yielded calls can overlap
background work. Here the large gap follows a completed call/PHI read. Its cause
is not established; stderr has no retry/reconnect/timeout diagnostic. The gap
remains charged in the reported wall time. Similar native-capture times and local
CPU do not establish a cause for the end-to-end latency difference.
Both models avoid the C tool. They still read numerous CFG neighborhoods to
construct a few path witnesses; Code Mode again searches an internally collected
successor inventory. This recurring composition cost motivates testing a shared,
bounded recovered-path query next. It is not implemented by this metadata change.
Availability behavior under a stock/unconfigured provider is not newly established
by this native-IR model pair. No broad complex-software superiority or stable
Code Mode advantage is claimed.
The earlier [v1 results](control-query-study.md) are retained rather than replaced.
Local v2 records are `sqlite-controller-{direct,codemode}-v2*`,
`controller-summary-repeat-costs.json`, `discovery-summary-answer-source-checks.json`
and `discovery-summary-client-timing.json`. Kernel peaks include charged file
cache, not RSS; startup/final generation outside the first/last client call is
not covered by the interval union. All whole-task costs remain in the main table.
+261
View File
@@ -0,0 +1,261 @@
# Task coverage before cost comparison
The callable projection now also has a completed [PHI-format model pair](trials.md).
Both answers reconstruct all four alternatives with exact retained identities,
independent machine/string checks and partial-scope limits. An observed reference
lookup mismatch adds work in the direct lane; its costs remain recorded and that
discovery boundary needs correction before another same-question comparison.
Code Mode can only compose facts the underlying API actually supplies. A task
cost is comparable after reviewing the completed answer and its evidence. A
successful tool call, fewer response bytes or more graph records is insufficient.
No claim of complete reverse-engineering capability follows from these tasks.
The [boundary-facet question/oracle](boundary-oracle.md) now also has a completed
real-model pair. Both answers correctly use calls and boundary values despite
full-graph capacity failure, reuse one VM analysis and preserve definition/use
and runtime uncertainty. Code Mode is faster in this sample and uses slightly
less cumulative input, while uncached input and maximum response context are
higher. See the full costs and independent source checks in [trials.md](trials.md).
This verifies the narrower recovered-call capability; it does not supply selected
definition bodies when the full graph is unavailable.
The next completed pair reuses that exact question and oracle after adding compact
call counts to the shared snapshot facet. Both adapters receive the same new
metadata, derived after native validation from the complete retained call set;
the engine, fact methods and selection semantics are unchanged. The hypothesis
is that avoiding full-set paging for these counts reduces task costs. Count
coverage remains recovered block-member calls, not complete machine calls or
runtime binding. Both answers satisfy the same oracle and avoid call-set paging.
Cumulative input is lower in both new samples, but elapsed/uncached costs improve
only for direct; direct now beats Code Mode within the pair. These observations
support useful shared aggregates, without establishing a general efficiency
effect. Selected rows/full source Evidence remain available for composition and
audit; all native VM function records equal the earlier captures.
The atomic direct and Code Mode lanes share the same method registry, provider
owner, selectors, failures and retained sources. The traditional lane selects
relevant production tools, including the discovery route advertised by its
errors; its selection and extra discovery guidance are recorded. Use the same
target, engine, authority and question. Freeze runtime files for each model batch.
Keep full original errors, retries and partial answers in the record. Never show
this oracle document or repository sources to a measured model.
Review task facts separately from answer length. A confident false physical
branch target fails the value-origin task even if its reconstructed IR equation
is right. An answer stopping at an import stub does not complete a task whose
other lane traces the formatter implementation. A bounded missing graph is not
an empty graph. Mark unsupported facts unknown and report incompletion when the
question actually needs them.
Cache regimes are distinct: fresh analysis captures, a reused capture in the
same lease, a validated persistent project in a new session, OS file cache and
the model's reported prompt-cache tokens. These experiments do not clear the OS
cache. The prototype has no cross-session result cache. Whole-model cold and
reused-project trials therefore remain separate from the API-only same-lease
cache benchmark. Report cumulative input, included cached input, uncached input,
output and included reasoning; do not invent server compute or price savings.
All resource trials are serial with one CPU, 4 GiB hard memory, early stop at
3 GiB, and an observed cleanup receipt. Kernel family memory includes charged
file cache. A single stochastic trial is an observation, not a reliable ranking;
API-only replay cannot replace real model trials or establish their token cost.
The CLI transcripts establish that all lanes have a client JavaScript `exec`
surface, even with `code_mode=false` requested. Count actual model responses,
client dispatch/wait calls and MCP requests separately. This comparison is not
an ablation against a client incapable of code composition. The optional
`agent-trial.py --normalize-mcp-guidance` adds identical envelope/stopping guidance
to any lane: select `structuredContent` or parsed text once, avoid printing both
encodings, stop when supported and close the target. It is recorded explicitly;
the initial SQLite and VM rounds do not have that later guidance. Their native
analysis commands/profiles also differ (selected functions versus production
project and facet workflows); engine equality alone does not isolate Code Mode.
The pinned SQLite artifact is `/usr/lib/x86_64-linux-gnu/libsqlite3.so.0.8.6`,
SHA-256 `2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8`.
The malformed-MATCH oracle and earlier unequal-depth results are retained in
[trials.md](trials.md). The next VM task is fixed in `sqlite-vm-question.txt`
before model trials. Its oracle is checked with GNU `objdump -d -M intel` over
the shipped executable, independently of both model answers and Kuna IR. Dynamic
symbol inventory (`nm -D --defined-only`) identifies `sqlite3VdbeExec` at
`0xea6d0`. Reconstructed C and printer line mappings help locate checks, but do
not replace the physical instruction evidence:
| Required local fact | Independently checked anchors |
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Open and release strings are distinct | `0x12c500` and `0x12c538`; loads at `0xf2381` and `0xf2437` |
| Operation selector zero takes the open path | Load `[op+4]` at `0xedbe5`, test `0xedbf0`, `JNE 0xf0340` at `0xedbf2` |
| Open is rejected for a positive signed counter | Load `[db+0xd8]` at `0xedbf8`, test `0xedbff`, `JG 0xf2372` at `0xedc01` |
| Release first resolves the named savepoint, then tests counter and selector | Chain `[db+0x2f0]` at `0xf0340`, links `+0x18` at `0xf0358`, name comparison `0xf036f`; signed `JLE` at `0xf0382` bypasses rejection, selector `==1` at `0xf0384` / `0xf0389` selects `0xf242d` |
| Both use the same emission/error tail | Open falls to `sqlite3VdbeError@plt` call `0xf238b`; release jumps there at `0xf2446`; local status becomes `5` at `0xf239d`, then jumps to `0xea828` at `0xf23b8` |
| Missing name differs | Null chain tests `0xf0347` / `0xf035f` reach `0xf1139`; separate format `"no such savepoint: %s"` and call `0xf115c` |
| Static authority and coverage remain explicit | Counter/selector names are interpretations of offsets; runtime feasibility, actual dynamic binding and the final result after shared error processing require additional evidence |
The VM's real native-IR exporter exceeds its operation capacity. It retains
3,654 lines of reconstructed C and complete source Evidence. This task tests
whether a model can use those available facts plus selected physical instruction
windows without inventing a recovered graph. Its local status `5` must not be
silently promoted to an unconditional final function return: shared error
processing can still change behavior. No target execution is authorized here.
The post-serialization-fix Pragma task is fixed in `sqlite-pragma-question.txt`.
It tests a previously inaccessible code facet rather than treating a byte-limit
failure as a fast completed answer. The two experimental calling modes use the
same twelve methods and new engine digest `2290e8b1…`, with common normalization
guidance enabled in both. There is no new traditional cost cell for this task.
For the same pinned SQLite artifact, independent GNU instruction checks establish:
- `sqlite3Pragma` entry `0xb90e0`; value-pointer test `0xbae56` / branch `0xbae5c`
distinguishes the read path from change handling at `0xb9b8c`.
- `0xb9b90` tests connection byte `+0x65`; zero branches at `0xb9b94` to diagnostic
selection at `0xbc58a`. This precedes the additional selector-one bypass at
`0xb9b9a` / `0xb9b9f`, so their ordering must be preserved.
- Allowed local update computes `(value+1)&7`, substitutes one for zero, and
stores the selected record's byte `+0x10` at `0xb9bdc`; byte `+0x11` becomes one
at `0xb9be3`. The input interpretation and source member names are derivations.
- The actual diagnostic call is `0xbc596` through `sqlite3ErrorMsg@plt` at
`0x2a1e0`; `0xbc59b` jumps to common cleanup `0xb9293`.
- Cleanup releases both temporary strings, checks the stack canary, and returns
at `0xb92d9`. Do not invent a fixed numeric return from this reconstructed
void routine. No SQL-level runtime trigger is demonstrated.
Pragma's complete retained code and mappings are checked equal before/after the
serialization fix. Its recovered graph remains explicitly unavailable at the
encoded-byte capacity; that is a coverage limitation in both experimental lanes.
The next seeded table-composition task is fixed in `sqlite-table-question.txt`.
Both experimental modes have the same thirteen methods including `bytes`; a
traditional comparison is not claimed because its selected catalog/available
Kuna byte capability has not been established for this task. GNU disassembly of
the pinned artifact shows `sqlite3GetToken` at `0xe1480`: unsigned input byte load
at `0xe1480`, class-table base `0x12bcc0` at `0xe1484`, bound `0x1e` at `0xe1492`,
class reload `0xe1498`, jump-table base `0x12b600` at `0xe149c`, sign-extending
32-bit table load at `0xe14a3`, base addition `0xe14a7`, indirect jump `0xe14aa`.
The out-of-range path begins `0xe14f8`.
Independent direct file reads are valid here because `readelf -lW` binds this
artifact's selected addresses to the same file offsets in its read-only LOAD
segment (`0x11a000..0x154bfc`). A Python `struct.unpack_from('<i', ...)` check of
the actual table bytes gives these initial dispatch facts, before model trials:
| Input byte | Class | Signed displacement | Initial machine destination |
| ---------- | ----: | ------------------: | --------------------------- |
| `0x2d` | 11 | -302928 | `0xe16b0` |
| `0x2f` | 16 | -302144 | `0xe19c0` |
| `0x27` | 8 | -302480 | `0xe1870` |
| `0x22` | 8 | -302480 | `0xe1870` |
| `0x3f` | 6 | -302272 | `0xe1940` |
| `0x80` | 27 | -303440 | `0xe14b0` |
This oracle establishes static table/dispatch arithmetic, not final token
semantics, future runtime table contents or a feasible SQL input. Models must
retain those boundaries. This document is not supplied to measured models.
## Cross-function facts work; adapter gains remain mixed
The structured-call experiment closes an observed native export gap: the call's
fspec annotation does not identify its target code address, and an argument's
SSA storage is not its passing location. Reusing the native call-spec owner now
allows a model to connect a caller value to a callee input without parsing a
display string. Real SQLite answers support this connection with machine
instructions, trace a shared parenthesis counter across two functions, and
preserve the limits of recovered slots, aliases and runtime feasibility.
The first question pair omitted oracle-required alternative return paths in both
answers. Its wording was less explicit than its oracle, so that result stays a
partial-coverage record. A new question clarification was committed before the
next pair; both then satisfy the task. The failed engine-pin setup launch also
remains recorded. No sample is silently converted into a completed task.
In the correctness-equal pair, Code Mode uses 596,978 cumulative input tokens and
156.821 seconds versus direct's 611,321 and 147.424 seconds. Uncached input,
output, largest observed response input and family CPU are higher for Code Mode;
family memory peak is lower. Both use the same fourteen fact methods and a client
with JavaScript dispatch. The evidence supports usable composable call/input
facts, without proving that this server adapter is faster or cheaper. Broader
complex-software superiority and provider parity remain unproven.
Two remaining boundaries deserve independent experiments. First, the initial call view lived inside full recovered IR, so graph capacity
could hide a small otherwise useful call view. The next exporter revision now
captures calls and their boundary values independently; real VM verification
retains both while the graph exceeds capacity. Second, shallow outgoing references should serve a callee/reference list before
requesting deeper argument/value recovery. The subsequent implementation now
exposes Kuna's existing `xrefs --from` through the shared parser, with native kind
filters, explicit scope and paging. Real VM known-target references match an
independent disassembly pair set, and remain available when the full IR facet
exceeds capacity. The next pre-pinned model question measures this use directly. Keeping those costs
and coverage distinctions explicit is more useful than treating a smaller tool
catalog as proof of better analysis.
The shallow-reference question now completes through both real-model adapters.
Each composes 396 VM reference rows into 171 exact destinations and 16 calls to
the selected PLT address, then distinguishes a real stack-check call absent from
optimized IR. Both keep unresolved indirect/discovery/runtime limits. Native
reference pairs from both model sessions match the complete independent set of
396 direct immediate machine calls; the separate 21 indirect instructions are
not silently included in those known-target totals.
In this one pair, Code Mode takes 93.837 seconds and 264,680 cumulative input
versus direct's 106.183 and 285,086. Their maximum observed response input
contexts are almost equal. This is useful positive evidence for selected facts
plus local aggregation, while prior completed tasks show mixed adapter costs.
It supports continuing the experiment, not a universal speed/token/provider
superiority claim. Tool coverage and representation semantics were prerequisites
for this comparison: a recovered-call-only view would have missed a real call,
and VM full-IR capacity cannot establish that its shallow references are absent.
An additional shared CLI/API run with the unpatched stock Kuna 1.833 executable
also returns the same 396/171/16 VM aggregates, with fresh owned HOME/cache. The
outgoing-reference capability uses native support, independently of the opt-in
IR exporter. It takes 3.044 family wall / 2.695 CPU seconds and 182.6 MiB peak,
with cleanup verified and OOM 0; these scripted costs are not model-token data or
an adapter comparison. Stock external-spec freshness is still outside the engine
binary digest. Full repository typechecking remains resource-limited as recorded
in `native-engine.md`; source build, focused tests, changed-test typing and full
lint/module checks pass.
The bounded call-rooted definition projection now supports a local VM PHI task
that full-graph capacity previously prevented. Four real-model answers over two
revisions correctly recover both PHIs, all four alternatives and machine
transfers, with source identities and global partial coverage retained. This is
selected static-task coverage, not general complex-software superiority.
The discovery correction removes an observed name-list miss and fixes defaulted
input schemas, but the second pair does not show stable cost improvement. Direct
has a 120-second native timeout before a successful retry; Code Mode changes its
query strategy and costs more than its first run. The complete costs and failure
remain in [the ledger](trials.md#phi-alternatives-after-named-discovery-correction).
Fairness requires sufficient facts, correct discovery and honest retry reporting.
The wide-PHI experiment provides a more precise candidate atom: an input slot is
an individually selectable relationship, not just an array inside an operation.
Its identity includes the operation and slot index; several relationships can
share one value while preserving different predecessor edges. A value definition
can then be composed with selected operation/value reads. Both measured models
recover those distinctions and separate retained-node absence from unretained
membership without fetching all 156 slots.
This validates the shared query boundary, not adapter superiority. Code Mode
groups the same seven fact requests, but four discovery lookups erase the
MCP-request reduction at the observed model-response/client-dispatch level. Its
95.699 seconds versus direct's 91.817, nearly equal cumulative input and lower
uncached input remain a mixed single sample. Discovery is itself part of the
analyst workflow and deserves a separate test. Broader behavior reconstruction,
complete large-function CFG/use coverage, aliases and a universal RE basis are
still unproven. See [the complete scoped results](trials.md#selected-wide-phi-input-relationships).
The same question after adding a static method index again completes correctly
through both adapters. Code Mode now uses two discovery calls instead of four,
without changing the seven fact reads. Observed model responses decrease by one,
but total time increases slightly; direct also takes longer and uses fewer input
tokens without changing query counts. The second pair is approximately 98.8
seconds each, with more cumulative and less uncached input for Code Mode. This
supports the index's discoverability, while leaving whole-task cost mixed.
There is a further distinction to test: an atomic fact API does not itself make
native computation atomic. A fresh selected-slot question still incurs an entire
function decompilation and C rendering. Phase costs are unmeasured, so neither
removing C nor introducing persistent state is yet justified as a speed fix.
Measure that boundary before claiming analysis-time improvement from narrower
fact responses.
+244
View File
@@ -0,0 +1,244 @@
import { getQuickJS } from "quickjs-emscripten";
import { methods } from "./api.mjs";
import { MAX_BRIDGE_BYTES as MAX_BRIDGE, EXECUTION_LIMITS } from "./limits.mjs";
import { serializeJson } from "./json-capacity.mjs";
import { evidenceIds, serializationFailure } from "./fact-provenance.mjs";
import { projectFactFailure } from "./fact-error.mjs";
const MAX_OUTPUT = EXECUTION_LIMITS.output_utf8_bytes;
const failure = (code, message) => ({ ok: false, error: { code, message } });
const projectGuestError = (code, error) => {
const message =
typeof error?.message === "string" ? error.message : String(error);
// Check raw size first: JSON escaping expands each code unit at most sixfold,
// so the second check has a 6×32 KiB string bound plus a fixed envelope.
if (
Buffer.byteLength(message) > MAX_OUTPUT ||
Buffer.byteLength(JSON.stringify({ code, message })) > MAX_OUTPUT
)
return {
code: "output_budget",
message: `JavaScript error exceeds the ${MAX_OUTPUT / 1024} KiB output budget; its message is omitted. Native Evidence remains retained.`,
details: {
original_error_code: code,
original_message_code_units: message.length,
original_message_omitted: true,
},
};
return { code, message };
};
export const executeJavaScript = async (
session,
code,
{
signal = new AbortController().signal,
timeoutMs = EXECUTION_LIMITS.timeout_ms.default,
cpuBudgetMs = EXECUTION_LIMITS.execution_cpu_ms,
} = {},
) => {
if (Buffer.byteLength(code) > EXECUTION_LIMITS.code_utf8_bytes)
return failure(
"code_budget",
`JavaScript source exceeds ${EXECUTION_LIMITS.code_utf8_bytes / 1024} KiB`,
);
const started = performance.now();
const context = session.context;
const lease = context?.lease;
const stop = new AbortController();
const combined = AbortSignal.any([signal, stop.signal]);
const deadline = Date.now() + timeoutMs;
const timer = setTimeout(() => stop.abort(), timeoutMs);
const QuickJS = await getQuickJS();
const runtime = QuickJS.newRuntime();
runtime.setMemoryLimit(EXECUTION_LIMITS.execution_heap_mib * 1024 * 1024);
runtime.setMaxStackSize(EXECUTION_LIMITS.execution_stack_bytes);
const budget = { used: 0, deadline: 0, exhausted: false };
const runGuest = (work) => {
budget.deadline = Date.now() + Math.max(1, cpuBudgetMs - budget.used);
const before = performance.now();
try {
return work();
} finally {
budget.used += performance.now() - before;
}
};
runtime.setInterruptHandler(() => {
budget.exhausted ||= Date.now() >= budget.deadline;
return budget.exhausted || combined.aborted || Date.now() >= deadline;
});
const vm = runtime.newContext();
const pending = new Set();
const calls = [];
const state = { disposed: false, evidence: new Set() };
const pump = () => {
if (!state.disposed) {
const result = runGuest(() => runtime.executePendingJobs());
if (result.error) {
result.error.dispose();
stop.abort();
}
}
};
installBridge(vm, session, { combined, lease, calls, pending, pump, state });
let outcome;
try {
const text = await evaluateGuest(vm, code, { runGuest, pump, combined });
if (Buffer.byteLength(text) > MAX_OUTPUT)
outcome = {
ok: false,
error: {
code: "output_budget",
message: `Return a smaller projection (${MAX_OUTPUT / 1024} KiB UTF-8 output budget); native Evidence remains retained`,
},
};
else
outcome = {
ok: true,
value: text === "undefined" ? null : JSON.parse(text),
};
} catch (error) {
outcome = {
ok: false,
error: projectGuestError(
budget.exhausted
? "cpu_budget"
: combined.aborted
? "cancelled"
: "javascript_error",
budget.exhausted
? "Guest synchronous execution budget exceeded"
: error,
),
};
} finally {
clearTimeout(timer);
stop.abort();
await Promise.allSettled(pending);
state.disposed = true;
vm.dispose();
runtime.dispose();
}
return {
...outcome,
context,
evidence_ids: [...state.evidence],
calls,
elapsed_ms: performance.now() - started,
};
};
const prepareBridgeResponse = (response) => {
const encoded = serializeJson(response, MAX_BRIDGE);
if (encoded.ok) return { response, text: encoded.text };
const delivered = serializationFailure(
response,
encoded.error,
"quickjs_bridge",
"bridge_budget",
),
bounded = serializeJson(delivered, MAX_BRIDGE);
if (!bounded.ok)
throw new Error("Bridge capacity diagnostic could not be encoded");
return { response: delivered, text: bounded.text };
};
const installBridge = (
vm,
session,
{ combined, lease, calls, pending, pump, state },
) => {
const bridge = vm.newFunction("analysis", (methodHandle, inputHandle) => {
const name = vm.getString(methodHandle);
const inputText = vm.getString(inputHandle);
if (
calls.length >= EXECUTION_LIMITS.max_host_calls ||
Buffer.byteLength(inputText) > MAX_BRIDGE
)
throw new Error("Host call or argument budget exceeded");
const promise = vm.newPromise();
const index = calls.length;
const started = performance.now();
calls.push({
method: name,
input: JSON.parse(inputText),
status: "pending",
});
const work = Promise.resolve()
.then(async () => {
const response = await session.call(
name,
JSON.parse(inputText),
combined,
lease,
);
for (const id of evidenceIds(response)) state.evidence.add(id);
const { response: delivered, text } = prepareBridgeResponse(response);
calls[index].status = delivered.ok ? "ok" : "error";
if (!delivered.ok) calls[index].error = delivered.error;
calls[index].elapsed_ms = performance.now() - started;
if (!state.disposed) {
const value = vm.newString(text);
promise.resolve(value);
value.dispose();
pump();
}
})
.catch((error) => {
const { response, text } = prepareBridgeResponse({
ok: false,
context: session.context,
error: projectFactFailure(error, "bridge_failed"),
});
for (const id of evidenceIds(response)) state.evidence.add(id);
calls[index].status = "error";
calls[index].error = response.error;
calls[index].elapsed_ms = performance.now() - started;
if (!state.disposed) {
const value = vm.newString(text);
promise.resolve(value);
value.dispose();
pump();
}
})
.finally(() => pending.delete(work));
pending.add(work);
return promise.handle;
});
vm.setProp(vm.global, "__analysis", bridge);
bridge.dispose();
};
const evaluateGuest = async (vm, code, { runGuest, pump, combined }) => {
const bootstrap = `globalThis.rea=Object.freeze(Object.fromEntries(${JSON.stringify(Object.keys(methods))}.map(name=>[name,async(input={})=>JSON.parse(await __analysis(name,JSON.stringify(input)))])));`;
vm.unwrapResult(runGuest(() => vm.evalCode(bootstrap))).dispose();
const promiseHandle = vm.unwrapResult(
runGuest(() =>
vm.evalCode(
`(async()=>JSON.stringify(await(async()=>{\n${code}\n})()))()`,
),
),
);
try {
const resolved = vm.resolvePromise(promiseHandle);
pump();
// A never-settling guest Promise must not hang the MCP request forever.
const aborted = new Promise((_, reject) => {
if (combined.aborted) {
reject(new Error("Execution cancelled"));
return;
}
combined.addEventListener(
"abort",
() => reject(new Error("Execution cancelled or timed out")),
{ once: true },
);
});
const result = await Promise.race([resolved, aborted]);
const value = vm.unwrapResult(result);
const text = vm.getString(value);
value.dispose();
return text;
} finally {
promiseHandle.dispose();
}
};
@@ -0,0 +1,120 @@
import test from "node:test";
import assert from "node:assert/strict";
import { executeJavaScript } from "./executor.mjs";
const fake = {
context: { lease: "test" },
call: async (name, input) => ({ ok: true, data: { name, input } }),
};
test("real QuickJS composes async API calls and does not expose host globals", async () => {
const result = await executeJavaScript(
fake,
'const a=await rea.strings({query:"x"}); const b=await rea.operations({ids:[a.data.name]}); return {a,b,host:[typeof process,typeof require,typeof fetch]};',
);
assert.equal(result.ok, true, JSON.stringify(result));
assert.deepEqual(result.value.host, ["undefined", "undefined", "undefined"]);
assert.equal(result.calls.length, 2);
assert.equal(result.value.b.data.input.ids[0], "strings");
});
test("infinite guest execution and never-resolving promises terminate", async () => {
const loop = await executeJavaScript(fake, "while(true){}", {
timeoutMs: 30,
});
assert.equal(loop.ok, false);
const stalled = await executeJavaScript(
fake,
"await new Promise(()=>{});return 1",
{ timeoutMs: 30 },
);
assert.equal(stalled.ok, false);
});
test("output budgets and failures survive without silently clipping evidence", async () => {
const result = await executeJavaScript(fake, 'return "x".repeat(40000)');
assert.equal(result.error.code, "output_budget");
const failure = await executeJavaScript(
fake,
'throw new Error("explicit failure")',
);
assert.equal(failure.ok, false);
});
test("guest CPU budget is independent from the native-analysis wall deadline", async () => {
const before = performance.now();
const result = await executeJavaScript(fake, "while(true){}", {
timeoutMs: 5000,
cpuBudgetMs: 25,
});
assert.equal(result.error.code, "cpu_budget");
assert.ok(performance.now() - before < 2000);
});
test("cancelled reads keep partial-observation Evidence in the execution receipt", async () => {
const result = await executeJavaScript(
{
context: { lease: "partial" },
call: async () => ({
ok: false,
error: {
code: "cancelled",
details: {
partial_observation: { source: { evidence_id: "ev_partial" } },
},
},
}),
},
"return await rea.strings({query:'x'})",
);
assert.deepEqual(result.evidence_ids, ["ev_partial"]);
assert.equal(result.value.error.code, "cancelled");
});
test("failed compositions keep completed facts and their provenance after draining", async () => {
const owner = {
context: { lease: "retained" },
call: async () => ({ ok: true, data: { evidence_id: "ev_retained" } }),
};
for (const ending of [
'throw new Error("after analysis")',
'return "x".repeat(40000)',
]) {
const result = await executeJavaScript(
owner,
`await rea.strings({}); ${ending}`,
);
assert.equal(result.ok, false);
assert.deepEqual(result.evidence_ids, ["ev_retained"]);
assert.deepEqual(result.context, owner.context);
assert.equal(result.calls[0].status, "ok");
}
});
test("guest exceptions obey output capacity, including JSON expansion, and preserve observations", async () => {
for (const code of [
'throw new Error("x".repeat(40000))',
'throw new Error("\\0".repeat(6000))',
]) {
const result = await executeJavaScript(
{
context: { lease: "error-output" },
call: async () => ({
ok: true,
data: { evidence_id: "ev_before_error" },
}),
},
`await rea.strings({}); ${code}`,
);
assert.equal(result.ok, false);
assert.equal(result.error.code, "output_budget");
assert.equal(result.error.details.original_error_code, "javascript_error");
assert.equal(result.error.details.original_message_omitted, true);
assert.ok(Buffer.byteLength(JSON.stringify(result.error)) <= 32768);
assert.deepEqual(result.evidence_ids, ["ev_before_error"]);
assert.equal(result.context.lease, "error-output");
}
const ordinary = await executeJavaScript(
fake,
'throw new Error("x".repeat(10000))',
);
assert.equal(ordinary.error.code, "javascript_error");
assert.ok(ordinary.error.message.includes("x".repeat(10000)));
});
@@ -0,0 +1,36 @@
import { projectAnalysisError } from "../../dist/domain/analysisErrorProjection.js";
import { z } from "zod";
// Shared expected-failure algebra; execution adapters do not depend on native protocols.
export class FactFailure extends Error {
constructor(code, message, details = {}) {
super(message);
this.code = code;
this.details = details;
}
}
export const projectFactFailure = (error, fallback = "analysis_failed") => ({
code:
error instanceof z.ZodError
? "invalid_input"
: typeof error?.code === "string" && error.code
? error.code
: fallback,
message: typeof error?.message === "string" ? error.message : String(error),
details: error?.details ?? {},
});
export const requireResult = (result, code = "provider_failure") => {
if (!result.ok) {
const failure = result.error?._tag
? projectAnalysisError(result.error)
: result.error;
throw new FactFailure(
failure?.code ?? code,
String(failure?.message ?? failure?.reason ?? failure),
{ failure },
);
}
return result.value;
};
@@ -0,0 +1,60 @@
// Transport failures keep the lease and the already retained observation sources.
const dataProperty = (value, key) =>
value && typeof value === "object"
? Object.getOwnPropertyDescriptor(value, key)?.value
: undefined;
export const evidenceIds = (response) => {
const ids = new Set();
const add = (id) => {
if (typeof id === "string" && id) ids.add(id);
};
const error = dataProperty(response, "error"),
details = dataProperty(error, "details"),
observation =
dataProperty(response, "data") ??
dataProperty(details, "partial_observation"),
results = dataProperty(observation, "results");
for (const row of [observation, ...(Array.isArray(results) ? results : [])]) {
add(dataProperty(dataProperty(row, "source"), "evidence_id"));
add(dataProperty(row, "evidence_id"));
add(
dataProperty(
dataProperty(dataProperty(row, "error"), "details"),
"evidence_id",
),
);
}
add(dataProperty(details, "evidence_id"));
for (const values of [
dataProperty(response, "evidence_ids"),
dataProperty(details, "evidence_ids"),
])
if (Array.isArray(values)) for (const id of values) add(id);
return [...ids];
};
export const serializationFailure = (response, failure, scope, code) => {
const ids = evidenceIds(response),
primary = response?.ok === false ? response.error?.code : undefined;
return {
ok: false,
context: dataProperty(response, "context") ?? null,
error: {
code: primary ?? (failure.kind === "capacity" ? code : "invalid_result"),
message:
failure.kind === "capacity"
? `Selected response exceeds the ${scope} byte budget. Select fewer fields or a smaller page; use any reported Evidence IDs to inspect retained observations.`
: `Selected response cannot be JSON encoded: ${failure.reason}`,
details: {
scope,
...failure,
evidence_ids: ids,
evidence_retention: ids.length ? "retained_by_lease" : "unknown",
...(primary
? { original_message_omitted: true, original_details_omitted: true }
: {}),
},
},
};
};
@@ -0,0 +1,76 @@
// Shared read projections and partial batch semantics; no provider protocols.
// Parsed JSON facts are owned by their cache. SDK callers may retain views,
// but must not be able to change later reads under the same Evidence identity.
export function freezeFacts(value) {
if (value && typeof value === "object") {
for (const child of Object.values(value)) freezeFacts(child);
Object.freeze(value);
}
return value;
}
export const sourceSummary = ({
evidence_id,
sha256,
bytes,
elapsed_ms,
capture_complete,
}) => ({
evidence_id,
sha256,
bytes,
elapsed_ms,
...(capture_complete === undefined ? {} : { capture_complete }),
});
export const projectFact = (row, fields, identity) =>
fields
? Object.fromEntries(
[...new Set([...identity, ...fields])]
.filter((key) => Object.hasOwn(row, key))
.map((key) => [key, row[key]]),
)
: row;
export const pageFacts = (rows, input, identity = []) => ({
items: rows
.slice(input.offset, input.offset + input.limit)
.map((row) => projectFact(row, input.fields, identity)),
total: rows.length,
next_offset:
input.offset + input.limit < rows.length
? input.offset + input.limit
: null,
});
export async function readFactBatch(requests, capture, read) {
const results = [];
for (const request of requests) {
let source;
try {
const captured = await capture(request);
source = captured.source;
const facts = await read(captured, request);
results.push({
...facts,
ok: true,
address: request.address,
source: sourceSummary(source),
});
} catch (error) {
results.push({
ok: false,
address: request.address,
error: {
code: error.code ?? "provider_failure",
message: error.message,
details: {
...error.details,
...(source ? { evidence_id: source.evidence_id } : {}),
},
},
});
}
}
return { results };
}
@@ -0,0 +1,21 @@
// Read-only kernel counters for the currently bounded diagnostic payload.
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
export async function familyCounters() {
const group = (await readFile("/proc/self/cgroup", "utf8"))
.split("\n")
.find((row) => row.startsWith("0::"))
?.slice(3);
assert.ok(group?.includes("rea-efficiency-"), "Run under resource-run.py");
const cpu = (await readFile(`/sys/fs/cgroup${group}/cpu.stat`, "utf8")).match(
/^usage_usec (\d+)$/mu,
);
assert.ok(cpu, "Missing cgroup CPU counter");
return {
cpu: Number(cpu[1]),
peak: Number(
(await readFile(`/sys/fs/cgroup${group}/memory.peak`, "utf8")).trim(),
),
};
}
@@ -0,0 +1,90 @@
# Native function-boundary oracle
Freeze the question, oracle, runtime and complete catalogs before real models.
Question contains the observed formats but no addresses/counts/native IDs.
The target is the same stripped Debian OpenSSH client as the warning study:
`/usr/bin/ssh`, SHA-256
`04f2ff5f506a3f332e7adeb1478a4c551ae74acdd328e6fb5c2495664d4064e6`.
Use the new pinned experimental engine for both lanes, not a stock capability
claim. Verify the final engine's complete prior function records unchanged except
for the added independent parameters facet before scoring model answers.
References select banner function `0x25cb0` (banner `0xc8628`, xref `0x25d14`)
and strict-diagnostic caller `0x280c0` (format `0xc9018`, xref `0x28e6c`).
The selected direct call is `0x28d53 -> 0x25cb0`; another incoming caller is
not the requested caller. These are native/reference observations, not guessed
original source names. Global reference discovery remains incomplete.
Both native prototypes report model label `__stdcall`, model_unknown false,
inputs_locked/output_locked false, variadic false, input_errors/output_errors
false. The label is not evidence for a Windows ABI, original signature or
runtime binding; flags report native state, not model correctness. Every native
parameter/output in these two captures has type/name/size locks, this_pointer,
indirect_storage and hidden_return false.
Banner prototype has four entries, all eight bytes:
| Native index | Storage |
| ------------ | ------------------- |
| 0 | register:0x38 (RDI) |
| 1 | register:0x30 (RSI) |
| 2 | register:0x10 (RDX) |
| 3 | register:0x8 (RCX) |
Its output is explicitly is_void true, size 0 and null storage; native type_name
is an empty string, which must not erase the explicit void observation.
Its complete retained graph has three is_input values. Only native entries 0
and 3 have exact retained input matches; entries 1/2 do not. No original source
arity or absence of source parameters follows from either count/missing match.
Caller prototype has ten native entries:
| Native index | Storage / bytes |
| ------------ | ----------------- |
| 0 | register:0x38 / 8 |
| 1 | register:0x30 / 8 |
| 2 | register:0x10 / 8 |
| 3 | register:0x8 / 2 |
| 4 | register:0x80 / 8 |
| 5 | register:0x88 / 4 |
| 6 | stack:0x8 / 4 |
| 7 | stack:0x10 / 4 |
| 8 | stack:0x18 / 4 |
| 9 | stack:0x20 / 8 |
Its output is is_void false, eight-byte register:0x0 (RAX), type_name xunknown8.
This is a recovered return descriptor, not proof of original 64-bit C return
type. Its complete graph has 44 is_input values; every native parameter tuple
has an exact input match. Extra input varnodes do not thereby become formals.
Preserve stack coordinates as native values without inventing a cross-call
stack rebase, alias/subregister/split/join interpretation or source ordinals.
Selected caller CALL `0x28d53:779` passes value `v10000a9cf` at recovered input 1 in RDI
(register:0x38 / 8), matching banner native slot 0's storage. The banner's
matched input value is `v30000002e`; its first helper call `0x25cc3:1e`
uses that identity at input 1 and targets `0x42c20`. Exact caller value IDs and
all matched callee/caller input IDs must be checked against the actual delivered
sources, retaining separate snapshot scopes even when storage or IDs coincide.
[Existing independent machine evidence](ssh-warning-oracle.md) verifies
`MOV RDI,R15` at `0x28d50`, CALL `0x28d53 -> 0x25cb0`, incoming RDI saved
to R13 at `0x25cbc`, and helper CALL `0x25cc3 -> 0x42c20` with RDI unchanged.
A matching register and known direct target support this selected transfer;
they are not cross-function SSA equality or general aliases/runtime feasibility.
Score the complete answer for owner/caller, both full native parameter
inventories and return/flag semantics, raw input counts and exact matches,
explicit missing/unknown interpretation, selected cross-function pointer and
machine corroboration, source identities, target digest, scope and close.
Both routes get the same question, complete twenty/four-tool catalogs, requested
`gpt-6.1-sol/high` via Codex 0.161.0, fresh isolated leases/private caches and
common discovery/envelope/wait guidance. Charge whole-task cumulative/cached/
uncached input, output/reasoning, model responses, calls/retries/waits, wall/CPU
and kernel family memory. Preserve every attempt. No traditional-provider cell
is claimed for these native-only model facts. Remote model build/compute,
OS/model caches and host contention remain uncontrolled. No PR/main merge.
The banner's two exact retained input matches are slot 0 `v30000002e` and
slot 3 `v3000004b5`. Caller slots 0–9 match respectively `v30000005b`,
`v300000072`, `v30000007a`, `v700000032`, `v300000008`, `v500000082`,
`v50000b767`, `v50000b044`, `v500002b57`, `v10001374c`. These are evidence-
scoped native IDs, not cross-function globally stable object identities.
@@ -0,0 +1,38 @@
Analyze {{artifact_path}} statically from these two observed formats:
- REMOTE HOST IDENTIFICATION HAS CHANGED
- Host key for %.200s has changed and you have requested strict checking.
Identify the function that passes the banner format to its logging/formatting
call, and the caller that owns the strict-checking diagnostic. Establish both
from real references, not guessed source names. Reuse one retained native
capture per selected function and selected structured facts.
For both functions, inspect the native recovered function prototype separately
from raw input varnodes. Report its parameter-entry count, each native parameter
index with storage/width, return descriptor including explicit void/type/storage
knowledge, native model label, lock state and recovery-error flags. The model
label and recovered entries are not a proven original ABI or source signature.
Keep explicit unknowns and native hidden/indirect-storage flags.
Count retained values marked is_input in each complete recovered graph. For
each native parameter storage tuple, determine whether an exact space/offset/
width match exists among those retained input values, preserving matched value
IDs and explicitly reporting missing matches. Do not treat missing retained
matches as proof that a source parameter is absent. Do the two inventories
mean the same thing? Can either count establish original source arity? Use
the observed facts to explain the distinction, without parsing a C declaration.
At the selected direct caller-to-banner-function call, show the target and the
passed pointer's recovered operand index, value identity, storage and width.
Relate that transfer to the callee's matching native parameter entry and its
first helper-call use. Keep the two snapshots' SSA identities separate; matching
storage is not cross-function SSA equality or a general alias proof. Verify
the selected pointer setup/call and callee helper use with focused machine
instructions, including actual call targets and passing registers.
Return a focused answer with real Evidence IDs, target digest and necessary
coverage. Distinguish native recovered model observations, storage-based
connections and machine corroboration from original signature/ABI/runtime
claims. Preserve unresolved stack rebasing, split/join/subregister mappings,
aliases, runtime binding and feasibility. Do not return complete C/graph reports
or execute the target. Close the target lease.
@@ -0,0 +1,263 @@
# Native function boundaries as independent facts
The selected cross-function SSH task needs to distinguish recovered formal
prototype entries from raw input varnodes. The existing value is_input flag is
not formal membership: it also includes stack/global inputs. Recovering an
original source signature from either inventory would be unsupported.
A new shared `parameters` query selects native prototype indices, fields and
pages, with a separately projected return descriptor, native model label,
lock/variadic/recovery-error flags and retained Evidence. Defaults omit display
names/type strings. Explicit void, unknown storage/type, known missing native
indices, unavailable store and malformed capture remain distinct. Source arity,
ABI truth, runtime binding, aliases, stack rebasing and split/join mappings stay
unknown. Call-site argument storage is a separate fact. The analyst can compose
it with selected callee prototype/storage/value facts while retaining both
snapshots' identities and the selected machine corroboration.
One native function-prototype owner exports an independent parameters facet.
Its extraction does not depend on full CFG/call enumeration, and optional encoded
output budgeting retains typed omission reasons and readable code. The renderer
restores owned JSON fields by identity rather than a numeric position invalidated
by removing other independent facets. Native address/storage serialization and
JS storage contracts each have one shared owner for call sites and function
prototypes; parameters do not depend on a call-record schema's nested shape.
Shared application admission keeps the same named methods for SDK, CLI and both
MCP adapters. There are seventeen methods, twenty direct tools and four Code
Mode tools. No integration with stock Kuna or other providers is claimed.
The native overlay is pinned to upstream
`fe01d6294eb0d1053ce343c8943646df88e143fc`; the REA experiment was refreshed from
main `f22e8e726` before this change. Forward/reverse patch checks pass against
the pinned base/current source. All generated binaries, captures and caches stay
local. No PR or merge into main is intended.
## Current executed evidence
The first real SSH candidate engine is
`6aae471bef4434eb3acea98b497c6df58e3a9fa71021178c89bbbc3d96109080`.
Actual Code Mode MCP checks both functions, full/selected/empty parameter
queries, paging, exact retained input-location matches, repeated
metadata and complete source fidelity: removing only the added parameters facet
leaves each complete prior native function record unchanged. Banner `0x25cb0`
has four native prototype slots but three retained is_input values; slots 1/2
have no exact retained input match. Caller `0x280c0` has ten prototype slots and
44 raw input values, with all ten native storage tuples matched. Native labels
and flags are observations, not original source arity/ABI proof. Full expected
facts and limits are in the [oracle](function-boundary-oracle.md).
The JS suite passes 94 tests, including projection-only/unavailable/malformed
prototype reads, native identities/order/paging, explicit void versus unknown,
immutable SDK metadata and runtime/JSON Schema agreement. Both actual converted
MCP catalogs pass named schema/admission checks. Two native constructor tests
pass: absent stores stay unavailable, and native slots/void/return storage/locks
remain distinct. Full native workspace/corpus gates are unexecuted.
| Executed stage | Family wall s | CPU s | Kernel peak MiB |
| ------------------------------------- | ------------: | ------: | --------------: |
| Latest-main cached runtime build | 43.328 | 41.531 | 3,057.8 |
| Initial 94 JS tests | 29.271 | 9.085 | 82.1 |
| Initial converted catalog checks | 10.592 | 2.281 | 136.5 |
| Candidate real Code Mode SSH verifier | 8.676 | 8.439 | 319.9 |
| Candidate opt1 native build | 447.973 | 414.263 | 2,174.7 |
| Native constructor tests, two passed | 264.382 | 264.031 | 2,815.2 |
All completed rows have OOM/kill zero and verified payload cleanup, under one
CPU / 4 GiB hard / 3 GiB early-stop bounds. Kernel peaks include charged file
cache, not RSS. JS/schema validation overlapped bounded compilation on the same
CPU and is not an analysis-speed benchmark. The initial native build accidentally
selected default release optimization rather than the original opt1 profile; it
was deliberately interrupted after 135.878 seconds and its unique owned scope
verified inactive. Its final counters are unavailable. The corrected opt1
candidate build above completed; no interrupted build is reported as passing.
## Final native and public-boundary checks
The final engine is
`770ac3f2e66f23bfb825cb7b7231ccd9996837ea90a0f7f1cd48a8a47334f047`,
version 0.1.0, release opt1 with embedded specs. The committed full overlay hash
is `20ded012973157412706efc5b1834f9d6530a9e98e9e3bdc26ab34120ac7bac0`.
The complete native source still exactly matches that patch after building.
The earlier candidate's prototype facts and the final engine agree, and both
actual MCP routes independently reproduce the same full native boundary facts.
All prior function fields remain equal to the old complete goldens.
Thirteen native JSON producer tests pass, including the three new cases:
oversized parameters preserve established graph/call coverage in the fixture;
small independent parameters are reclaimed after graph/call omission; restoring
fields after other removals uses identity rather than a stale array position.
The two constructor tests and these JSON tests are focused runs; the complete
native library, CLI, workspace, stage and corpus gates are not claimed.
Real zlib SDK reads preserve cached metadata/storage against caller mutation.
The real CLI composes snapshot and a selected parameter/return read. Separate
real SDK checks use the old `a9ca8a8a...` experimental engine and upstream stock
1.833 (`d858918b...`): unavailable parameters are explicit, linked to the retained
Evidence, and code stays readable. The old native capture reports not-captured;
stock lacks the experimental capability. Neither fabricates a zero-entry
prototype. All three use explicitly pinned local engines, without global setup.
| Additional executed stage | Family wall s | CPU s | Kernel peak MiB |
| ------------------------------------- | ------------: | ------: | --------------: |
| Native JSON tests, 13 passed | 315.129 | 314.664 | 2,138.6 |
| Final native runtime build | 102.590 | 102.370 | 621.6 |
| Final Code Mode SSH verifier | 8.778 | 8.527 | 324.2 |
| Final direct SSH verifier | 9.690 | 9.319 | 300.4 |
| Final JS suite, 94 passed | 16.707 | 12.217 | 83.3 |
| Final converted schema/catalog check | 5.392 | 3.856 | 134.8 |
| Real final-engine zlib SDK | 3.665 | 2.782 | 113.8 |
| Real old-native SDK unavailable check | 5.081 | 3.420 | 125.9 |
| Real stock SDK unavailable check | 4.178 | 2.983 | 101.0 |
| Real zlib CLI | 4.006 | 2.907 | 118.5 |
All have OOM/kill zero and verified payload cleanup under the same one-CPU,
4 GiB hard / 3 GiB early-stop controls. Kernel peaks include charged file cache,
not RSS. These are check/build observations with uncontrolled host conditions,
not proof of native analysis acceleration. Final JS/schema checks cover the
shared storage refactor and the native admission helper shared by existing
values/calls/switches/blocks/path and the new method. Lint has no warnings and
all changed-file formatting passes. Full REA production gates are unexecuted.
## Frozen real-model protocol and results
The [question](function-boundary-question.txt), [oracle](function-boundary-oracle.md)
and complete runtime/HEAD were frozen at
`5ca00675b7fe487ba991c6fc6cd09ae67a7af24c`. The question starts from two formats,
with no addresses/counts/native IDs/paths. Both enabled-tool manifests come from
the actual SDK catalog: twenty direct tools or four Code Mode tools. The exact
prompt and runtime source digests match between lanes; common discovery,
envelope/stopping and wait guidance is identical, with each lane's exact names.
Order is direct then Code Mode, using fresh isolated leases/private native
caches. Requested model/settings are `gpt-6.1-sol/high`, Codex 0.161.0. OS/model
caches, host contention, remote compute and the resolved service model build are
uncontrolled/unmeasured. This is a new question stratum, not a before/after
comparison with the earlier guard/warning question or a traditional-provider
cell for facts its selected interface does not expose.
Both complete answers pass agent review against the frozen criteria. They find
both owners from references, report the 4/10 native entries versus 3/44 raw
inputs, preserve every exact tuple/value-ID match and the two missing banner
matches, distinguish explicit void from null storage, and retain native model,
lock/error/hidden/indirect flags without claiming original source arity/ABI.
They correctly connect the selected caller operand through passing storage to
the callee's native entry/input and first helper, keeping the SSA IDs separate,
with focused machine corroboration and explicit stack/alias/runtime limitations.
Neither calls `code` or parses a C declaration. Each uses one capture per
selected function. Both close the lease.
Scripted checks verify every cited source's bytes/hash and target/engine identity,
complete prior native function fidelity except the added parameters facet,
prototype metadata/entries/output, raw input counts and all native tuple matches.
Direct cites nine observed sources; Code Mode cites ten. Full-answer grading is
primary-agent review, not a human declaration or automated language grading.
API lease handles expire on close; the explicitly requested raw Evidence
files remain available locally for the recorded source audit.
| Whole-task measure | Direct atomic | Code Mode |
| ------------------------------- | ------------: | --------: |
| Cumulative input tokens | 331,674 | 359,789 |
| Included cached input | 282,624 | 319,232 |
| Uncached input | 49,050 | 40,557 |
| Output tokens | 4,848 | 5,564 |
| Included reasoning output | 766 | 702 |
| Observed model responses | 12 | 13 |
| Client executions / waits | 11 / 0 | 12 / 0 |
| MCP attempts | 23 | 12 |
| Fact reads | 20 | 26 |
| Parameter reads, included above | 2 | 4 |
| Rejected MCP / inner API reads | 0 / 0 | 0 / 0 |
| Model wall seconds | 118.393 | 125.730 |
| Family wall seconds | 119.210 | 126.269 |
| Family CPU seconds | 18.682 | 18.944 |
| Kernel process-family peak MiB | 676.1 | 670.8 |
Per-response usage sums match the ledgers. Cached input is included in input;
reasoning is included in output. Discovery, schemas, extra reads and waiting
remain charged. Both actual clients already expose JavaScript execution despite
the configured feature flags, so this compares MCP adapters within that common
client surface. Every runtime/target/engine fingerprint remains unchanged;
both families have OOM/kill zero, verified payload cleanup and removed private
profiles. Code Mode actually invokes the guest executor and native fact APIs.
Code Mode uses fewer MCP requests and less uncached input, but more cumulative
input/output/responses, more fact reads and slightly more wall/CPU time. Its
local peak memory is slightly lower. It rereads selected parameter storage
inside a later guest program for a join; these are cached fact reads, not extra
native captures. These mixed costs do not establish a stable adapter advantage,
a causal speedup, original native-prototype accuracy or broad complex-software
superiority. No failed or under-equipped model attempt is silently discarded.
## What the composition requires
The selected caller value itself is at native `register:0xb8/8`, while the call
passes it in `register:0x38/8`. Joining the caller value's own coordinate directly
to the callee prototype would miss the real connection. The useful reusable
facts are distinct: the value identity/storage, its call operand occurrence,
that occurrence's passing location, the selected direct target, the callee's
recovered prototype entry and its retained input value/use. Machine instructions
corroborate the selected transfer; matching coordinates alone are not equality.
```mermaid
flowchart LR
V["Caller SSA value; own storage R15"] -->|"call operand 1"| C["Selected call; passing RDI/8"]
C -->|"direct target + machine CALL"| P["Callee native prototype slot 0; RDI/8"]
P -.->|"exact retained storage match"| I["Separate callee input SSA identity"]
I -->|"operand occurrence"| H["First helper CALL input 1"]
```
The prototype inventory and raw input inventory are also different fact sets.
Their native IDs, roles, widths, recovery authority and source scope must survive
composition. More granular JSON alone cannot supply that meaning. This experiment
now exposes those distinctions and demonstrates correct composition by two real
models on the stripped SSH artifact, while keeping original signatures, generic
interprocedural aliases, stack rebasing and full machine-flow recovery unknown.
Raw local records include `parameters-*`, `ssh-boundary-{direct,codemode}-v1*`,
`boundary-model-costs.json`, `boundary-answer-checks.json` and
`boundary-answer-review.json` under `.cache/atomic-codemode/`. No binaries,
provider project files, dependencies, private profiles or local check scripts
are committed. No PR/main merge or integration readiness is claimed.
## Post-model malformed-facet hardening
Final source review found a related admission bug: the outer function schema
validated every `*_error` as text before the independent facet reader ran.
A malformed child failure value could therefore reject the whole function,
losing valid code or unrelated graph/prototype facts. The new parameter field
had copied that existing coupling. This is deterministic malformed-boundary
reproduction, not an observed failure emitted by the real Rust engine.
The parent now admits opaque child error values; the single shared facet owner
validates a present reason as text and returns its tagged failure locally.
Graph Evidence access reuses that owner when the graph is absent instead of
reinterpreting raw failure values. Identity, function count, code and entry/input
admission remain parent responsibilities. Complete source Evidence is preserved.
There is no second failure parser or silent conversion of bad values to absence.
Replaying the old parent decoder from `5ca00675b` with the same failing path
rejects all 25 malformed fixtures (five facets, five non-text reason shapes).
The current decoder preserves code in all 25. Regression cases also retain a
healthy graph/source view for unrelated malformed facets, and a healthy prototype
when the graph's failure value is malformed. The new negative test has its own
small module instead of expanding the already large IR-semantic test file.
The 95-test suite passes (4.850 family wall / 4.639 CPU seconds / 84.9 MiB),
followed by the focused eight-case files after moving that new test (1.025 /
0.833 / 61.1). Both real SSH MCP routes repeat successfully on the hardened
source and preserve every previously verified native boundary fact and complete
old-function fidelity. Their Code Mode/direct families cost 8.677 / 8.467 /
321.5 MiB and 8.475 / 8.183 / 299.6 MiB respectively; all completed checks have
OOM/kill zero and verified cleanup. The engine/patch are unchanged.
After moving the new test, the complete explicit Node glob again passes all 95
cases (5.052 family wall / 4.857 CPU seconds / 82.6 MiB). The repository's
`verify:test-discovery` inventory check also passes: 1,441 files discovered once
(1.328 / 0.988 / 150.5 MiB). That inventory check does not execute those files;
the experiment's executed test scope is the explicit Node suite above.
The real-model table remains pinned to the earlier `5ca00675b` runtime; those
models were not rerun after this malformed-input-only change. Post-hardening
module/public-provider checks do not become new model measurements. Local
reproduction/check receipts are `parameters-facet-before-after*`,
`parameters-facet-failure-*`, `parameters-hardened-*` and the final test/discovery
records. The full repository/native gates remain unexecuted.
@@ -0,0 +1,33 @@
import { parseKunaInventory } from "../../dist/kuna/KunaProjectFiles.js";
import { requireResult } from "./fact-error.mjs";
import { freezeFacts, pageFacts } from "./fact-reads.mjs";
export const parseFunctionFacts = (text) =>
freezeFacts(
requireResult(parseKunaInventory(text), "invalid_provider_output"),
);
export function selectFunctionFacts(functions, input) {
const addresses = input.addresses && new Set(input.addresses);
const normalize = (name) =>
input.case_sensitive ? name : name.toLowerCase();
const query = normalize(input.query);
const matches = functions.filter(
(entry) =>
(!addresses || addresses.has(entry.address)) &&
[entry.name, ...entry.aliases].some((name) =>
input.exact
? normalize(name) === query
: normalize(name).includes(query),
),
);
return {
...pageFacts(matches, input, ["address"]),
coverage: {
scope: "native callable-entry inventory, including import stubs",
discovery: "unknown",
extents: "upper bounds clipped at the next entry; zero means unmeasured",
symbol_binding_at_runtime: "unknown",
},
};
}
@@ -0,0 +1,93 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseFunctionFacts, selectFunctionFacts } from "./function-facts.mjs";
import { readFactBatch } from "./fact-reads.mjs";
import { FactFailure } from "./fact-error.mjs";
test("function names retain multiple entries and aliases instead of choosing a PLT or implementation", () => {
const facts = parseFunctionFacts(
JSON.stringify({
functions: [
{
name: "format_error",
address_hex: "0x1000",
aliases: ["format_error@plt"],
size: 16,
},
{
name: "format_error",
address_hex: "0x2000",
aliases: ["FormatError"],
size: 0,
},
],
}),
);
const query = {
query: "format_error",
exact: true,
case_sensitive: true,
offset: 0,
limit: 20,
};
assert.deepEqual(
selectFunctionFacts(facts, query).items.map((item) => item.address),
["0x1000", "0x2000"],
);
assert.equal(
selectFunctionFacts(facts, { ...query, query: "format_error@plt" }).items[0]
.address,
"0x1000",
);
assert.equal(
selectFunctionFacts(facts, {
...query,
query: "FORMAT_ERROR",
case_sensitive: false,
}).total,
2,
);
assert.deepEqual(
selectFunctionFacts(facts, {
...query,
addresses: ["0x2000"],
fields: ["size"],
}).items,
[{ address: "0x2000", size: 0 }],
);
assert.throws(() => {
facts[0].aliases.push("foreign");
});
});
test("batch transport and decoder failures preserve successful items and captured source identity", async () => {
const attempts = [];
const result = await readFactBatch(
[{ address: "0x1" }, { address: "0x2" }, { address: "0x3" }],
async (request) => {
attempts.push(request.address);
if (request.address === "0x2")
throw new FactFailure("capacity", "transport bound");
return {
source: {
evidence_id: `ev_${request.address}`,
sha256: "digest",
bytes: 3,
elapsed_ms: 1,
},
};
},
async (_, request) => {
if (request.address === "0x3")
throw new FactFailure(
"invalid_provider_output",
"decoder rejected source",
);
return { items: [{ value: 1 }] };
},
);
assert.deepEqual(attempts, ["0x1", "0x2", "0x3"]);
assert.equal(result.results[0].items[0].value, 1);
assert.equal(result.results[1].error.code, "capacity");
assert.equal(result.results[2].error.details.evidence_id, "ev_0x3");
});
@@ -0,0 +1,2 @@
// Bounds admitted by the native graph owner, also used for graph selections.
export const MAX_GRAPH_BLOCKS = 12000;
@@ -0,0 +1,109 @@
// The machine-decoding boundary is separate from optimized recovered IR.
import { z } from "zod";
import { FactFailure } from "./fact-error.mjs";
import { NATIVE_OUTPUT_BYTES } from "./limits.mjs";
const hex = z.string().regex(/^0x(?:0|[1-9a-f][0-9a-f]{0,15})$/u);
const rowSchema = z.object({
address_hex: hex,
size: z.number().int().positive().max(65536),
bytes: z.string().regex(/^(?:[0-9a-f]{2})+$/u),
mnemonic: z.string(),
operands: z.string(),
text: z.string(),
});
const envelopeSchema = z.object({
binary: z.string(),
kind: z.literal("code"),
start_hex: hex,
end_hex: hex,
count: z.number().int().nonnegative().max(4096),
bytes: z.number().int().nonnegative(),
truncated: z.boolean(),
notes: z.array(z.string()),
});
const requireFact = (condition, message) => {
if (!condition) throw new FactFailure("invalid_provider_output", message);
};
export function parseInstructions(
text,
inputPath,
request,
fields = ["bytes", "text"],
) {
try {
requireFact(
Buffer.byteLength(text) <= NATIVE_OUTPUT_BYTES,
"Instruction source exceeds transport capacity",
);
const raw = JSON.parse(text);
requireFact(
Array.isArray(raw?.instructions) && raw.instructions.length <= 4096,
"Instruction window exceeds decoded-row capacity",
);
const doc = envelopeSchema.parse(raw);
requireFact(
doc.binary === inputPath && doc.start_hex === request.address,
"Instruction source does not match the selected input/window",
);
requireFact(
doc.count === raw.instructions.length && doc.count <= request.count,
"Instruction count does not match the requested window",
);
let next = BigInt(request.address);
const items = raw.instructions.map((value) => {
const row = rowSchema.parse(value);
requireFact(
BigInt(row.address_hex) === next && row.bytes.length === row.size * 2,
"Instruction bytes/size or sequential address mismatch",
);
next += BigInt(row.size);
const fact = {
address: row.address_hex,
size: row.size,
status: row.mnemonic === ".byte" ? "undecoded" : "decoded",
bytes: row.bytes,
mnemonic: row.mnemonic,
operands: row.operands,
text: row.text,
};
return Object.fromEntries(
[...new Set(["address", "size", "status", ...fields])].map((key) => [
key,
fact[key],
]),
);
});
requireFact(
next === BigInt(doc.end_hex) &&
next - BigInt(request.address) === BigInt(doc.bytes),
"Instruction window end/byte coverage mismatch",
);
return {
items,
resume_address: doc.end_hex,
coverage: {
authority: "machine bytes and native linear decoding; not recovered IR",
request,
listed_count: items.length,
truncated: doc.truncated,
notes: doc.notes,
alignment:
"caller-selected start; runtime execution and instruction alignment are not established",
},
};
} catch (error) {
if (error instanceof FactFailure) throw error;
throw new FactFailure(
"invalid_provider_output",
"Native instruction window does not match the declared format",
{
reason:
error instanceof z.ZodError
? error.issues[0]?.message.slice(0, 256)
: String(error.message).slice(0, 256),
},
);
}
}
@@ -0,0 +1,92 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseInstructions } from "./instruction-facts.mjs";
const document = (address = "0xd97e") => ({
binary: "/private/input",
kind: "code",
start_hex: address,
end_hex: `0x${(BigInt(address) + 6n).toString(16)}`,
count: 1,
bytes: 6,
truncated: true,
notes: ["selected window"],
instructions: [
{
address_hex: address,
size: 6,
bytes: "0f87e9080000",
mnemonic: "JA",
operands: "0xe26d",
text: "JA 0xe26d",
},
],
});
const parse = (doc, address = doc.start_hex) =>
parseInstructions(JSON.stringify(doc), "/private/input", {
address,
count: 1,
});
test("instruction facts preserve exact bytes/addresses and do not substitute an optimized CFG target", () => {
const result = parse(document());
assert.equal(result.items[0].address, "0xd97e");
assert.equal(result.items[0].text, "JA 0xe26d");
assert.equal(result.items[0].bytes, "0f87e9080000");
assert.equal(result.items[0].status, "decoded");
assert.deepEqual(result.coverage.notes, ["selected window"]);
const high = document("0x20000000000001");
high.instructions[0].address = Number(BigInt(high.start_hex));
assert.equal(parse(high).items[0].address, "0x20000000000001");
});
test("unknown bytes remain undecoded and projection retains byte-range identity", () => {
const doc = document();
doc.instructions[0].mnemonic = ".byte";
const result = parseInstructions(
JSON.stringify(doc),
"/private/input",
{ address: "0xd97e", count: 1 },
["mnemonic"],
);
assert.deepEqual(result.items[0], {
address: "0xd97e",
size: 6,
status: "undecoded",
mnemonic: ".byte",
});
});
test("wrong target/window, gaps, extent and byte-size contradictions fail at decoding boundary", () => {
for (const mutate of [
(doc) => {
doc.binary = "/other/input";
},
(doc) => {
doc.instructions[0].address_hex = "0xd97f";
},
(doc) => {
doc.instructions[0].size = 5;
},
(doc) => {
doc.end_hex = "0xd985";
},
(doc) => {
doc.count = 2;
},
]) {
const doc = document();
mutate(doc);
assert.throws(
() => parse(doc),
(error) => error.code === "invalid_provider_output",
);
}
assert.throws(() => parse(document(), "0xd970"), /window/u);
});
test("decoded-row capacity rejects oversized malformed arrays before expanding errors", () => {
const doc = document();
doc.instructions = Array.from({ length: 4097 }, () => ({}));
assert.throws(() => parse(doc), /capacity/u);
});
@@ -0,0 +1,182 @@
// Admit standard JSON encoding before allocating its expanded string.
import { types } from "node:util";
// JSON must escape controls and unpaired surrogates.
// eslint-disable-next-line no-control-regex
const escaped = /["\\\u0000-\u001f\ud800-\udfff]/u;
const shortEscapes = new Set([8, 9, 10, 12, 13]);
const omitted = (value) =>
value === undefined ||
typeof value === "function" ||
typeof value === "symbol";
// Above the remaining budget this returns a lower bound; otherwise it is exact.
const quotedBytes = (text, remaining) => {
if (text.length + 2 > remaining) return text.length + 2;
if (!escaped.test(text)) return Buffer.byteLength(text) + 2;
let bytes = 2;
for (let i = 0; i < text.length && bytes <= remaining; i++) {
const c = text.charCodeAt(i);
if (c === 34 || c === 92) bytes += 2;
else if (c < 32) bytes += shortEscapes.has(c) ? 2 : 6;
else if (c < 128) bytes++;
else if (c < 2048) bytes += 2;
else if (c >= 0xd800 && c <= 0xdbff) {
const next = text.charCodeAt(i + 1);
if (next >= 0xdc00 && next <= 0xdfff) {
bytes += 4;
i++;
} else bytes += 6;
} else bytes += c >= 0xdc00 && c <= 0xdfff ? 6 : 3;
}
return bytes;
};
const invalid = (reason) => ({
ok: false,
error: { kind: "invalid_json", reason },
});
class JsonMeasure {
bytes = 0;
stack = [];
ancestors = new Set();
constructor(limit) {
this.limit = limit;
}
capacity(minimum = this.bytes) {
return {
ok: false,
error: {
kind: "capacity",
limit_bytes: this.limit,
minimum_encoded_bytes: minimum,
},
};
}
add(count) {
this.bytes += count;
return this.bytes > this.limit ? this.capacity() : null;
}
enter(value) {
const validity = validateContainer(value, this.ancestors);
if (!validity.ok) return validity;
const array = Array.isArray(value),
minimum = array && value.length ? 2 * value.length + 1 : 2;
if (array && this.bytes + minimum > this.limit)
return this.capacity(this.bytes + minimum);
const failure = this.add(2);
if (failure) return failure;
const keys = array ? null : Object.keys(value);
this.ancestors.add(value);
this.stack.push({ kind: "exit", value });
this.stack.push({
kind: array ? "array" : "object",
value,
keys,
length: array ? value.length : keys.length,
index: 0,
first: true,
});
return null;
}
member(frame) {
if (frame.index === frame.length) return null;
const key =
frame.kind === "array"
? String(frame.index++)
: frame.keys[frame.index++],
descriptor = Object.getOwnPropertyDescriptor(frame.value, key);
if (descriptor?.get || descriptor?.set)
return invalid("JSON capacity admission does not invoke accessors");
if (frame.kind === "array" && !descriptor && key in frame.value)
return invalid("Inherited array elements are not owned JSON facts");
const child = descriptor?.value;
this.stack.push(frame);
if (frame.kind === "object") {
if (omitted(child)) return null;
const failure = this.add(
(frame.first ? 0 : 1) + quotedBytes(key, this.limit - this.bytes) + 1,
);
if (failure) return failure;
frame.first = false;
} else if (frame.index > 1) {
const failure = this.add(1);
if (failure) return failure;
}
this.stack.push({
kind: "value",
value: frame.kind === "array" && omitted(child) ? null : child,
});
return null;
}
value(value) {
if (value === null) return this.add(4);
switch (typeof value) {
case "string":
return this.add(quotedBytes(value, this.limit - this.bytes));
case "boolean":
return this.add(value ? 4 : 5);
case "number":
return this.add(Number.isFinite(value) ? String(value).length : 4);
case "object":
return this.enter(value);
default:
return invalid(`Unsupported JSON value: ${typeof value}`);
}
}
run(value) {
this.stack.push({ kind: "value", value });
while (this.stack.length) {
const frame = this.stack.pop();
if (frame.kind === "exit") {
this.ancestors.delete(frame.value);
continue;
}
const failure =
frame.kind === "value" ? this.value(frame.value) : this.member(frame);
if (failure) return failure;
}
return { ok: true, bytes: this.bytes };
}
}
const validateContainer = (value, ancestors) => {
if (types.isProxy(value))
return invalid("Proxy values are not owned JSON facts");
const array = Array.isArray(value),
prototype = Object.getPrototypeOf(value),
toJSON =
Object.getOwnPropertyDescriptor(value, "toJSON") ??
(prototype && Object.getOwnPropertyDescriptor(prototype, "toJSON")) ??
(prototype === Array.prototype &&
Object.getOwnPropertyDescriptor(Object.prototype, "toJSON"));
if (toJSON?.get || toJSON?.set || typeof toJSON?.value === "function")
return invalid("JSON capacity admission does not invoke custom toJSON");
if (
prototype !== (array ? Array.prototype : Object.prototype) &&
prototype !== null
)
return invalid("Only plain JSON records and arrays are supported");
if (ancestors.has(value)) return invalid("Cyclic JSON value");
return { ok: true };
};
/** Exact UTF-8 size when admitted; bounded traversal and honest lower bounds otherwise. */
export const measureJson = (value, limit) => {
if (!Number.isSafeInteger(limit) || limit < 0)
return invalid("JSON byte limit must be a nonnegative safe integer");
return new JsonMeasure(limit).run(value);
};
export const serializeJson = (value, limit) => {
const measured = measureJson(value, limit);
if (!measured.ok) return measured;
try {
const text = JSON.stringify(value);
if (typeof text !== "string" || Buffer.byteLength(text) !== measured.bytes)
return invalid("JSON value changed during encoding");
return { ok: true, text, bytes: measured.bytes };
} catch {
return invalid("JSON encoding failed after capacity admission");
}
};
@@ -0,0 +1,95 @@
import assert from "node:assert/strict";
import { mock, test } from "node:test";
import { measureJson, serializeJson } from "./json-capacity.mjs";
test("JSON admission matches native UTF-8 encoding, including aliases and omitted slots", () => {
const sparse = [];
sparse.length = 3;
sparse[0] = undefined;
sparse[2] = () => 1;
const shared = { text: '"\\\b\t\n\f\r\u0000Δ😀\ud800\udfff' };
for (const value of [
null,
false,
-0,
NaN,
Infinity,
1e-20,
{},
[],
sparse,
{ shared, alias: shared, omitted: undefined },
{ [shared.text]: [shared.text, null] },
]) {
const text = JSON.stringify(value),
bytes = Buffer.byteLength(text);
assert.deepEqual(measureJson(value, bytes), { ok: true, bytes });
assert.equal(serializeJson(value, bytes).text, text);
const small = measureJson(value, bytes - 1);
assert.equal(small.error.kind, "capacity");
assert(small.error.minimum_encoded_bytes > bytes - 1);
assert(small.error.minimum_encoded_bytes <= bytes);
}
});
test("capacity failure precedes JSON allocation for raw size and escaping expansion", () => {
const original = JSON.stringify;
const spy = mock.method(JSON, "stringify", (...args) => original(...args));
try {
for (const value of [
{ text: "a".repeat(2048) },
{ text: "\\".repeat(800) },
]) {
assert.equal(serializeJson(value, 1024).error.kind, "capacity");
}
assert.equal(spy.mock.callCount(), 0);
const huge = [];
huge.length = 1_000_000_000;
assert.equal(measureJson(huge, 1024).error.kind, "capacity");
} finally {
spy.mock.restore();
}
});
test("unknown values do not invoke getters, proxies or custom serializers", () => {
let invoked = 0;
const getter = Object.defineProperty({}, "text", {
enumerable: true,
get: () => ++invoked,
});
const custom = { toJSON: () => ++invoked };
const proxy = new Proxy({}, { get: () => ++invoked });
const cycle = {};
cycle.self = cycle;
for (const value of [getter, custom, proxy, cycle, 1n, undefined, new Date()])
assert.equal(serializeJson(value, 65536).error.kind, "invalid_json");
assert.equal(invoked, 0);
const prior = Object.getOwnPropertyDescriptor(Object.prototype, "toJSON");
let inherited;
try {
Object.defineProperty(Object.prototype, "toJSON", {
configurable: true,
value: () => ++invoked,
});
inherited = measureJson([], 65536);
} finally {
if (prior) Object.defineProperty(Object.prototype, "toJSON", prior);
else delete Object.prototype.toJSON;
}
assert.equal(inherited.error.kind, "invalid_json");
assert.equal(invoked, 0);
});
test("deterministic mixed Unicode cases preserve exact expansion boundaries", () => {
let state = 0x12345678;
const next = () => (state = (Math.imul(state, 1664525) + 1013904223) >>> 0);
for (let n = 0; n < 1500; n++) {
const text = Array.from({ length: next() % 100 }, () =>
String.fromCharCode(next() % 65536),
).join("");
const value = { [text]: [text, n, n % 2 === 0, { text }] };
const bytes = Buffer.byteLength(JSON.stringify(value));
assert.equal(measureJson(value, bytes).bytes, bytes);
assert.equal(measureJson(value, bytes - 1).error.kind, "capacity");
}
});
@@ -0,0 +1,86 @@
--- a/decompiler/crates/kuna-console/src/project.rs
+++ b/decompiler/crates/kuna-console/src/project.rs
@@ -693,6 +693,17 @@
flow_ovr.extend(seed.flow_overrides.iter().cloned());
let replay = crate::assertions::has_symbol_scoped(prog, &name, single_target);
prog.arch_mut().kuna_record_names = replay;
+ let mut profile_clock = (want_atomic_facts
+ && std::env::var_os("KUNA_EXPERIMENT_ATOMIC_TIMING").as_deref()
+ == Some(std::ffi::OsStr::new("1")))
+ .then(std::time::Instant::now);
+ let mut profile_phase = |phase: &str| {
+ if let Some(clock) = profile_clock.as_mut() {
+ let now = std::time::Instant::now();
+ eprintln!("{{\"kind\":\"rea_atomic_phase\",\"address\":\"0x{byte_address:x}\",\"phase\":\"{phase}\",\"wall_ns\":{}}}", now.duration_since(*clock).as_nanos());
+ *clock = std::time::Instant::now();
+ }
+ };
let step = crate::decompile_step::decompile_one(
prog.arch_mut(),
&name,
@@ -751,6 +762,7 @@
}
other => other,
};
+ profile_phase("decompile_drive");
match result {
Ok(mut fd) => {
// (kuna `--assert`) The flow overrides the follower REFUSED are only
@@ -813,6 +825,7 @@
kuna_decomp::kuna_elemptr::record(prog.arch_mut(), &fd);
prog.arch_mut().print_mut().set_record_pointer_arguments(want_pointer_arguments);
let rendered = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
+ profile_phase("pre_render_metadata");
// Trim the surrounding newlines the same way `kuna decompile`
// does (`decompile.rs::trim_newlines`), so the per-function
// `code` is byte-identical to the single-shot path.
@@ -826,6 +839,7 @@
};
let pointerargs = prog.arch_mut().print_mut().take_pointer_arguments(&untrimmed);
let code = untrimmed.trim_matches('\n').to_string();
+ profile_phase("render_c");
let globals = kuna_decomp::decompile_drive::extract_global_objects(prog.arch());
let field_calls = kuna_decomp::kuna_calltargettype::field_declarations(prog.arch(), &fd);
let mut variables =
@@ -848,15 +862,20 @@
prog, &fd, &var_refs, &raw_tokens, &untrimmed, &code, &variables,
))
});
+ profile_phase("metadata_extract");
if want_atomic_facts {
let detail = detail.get_or_insert_with(Default::default);
let membership = kuna_decomp::atomic_membership::inspect(&fd);
+ profile_phase("membership");
detail.atomic_calls = Some(membership.as_ref().map_err(Clone::clone)
.and_then(|m| kuna_decomp::atomic_calls::collect_all(&fd, m)));
+ profile_phase("calls");
detail.atomic_facts = Some(membership.as_ref().map_err(Clone::clone)
.and_then(|m| kuna_decomp::atomic_facts::collect(prog.arch(), &fd, m)));
+ profile_phase("full_graph");
detail.atomic_projection = Some(membership.as_ref().map_err(Clone::clone)
.and_then(|m| kuna_decomp::atomic_projection::collect(prog.arch(), &fd, m)));
+ profile_phase("projection");
}
for variable in &mut variables {
for address in &mut variable.addresses {
@@ -881,6 +900,7 @@
.as_ref()
.map(|ctx| ctx.scan(&fd, byte_address))
.unwrap_or_default();
+ profile_phase("metadata_tail");
(code, variables, types, (globals, field_calls), proto, line_mappings, callee_hints, detail, pointerargs, stack_objects)
}));
match rendered {
--- a/docs/spec/00-overview.md
+++ b/docs/spec/00-overview.md
@@ -3496,3 +3496,10 @@
runtime reachability. Collection uses the same live function after C rendering;
no second decompilation is performed. Complete source Evidence keeps the native
frontier while callers may select a compact summary and individual facts.
+
+An experiment-only timing overlay recognizes `KUNA_EXPERIMENT_ATOMIC_TIMING=1`
+only with atomic capture enabled. It records sequential per-function wall times
+to stderr for the decompile drive, pre-render metadata, C rendering, metadata
+extraction, membership, calls, full graph, projection and metadata tail. It does
+not change analysis parameters or JSON facts. Loading, setup and final JSON
+encoding are outside these phase intervals; phase CPU costs are not measured.
@@ -0,0 +1,28 @@
--- a/decompiler/crates/kuna-decomp/src/substrate/atomic_facts.rs
+++ b/decompiler/crates/kuna-decomp/src/substrate/atomic_facts.rs
@@ -64,10 +64,10 @@
pub fn collect(arch: &Architecture, fd: &Funcdata) -> Result<FunctionFacts, String> {
// Bounds cover allocations before JSON serialization, independently of the
// transport byte budget. Overflow is an unavailable facet, not clipped IR.
- const MAX_OPERATIONS: usize = 12_000;
- const MAX_VALUES: usize = 36_000;
- const MAX_INPUTS: usize = 50_000;
- const MAX_DISPLAY_BYTES: usize = 2 * 1024 * 1024;
+ const MAX_OPERATIONS: usize = 32_000;
+ const MAX_VALUES: usize = 72_000;
+ const MAX_INPUTS: usize = 128_000;
+ const MAX_DISPLAY_BYTES: usize = 16 * 1024 * 1024;
if fd.bblocks_get_size() <= 0 {
return Err("recovered basic-block graph is unavailable".into());
}
--- a/decompiler/crates/kuna-decomp/src/substrate/atomic_values.rs
+++ b/decompiler/crates/kuna-decomp/src/substrate/atomic_values.rs
@@ -7,7 +7,7 @@
use slotmap::Key;
use std::collections::BTreeSet;
-pub const MAX_TEXT_BYTES: usize = 2 * 1024 * 1024;
+pub const MAX_TEXT_BYTES: usize = 16 * 1024 * 1024;
#[derive(Debug, Clone, Serialize)]
pub struct ValueFact {
pub id: String,
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,189 @@
# Selective string facts and bounded result encoding
The branch refreshed main to `3e8236639` in `b2a2ab29c` before this work. This is
an experiment with no PR or merge into main. Native Kuna remains pinned to
`2e398e7229e30b6d2387a802db8a0050764119a6b457020d334855e36e69d6c5`.
## Reproduced failure
An atomic object can contain a large field. Paging one row does not bound its
string value. A static Linux ELF contains a 2,101,248-byte plain string and a
1,052,672-byte backslash-heavy string; escaping makes each response exceed 2 MiB.
The fixture is synthetic, never executed, and chmod 0444. Its SHA-256 is
`bc9a2090e71f780771b388da86a57cdeef428ac235ba6b67051fd05cca688b22`.
The portable generator reproduced that digest in a different directory. An
independent ELF PT_LOAD/file check matched both complete generated payloads.
Before the change, real SDK and Direct MCP returned full 2.1 MiB responses.
Code Mode serialized them first, then replaced them with `bridge_budget`. The
inner error lacked context and an Evidence handle; only the outer execution
receipt retained the ID. A guest could not recover using its returned value.
There was no string field selection. The first Direct verifier assumed SDK
input-validation errors were JSON and failed on the deliberately unsupported
`fields` argument. Its corrected probe records that raw MCP rejection explicitly.
Preserve both attempts; this was a verifier assumption, not a provider failure.
## Shared facts, boundary-owned limits
The existing `strings` method accepts optional `fields` selecting `value`,
`provider_value` and `decoding`. `fields:[]` keeps address and encoded metadata,
including encoding, byte extent and NUL status. Identity survives text omission.
Default SDK reads still return full selected values; the VM's transfer limit is
not imposed on SDK callers. One projection serves SDK, CLI, Direct and Code Mode,
using one parsed native catalog per lease. Field/page/query choices do not cause
another native string scan.
One JSON owner measures UTF-8 bytes before allocating expanded JSON, including
keys, separators, escaping, paired/unpaired surrogates, omitted fields, sparse
arrays and repeated references. Cycles and unsupported objects fail explicitly;
accessors, proxies and custom `toJSON` are not invoked. Successful measurements
are exact; refusals report honest lower bounds. Standard `JSON.stringify` still
performs admitted encoding. Tests compare it against the measurement, including
1,500 deterministic Unicode cases and allocation-order checks.
The QuickJS bridge remains 2 MiB. This experimental MCP profile bounds encoded
tool-result bodies at 1 MiB, motivated by observed client truncation. It counts
the second escaping layer and target-content metadata. JSON-RPC framing and
client rendering are separate and can impose other limits. This is an advertised
profile policy, not a universal MCP protocol limit; both modes report it through
`reference.transport_limits`. CLI/SDK have separate transport behavior.
Transport errors keep context, retained Evidence IDs and failure scope rather
than fake empty facts. Existing primary failures remain primary when oversized
diagnostics are omitted. Unsupported JSON differs from capacity. Source collection
uses declared provenance fields, never text resembling IDs. Code Mode can recover
inside one program with metadata or an Evidence window. Call records describe
delivered outcomes and settle after host failures. One shared error projector
handles primitive thrown values. MCP traces record admitted results, avoiding
serialization of discarded large fact payloads.
## Executed verification
- All 101 experimental tests passed. Changed-file lint and formatting passed.
- Real large-string SDK, Direct and Code Mode verifiers passed metadata-first
reads, default SDK compatibility, contextual capacity errors, cache reuse,
selected prefixes/tails and five full raw source hashes each. Code Mode also
recovered inside one actual MCP execution for each oversized call.
- The experimental CLI returned compact metadata for both objects. Actual
converted catalogs/named string schemas passed valid/invalid field selection.
Counts remain 19 methods, 22 Direct tools and four Code tools.
- Real SQLite checks through all three interfaces preserved eleven reference
sites, pages, source rows, NUL/non-NUL facts and machine bytes. Real x86 SSH
complete-function/prototype fidelity also passed.
- Latest-main runtime build passed: 32.334 s / 32.152036 CPU s, kernel family peak
3,014.6 MiB. Full `check:fast` was not retried after its earlier bounded refusal.
No `check:pr`, exhaustive corpus or new Ghidra/Hopper/IDA coverage is claimed.
Without display text the selected response falls from about 2.1 MiB to 1.3 KiB.
These are bytes, not model tokens or a speed claim. Native full-inventory capture
and its 8 MiB bound remain; field selection does not push filtering/decoding into
the producer or prove larger-binary coverage. Source handles last for the lease;
explicit harness copies survive close.
Representative bounded receipts, all verifying payload cleanup and OOM=0:
| Verification | Wall | Local family CPU | Kernel family peak |
| ------------------------------- | -------------------------: | ----------------------------------: | ------------------------: |
| 101 JS tests | 5.857 s | 5.659277 s | 85.8 MiB |
| SDK large-string verifier | 3.141 s | 2.865835 s | 357.7 MiB |
| Direct large-string verifier | 3.543 s | 3.358844 s | 378.6 MiB |
| Code Mode large-string verifier | 3.744 s | 3.561268 s | 414.2 MiB |
| SQLite SDK / Direct / Code | 14.919 / 15.522 / 16.843 s | 14.548969 / 15.177856 / 16.466928 s | 480.6 / 312.0 / 332.9 MiB |
| SSH fidelity | 8.476 s | 8.230673 s | 304.1 MiB |
| Actual catalog/schema discovery | 1.932 s | 1.752482 s | 144.7 MiB |
Cold metadata-first calls took 843 / 901 / 967 ms in SDK / Direct / Code Mode;
warm repeats took 1.0 / 3.3 / 37.5 ms. Cold means a fresh lease, not cold kernel
pages. Code Mode recreates its guest per execution. The verifiers do different
validation work: whole-suite peaks/times are not equivalent-task comparisons.
Scripted probes consume no model tokens. Build early stop is 3.25 GiB, analysis
3 GiB; one CPU, hard cap 4 GiB, no swap. Kernel family memory includes file cache,
not just RSS. Verified payload-exit counters are used; final exited-cgroup
counters are unavailable.
The [question](large-string-question.txt) and [oracle](large-string-oracle.md)
are frozen before actual model trials. Keep all outcomes/costs separately. The
old Code Mode refusal is not a successful equivalent timing baseline.
## Frozen actual model trials
Both isolated model runs completed at runtime
`185bf90c417150904067eb9b3f89e69a06c2dc8e`, using the precommitted question/oracle,
the same ELF and native engine, serially in fresh profiles/stores. Codex was
0.161.0; requested model `gpt-6.1-sol`, reasoning `high`. The resolved remote
model build and server compute remain unmeasured. Both have the common client
JavaScript executor; Code Mode actually invokes the isolated MCP execution tool.
The Code Mode answer passes every frozen criterion. Direct obtains correct
metadata, byte counts, source identity and actual bytes, but its final table
labels two **17-byte** hex prefixes as the requested first 16. It requested
19/21-byte full-marker windows, which the provider returned correctly with
explicit `returned_bytes`; the error occurs in answer-level slicing/reporting.
Therefore Direct fails the exact-window reporting criterion. No model rerun or
answer repair is substituted for that original failure.
Code Mode requests 16-byte heads and nine-byte tails, then reports the required
eight tail bytes correctly. The second tail returns only eight, with an explicit
native note that the segment ends at exclusive `0x704002`; the answer preserves
that partial read. Independent ELF headers corroborate the boundary. Both use
`fields:[]` immediately: no large text is returned to model context, no capacity
retry is needed, and both demonstrate the same retained source through a small
Evidence read. Scripted tests, rather than these model paths, exercise recovery.
All five cited IDs in each answer match actual traces and retained native records.
All five raw files per lane pass artifact/engine identity and byte/hash checks.
Both have one inventory capture and four byte captures. Full source values stay
in the provider/harness, while selected MCP responses remain small. API handles
expire on close; explicitly retained harness copies remain on disk. This is
agent review of complete answers against the frozen oracle, not human readiness.
| Whole-task metric | Direct | Code Mode |
| ------------------------------------ | -------------------------: | ---------: |
| Frozen semantic result | fail: 17 bytes labelled 16 | pass |
| Cumulative input tokens | 128,284 | 105,724 |
| Cached input, included above | 114,432 | 94,464 |
| Uncached input | 13,852 | 11,260 |
| Output tokens | 2,141 | 2,602 |
| Reasoning, included in output | 379 | 922 |
| Unique model responses | 7 | 7 |
| Client exec / wait calls | 6 / 0 | 6 / 0 |
| MCP attempts | 7 | 6 |
| Rejected requests / capacity retries | 0 / 0 | 0 / 0 |
| Reference help calls | 1 | 2 |
| Fact API reads | 4 | 4 |
| Native captures | 5 | 5 |
| Model wall | 51.906 s | 62.413 s |
| Whole-family wall | 52.485 s | 62.936 s |
| Local family CPU | 7.003758 s | 7.008494 s |
| Kernel family peak | 652.2 MiB | 648.8 MiB |
Code Mode makes two actual `execute_javascript` requests containing four API
reads; Direct makes four fact requests. Unique per-response token sums match
runner summaries. Cached input and reasoning are included as labeled, not added
twice. Both verified payload receipts show OOM=0, no abort, complete owned cleanup,
profiles removed and unchanged artifact/engine/relevant runtime fingerprints.
These are fresh-lease observations, not cold kernel-cache or warm-model repeats;
remote cache state and latency remain uncontrolled.
The smaller Code Mode input does not establish faster analysis: it takes longer
wall time here, CPU is nearly identical, and the byte-window choices differ.
Because only Code Mode passes the exact reporting criterion, costs cannot rank
these profiles at matched answer correctness. This synthetic capacity task also
does not establish superiority on complex applications. It demonstrates actual
model use of the corrected selective interface and exposes a separate model
reporting failure; the real SQLite/SSH regressions establish their narrower scopes.
Answer SHA-256:
- Direct: `6dc8454b87c9a0c6e2e579e7f00bc970e92e5b7ef5586378ee1db4ba23e2212d`
- Code Mode: `ee8386d9d27210d5b862b5d6d9a067c4f6058eb5940415f47e0f5a9dbe9a8d34`
Local artifact SHA-256 (raw provider documents are uncommitted):
- `large-string-model-costs.json`: `6d85d001d5233a92aa3a6efdd3942d4e89c1bfb244eb955adb708a15c194dd6d`
- `large-string-answer-review.json`: `b7453d6bc77ae85a208aa70340db1b72ad6612606b2e008b9303388bdb59c26f`
- `large-string-direct-v1.log`: `4673f3f478294925ec8c7c641e55f6e5c631f1ad235d04c2a4dc7383e857f9ce`
- `large-string-codemode-v1.log`: `8d19907adb44d1a3e7c5d1959e9187f105294c4396b9d550aa60481f848f272a`
- `capacity-before-sdk.log`: `738424765c116728fbf134b69738023628ff06462525dc67cf509526604017e7`
- `capacity-before-v2-direct.log`: `0ba462c0d79f90fed6bad1b2116136fb5d54e95420bfbc1abf2c0b53142c574e`
- `capacity-before-v2-codemode.log`: `fad93da28b481481f7c386b3c7ed7e801da19edb9d541730bce77a9bde1b1ee3`
@@ -0,0 +1,190 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { executeJavaScript } from "./executor.mjs";
import { methods } from "./api.mjs";
import { freezeFacts } from "./fact-reads.mjs";
import { selectStringFacts } from "./string-facts.mjs";
import { encodeMcpResult } from "./mcp-result-encoding.mjs";
import { evidenceIds, serializationFailure } from "./fact-provenance.mjs";
import { MAX_BRIDGE_BYTES, MAX_MCP_RESULT_BYTES } from "./limits.mjs";
import { AtomicSession } from "./session.mjs";
test("string selection preserves encoded identity without the display payload", () => {
const inventory = freezeFacts({
scanned: "sections",
items: [
{
address: "0x1000",
value: "REA " + "x".repeat(65536),
string: {
encoding: "ascii",
byte_length: 65541,
nul_terminated: true,
termination: "present_or_not_required",
},
},
],
});
const input = methods.strings.input.parse({ query: "REA", fields: [] });
const selected = selectStringFacts(inventory, input);
assert.equal(selected.total, 1);
assert.deepEqual(Object.keys(selected.items[0]), ["address", "string"]);
assert.equal(selected.items[0].string.nul_terminated, true);
selected.items.length = 0;
assert.equal(selectStringFacts(inventory, input).items.length, 1);
assert.equal(
selectStringFacts(inventory, { ...input, fields: ["value"] }).items[0]
.value,
inventory.items[0].value,
);
});
test("MCP capacity includes outer escaping and keeps an actionable Evidence link", () => {
const response = {
ok: true,
context: { lease: "fixture" },
data: {
source: { evidence_id: "ev_fixture" },
value: '"'.repeat(300000),
},
};
assert(Buffer.byteLength(JSON.stringify(response)) < MAX_MCP_RESULT_BYTES);
const encoded = encodeMcpResult(response);
assert.equal(encoded.result.ok, false);
assert.equal(encoded.result.error.code, "result_budget");
assert.equal(encoded.result.error.details.scope, "mcp_reply");
assert.deepEqual(encoded.result.error.details.evidence_ids, ["ev_fixture"]);
assert.deepEqual(encoded.result.context, response.context);
assert(
Buffer.byteLength(JSON.stringify(encoded.reply)) <= MAX_MCP_RESULT_BYTES,
);
});
test("bridge capacity can be recovered inside the same composition with truthful call status", async () => {
const context = { lease: "fixture" },
source = { evidence_id: "ev_fixture" };
const session = {
context,
call: async (name) =>
name === "strings"
? {
ok: true,
context,
data: { source, value: "x".repeat(MAX_BRIDGE_BYTES + 1) },
}
: { ok: true, context, data: { source, text: "retained prefix" } },
};
const reply = await executeJavaScript(
session,
`
const result=await rea.strings({query:"fixture"});
if(result.ok)return {unexpected:true};
const id=result.error.details.evidence_ids[0];
const source=await rea.evidence({evidence_id:id,limit:32});
return {code:result.error.code,context:result.context,id,prefix:source.data.text};
`,
);
assert.equal(reply.ok, true);
assert.deepEqual(reply.value, {
code: "bridge_budget",
context,
id: "ev_fixture",
prefix: "retained prefix",
});
assert.deepEqual(reply.evidence_ids, ["ev_fixture"]);
assert.deepEqual(
reply.calls.map((c) => c.status),
["error", "ok"],
);
});
test("transport diagnostics preserve the primary failure and only declared provenance", () => {
const response = {
ok: false,
context: { lease: "fixture" },
error: {
code: "cleanup_incomplete",
message: "long diagnostic",
details: {
evidence_id: "ev_one",
partial_observation: {
results: [{ source: { evidence_id: "ev_two" } }],
},
},
},
};
const failure = serializationFailure(
response,
{ kind: "capacity", limit_bytes: 1, minimum_encoded_bytes: 2 },
"fixture",
"result_budget",
);
assert.equal(failure.error.code, "cleanup_incomplete");
assert.equal(failure.error.details.original_details_omitted, true);
assert.deepEqual(evidenceIds(failure), ["ev_two", "ev_one"]);
assert.deepEqual(evidenceIds({ data: { value: "ev_unrelated" } }), []);
});
test("unsupported native result values stay distinct from capacity failures", () => {
const encoded = encodeMcpResult({
ok: true,
context: { lease: "fixture" },
data: { source: { evidence_id: "ev_fixture" }, unsupported: new Map() },
});
assert.equal(encoded.result.error.code, "invalid_result");
assert.equal(encoded.result.error.details.kind, "invalid_json");
assert.deepEqual(encoded.result.error.details.evidence_ids, ["ev_fixture"]);
});
test("unexpected host failures settle their call record and preserve primary provenance", async () => {
const session = {
context: { lease: "fixture" },
call: async () => {
throw Object.assign(new Error("backend failure"), {
code: "fixture_failure",
details: { evidence_id: "ev_fixture" },
});
},
};
const result = await executeJavaScript(
session,
'return await rea.strings({query:"fixture"});',
);
assert.equal(result.ok, true);
assert.equal(result.value.error.code, "fixture_failure");
assert.equal(result.calls[0].status, "error");
assert.equal(result.calls[0].error.code, "fixture_failure");
assert.deepEqual(result.evidence_ids, ["ev_fixture"]);
});
test("primitive failures produce terminal SDK and bridge outcomes", async () => {
const context = { lease: "fixture" };
const owner = {
context,
strings: async () => {
throw null;
},
close: async () => {},
};
const session = new AtomicSession(async () => owner);
try {
await session.open("fixture");
const result = await session.call("strings", { query: "fixture" });
assert.equal(result.error.code, "analysis_failed");
assert.equal(result.error.message, "null");
} finally {
await session.close();
}
const bridge = await executeJavaScript(
{
context,
call: async () => {
throw null;
},
},
'return await rea.strings({query:"fixture"});',
);
assert.equal(bridge.value.error.code, "bridge_failed");
assert.equal(bridge.value.error.message, "null");
assert.equal(bridge.calls[0].status, "error");
});
@@ -0,0 +1,39 @@
# Frozen large-string capacity task
The fixture is a synthetic x86-64 ELF generated by
`create-capacity-fixture.py NEW_DIRECTORY` with installed GNU binutils. The target
is never executed and has no executable filesystem permission. This tests real
Kuna/MCP capacity and composition; it does not establish application-analysis
quality, broad complex-software superiority or provider parity.
Expected ELF SHA-256:
`bc9a2090e71f780771b388da86a57cdeef428ac235ba6b67051fd05cca688b22`.
Both payload files are independently available in the new fixture directory.
Read ELF program headers to corroborate their complete PT_LOAD-backed extents;
the model must use only its allowed static RE tools, not those fixture files.
| Object marker | Start | Encoded bytes including NUL | Inclusive end | First 16 bytes | Final 8 bytes |
| --------------------- | -------- | --------------------------: | ------------- | -------------------------------- | ---------------- |
| REA_CAPACITY_PLAIN: | 0x402000 | 2,101,249 | 0x603000 | 5245415f43415041434954595f504c41 | 4141414141414100 |
| REA_CAPACITY_ESCAPED: | 0x603001 | 1,052,673 | 0x704001 | 5245415f43415041434954595f455343 | 5c5c5c5c5c5c5c00 |
The provider reports ASCII and `nul_terminated: true` for both. Query counts are
one each with exhausted pages in this retained inventory; artifact-wide discovery
remains unknown. Both queries share one native inventory Evidence in one target
lease. That handle must actually be readable through a bounded Evidence window.
Its exact ID is lease/source-specific; it is not the ELF digest. End addresses
are derived from exact coordinate plus byte length minus one. NUL/byte observations
do not prove original C object boundaries, runtime use, references or live state.
Grade the complete answers against all of these facts, actual calls, cited IDs,
artifact/engine identity and raw capture hashes. The Code Mode lane must actually
use the isolated `rea-codemode` MCP execution entrypoint. Direct has the same 19
fact methods through 22 tools; Code Mode has four MCP tools. Both have the common
client JavaScript executor. Count all responses, schemas/help, failures, retries,
cached/uncached input, output/reasoning, wall, local CPU and kernel family peak.
Record unavailable costs and every failed run; do not rerun to choose a winner.
The historical interface returned oversized Direct text and refused the Code
Mode bridge without an inner context/Evidence link; it had no string field
selection. Those failures are retained separately. They do not establish an
equivalent successful old Code Mode task for timing comparisons.
@@ -0,0 +1,14 @@
Analyze {{artifact_path}} statically. It contains large encoded runs beginning
with the exact markers REA_CAPACITY_PLAIN: and REA_CAPACITY_ESCAPED:.
For each retained object, establish its address, encoding, encoded byte length,
inclusive end address and provider-reported NUL termination. Corroborate the
first 16 and final 8 bytes using focused loaded-image windows. Keep ambiguous
matches and unknown discovery explicit. Do these selections share a retained
source? Verify that a small window of that source is readable and cite real
Evidence IDs with target and engine identity.
The blob contents are irrelevant to the answer: keep full text out of model
context and return compact metadata/hex windows. Distinguish encoded spans from
source-level object boundaries, runtime use and live memory. No target execution.
Close the target lease.
+27
View File
@@ -0,0 +1,27 @@
// Shared application resource policy, independent of native wire formats.
export const MAX_NATIVE_SOURCES = 128;
export const MAX_RETAINED_SOURCE_BYTES = 64 * 1024 * 1024;
export const NATIVE_OUTPUT_BYTES = 8 * 1024 * 1024;
export const MAX_BRIDGE_BYTES = 2 * 1024 * 1024;
// The observed client clips oversized MCP results. Bound this profile's tool
// result body, including escaped text; JSON-RPC/client framing is separate.
export const MAX_MCP_RESULT_BYTES = 1024 * 1024;
// Aggregate selected bytes keep hex at 128 KiB, with headroom for provenance.
export const MAX_BYTE_BATCH_BYTES = 64 * 1024;
export const MAX_BYTE_WINDOWS = 16;
// Shared execution defaults/resource bounds and MCP timeout admission policy.
const executionWallMs = 120_000;
export const EXECUTION_LIMITS = Object.freeze({
execution_heap_mib: 64,
execution_stack_bytes: 512 * 1024,
execution_cpu_ms: 2000,
timeout_ms: Object.freeze({
minimum: 100,
maximum: executionWallMs,
default: executionWallMs,
}),
code_utf8_bytes: 32768,
output_utf8_bytes: 32768,
max_host_calls: 64,
});
@@ -0,0 +1,102 @@
# Main refresh and shared-owner compatibility
The experiment was refreshed from main
`60bf1024592888b5efb78f9c9458b4633da298bd` at merge commit `8e0aa73db`.
This updates only the experimental branch; no PR or integration merge is intended.
The [OpenSSH model comparison](ssh-warning-study.md) remains a historical result
at frozen runtime `09677946c`. Its model runs were not repeated on this new
compiled runtime, and its costs must not be relabeled as current measurements.
## Producing boundaries
Main now requires caller-owned file resources when inspecting Kuna. The session
owns an `ArtifactResourceScope` before attempting an open, including when no
target lease is established. A failed descriptor close keeps its exact owner;
close retries it, and another open cannot acquire a replacement until cleanup
succeeds. The shared native-installation adapter reuses main's error projection
and cleanup leases. The diagnostic native profiler uses the same adapter and
retains its own file scope through final cleanup. No fallback installation
parser or parallel resource manager was added.
Main also replaced the whole-string inventory parser with
`KunaStringInventoryReader`. The experiment feeds its bounded retained source
through that owner and freezes the validated inventory once. The underlying
capture still retains complete source Evidence; this adapter update does not
establish streaming native capture or a new analysis speedup.
The initial source test invocation failed to load the removed string-parser
export. After updating that boundary, 65 Code Mode/API tests and the 15 shared
atomic-fact tests pass. The two new cases verify failed-open cleanup and
replacement admission. Focused lint reports no warnings, and formatting passes.
## Real artifact checks
The unchanged preserved `a9ca8a8a...` experimental engine is used throughout.
Both actual MCP adapters repeat the stripped OpenSSH value task, checking all
250 selected SSA versions and 369 operand occurrences against the earlier
complete native graph. Both caller/emitter function records equal the prior
goldens, including C, calls and graph fields. Each route executes fifteen MCP
requests; these are verification scripts, not new model trials.
A first Code Mode verifier attempt omitted its required evaluator Evidence
directory. Its reads succeeded but its later producer comparison failed. That
attempt remains recorded; the verifier now validates the required setting
before analysis, and both complete reruns pass with separate source directories.
Linux MCP failure injection rejects two close attempts for the actual engine
fingerprint descriptor. Procfs confirms the same descriptor remains open after
the failed initial open and blocked replacement, then disappears after the
successful close retry. The lease stays null until a later open succeeds.
Both adapters also repeat the existing native-close failure/retry scenario.
These failures are injected, not observed OS or engine cleanup incidents.
Real zlib SDK reads preserve cached strings, aliases and source metadata against
caller mutation and verify the complete Evidence digest. SDK cleanup/replacement
retry checks pass on SSH. The native profiler completes two zlib `inflateReset`
captures at `0xbf00` with equal function records; internal timing is disabled.
The generated traditional baseline still contains exactly the sixteen declared
native/session/view tools, matching the earlier corrected manifest. Declared
catalog coverage does not prove every operation's live behavior.
## Executed resource costs
| Scope | Family wall s | Family CPU s | Kernel peak MiB |
| ---------------------------------- | ------------: | -----------: | --------------: |
| Locked dependency install | 20.462 | 19.525 | 1,601.2 |
| Runtime and packaged-skill build | 85.441 | 84.797 | 2,730.4 |
| Code Mode/API tests, 65 | 4.447 | 4.234 | 87.5 |
| Shared atomic-fact tests, 15 | 0.623 | 0.439 | 43.9 |
| SSH value queries, Code Mode | 9.382 | 9.146 | 336.5 |
| SSH value queries, direct | 8.976 | 8.759 | 346.5 |
| Engine descriptor retry, Code Mode | 2.036 | 1.769 | 198.0 |
| Engine descriptor retry, direct | 1.935 | 1.728 | 184.8 |
| Native close retry, Code Mode | 1.831 | 1.650 | 188.9 |
| Native close retry, direct | 1.744 | 1.559 | 182.4 |
| SDK inventory immutability | 1.530 | 1.285 | 123.8 |
| SDK cleanup/replacement retry | 1.831 | 1.602 | 128.1 |
| Native profiler, two captures | 1.931 | 1.683 | 110.2 |
| Actual baseline catalog generation | 3.943 | 3.727 | 438.2 |
All use one CPU, 4 GiB hard / 3 GiB early-stop memory bounds, OOM/kill 0 and
verified payload cleanup. Kernel process-family peaks include charged file
cache, not RSS. Source receipts remain under `.cache/atomic-codemode/main-refresh-*`.
The unsuccessful initial test/load attempt costs 3.138 wall / 2.942 CPU seconds,
79.8 MiB; the incomplete verifier attempt costs 9.181 / 8.941 seconds, 353.2 MiB.
Both also have OOM 0 and verified cleanup.
The successful query verifiers retain separate fresh leases/native caches:
| Phase | Code Mode wall / CPU s | Direct wall / CPU s |
| ------------------------------------------- | ---------------------: | ------------------: |
| Two fresh native captures | 7.354 / 7.346 | 7.139 / 7.087 |
| First indexed task, all 250 values/369 uses | 0.233 / 0.234 | 0.167 / 0.168 |
| Same-lease selected one-value/use read | 0.008 / 0.009 | 0.008 / 0.006 |
The last two rows complete different tasks; they do not measure a warm-task
speedup. The native profiler's fresh/second-process captures take 643.1/453.9 ms,
with private native cache reuse, without separate CPU or peak measurements.
The family table includes startup, capture, reads and cleanup. Cumulative peaks
do not isolate warm memory; OS caches and host contention are uncontrolled.
No new real-agent token measurement was performed in this refresh. Full
repository/native test suites, other providers, and new real-agent comparisons
on this refreshed runtime remain unverified.
@@ -0,0 +1,32 @@
// Own the complete MCP tool-result body, including the second JSON escaping layer.
import { TARGET_CONTENT_RESULT_META } from "../../dist/server/toolResultEncoding.js";
import { MAX_MCP_RESULT_BYTES } from "./limits.mjs";
import { measureJson, serializeJson } from "./json-capacity.mjs";
import { serializationFailure } from "./fact-provenance.mjs";
const envelope = (text) => ({
content: [{ type: "text", text }],
_meta: TARGET_CONTENT_RESULT_META,
});
const attempt = (value) => {
const encoded = serializeJson(value, MAX_MCP_RESULT_BYTES);
if (!encoded.ok) return encoded;
const reply = envelope(encoded.text),
measured = measureJson(reply, MAX_MCP_RESULT_BYTES);
return measured.ok ? { ok: true, reply } : measured;
};
export const encodeMcpResult = (value) => {
const encoded = attempt(value);
if (encoded.ok) return { result: value, reply: encoded.reply };
const result = serializationFailure(
value,
encoded.error,
"mcp_reply",
"result_budget",
),
fallback = attempt(result);
if (!fallback.ok)
throw new Error("MCP capacity diagnostic could not be encoded");
return { result, reply: fallback.reply };
};
@@ -0,0 +1,70 @@
"""Lossless encoding feasibility on retained native JSON; no provider implementation."""
import argparse
import base64
import gzip
import hashlib
import json
from pathlib import Path
import time
def measure(source, output):
with source.open('rb') as stream:
raw = stream.read(32 * 1024 * 1024 + 1)
if len(raw) > 32 * 1024 * 1024:
raise ValueError('Input exceeds the diagnostic 32 MiB source bound')
document = json.loads(raw)
if len(document['functions']) != 1:
raise ValueError('Select one retained native function')
function = document['functions'][0]
graph = function['atomic_facts']
graph_json = json.dumps(graph, separators=(',', ':'), ensure_ascii=False).encode()
wall, cpu = time.perf_counter(), time.process_time()
compressed = gzip.compress(graph_json, compresslevel=1, mtime=0)
base64_data = base64.b64encode(compressed)
encode_cost = {'wall_ms': (time.perf_counter() - wall) * 1000,
'cpu_ms': (time.process_time() - cpu) * 1000}
wall, cpu = time.perf_counter(), time.process_time()
restored = gzip.decompress(base64.b64decode(base64_data, validate=True))
if restored != graph_json:
raise ValueError('Lossless byte roundtrip failed')
decode_cost = {'wall_ms': (time.perf_counter() - wall) * 1000,
'cpu_ms': (time.process_time() - cpu) * 1000}
results = {}
for name, data in [('gzip-base64', base64_data.decode()),
('gzip-hex', compressed.hex())]:
function['atomic_facts'] = {
'schema_version': 4, 'encoding': name,
'raw_bytes': len(graph_json), 'data': data,
}
results[name] = len(json.dumps(document, separators=(',', ':'),
ensure_ascii=False).encode())
report = {
'source': str(source), 'source_sha256': hashlib.sha256(raw).hexdigest(),
'original_document_bytes': len(raw), 'graph_json_bytes': len(graph_json),
'graph_statement_bytes': sum(len(op['statement'].encode()) for op in graph['operations']),
'graph_operations': len(graph['operations']),
'graph_values': len(graph['values']), 'graph_blocks': len(graph['blocks']),
'gzip_level': 1, 'gzip_bytes': len(compressed),
'candidate_document_bytes': results,
'public_transport_budget_bytes': 8 * 1024 * 1024,
'lossless_graph_byte_roundtrip': True,
'python_gzip_and_base64_encoding': encode_cost,
'python_base64_and_gzip_decoding': decode_cost,
'scope': 'Offline retained-source format feasibility, not a native/provider/model '
'implementation. Timings are Python only, not Rust/Node or agent savings. '
'Whole-run CPU/peak family memory are separate resource-run receipts.',
}
with output.open('x') as stream:
json.dump(report, stream, indent=2)
stream.write('\n')
print(json.dumps(report))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('source', type=Path)
parser.add_argument('output', type=Path)
args = parser.parse_args()
measure(args.source, args.output)
@@ -0,0 +1,186 @@
"""Size diagnostic SQLite SSA projections; does not implement a provider API."""
import argparse
from collections import deque
import hashlib
import json
from pathlib import Path
COLUMNS = {
'blocks': ['id', 'start', 'operations', 'predecessors', 'successors'],
'operations': ['id', 'address', 'block', 'opcode', 'statement', 'is_dead', 'inputs', 'output'],
'inputs': ['input_index', 'value_id', 'phi_predecessor', 'phi_predecessor_edge'],
'successors': ['id', 'target', 'index', 'polarity', 'condition_value', 'condition_test'],
'values': ['id', 'space', 'offset', 'size_bytes', 'is_constant', 'is_input',
'is_annotation', 'definition', 'type_name'],
}
def encoded(value):
return json.dumps(value, ensure_ascii=True, separators=(',', ':')).encode()
def bounded_source(path, budget):
with path.open('rb') as source:
raw = source.read(budget + 1)
assert len(raw) <= budget, 'Use a bounded native capture'
return raw
def verify_capture(golden, path):
raw = bounded_source(path, 8 * 1024 * 1024)
document = json.loads(raw)
assert len(document['functions']) == 1
candidate = document['functions'][0]
ordinary = lambda fn: {key: row for key, row in fn.items()
if not key.startswith('atomic_')}
assert ordinary(candidate) == ordinary(golden)
assert candidate['atomic_calls'] == golden['atomic_calls']
projection = candidate['atomic_projection']
assert projection['schema_version'] == 1
assert projection['coverage']['operation_budget'] == 4096
operations = {row['id']: row for row in golden['atomic_facts']['operations']}
values = {row['id']: row for row in golden['atomic_facts']['values']}
assert all(row == operations[row['id']] for row in projection['operations'])
assert all(row == values[row['id']] for row in projection['values'])
roots = [row['id'] for row in golden['atomic_calls']['items']]
assert projection['roots'] == roots
queue, queued, expected = deque(roots), set(roots), []
while queue and len(expected) < 4096:
key = queue.popleft()
if key not in operations:
continue
expected.append(key)
for operand in operations[key]['inputs']:
value = values.get(operand['value_id'])
definition = value['definition'] if value else None
if definition is not None and definition not in queued:
queued.add(definition)
queue.append(definition)
actual = [row['id'] for row in projection['operations']]
assert actual == expected
referenced = {row['output'] for row in projection['operations'] if row['output'] is not None} | {
i['value_id'] for row in projection['operations'] for i in row['inputs']
if i['value_id'] is not None}
assert len(projection['values']) == len(referenced)
assert {row['id'] for row in projection['values']} == referenced
missing = {row['definition'] for row in projection['values']
if row['definition'] is not None} - set(actual)
expected_frontier = {key: 'operation-budget' if key in operations
else 'outside-recovered-membership' for key in missing}
actual_frontier = {row['definition']: row['reason']
for row in projection['coverage']['frontier']}
assert len(actual_frontier) == len(projection['coverage']['frontier'])
assert actual_frontier == expected_frontier
return {'scope': 'Retained-source comparison, not independent machine/runtime equivalence',
'source': str(path), 'source_sha256': hashlib.sha256(raw).hexdigest(),
'ordinary_record_and_call_facet_equal': True,
'all_operation_and_value_records_equal': True,
'breadth_first_budget_and_frontier_match': True,
'operations': len(actual), 'values': len(referenced), 'frontier': len(missing)}
def pack(table, rows):
result = []
for row in rows:
assert set(row) == set(COLUMNS[table]), 'Do not silently omit unknown fields'
result.append([pack(key, row[key]) if key in ('inputs', 'successors') else row[key]
for key in COLUMNS[table]])
return result
def unpack(table, rows):
return [{key: unpack(key, value) if key in ('inputs', 'successors') else value
for key, value in zip(COLUMNS[table], row, strict=True)} for row in rows]
def projection(operations, values, roots, depth, cap):
retained, wave = set(roots), set(roots)
exhausted = False
for _ in range(depth):
following = {values[i['value_id']]['definition'] for key in wave
for i in operations[key]['inputs'] if i['value_id'] is not None
and values[i['value_id']]['definition'] in operations} - retained
if len(retained | following) > cap:
exhausted = True
break
retained |= following
wave = following
ids = {operations[key]['output'] for key in retained
if operations[key]['output'] is not None} | {
i['value_id'] for key in retained for i in operations[key]['inputs']
if i['value_id'] is not None}
frontier = {values[i['value_id']]['definition'] for key in retained
for i in operations[key]['inputs'] if i['value_id'] is not None
and values[i['value_id']]['definition'] is not None} - retained
payload = {'operations': [operations[key] for key in sorted(retained)],
'values': [values[key] for key in sorted(ids)]}
return {'requested_definition_depth': depth, 'operation_budget': cap,
'operation_budget_exhausted': exhausted, 'operations': len(retained),
'values': len(ids), 'encoded_bytes': len(encoded(payload)),
'unexpanded_definition_frontier': len(frontier)}
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('native_json', type=Path)
parser.add_argument('report_json', type=Path)
parser.add_argument('--verify-capture', type=Path,
help='Also compare a public projection capture with this full diagnostic')
args = parser.parse_args()
budget = 32 * 1024 * 1024
raw = bounded_source(args.native_json, budget)
document = json.loads(raw)
assert len(document['functions']) == 1
function = document['functions'][0]
assert function['address_hex'] == '0xea6d0', 'This is the seeded SQLite VM experiment'
graph = function['atomic_facts']
assert graph['schema_version'] == 3
assert len(graph['operations']) <= 32000 and len(graph['values']) <= 72000
tables = ['blocks', 'operations', 'values']
assert set(graph) == {'schema_version', 'coverage', *tables}
packed = {'encoding': 'diagnostic-tuples-proposal-not-public',
'schema_version': graph['schema_version'], 'columns': COLUMNS,
'coverage': graph['coverage'],
**{key: pack(key, graph[key]) for key in tables}}
restored = {'schema_version': packed['schema_version'], 'coverage': packed['coverage'],
**{key: unpack(key, packed[key]) for key in tables}}
assert restored == graph
operations = {row['id']: row for row in graph['operations']}
values = {row['id']: row for row in graph['values']}
assert len(operations) == len(graph['operations'])
assert len(values) == len(graph['values'])
calls = function['atomic_calls']['items']
selected = [row['id'] for row in calls
if row['origin_address'] in ('0xf115c', '0xf238b')]
assert len(selected) == 2
report = {
'scope': 'Offline diagnostic sizes, not public-provider or model results. '
'Tuple roundtrip is lossless, but no native codec is implemented. '
'Projections follow retained SSA operands only; no CFG, aliases, '
'source equivalence or runtime proof. Bytes are not token/time savings.',
'source': str(args.native_json), 'source_sha256': hashlib.sha256(raw).hexdigest(),
'whole_native_document_bytes': len(raw), 'full_graph_bytes': len(encoded(graph)),
'lossless_tuple_graph_bytes': len(encoded(packed)), 'tuple_roundtrip_equal': True,
'estimated_whole_tuple_document_bytes': len(raw) - len(encoded(graph)) + len(encoded(packed)),
'operations': len(operations), 'values': len(values), 'blocks': len(graph['blocks']),
'inputs': sum(len(row['inputs']) for row in operations.values()),
'cfg_edges': sum(len(row['successors']) for row in graph['blocks']),
'statement_utf8_bytes': sum(len(row['statement'].encode()) for row in operations.values()),
'value_type_utf8_bytes': sum(len(row['type_name'].encode()) for row in values.values()),
'selected_call_projections': [projection(operations, values, selected, depth, 512)
for depth in range(1, 6)],
'all_call_projections': [projection(operations, values, [r['id'] for r in calls], depth, 4096)
for depth in range(1, 5)],
}
if args.verify_capture:
report['verified_projection'] = verify_capture(function, args.verify_capture)
with args.report_json.open('x') as output:
json.dump(report, output, indent=2)
output.write('\n')
print(json.dumps(report, indent=2))
if __name__ == '__main__':
main()
@@ -0,0 +1,132 @@
// Equivalent complete span occurrences through the existing exact-address API.
import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { AtomicSession } from "./session.mjs";
import { familyCounters } from "./family-counters.mjs";
import {
createVerifierRun,
completeVerifierRun,
assertVerifierCleanupComplete,
} from "../../scripts/lib/verifier-run.mjs";
const [binary, output] = process.argv.slice(2);
assert(
binary && output,
"Usage: node measure-reference-spans.mjs BINARY NEW_OUTPUT_JSON",
);
const session = new AtomicSession(),
verifier = createVerifierRun(),
failures = [];
const observations = [],
phases = [],
sources = new Map();
const call = async (method, input) => {
const r = await session.call(method, input);
assert.equal(r.ok, true, JSON.stringify(r));
for (const d of r.data.results ?? [r.data]) {
if (Object.hasOwn(d, "ok")) assert.equal(d.ok, true, JSON.stringify(d));
if (d.source) sources.set(d.source.evidence_id, d.source);
}
observations.push({ method, input, data: r.data });
return r.data;
};
const measure = async (phase, work) => {
const a = await familyCounters(),
start = performance.now();
const result = await work(),
b = await familyCounters();
phases.push({
phase,
elapsed_ms: performance.now() - start,
family_cpu_seconds: (b.cpu - a.cpu) / 1e6,
peak_bytes: b.peak,
});
return result;
};
let context, spans;
try {
await session.open(binary);
context = session.context;
assert.equal(
context.artifact_sha256,
"2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8",
);
spans = [];
for (const text of ["no such table", "sqlite_schema"]) {
const inventory = await call("strings", { query: text, limit: 128 });
const selected = inventory.items.filter((s) => s.value === text);
assert.equal(selected.length, 1);
const row = selected[0];
assert.equal(row.string.encoding, "ascii");
assert.equal(row.string.byte_length, 14);
const addresses = Array.from(
{ length: row.string.byte_length },
(_, i) => "0x" + (BigInt(row.address) + BigInt(i)).toString(16),
);
const input = {
addresses,
kinds: ["data"],
fields: ["fromFunction", "instruction"],
limit: 128,
};
const cold = await measure("cold-enumeration:" + text, () =>
call("references", input),
);
assert(cold.results.every((r) => r.next_offset === null));
const warm = await measure("warm-enumeration:" + text, () =>
call("references", input),
);
assert.deepEqual(warm, cold);
spans.push({
text,
start: row.address,
end_inclusive: addresses.at(-1),
rows: cold.results.flatMap((r) => r.items),
counts: cold.results.map((r) => [r.address, r.total]),
});
}
for (const source of sources.values()) {
let text = "",
offset = 0;
do {
const p = await session.call("evidence", {
evidence_id: source.evidence_id,
offset,
limit: 16384,
});
assert.equal(p.ok, true);
text += p.data.text;
offset = p.data.next_offset;
} while (offset !== null);
assert.equal(Buffer.byteLength(text), source.bytes);
assert.equal(
createHash("sha256").update(text).digest("hex"),
source.sha256,
);
}
} catch (error) {
failures.push(error.stack ?? String(error));
} finally {
session.abort();
try {
await session.close();
} catch (error) {
failures.push(error.stack ?? String(error));
}
}
const lifecycle = await completeVerifierRun(verifier);
assertVerifierCleanupComplete(lifecycle.process_lineage);
assert.deepEqual(failures, []);
await writeFile(
output,
JSON.stringify({
context,
spans,
phases,
observations,
source_count: sources.size,
lifecycle,
}),
{ flag: "wx" },
);
console.log(JSON.stringify({ spans, phases, source_count: sources.size }));
@@ -0,0 +1,193 @@
// One native program per missing-window batch; normalized facts share the byte owner.
import { z } from "zod";
import { hex } from "./api-contracts.mjs";
import { normalizeByteFacts, parseByteSourceJson } from "./byte-facts.mjs";
import { FactFailure, projectFactFailure } from "./fact-error.mjs";
import { freezeFacts, sourceSummary } from "./fact-reads.mjs";
import {
MAX_BYTE_BATCH_BYTES,
MAX_BYTE_WINDOWS,
NATIVE_OUTPUT_BYTES,
} from "./limits.mjs";
const count = z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER);
const document = z.strictObject({
schema_version: z.literal(1),
binary: z.string(),
window_count: count.min(1).max(MAX_BYTE_WINDOWS),
program_loads: z.literal(1),
output_bytes: count.min(1).max(NATIVE_OUTPUT_BYTES),
windows: z.array(z.unknown()).min(1).max(MAX_BYTE_WINDOWS),
});
const identity = {
source_row: count,
request_address_hex: hex,
requested_bytes: count.min(1).max(MAX_BYTE_BATCH_BYTES),
};
const window = z.discriminatedUnion("ok", [
z.strictObject({ ...identity, ok: z.literal(true), result: z.unknown() }),
z.strictObject({
...identity,
ok: z.literal(false),
error: z.strictObject({
code: z.literal("window_unavailable"),
message: z.string(),
}),
}),
]);
const counterKeys = [
"schema_version",
"window_count",
"program_loads",
"output_bytes",
"source_row",
"requested_bytes",
];
const key = (request) => `${request.address}:${request.length}`;
const failure = (cause, source, sourceRow) => {
const error =
cause instanceof z.ZodError
? {
code: "invalid_provider_output",
message: "Native byte batch has an invalid format",
details: { reason: cause.issues[0]?.message.slice(0, 256) },
}
: projectFactFailure(cause, "invalid_provider_output");
return {
...error,
details: {
...error.details,
...(source
? { evidence_id: source.evidence_id, source_retained: true }
: {}),
...(sourceRow === undefined ? {} : { source_row: sourceRow }),
},
};
};
export function parseNativeByteBatch(text, capture, requests) {
let doc;
try {
doc = document.parse(parseByteSourceJson(text, counterKeys));
if (
doc.binary !== capture.input ||
doc.output_bytes !== capture.output_bytes ||
Buffer.byteLength(text) > doc.output_bytes ||
doc.window_count !== requests.length ||
doc.windows.length !== requests.length
)
throw new FactFailure(
"invalid_provider_output",
"Native byte batch does not match its capture request",
);
} catch (cause) {
const error = failure(cause, capture.source);
throw new FactFailure(error.code, error.message, error.details);
}
return doc.windows.map((value, index) => {
const request = requests[index];
try {
const row = window.parse(value);
if (
row.source_row !== index ||
row.request_address_hex !== request.address ||
row.requested_bytes !== request.length
)
throw new FactFailure(
"invalid_provider_output",
"Native byte row describes a different requested window",
);
if (!row.ok)
return {
ok: false,
address: request.address,
error: failure(
new FactFailure(row.error.code, row.error.message),
capture.source,
index,
),
};
return {
ok: true,
address: request.address,
source_row: index,
source: sourceSummary(capture.source),
...normalizeByteFacts(row.result, capture.input, request),
};
} catch (cause) {
return {
ok: false,
address: request.address,
error: failure(cause, capture.source, index),
};
}
});
}
export class NativeByteBatchReads {
#loaded = new Map();
constructor(capture, readSource) {
Object.assign(this, { capture, readSource });
}
clear() {
this.#loaded.clear();
}
async read(input, signal) {
const current = new Map(
input.windows.flatMap((request) => {
const id = key(request),
loaded = this.#loaded.get(id);
return loaded ? [[id, loaded]] : [];
}),
);
const missing = [
...new Map(
input.windows
.filter((r) => !current.has(key(r)))
.map((r) => [key(r), r]),
).values(),
];
if (missing.length) {
try {
const selection = missing
.map((r) => `${r.address}:${r.length}`)
.join(",");
const capture = await this.capture(
"byte-batch:" + selection,
(path, outputBytes) => [
"read",
path,
"--atomic-windows",
selection,
"--json",
"--atomic-output-bytes",
String(outputBytes),
],
signal,
);
const rows = parseNativeByteBatch(
await this.readSource(capture.source.evidence_id),
capture,
missing,
);
for (const [index, row] of rows.entries()) {
const id = key(missing[index]),
frozen = freezeFacts(row);
current.set(id, frozen);
if (row.ok || row.error.code === "window_unavailable")
this.#loaded.set(id, frozen);
}
} catch (cause) {
for (const request of missing)
current.set(key(request), {
ok: false,
address: request.address,
error: failure(cause),
});
}
}
return {
results: input.windows.map((r) => structuredClone(current.get(key(r)))),
};
}
}
@@ -0,0 +1,221 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createHash } from "node:crypto";
import {
NativeByteBatchReads,
parseNativeByteBatch,
} from "./native-byte-batch.mjs";
import { FactFailure } from "./fact-error.mjs";
const a = { address: "0x1000", length: 2 },
b = { address: "0x2000", length: 2 };
const result = (request) => ({
binary: "/input",
kind: "data",
start: Number(BigInt(request.address)),
start_hex: request.address,
end: Number(BigInt(request.address) + 2n),
end_hex: "0x" + (BigInt(request.address) + 2n).toString(16),
count: 1,
bytes: 2,
hex: "0041",
truncated: false,
notes: [],
rows: [
{
address: Number(BigInt(request.address)),
address_hex: request.address,
size: 2,
bytes: "0041",
},
],
});
const report = (requests) => ({
schema_version: 1,
binary: "/input",
window_count: requests.length,
program_loads: 1,
output_bytes: 4096,
windows: requests.map((request, index) => ({
source_row: index,
request_address_hex: request.address,
requested_bytes: request.length,
ok: true,
result: result(request),
})),
});
const captured = (doc) => {
const text = typeof doc === "string" ? doc : JSON.stringify(doc);
return {
text,
capture: {
input: "/input",
output_bytes: 4096,
source: {
evidence_id: "ev_test",
sha256: createHash("sha256").update(text).digest("hex"),
bytes: Buffer.byteLength(text),
capture_complete: true,
},
},
};
};
const decode = (doc, requests = [a, b]) => {
const { text, capture } = captured(doc);
return parseNativeByteBatch(text, capture, requests);
};
test("one report keeps exact windows, shared source identity and per-window partial facts", () => {
const doc = report([a, { ...b, length: 3 }]),
rows = decode(doc, [a, { ...b, length: 3 }]);
assert.equal(rows[0].source.evidence_id, rows[1].source.evidence_id);
assert.deepEqual(
rows.map((r) => r.source_row),
[0, 1],
);
assert.equal(rows[0].coverage.status, "complete-for-requested-range");
assert.equal(rows[1].coverage.status, "partial");
assert.equal(rows[1].coverage.requested_bytes, 3);
assert.equal(rows[1].returned_bytes, 2);
assert.equal(rows[1].coverage.runtime_memory, "not-observed");
assert.equal(rows[1].coverage.original_file_mapping, "unknown");
});
test("native window errors and malformed individual data preserve valid sibling facts and Evidence", () => {
for (const mutate of [
(row) => {
row.ok = false;
delete row.result;
row.error = { code: "window_unavailable", message: "unmapped address" };
},
(row) => {
row.result.hex = "0000";
},
(row) => {
row.result.rows[0].address = 0x1000;
},
(row) => {
row.source_row = 0;
},
(row) => {
row.request_address_hex = a.address;
},
]) {
const doc = report([a, b]);
mutate(doc.windows[1]);
const rows = decode(doc);
assert(rows[0].ok);
assert.equal(rows[1].ok, false);
assert.equal(rows[1].error.details.evidence_id, "ev_test");
assert.equal(rows[1].error.details.source_row, 1);
assert.equal(rows[1].error.details.source_retained, true);
}
});
test("wrong envelope identity, count, format or rounded integer cannot publish invented empty success", () => {
for (const patch of [
{ binary: "/other" },
{ window_count: 1 },
{ program_loads: 2 },
{ output_bytes: 4095 },
{ schema_version: 2 },
{ windows: [] },
])
assert.throws(
() => decode({ ...report([a, b]), ...patch }),
(e) =>
e.code === "invalid_provider_output" &&
e.details.evidence_id === "ev_test",
);
const raw = JSON.stringify(report([a, b])).replace(
'"window_count":2',
'"window_count":2.00000000000000001',
);
assert.throws(() => decode(raw), { code: "invalid_provider_output" });
});
function owner() {
const captures = [],
sources = new Map();
let rejected;
const reads = new NativeByteBatchReads(
async (name, args) => {
if (rejected) {
const error = rejected;
rejected = undefined;
throw error;
}
const argv = args("/input", 4096);
assert.equal(argv[0], "read");
assert.equal(argv[1], "/input");
assert.equal(argv[2], "--atomic-windows");
assert.deepEqual(argv.slice(4), [
"--json",
"--atomic-output-bytes",
"4096",
]);
const requests = argv[3].split(",").map((part) => {
const [address, length] = part.split(":");
return { address, length: Number(length) };
});
const { text, capture } = captured(report(requests));
capture.source.evidence_id = "ev_" + (captures.length + 1);
captures.push({ name, requests });
sources.set(capture.source.evidence_id, text);
return capture;
},
(id) => sources.get(id),
);
return {
reads,
captures,
reject(error) {
rejected = error;
},
};
}
test("reordering, duplicate windows, mixed cached/new batches and caller mutation reuse exact facts", async () => {
const { reads, captures } = owner();
const first = await reads.read({ windows: [a, a, b] });
assert.equal(captures.length, 1);
assert.equal(captures[0].requests.length, 2);
assert.deepEqual(
first.results.map((r) => r.source_row),
[0, 0, 1],
);
first.results[0].hex = "ffff";
const reverse = await reads.read({ windows: [b, a] });
assert.equal(captures.length, 1);
assert.equal(reverse.results[1].hex, "0041");
const c = { address: "0x3000", length: 2 };
const mixed = await reads.read({ windows: [b, c, a] });
assert.equal(captures.length, 2);
assert.deepEqual(captures[1].requests, [c]);
assert.equal(
mixed.results[0].source.evidence_id,
first.results[2].source.evidence_id,
);
assert.notEqual(
mixed.results[1].source.evidence_id,
mixed.results[0].source.evidence_id,
);
reads.clear();
await reads.read({ windows: [a] });
assert.equal(captures.length, 3);
});
test("global capture failure retains cached successes and leaves transient failures retryable", async () => {
const { reads, captures, reject } = owner();
await reads.read({ windows: [a] });
reject(
new FactFailure("cancelled", "stopped", {
evidence_id: "ev_prefix",
source_retained: true,
source_complete: false,
}),
);
const partial = await reads.read({ windows: [a, b] });
assert(partial.results[0].ok);
assert.equal(partial.results[1].error.code, "cancelled");
assert.equal(partial.results[1].error.details.evidence_id, "ev_prefix");
const retry = await reads.read({ windows: [b] });
assert(retry.results[0].ok);
assert.equal(captures.length, 2);
});
@@ -0,0 +1,57 @@
import { z } from "zod";
import { nativeCall } from "./native-calls.mjs";
import {
ordinal,
value,
rowParser,
readNativeFacet,
requireFact,
} from "./native-contract.mjs";
const callFacet = z.strictObject({
schema_version: z.literal(1),
items: z.array(nativeCall).max(12000),
values: z.array(value).max(36000),
coverage: z.strictObject({
scope: z.string(),
blocks_examined: ordinal.min(1),
operations_examined: z
.number()
.int()
.nonnegative()
.max(Number.MAX_SAFE_INTEGER),
value_scope: z.string(),
machine_call_equivalence: z.literal("unknown"),
}),
});
const parseCall = rowParser(nativeCall, {
arguments: (row) => nativeCall.shape.arguments.element.parse(row),
});
const parseFacet = rowParser(callFacet, {
items: parseCall,
values: (row) => value.parse(row),
});
export const readCallFacet = (fn) =>
readNativeFacet(fn, "atomic_calls", "recovered calls", (raw) => {
requireFact(
raw && typeof raw === "object" && raw.schema_version === 1,
"Unsupported native call facet schema; expected 1",
);
for (const [name, limit] of [
["items", 12000],
["values", 36000],
])
requireFact(
Array.isArray(raw[name]) && raw[name].length <= limit,
`Native call ${name} exceeds capacity or has invalid shape`,
);
requireFact(
raw.items.reduce(
(sum, row) =>
sum + (Array.isArray(row?.arguments) ? row.arguments.length : 0),
0,
) <= 50000,
"Native call inputs exceed capacity",
);
return parseFacet(raw);
});
@@ -0,0 +1,159 @@
import { callCoverage } from "./native-calls.mjs";
import { requireFact, requireSameNativeValue } from "./native-contract.mjs";
import {
uniqueNative,
readNativeIdentities,
createNativeValueReader,
} from "./native-reads.mjs";
import { freezeFacts } from "./fact-reads.mjs";
export function indexCallFacet(facts) {
const calls = uniqueNative(facts.items),
values = uniqueNative(facts.values),
used = new Set();
requireFact(
calls.size <= facts.coverage.operations_examined,
"Native call count exceeds examined operation coverage",
);
const reference = (id) => {
requireFact(
id === null || values.has(id),
"Dangling native call-boundary value",
);
if (id !== null) used.add(id);
};
for (const row of calls.values()) {
requireFact(
row.id.split(":")[0] === row.origin_address,
"Native call origin/identity mismatch",
);
reference(row.target_value_id);
reference(row.output);
requireFact(
row.output === null || values.get(row.output).definition === row.id,
"Native call output/definition mismatch",
);
for (const [i, a] of row.arguments.entries()) {
reference(a.value_id);
requireFact(
a.input_index === i + 1 &&
(a.storage === null) === (a.storage_authority === null),
"Native call input/storage binding mismatch",
);
}
requireFact(
row.spec_available
? row.prototype !== null
: row.target === null &&
row.target_name === null &&
row.prototype === null &&
row.stack_offset === null &&
row.arguments.every((a) => a.storage === null),
"Native missing call specification has invented facts",
);
}
requireFact(
used.size === values.size,
"Native call boundary contains unrelated values",
);
for (const value of values.values())
if (value.definition !== null && calls.has(value.definition))
requireFact(
calls.get(value.definition).output === value.id,
"Native boundary value/known-call definition mismatch",
);
return { calls, values };
}
export function validateCallGraph(callIndex, graphIndex) {
const { calls, values } = callIndex,
{ operations } = graphIndex;
for (const row of calls.values()) {
const op = operations.get(row.id);
requireFact(
op &&
op.address === row.origin_address &&
op.block === row.block &&
op.opcode === row.opcode &&
op.is_dead === row.is_dead &&
op.output === row.output,
"Native call/graph ownership mismatch",
);
requireFact(
row.target_value_id === (op.inputs[0]?.value_id ?? null) &&
row.arguments.length === Math.max(0, op.inputs.length - 1) &&
row.arguments.every((a, i) => a.value_id === op.inputs[i + 1].value_id),
"Native call/graph operand mismatch",
);
}
for (const value of values.values())
requireSameNativeValue(
value,
graphIndex.values.get(value.id),
"Native call/graph value mismatch",
);
for (const op of operations.values())
requireFact(
!["CPUI_CALL", "CPUI_CALLIND"].includes(op.opcode) || calls.has(op.id),
"Native call operation omitted from call coverage",
);
}
const summarizeCalls = (calls, coverage) => {
const counts = {
CPUI_CALL: { known_target_count: 0, unknown_target_count: 0 },
CPUI_CALLIND: { known_target_count: 0, unknown_target_count: 0 },
};
for (const row of calls.values())
counts[row.opcode][
row.target === null ? "unknown_target_count" : "known_target_count"
]++;
return freezeFacts({
count: calls.size,
by_opcode: Object.entries(counts).map(([opcode, row]) => ({
opcode,
...row,
})),
coverage,
});
};
export function createCallViews(facts, indexes) {
const { calls, values } = indexes;
freezeFacts(facts);
const coverage = freezeFacts({
...callCoverage,
...facts.coverage,
definition_operations: "not collected in call-boundary facet",
});
const valueCoverage = freezeFacts({
...coverage,
scope: facts.coverage.value_scope,
});
return {
calls: (input) => ({
...readNativeIdentities(
calls,
{
fields: [
"spec_available",
"opcode",
"is_dead",
"target",
"target_name",
"arguments",
"output",
],
...input,
...(input.fields && {
fields: ["spec_available", "opcode", "is_dead", ...input.fields],
}),
},
(r) =>
!input.origin_addresses ||
input.origin_addresses.includes(r.origin_address),
),
coverage,
}),
values: createNativeValueReader(values, valueCoverage),
summary: summarizeCalls(calls, coverage),
value_count: values.size,
};
}
@@ -0,0 +1,48 @@
// The native owner supplies targets and passing locations; never parse display.
import { z } from "zod";
import { hex, ordinal, valueId, operationId } from "./native-contract.mjs";
import { nativeLocation, nativeStorage } from "./native-storage.mjs";
export const nativeCall = z.strictObject({
id: operationId,
origin_address: hex,
block: ordinal,
opcode: z.enum(["CPUI_CALL", "CPUI_CALLIND"]),
is_dead: z.boolean(),
target_value_id: valueId.nullable(),
spec_available: z.boolean(),
target: nativeLocation.nullable(),
target_name: z.string().min(1).nullable(),
arguments: z.array(
z.strictObject({
input_index: z.number().int().positive().max(0x7fffffff),
value_id: valueId.nullable(),
storage: nativeStorage.nullable(),
storage_authority: z
.enum(["final-input-storage", "locked-prototype"])
.nullable(),
}),
),
output: valueId.nullable(),
prototype: z
.strictObject({
model: z.string().nullable(),
model_unknown: z.boolean().nullable(),
inputs_locked: z.boolean(),
variadic: z.boolean(),
parameter_shift: z.number().int().min(-0x80000000).max(0x7fffffff),
})
.nullable(),
stack_offset: hex.nullable(),
});
export const callCoverage = Object.freeze({
scope: "all retained CALL/CALLIND operations in this recovered function",
target_authority: "native recovered call specification; not runtime binding",
argument_authority:
"native finalized passing storage or locked prototype; null remains unknown",
source_parameter_ordinals: "unknown",
source_signature: "unknown",
machine_call_equivalence: "unknown",
memory_alias_dependencies: "unknown",
});
@@ -0,0 +1,367 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseNativeIR } from "./native-ir.mjs";
test("malformed compressed graph leaves independent call facts and code readable", () => {
const doc = fixture();
const originalCode = doc.functions[0].code;
doc.functions[0].atomic_facts = {
schema_version: 4,
encoding: "gzip-base64",
raw_bytes: 64,
data: "AAAA",
};
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.code, originalCode);
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.equal(model.facets.calls.availability, "available");
assert.equal(model.calls({}).total, 2);
});
const input = (input_index, value_id) => ({
input_index,
value_id,
phi_predecessor: null,
phi_predecessor_edge: null,
});
const value = (id, space, offset, flags = {}) => ({
id,
space,
offset,
size_bytes: 8,
is_constant: false,
is_annotation: false,
is_input: false,
definition: null,
type_name: "",
...flags,
});
const callOperations = () => [
{
id: "0x1100:0",
address: "0x1100",
block: 0,
opcode: "CPUI_CALL",
statement: "deliberately misleading target 0xbad",
is_dead: false,
inputs: [input(0, "v0"), input(1, "v1"), input(2, "v2")],
output: null,
},
{
id: "0x1110:0",
address: "0x1110",
block: 0,
opcode: "CPUI_CALLIND",
statement: "not a signature",
is_dead: false,
inputs: [input(0, "v2")],
output: null,
},
];
const fixtureValues = () => [
value("v0", "fspec", "0x10000", { is_annotation: true }),
value("v1", "const", "0x2a", { is_constant: true }),
value("v2", "register", "0x30", { is_input: true }),
];
function fixture() {
const operations = callOperations(),
values = fixtureValues();
const rows = [
{
id: "0x1100:0",
spec_available: true,
target: { space: "ram", offset: "0x2000" },
target_name: "callee",
arguments: [
{
input_index: 1,
value_id: "v1",
storage: { space: "register", offset: "0x38", size_bytes: 8 },
storage_authority: "final-input-storage",
},
{
input_index: 2,
value_id: "v2",
storage: null,
storage_authority: null,
},
],
output: null,
prototype: {
model: "__cdecl",
model_unknown: false,
inputs_locked: false,
variadic: false,
parameter_shift: 0,
},
stack_offset: null,
},
{
id: "0x1110:0",
spec_available: false,
target: null,
target_name: null,
arguments: [],
output: null,
prototype: null,
stack_offset: null,
},
];
return {
binary: "/input",
count: 1,
language: "c",
error: null,
functions: [
{
address_hex: "0x1000",
code: "retained code",
error: null,
atomic_facts: {
schema_version: 3,
blocks: [
{
id: 0,
start: "0x1000",
operations: operations.map((o) => o.id),
predecessors: [],
successors: [],
},
],
operations,
values,
coverage: {
scope: "native graph",
machine_semantic_equivalence: "unknown",
indirect_branch_operations: [],
omitted_definition_ids: [],
issues: [],
},
},
atomic_calls: {
schema_version: 1,
items: rows.map((row, i) => ({
...row,
origin_address: operations[i].address,
block: 0,
opcode: operations[i].opcode,
is_dead: false,
target_value_id: operations[i].inputs[0].value_id,
})),
values: structuredClone(values),
coverage: {
scope: "all recovered block-member CALL/CALLIND operations",
blocks_examined: 1,
operations_examined: 2,
value_scope:
"call inputs including target and outputs only; definitions may be outside this facet",
machine_call_equivalence: "unknown",
},
},
},
],
};
}
test("structured calls separate fspec identity, SSA value and passing location; missing targets stay unknown", () => {
const model = parseNativeIR(JSON.stringify(fixture()), "0x1000");
const result = model.calls({ limit: 1 });
assert.equal(result.total, 2);
assert.equal(result.next_offset, 1);
const row = result.items[0];
assert.deepEqual(row.target, { space: "ram", offset: "0x2000" });
assert.equal(row.arguments[0].value_id, "v1");
assert.equal(row.arguments[0].storage.offset, "0x38");
assert.equal(row.arguments[1].storage, null);
assert.equal(model.values({ ids: ["v1"] }).items[0].offset, "0x2a");
assert.equal(Object.hasOwn(row, "prototype"), false);
assert.throws(() => {
row.arguments[0].storage.offset = "0xbad";
}, TypeError);
const unknown = model.calls({ offset: 1 }).items[0];
assert.equal(unknown.target, null);
assert.equal(unknown.spec_available, false);
assert.equal(result.coverage.machine_call_equivalence, "unknown");
assert.equal(result.coverage.source_parameter_ordinals, "unknown");
});
test("selected call pages and function input values compose without full reports", () => {
const model = parseNativeIR(JSON.stringify(fixture()), "0x1000");
const result = model.calls({
ids: ["0x1100:0", "missing"],
origin_addresses: ["0x1100"],
fields: ["prototype"],
});
assert.deepEqual(result.missing, ["missing"]);
assert.deepEqual(
Object.keys(result.items[0]).sort(),
[
"id",
"origin_address",
"block",
"spec_available",
"opcode",
"is_dead",
"prototype",
].sort(),
);
assert.equal(
model.calls({ ids: ["0x1100:0"], origin_addresses: [] }).total,
0,
);
assert.deepEqual(
model.values({ is_input: true }).items.map((v) => v.id),
["v2"],
);
assert.equal(model.values({ is_input: true, ids: ["v1"] }).total, 0);
});
test("bad call facets preserve valid graph and code; cross-facet conflicts disable call composition", () => {
const changes = [
(f) => {
f.items.pop();
},
(f) => {
f.items.push(f.items[0]);
},
(f) => {
f.items[0].arguments[0].value_id = "v2";
},
(f) => {
f.items[0].arguments[0].input_index = 0;
},
(f) => {
f.items[0].arguments[0].storage_authority = null;
},
(f) => {
f.items[1].target = { space: "ram", offset: "0x2000" };
},
(f) => {
f.values[1].offset = "0x2b";
},
(f) => {
f.schema_version = 2;
},
];
for (const change of changes) {
const doc = fixture();
change(doc.functions[0].atomic_calls);
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.code, "retained code");
assert.equal(model.facets.recovered_ir.availability, "available");
assert.equal(model.facets.calls.availability, "unavailable");
assert.throws(
() => model.calls({}),
(e) => e.code === "invalid_provider_output",
);
assert.equal(model.values({ ids: ["v1"] }).items[0].offset, "0x2a");
}
});
test("graph capacity failure retains calls, boundary values and explicit unreadable definitions", () => {
const doc = fixture(),
fn = doc.functions[0];
delete fn.atomic_facts;
fn.atomic_facts_error = "atomic operation capacity exceeded";
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.equal(model.facets.calls.availability, "available");
assert.equal(model.facets.values.scope, "call-boundary-only");
assert.equal(model.calls({}).total, 2);
const values = model.values({ ids: ["v0", "v1", "missing"] });
assert.equal(values.items[0].space, "fspec");
assert.equal(values.items[1].offset, "0x2a");
assert.deepEqual(values.missing, ["missing"]);
assert.match(values.coverage.value_scope, /only/);
assert.equal(values.coverage.scope, values.coverage.value_scope);
const retained = values.items[1];
const located = model.values({
locations: [
{
space: retained.space,
offset: retained.offset,
size_bytes: retained.size_bytes,
},
],
});
assert.deepEqual(located.items, [retained]);
assert.equal(located.coverage.scope, values.coverage.scope);
assert.throws(
() => model.edges({ kind: "value_uses", seeds: [retained.id] }),
(e) => e.code === "capability_unavailable",
);
assert.throws(
() => model.select({}),
(e) => e.code === "capability_unavailable",
);
assert.equal(
model.calls({ ids: ["0x1110:0"], fields: ["target_value_id"] }).items[0]
.target_value_id,
"v2",
);
});
test("malformed graph is isolated from valid calls; call-only malformed identities still fail", () => {
const doc = fixture();
doc.functions[0].atomic_facts.operations[0].output = "vbad";
let model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.equal(model.facets.calls.availability, "available");
assert.equal(model.values({ is_input: true }).items[0].id, "v2");
doc.functions[0].atomic_calls.items[0].target_value_id = "vdead";
model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.calls.availability, "unavailable");
assert.throws(
() => model.values({}),
(e) => e.code === "invalid_provider_output",
);
assert.equal(model.code, "retained code");
});
test("capture call counts distinguish target knowledge from opcode and include dead rows", () => {
const doc = fixture(),
fn = doc.functions[0];
delete fn.atomic_facts;
fn.atomic_facts_error = "capacity";
const [direct, indirect] = fn.atomic_calls.items;
direct.target = null;
direct.is_dead = true;
indirect.target = { space: "ram", offset: "0x3000" };
indirect.spec_available = true;
indirect.prototype = direct.prototype;
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.deepEqual(model.facets.calls.by_opcode, [
{ opcode: "CPUI_CALL", known_target_count: 0, unknown_target_count: 1 },
{ opcode: "CPUI_CALLIND", known_target_count: 1, unknown_target_count: 0 },
]);
assert.equal(model.facets.calls.count, 2);
assert.equal(model.facets.calls.coverage.machine_call_equivalence, "unknown");
assert.equal(model.calls({ ids: [direct.id], fields: [] }).total, 1);
assert.equal(model.facets.calls.count, 2);
assert.throws(() => {
model.facets.calls.by_opcode[0].known_target_count = 99;
}, TypeError);
});
test("an empty available call facet has zero counts; unavailable counts remain absent", () => {
const doc = fixture(),
fn = doc.functions[0];
delete fn.atomic_facts;
fn.atomic_facts_error = "capacity";
fn.atomic_calls.items = [];
fn.atomic_calls.values = [];
let model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.calls.availability, "available");
assert.equal(model.facets.calls.count, 0);
assert.ok(
model.facets.calls.by_opcode.every(
(r) => r.known_target_count === 0 && r.unknown_target_count === 0,
),
);
delete fn.atomic_calls;
fn.atomic_calls_error = "capacity";
model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.calls.availability, "unavailable");
assert.equal(Object.hasOwn(model.facets.calls, "count"), false);
assert.equal(Object.hasOwn(model.facets.calls, "by_opcode"), false);
});
@@ -0,0 +1,99 @@
// Per-lease native work. A proven byte refusal remains valid as storage only shrinks.
import { FactFailure } from "./fact-error.mjs";
import { MAX_NATIVE_SOURCES } from "./limits.mjs";
const reuse = Object.freeze({
kind: "source_budget_refusal",
scope: "target_lease",
});
const refusalFields = new Set([
"scope",
"limit_bytes",
"observed_bytes_at_least",
"evidence_id",
"source_retained",
"source_complete",
]);
const retainRefusal = (error) => {
try {
if (!(error instanceof FactFailure)) return;
const own = Object.getOwnPropertyDescriptors(error);
if (
own.code?.value !== "resource_constraint" ||
typeof own.message?.value !== "string"
)
return;
const fields = Object.getOwnPropertyDescriptors(own.details?.value);
if (
Object.keys(fields).some((key) => !refusalFields.has(key)) ||
Object.values(fields).some(
(field) =>
!Object.hasOwn(field, "value") ||
(field.value !== null &&
!["string", "number", "boolean"].includes(typeof field.value)),
)
)
return;
const details = Object.fromEntries(
Object.entries(fields).map(([key, field]) => [key, field.value]),
);
if (
details.scope !== "native_source" ||
details.source_retained !== true ||
details.source_complete !== false ||
typeof details.evidence_id !== "string" ||
!details.evidence_id ||
!Number.isSafeInteger(details.limit_bytes) ||
details.limit_bytes < 1 ||
!Number.isSafeInteger(details.observed_bytes_at_least) ||
details.observed_bytes_at_least <= details.limit_bytes
)
return;
return new FactFailure(
own.code.value,
own.message.value,
Object.freeze(details),
);
} catch {
// Unknown host failures retain their original identity and remain uncached.
return;
}
};
export class NativeCaptureCache {
#entries = new Map();
clear() {
this.#entries.clear();
}
async read(key, load) {
let pending = this.#entries.get(key);
const reused = pending !== undefined;
if (!pending) {
pending = Promise.resolve()
.then(load)
.then(
(value) => ({ ok: true, value }),
(error) => {
const refusal = retainRefusal(error);
return {
ok: false,
error: refusal ?? error,
reusable: refusal !== undefined,
};
},
);
if (this.#entries.size < MAX_NATIVE_SOURCES)
this.#entries.set(key, pending);
}
const result = await pending;
if (result.ok) return result.value;
if (!result.reusable) {
if (this.#entries.get(key) === pending) this.#entries.delete(key);
throw result.error;
}
throw new FactFailure(result.error.code, result.error.message, {
...result.error.details,
...(reused ? { cached_observation: reuse } : {}),
});
}
}
@@ -0,0 +1,193 @@
import assert from "node:assert/strict";
import test from "node:test";
import { NativeCaptureCache } from "./native-capture-cache.mjs";
import { FactFailure } from "./fact-error.mjs";
import { MAX_NATIVE_SOURCES } from "./limits.mjs";
const refusal = () =>
new FactFailure("resource_constraint", "native source cannot fit", {
scope: "native_source",
limit_bytes: 8,
observed_bytes_at_least: 9,
evidence_id: "ev_owned",
source_retained: true,
source_complete: false,
});
test("capacity reuse preserves observed facts, reports reuse and isolates mutable SDK error views", async () => {
const cache = new NativeCaptureCache();
let runs = 0,
first;
const load = async () => {
runs++;
throw refusal();
};
await assert.rejects(cache.read("strings", load), (error) => {
first = error;
assert.equal(error.details.cached_observation, undefined);
return true;
});
first.details.evidence_id = "caller edit";
first.details.limit_bytes = 999;
await assert.rejects(cache.read("strings", load), (error) => {
assert.equal(error.code, "resource_constraint");
assert.equal(error.details.evidence_id, "ev_owned");
assert.equal(error.details.limit_bytes, 8);
assert.deepEqual(error.details.cached_observation, {
kind: "source_budget_refusal",
scope: "target_lease",
});
return true;
});
assert.equal(runs, 1);
cache.clear();
await assert.rejects(cache.read("strings", load));
assert.equal(runs, 2);
});
test("concurrent reads share one capture and capture keys remain independent", async () => {
const cache = new NativeCaptureCache();
let finish,
runs = 0;
const load = () => {
runs++;
return new Promise((resolve) => {
finish = resolve;
});
};
const a = cache.read("one", load),
b = cache.read("one", load);
await Promise.resolve();
assert.equal(runs, 1);
const value = Object.freeze({ source: { evidence_id: "ev_one" } });
finish(value);
assert.strictEqual(await a, value);
assert.strictEqual(await b, value);
assert.strictEqual(
await cache.read("one", () => {
throw new Error("must reuse");
}),
value,
);
assert.equal(await cache.read("two", async () => 2), 2);
});
test("cancelled, cleanup, IO, unknown and unproven capacity failures stay retryable observations", async () => {
const base = refusal();
for (const failure of [
undefined,
null,
false,
0,
"failure",
new FactFailure("cancelled", "cancelled"),
new FactFailure("cleanup_incomplete", "unknown process ownership", {
source_capture_failure: base,
}),
new FactFailure("source_write_failed", "disk full"),
{ code: base.code, details: base.details },
new FactFailure("resource_constraint", "other resource", {
scope: "memory",
}),
new FactFailure(base.code, base.message, {
...base.details,
observed_bytes_at_least: 8,
}),
new FactFailure(base.code, base.message, {
...base.details,
source_complete: true,
}),
new FactFailure(base.code, base.message, {
...base.details,
unknown: { state: "live" },
}),
new FactFailure(base.code, base.message, {
...base.details,
cleanup_incomplete: "unconfirmed descriptor close",
}),
new FactFailure(base.code, base.message, {
...base.details,
unknown: "live state",
}),
new FactFailure(base.code, base.message, {
...base.details,
source_retained: false,
}),
new FactFailure(base.code, base.message, {
...base.details,
evidence_id: undefined,
}),
]) {
const cache = new NativeCaptureCache();
let runs = 0;
for (let i = 0; i < 2; i++) {
let rejected = false;
try {
await cache.read("key", async () => {
runs++;
throw failure;
});
} catch (error) {
rejected = true;
assert.strictEqual(error, failure);
}
assert(rejected);
}
assert.equal(runs, 2);
}
});
test("failure classification never invokes accessors or substitutes an inspection error", async () => {
let reads = 0,
runs = 0;
const details = Object.defineProperty({}, "scope", {
enumerable: true,
get() {
reads++;
throw new Error("must not inspect");
},
});
const original = new FactFailure(
"resource_constraint",
"unknown source failure",
details,
),
cache = new NativeCaptureCache();
for (let i = 0; i < 2; i++)
await assert.rejects(
cache.read("key", async () => {
runs++;
throw original;
}),
(error) => error === original,
);
assert.equal(reads, 0);
assert.equal(runs, 2);
});
test("memo retention stays within the source-count policy without refusing uncached results", async () => {
const cache = new NativeCaptureCache();
for (let i = 0; i < MAX_NATIVE_SOURCES; i++)
await assert.rejects(
cache.read(String(i), async () => {
throw refusal();
}),
);
let runs = 0;
for (let i = 0; i < 2; i++)
assert.equal(
await cache.read("beyond memo capacity", async () => {
runs++;
return "still delivered";
}),
"still delivered",
);
assert.equal(runs, 2);
await assert.rejects(
cache.read("0", async () => {
throw new Error("existing memo lost");
}),
(error) =>
error.details.cached_observation.kind === "source_budget_refusal",
);
});
@@ -0,0 +1,29 @@
// Bind a streaming decoder's validated facts to the raw bytes owned by the capture.
import {
FactFailure,
projectFactFailure,
requireResult,
} from "./fact-error.mjs";
import { freezeFacts } from "./fact-reads.mjs";
export function requireNativeCaptureFacts(capture) {
try {
const facts = requireResult(capture.parsed, "invalid_provider_output");
if (
facts.sha256 !== capture.source.sha256 ||
facts.bytes !== capture.source.bytes
)
throw new FactFailure(
"invalid_provider_output",
"Parsed facts and retained source identities disagree",
);
return freezeFacts(facts);
} catch (cause) {
const failure = projectFactFailure(cause, "invalid_provider_output");
throw new FactFailure(failure.code, failure.message, {
...failure.details,
evidence_id: capture.source.evidence_id,
source_retained: true,
});
}
}
@@ -0,0 +1,98 @@
// Fixed per-lease catalogs share source admission; queries do not create cache keys.
import { parseFunctionFacts, selectFunctionFacts } from "./function-facts.mjs";
import { selectStringFacts } from "./string-facts.mjs";
import { parseNativeStorageMap } from "./native-storage-map.mjs";
import { sourceSummary } from "./fact-reads.mjs";
import { FactFailure } from "./fact-error.mjs";
import { requireNativeCaptureFacts } from "./native-capture-facts.mjs";
import { KunaStringInventoryReader } from "../../dist/kuna/KunaStringInventory.js";
const catalogs = {
functions: {
arguments: (path) => ["functions", path, "--json"],
parse: parseFunctionFacts,
},
strings: {
arguments: (path) => [
"strings",
path,
"--json",
"--encoding",
"all",
"--min-length",
"5",
"--termination",
"any",
"--no-xrefs",
],
reader: () => new KunaStringInventoryReader(),
},
storage: {
arguments: (path) => ["storage-map", path, "--json"],
parse: parseNativeStorageMap,
},
};
export class NativeCatalogReads {
#loaded = new Map();
constructor(capture, readSource, requireStorage) {
this.capture = capture;
this.readSource = readSource;
this.requireStorage = requireStorage;
}
async #load(name, signal) {
if (name === "storage") this.requireStorage();
if (!this.#loaded.has(name)) {
const definition = catalogs[name],
capture = await this.capture(
name,
definition.arguments,
signal,
definition.reader,
);
let facts;
if (definition.reader) facts = requireNativeCaptureFacts(capture);
else {
try {
facts = await definition.parse(
await this.readSource(capture.source.evidence_id),
capture.input,
);
} catch (error) {
throw new FactFailure(
error.code ?? "invalid_provider_output",
error.message,
{
...error.details,
evidence_id: capture.source.evidence_id,
source_retained: true,
},
);
}
}
this.#loaded.set(name, {
facts,
source: Object.freeze(sourceSummary(capture.source)),
});
}
return this.#loaded.get(name);
}
async functions(input, signal) {
const { facts, source } = await this.#load("functions", signal);
return { source, ...selectFunctionFacts(facts, input) };
}
async strings(input, signal) {
const { facts, source } = await this.#load("strings", signal);
return { source, ...selectStringFacts(facts, input) };
}
async spaces(input, signal) {
const { facts, source } = await this.#load("storage", signal);
return { source, ...facts.spaces(input) };
}
async registers(input, signal) {
const { facts, source } = await this.#load("storage", signal);
return { source, ...facts.registers(input) };
}
clear() {
this.#loaded.clear();
}
}
@@ -0,0 +1,122 @@
# Native computation and retained fact coverage
This diagnostic separates native computation from fact selection and Code Mode
dispatch after the wide-operand model pairs. It does not change those adapters
or establish model-token savings.
## Phase instrument and actual measurements
Use experiment commit `7d0da075e` and its versions of both patches to reproduce
these historical measurements. Apply `kuna-native-ir.patch`, then
`kuna-atomic-timing-diagnostic.patch`, to Kuna
`fe01d6294eb0d1053ce343c8943646df88e143fc`. Reuse existing compiled specs and the
one-job opt-level-1 embed-specs build in `native-engine.md`. Preserved engine:
`c755184455b8fe8950a5194788d954bc0476602779b6dd614cb893a230f6fde7`;
overlay: `b2ddfd5b6d3fc4a386cfbb07d97fbd0fcbfd8279837ce68327e62baa3e0f3018`.
The preceding `a0685486...` public executable remains independently preserved.
The instrument requires `--atomic-facts` and the exact environment value
`KUNA_EXPERIMENT_ATOMIC_TIMING=1`. It emits nine sequential per-function wall
intervals to stderr, excluding logging time from the next interval. Disabled
instrumentation emits none. Analysis parameters and JSON facts are unchanged.
These are phase wall times, not phase CPU. Loading, preparation before the drive
and final output encoding are outside the intervals; the residual cannot all be
attributed to one phase.
`profile-native.mjs` uses production target/installation/process owners and a
private runtime/cache root. Its diagnostic launcher adds only the timing flag;
ambient environment is not persisted. It measures two new native processes:
fresh private cache, then the same cache/staged input. This second process is
distinct from the API owner's warm result-cache hit. Complete stdout/stderr and
digests are retained before validation. OS cache remains uncontrolled.
```sh
python3 experiments/analysis-efficiency/resource-run.py --observe-payload-exit -- \
node experiments/atomic-codemode/profile-native.mjs \
/absolute/diagnostic-kuna /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 \
0xea6d0 /absolute/new-profile.json /absolute/prior-public-capture.json
```
Add `--without-timing` for the disabled control. Target: SQLite Debian
`3.40.1-2+deb12u2` amd64, SHA-256
`2e6eef9a727f081f0d453b4e5e6cbd8b9ef8b6f86cbf7681cbad444d3b0b55c8`.
VM entry is `0xea6d0`; parser-helper entry is `0x64060`.
| Wall milliseconds | VM fresh | VM same cache/new process | Helper fresh | Helper same cache/new process |
| --------------------- | ---------: | ------------------------: | -----------: | ----------------------------: |
| Entire owned request | 36,336.306 | 36,353.240 | 2,339.393 | 2,193.311 |
| Decompile drive | 33,681.369 | 33,855.870 | 256.200 | 266.629 |
| C rendering | 220.052 | 215.235 | 9.399 | 7.416 |
| Metadata extraction | 64.434 | 128.247 | 1.576 | 1.564 |
| Membership scan | 3.259 | 3.496 | 0.137 | 0.093 |
| Call facts | 2.889 | 3.328 | 0.245 | 0.133 |
| Full graph collection | 0.006* | 0.007* | 6.993 | 5.473 |
| Projection collection | 31.383 | 31.711 | 1.955 | 1.770 |
Pre-render/tail metadata also appear in the nine-interval raw receipts. `*` VM
full-graph collection fails its early operation-capacity check; these numbers
do not time a complete graph export. Whole-function analysis nevertheless
produces the live IR. Each function record deeply equals its prior public golden
and its repeat. The disabled helper control also agrees, with zero timing rows.
| Whole-run resource scope | Family wall seconds | CPU seconds | Kernel peak MiB |
| ------------------------------------- | ------------------: | ----------: | --------------: |
| Instrument build | 115.279 | 92.082 | 760.7 |
| VM, two processes plus validation | 74.218 | 73.867 | 572.2 |
| Helper, two processes plus validation | 5.554 | 5.328 | 191.9 |
| Disabled helper, two processes | 5.556 | 5.409 | 191.8 |
| Final cached build | 0.322 | 0.155 | 26.8 |
All use one CPU, 4 GiB hard / 3 GiB early-stop bounds, verified cleanup and OOM 0.
Kernel peak includes charged file cache, not RSS. Final build keeps the same
digest. Patch forward/reverse and lenient `check-spec` pass; full native corpus,
stages and workspace gates remain unexecuted. No upstream commit/PR or integration
readiness is claimed. Receipts/raw sources are local
`phase-timing-{vm,helper,helper-off}.json*` and resource logs under
`.cache/atomic-codemode/`.
C rendering is below 1% of this VM request; skipping it cannot remove the
approximately 34-second drive. The helper instead spends most time outside the
instrumented phases, requiring further profiling before choosing persistent
state. Same-cache new processes reanalyze. Previously measured same-lease API
source reuse remains a separate approximately 40 ms path.
## Lossless full-graph encoding feasibility
The earlier diagnostic source has 21,349 operations, 35,755 values and 1,229
blocks, with no omitted definition IDs. Its whole document is 17,801,972 bytes;
the graph is 17,008,223 bytes, including 2,255,616 bytes of operation display and
90,013 bytes of value type names. Plain tuple packing was still too large.
```sh
python3 experiments/analysis-efficiency/resource-run.py --observe-payload-exit -- \
python3 experiments/atomic-codemode/measure-native-encoding.py \
/absolute/diagnostic-native.json /absolute/new-encoding-report.json
```
Gzip level 1 makes the graph 2,020,464 bytes. Hypothetical documents retaining
ordinary C/metadata/calls and replacing only the graph with a typed envelope are:
| Encoding | Entire JSON bytes | Existing transport budget |
| ------------- | ----------------: | ------------------------: |
| gzip + base64 | 3,487,776 | 8,388,608 |
| gzip + hex | 4,834,749 | 8,388,608 |
The graph byte roundtrip is exact. Python gzip/base64 encode costs 69.037 ms
wall / 69.037 ms CPU; decode 34.632 / 34.571 ms. Whole sizing task: 0.826 wall /
0.654 CPU seconds, 169.8 MiB peak, cleanup verified and OOM 0. These are offline
Python feasibility measurements, not Rust/Node timings, native output, public
support or agent savings. Source SHA-256:
`0a31513350be440983094710197b155a2ec8c49d28852bb20a524292091637b7`;
reproducible receipt: `full-graph-encoding-repro.json` beside its resource log.
This supports testing bounded lossless transport before introducing live-function
ownership or repeating analysis for missing definitions. Required checks include
allocation/encoding growth, bounded inflation, exact format/length/row admission,
malformed-graph isolation from calls/C, complete Evidence access, actual CPU and
memory, fallback behavior and real-model workflows. The shared owner must return
selected facts rather than send an encoded graph to the agent. The current
public engine at this sizing checkpoint still has a bounded call-rooted
projection. The [subsequent implementation](native-graph-transport-study.md)
now verifies full recovered-graph access through bounded native/Node encoding
and both public MCP adapters; real-model verification remains separate.
@@ -0,0 +1,111 @@
// Shared native identity/value contracts and bounded row/facet decoding.
import { z } from "zod";
import { FactFailure } from "./fact-error.mjs";
import { ok, err } from "../../dist/domain/result.js";
export const requireFact = (condition, reason) => {
if (!condition) throw new FactFailure("invalid_provider_output", reason);
};
export const hex = z.string().regex(/^0x(?:0|[1-9a-f][0-9a-f]{0,15})$/u);
export const nativeLocationKey = ({ space, offset, size_bytes }) =>
JSON.stringify([space, offset, size_bytes]);
export const edgeId = z.string().regex(/^\d+:\d+$/u);
export const ordinal = z.number().int().nonnegative().max(0x7fffffff);
export const valueId = z.string().regex(/^v[0-9a-f]{1,16}$/u);
export const operationId = z
.string()
.regex(/^0x[0-9a-f]{1,16}:[0-9a-f]{1,8}$/u);
export const value = z.strictObject({
id: valueId,
space: z.string().nullable(),
offset: hex,
size_bytes: z.number().int().positive().max(0x7fffffff),
is_constant: z.boolean(),
is_input: z.boolean(),
is_annotation: z.boolean(),
definition: operationId.nullable(),
type_name: z.string(),
});
export const requireSameNativeValue = (value, reference, message) =>
requireFact(
reference &&
Object.entries(value).every(([key, v]) => reference[key] === v),
message,
);
export const rowParser = (schema, arrays, fields = {}) => {
const metadata = schema.omit(
Object.fromEntries(
[...Object.keys(arrays), ...Object.keys(fields)].map((key) => [
key,
true,
]),
),
);
return (raw) => {
const metadataFields = { ...raw };
for (const key of [...Object.keys(arrays), ...Object.keys(fields)])
delete metadataFields[key];
const result = metadata.parse(metadataFields);
for (const [key, parse] of Object.entries(arrays)) {
requireFact(Array.isArray(raw[key]), `Native ${key} must be an array`);
result[key] = raw[key].map(parse);
}
for (const [key, parse] of Object.entries(fields))
result[key] = parse(raw[key]);
return result;
};
};
export const formatFailure = (error) => {
if (error instanceof FactFailure) return error;
const details =
error instanceof z.ZodError
? {
issues: error.issues.slice(0, 8).map(({ path, code, message }) => ({
path,
code,
message: message.slice(0, 160),
})),
}
: { reason: String(error.message).slice(0, 256) };
return new FactFailure(
"invalid_provider_output",
"Native source does not match the declared format",
details,
);
};
export const readNativeFacet = (fn, name, label, parse) => {
try {
const reason = fn[`${name}_error`];
if (reason !== undefined) {
requireFact(
fn[name] === undefined,
`Native ${label} is both present and unavailable`,
);
requireFact(
typeof reason === "string",
`Native ${label} failure reason must be text`,
);
return err(
new FactFailure(
"capability_unavailable",
`Native ${label} facet is unavailable`,
{
native_error: reason.slice(0, 1024),
native_error_truncated: reason.length > 1024,
},
),
);
}
if (fn[name] === undefined)
return err(
new FactFailure(
"capability_unavailable",
`Native ${label} facet was not captured`,
{ availability: "not-captured" },
),
);
return ok(parse(fn[name]));
} catch (error) {
return err(formatFailure(error));
}
};
@@ -0,0 +1,687 @@
# Native recovered IR experiment
Stock Kuna's diagnostic text omits CFG successors and does not encode operand or
phi edge identities. `kuna-native-ir.patch` is a read-only exploratory exporter
against [Kuna v1.833](https://github.com/Noelo-Lab/kuna/tree/fe01d6294eb0d1053ce343c8943646df88e143fc).
It is not an upstream release or an integrated REA capability. No upstream commit,
PR or merge is being made.
The sections below record successive pinned prototypes and their historical
limits. For current comparison scope use the [capability map](capability-map.md),
[full-graph transport study](native-graph-transport-study.md) and
[independent switch study](switch-study.md), together with the live contracts.
`decompile --json --atomic-facts` captures the live function that produced C.
The default path does not collect the facet. Graph records include ordered CFG
edges, native value identities, indexed operands, outputs and phi input bindings
to particular incoming edges. Duplicate instruction origins or predecessor blocks
do not collapse identities. Values are local to one snapshot. Constant offsets
remain hexadecimal u64 address-space offsets, with width and annotation status
separate; they are not arbitrary-width computed bitvectors.
`native-ir.mjs` owns validation, immutable indexes and selected reads.
`control-dependence.mjs` derives control dependence using immediate
postdominators of the reversed graph, with linear retained graph state and a
bounded work count. It treats zero-successor recovered blocks as exits and
considers finite paths only. Exit-unreachable blocks, indirect-branch operations,
missing definitions, runtime successors and memory alias limitations stay
explicit. This is not a proof of feasible runtime paths.
The shared API adds `values`, `blocks` and `relations(kind:"controllers")`.
Diagnostic SSA sessions report these missing capabilities explicitly. Native
definition/use edges include operand and phi bindings; diagnostic printed
occurrences retain their original, weaker semantics. CLI, SDK and both MCP
adapters use the same owner. Ordinary source summaries are compact; `evidence`
retains the exact command argv and separate display argv, complete output and
digest. Earlier trials substituted display paths in `arguments`; they must not
be retroactively claimed to have captured exact argv.
To reproduce, check out the pinned upstream revision in a disposable directory
and apply this patch with `git apply`. Reuse already compiled `.sla` files from
the corresponding stock release under the same relative `specs/` paths; do not
recompile specs or replace existing unrelated files. Build from the REA root:
```sh
env CARGO_INCREMENTAL=0 CARGO_PROFILE_RELEASE_DEBUG=0 \
CARGO_PROFILE_RELEASE_OPT_LEVEL=1 CARGO_PROFILE_RELEASE_LTO=false \
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 \
python3 experiments/analysis-efficiency/resource-run.py --observe-payload-exit -- \
cargo build --manifest-path /absolute/kuna/decompiler/Cargo.toml \
--locked --release -j1 -p kuna-cli --features embed-specs
```
Select that executable through `REA_KUNA_COMMAND` and explicitly pin its actual
SHA-256 through `REA_ATOMIC_NATIVE_IR_ENGINE_SHA256`. Native IR requires embedded
specs and rejects a caller-supplied `--sleighpath`; the provider creates a fresh
owned engine cache per lease. The executable digest therefore covers its embedded
assets, without reusing an unvalidated external spec cache. The current prototype
uses optimization level 1, not the stock release's assumed optimization profile;
comparisons must retain this difference or use the same engine in all lanes.
Native extraction bounds blocks/operations at 12,000, values at 36,000, input and
CFG edges at 50,000 and display text at 2 MiB, before the 8 MiB transport bound.
Capacity overflow makes this facet unavailable, preserving C and a reason. The
provider retains at most two 8 MiB native indexes (two 2 MiB diagnostic indexes)
and 64 MiB of complete source captures per lease. The outer observer still
enforces one CPU, 4 GiB hard memory and early termination at 3 GiB.
Real Linux zlib verification produced 3,860 operations, 5,898 values, 472 blocks,
779 CFG edges and 790 phi operations. Its 5,533,649-byte native JSON has no omitted
definitions or reported producer issues. C is byte-identical to the previously
captured stock 1.833 JSON (52,431 characters), and line mappings are identical.
The CLI composition independently discovers the string, owning function, store
and its two local controllers. Its observed cold session takes 9.191 seconds,
8.887 process-family CPU seconds and 198.9 MiB kernel memory peak, with verified
cleanup and zero OOM kills. This scripted lane is not a real-model cost result.
Targeted JS checks cover malformed/foreign identities, dangling relations, phi
order, exact hex offsets, immutable facts, loop/exit coverage, resource failure,
and all 64 four-node DAGs against an independent path-enumeration oracle.
Upstream `check-spec` passes. The full upstream corpus, stages and workspace gates
have not run; this patch is not declared upstream-ready. The model comparisons
and subsequent boundary findings below do not establish wider provider parity.
The value-origin model comparison exposed a representation boundary: optimized
recovered blocks can absorb a machine predecessor, so an IR edge is not an actual
branch instruction target. The experimental API now names operation locations
`origin_address`, their selector `origin_addresses`, and block locations
`origin_start`; printed CFG targets use `target_origin`. These replace the old
ambiguous fields without aliases. Historical captures retain their pinned old
contracts. Raw upstream JSON is preserved unchanged in Evidence.
The added `instructions` method batches selected machine-address windows, using
Kuna's existing [disassemble CLI](https://github.com/Noelo-Lab/kuna/blob/fe01d6294eb0d1053ce343c8943646df88e143fc/decompiler/crates/kuna-cli/src/disassemble.rs),
with exact bytes, decoded text, extent, coverage and per-window errors. Kuna
already has focused agent-oriented read surfaces; its port ancestry does not
establish which primitives are missing. No assembly decoding or branch-target
parser is duplicated in the MCP adapter.
Windows are capped at 4,096 decoded rows and 16 windows per call, sharing the
8 MiB capture and 64 MiB retained-source budgets. A real maximum-row CLI test
returns 4,096 rows in an 842,106-byte source, taking 1.227 family wall seconds,
1.042 CPU seconds and 112.0 MiB kernel memory peak. Both real stock and patched
MCP tests preserve good windows alongside an unmapped-address failure and report
the actual `JA 0xe26d` / `JMP 0xd9c9` bytes. The representation revision had 33
targeted tests; its subsequent real-model trial is recorded below.
That fresh trial now verifies the missing machine path correctly; see
[actual task costs](trials.md). The SQLite task then exposes a separate missing
primitive: name/alias lookup across distinct callable entries. `functions` now
reuses the production inventory parser, preserving every matching entry, import
stub ambiguity, original aliases, clipped extents and unknown runtime binding.
The inventory is read/validated once per lease, and query/field/page selection
returns only the requested view. Batch xref and instruction reads share one
partial-outcome owner, retaining good observations and source IDs on failures.
A real `sqlite3VdbeExec` capture at `0xea6d0` also exceeds the graph export's
operation capacity while producing 126,519 characters of valid C. The old adapter
incorrectly rejects the entire capture. The revised owner validates the function
envelope and input identity independently, then models graph availability as a
facet result. Code and its language remain available under the same handle;
graph counts stay unknown and graph reads return their reason and Evidence ID.
The real MCP regression reads 3,654 code lines after the graph failure and verifies
that `sqlite3Fts3ErrMsg` has distinct entries `0x268f0` and `0x5efc0`. Native graph
capacity remains a real limitation, not a resolved scalability claim.
`verify-cache.mjs` measures a real cold/warm pair within one open lease. Cold zlib
snapshot reading takes 6,934.4 ms / 6.928 family CPU seconds; warm reading takes
67.7 ms / 0.068 CPU seconds and preserves the exact snapshot/Evidence ID. The
cumulative kernel memory peak is 275.1 MiB for both phases; the warm number is an
upper bound on its isolated phase peak. This is an API-only measurement, with no
model token result or cross-session cache claim. Targeted tests now total 38,
including late cancellation retaining partial facts and their provenance.
A subsequent real boundary sweep found a different loss of usable facts:
`sqlite3Pragma` (`0xb90e0`) and `sqlite3Parser` (`0xb3d00`) stay below the row
limits but overflow the provider's 8 MiB stdout budget. Both public snapshots
fail, losing C as well as IR. A separate diagnostic capture with a stated 32 MiB
observer limit establishes the exact producer sizes; it is not relabeled as a
successful public-provider workflow. The old engine is preserved locally by its
`7d357e75…` digest for historical reproduction.
| Function | Previous pretty JSON bytes | Revised source bytes | C characters | Revised graph |
| --------------- | -------------------------: | -------------------: | -----------: | ----------------------------------------------- |
| `sqlite3Parser` | 8,492,810 | 4,526,811 | 50,508 | All 5,164 operations retained |
| `sqlite3Pragma` | 16,728,407 | 136,501 | 67,300 | Explicitly unavailable at encoded-byte capacity |
The structural fix is at the producing serialization boundary. Atomic output
uses the existing record producer and shared compact ASCII-safe writer.
`--atomic-output-bytes` takes an explicit encoded-document budget (default 8 MiB);
the provider passes the same bound it supervises. The writer checks each encoded
write before growing its bounded buffer, accounting for escaping and newline.
If necessary, the document drops only the graph and records an exact facet
failure. C, line mappings and metadata survive under the same Evidence. If even
the base document cannot fit, the command fails rather than clipping it or
repeating the analysis. Ordinary non-atomic JSON keeps its previous formatting.
Row limits alone never promise that the whole encoded graph fits.
The rebuilt local engine is SHA-256
`2290e8b13caabe30aab6832ab163d92925b2e652eebf7fc0cdbe65b889cb251b`
(same pinned source/release profile plus the revised patch). Real Code Mode MCP
verification succeeds for both functions. The preserved C and line mappings are
identical to the earlier full diagnostic captures; the Parser graph is also
deep-equal, and retained source hashes verify. Pragma's unknown graph counts and
failed graph reads retain the correct source ID. No limit was increased.
The first successful revised MCP check took 13.721 family wall seconds, 13.461
CPU seconds and 326.9 MiB kernel family peak, with verified cleanup and no OOM.
This is a two-function API regression, not a model-cost comparison or a claimed
analysis speedup. Native writer/escaping checks (14) and graph-only fallback (1)
pass in the release test binary; the shared JS tests (38), SDK ownership probe,
lint and patch apply/reverse checks pass. Full upstream corpus/stages/workspace
gates still have not run. The first MCP launch used a stale pre-format-build hash
and was correctly refused; the retained successful retry uses the digest above.
The `bytes` primitive reuses Kuna's existing `read --as data --json` protocol.
Unlike instruction decoding, it asks for an exact byte range. It disables the
global `listing` / `fast_funcdisc` passes for this data-only query; instructions
retain their existing profile. A native probe returns exactly equal JSON with
and without those flags. Its 484 / 290 ms timings share a workspace and run in
that order, so they do not establish an isolated speedup. Native/source ownership,
freshness, decoded-window admission and partial batches remain shared.
Real public MCP checks pass in native Code Mode, native direct and stock 1.833
Code Mode: a known 53-byte string, a 4-of-16-byte read at a mapped-image boundary,
an unmapped address, same-source cache reuse and the 64 KiB maximum. Both adapter
catalogs validate after SDK conversion. The byte parser rejects wrong subjects,
contradictory duplicated hex, invalid extents and rows, and preserves exact u64
addresses. Completeness follows examined byte coverage rather than the native
truncation flag. It never claims these loaded-image bytes are live memory or
proves an original-file mapping. Targeted JS tests now total 41.
## Structured call relations (wire version 2)
The next observed gap was input zero of CALL: a native `fspec` annotation is an
internal reference, not a code address. The read-only `atomic_calls.rs` exporter
now uses the existing `FuncCallSpecs` owner for recovered entry/name, model flags,
argument passing storage and stack offset. A single operation-to-spec index
avoids a linear lookup for every call. Input slots and SSA IDs remain separate
from passing locations. Finalized storage is admitted only at matching arity;
locked prototype storage is the alternative. Shifted inputs, placeholders,
missing specs, unavailable storage and unresolved indirect entries remain
explicit. There is no display-text parser or original-source ordinal claim.
`calls` provides ID/origin filtering, field projection and paging through the
shared SDK/CLI/MCP owner. Callee `values(is_input:true)` exposes retained input
values for exact storage candidate matching. Source schemas, unique call
ownership, call coverage, operand indexes/values and output identities are
validated before exposing an index; a bad or old-version graph preserves valid
C. Machine CALL instructions remain the independent check of a recovered edge.
Engine `64c6b3fe5737056fc29c10b0aad6c7cbd489ad7d17bd1726141b77bdcf5e15b7`
uses the same upstream revision, embedded specs and one-job build profile.
The rebuild took 317.090 family wall seconds, 315.808 CPU seconds and a 2,145.695
MiB kernel process-family memory peak (including charged file cache), OOM 0.
The previous compact exporter engine is preserved by its SHA-256 locally.
Real SQLite MCP verification passes both adapters, including a composed Code
Mode join: caller `0x65211 -> 0x64060`, argument passing storage
`register:0x38/8`, one matching callee input, and a bounded definition slice from
the context updates to that input. Formatter calls `0x5f031`/`0x5f062` point to
`0x2adc0`/`0x27e50`; their fspec offsets remain `0x10000`/`0x10001`.
All three functions' C, ordinary metadata/line mappings, blocks, operations,
values and existing coverage equal retained earlier captures. Those earlier
sources were pretty-printed: encoded-size changes are not a call-exporter
performance result. The structured call counts are 8, 33 and 2 respectively.
The Code Mode verifier took 7.872 family wall / 7.573 CPU seconds, 297.1 MiB;
the direct verifier took 7.771 / 7.499 seconds, 278.7 MiB. These differ in assertion
calls and warm file-cache state, so they are verification receipts, not a
controlled adapter speed comparison. Both verified cleanup and OOM 0. The
existing real zlib controller/phi/instruction verifier also passes with this
engine (10.992 wall / 10.795 CPU seconds, 285.7 MiB, cleanup verified, OOM 0).
`check-spec` passes in its default lenient mode; full upstream gates still have
not run. The independent cross-function question and acceptance criteria are in
[call-oracle.md](call-oracle.md), pinned before model evaluation.
The strengthened verifier additionally reads all five retained indirect calls in
this parser and checks their unknown targets. Machine bytes `ff5328` at
`0x644eb` independently describe a register-indirect CALL. The Code Mode rerun
passes (16.628 wall / 8.239 CPU seconds, 300.5 MiB); native test compilation was
also active on the same CPU, so its wall time is not an isolated performance
sample. The source checks pass 45 JS tests across both prototype directories and
two Python ledger tests; changed source lint and formatting pass.
A current coverage limit remains: call facts are part of the recovered IR
facet. A function that exceeds graph capacity also loses these call records,
even if a selected call-target view could fit. This is a reason to explore
independent fact facets; it must not be mistaken for proof of no calls or full
coverage on large functions. No full provider parity claim is made.
The current producer also passes fourteen native JSON-format tests. The initial
command compiled unrelated integration targets and a non-embedded CLI build,
which replaced Cargo's mutable `target/release/kuna`. Its 181.103 wall / 172.430
CPU seconds, 651.6 MiB peak and OOM 0 describe that broader compilation, not just
JSON test execution. Future focused commands should select `--bin kuna` and
`--features embed-specs`. The original embedded build restores from Cargo cache
and has the same `64c6b3f...` digest.
The first model launch after those tests correctly fails at `open_binary` with
`engine_profile_mismatch`; it produces no target Evidence and is not a completed
answer. Its rejected-trial costs are retained in `trials.md`. The producing
boundary is now fixed by preserving an independent executable copy in a directory
named by the full SHA-256, outside Cargo outputs. The model harness checks the
explicit experimental engine pin before copying credentials or launching a model,
and verifies the same bytes after the task. Changed/missing engines reject the
comparison while retaining costs. Other provider trials keep this field unknown.
Three regression tests cover missing/malformed pins, replacement and removal;
a real driver invocation with a wrong pin rejects before output/profile creation.
## Shallow outgoing references without decompilation
Kuna already supplies native `xrefs --from`, including exact-instruction and
owning-function queries. The shared `KunaReferenceFiles.ts` boundary now owns
both directions, validates direction-dependent peer fields and query ownership,
and preserves exact u64 endpoints and source-row occurrences. The old
incoming-facts-only parser is removed; both experimental consumers use the same
named query contract. Production incoming address-only queries keep their
existing projection and bounded cache semantics.
The experimental `references` method adds direction, explicit address/function
scope, native kind filtering and fields. Incoming function scope is rejected;
unknown outgoing function applicability, unattributed/excluded rows and unresolved
indirect/discovery/runtime coverage remain explicit. Native source cache keys
cover result-affecting query choices while scope, fields and pages reuse the same
source. `reference-reads.mjs` owns protocol selection/projection; the resource
owner and CLI/MCP adapters do not reinterpret native endpoint fields. Empty
field selection now requests the existing always-retained identities, rather
than being rejected without a format/resource reason.
Real outgoing CLI probes return 396 VM call-reference rows in 205,432 bytes,
versus one row/737 bytes for selected call site `0xf238b`. Four sequential probes
(VM function/instruction and wrapper function/instruction) take 6.772 family wall
/ 6.613 CPU seconds and 120.0 MiB peak. Each command takes about 1.6–1.7 seconds;
these are native metadata-query measurements with warm uncontrolled file caches,
not real-model speed/token results.
Independent GNU objdump decoding over the exported VM symbol (`0xea6d0`, size
`0x7e7e`) confirms all 396 `(origin,target)` pairs, 171 distinct exact targets,
and 16 calls to `0x296c0`. It also finds 21 indirect calls, outside these
known-target counts. In the wrapper, nine lifted machine call references compare
with eight retained IR calls: machine `0x6534b -> 0x29370` is an omitted
`__stack_chk_fail@plt` call. Its absence from optimized IR/C is not absence from
the executable. No native analysis or C behavior is changed to repair that
representation difference.
The real Code Mode MCP verifier passes paging, identity-only fields, scope-cache
reuse, exact sites, unknown applicability and local aggregation. It also captures
the VM anew: C is available, IR fails with `atomic operation capacity exceeded`,
and shallow references still work. This verifier takes 48.142 family wall /
47.803 CPU seconds, 610.1 MiB peak; VM decompilation/source capture itself takes
35.945 seconds. These are different requested capabilities, not an equivalent
workflow speedup claim. The direct verifier passes the same reference contract
without that VM decompilation (12.001 / 11.759 seconds, 256.8 MiB). Both verify
cleanup and OOM 0. An earlier direct-verifier attempt incorrectly expected target
metadata on an SDK input-validation error; the corrected verifier respects the
SDK rejection boundary. That failed assertion receipt is retained.
The exact focused boundary suites pass 38 tests, with a fresh strict production
build; changed-test strict typechecking and 45 experimental JS tests also pass.
Full lint/module boundaries and changed-file formatting pass. Repository lint
warnings remain outside this change. The focused build/test scope peaks at
3,030.6 MiB, below the 3 GiB early-stop line, with OOM 0. Two full `check:fast`
attempts (including serial execution and Go runtime memory controls) reach that
early-stop budget and are terminated before OOM; they are not reported as passed.
The changed-test typecheck uses 70.1 MiB and standalone full lint 919.0 MiB.
Full-repository typechecking and full upstream Kuna gates remain unverified.
The [next question/oracle](reference-oracle.md) are committed before model trials.
## Independent call and boundary-value facets
Graph schema 3 removes embedded call records. An independent `atomic_calls`
version-1 facet now carries every retained block-member CALL/CALLIND, target-input
SSA identity, origin/block/opcode/dead status, call specs and boundary values.
`atomic_values.rs` owns common native value interpretation. The call scan walks
native block membership without allocating an operation vector for every block;
its own call/input/value/text budgets do not depend on the 12,000-op graph cap.
The default native path still does not collect either facet and C analysis phases
are unchanged. All captures occur after the same C rendering.
The bounded serializer retains fitting facets independently and preserves ordinary
C/metadata. It tries the full document, graph without calls, calls without graph,
then the base record with both reasons. This keeps existing graph availability
when both facets individually fit but their combination does not. Facet contents
are moved for these bounded alternatives rather than cloned; no reanalysis or
clipped collection labeled complete is introduced.
The JS owner validates each facet independently with shared ID/value contracts
and row-wise admission. When both parse, call identities, origins, operands,
outputs and boundary values must agree with the graph owner. Bad call facts do
not erase a valid graph; a bad/oversized graph does not erase valid calls. Code
survives either failure. `values` uses the complete retained graph when present,
otherwise the explicitly scoped call-boundary set; absent IDs in that set do not
prove absence from the native function. Defining operation identities may remain
unreadable, and source signatures, source parameter ordinals, aliases and runtime
binding stay unknown. `is_dead` is always retained on call rows, like an
instruction decode status. CLI, SDK and both MCP adapters share these views.
The new preserved engine is
`e7d3f0cc8d8aae814bd6a2625a567d6aaad96c3fe2405a4f08dc8e065b851588`.
Its full rebuild took 315.815 family wall / 315.305 CPU seconds, 2,119.4 MiB
kernel process-family peak. Four focused native atomic-JSON tests pass, including
both overflow directions, both-overflow C preservation and graph preference when
the combined document is too large (95.981 / 95.631 seconds including test-target
compilation, 626.8 MiB). The final CLI rebuild after tests is 26.203 / 25.952
seconds, 492.7 MiB. It is copied outside Cargo outputs and pinned by full digest.
All these runs verify cleanup and OOM 0; full upstream gates remain unexecuted.
Real public MCP verification keeps VM C available, reports graph operation
capacity failure, and now exposes 416 calls plus 1,294 boundary values. The call
scan examines 21,349 operations over 1,229 blocks. It preserves 395 direct known
targets and 21 unresolved indirect calls; all direct pairs match independent
machine pairs except the omitted `0xf2493 -> 0x29370` stack-check call. All 21
indirect origin addresses also match independent disassembly. Selected
`0xf115c`/`0xf238b` calls target `0x296c0`; their fspec inputs remain separate
annotation values. Repeated snapshots reuse the same handle and source, and an
explicit unavailable graph read fails without hiding these retained facts.
The VM source grows from 273,703 to 793,791 bytes to retain this new data; the
wrapper grows from 202,206 to 208,083 bytes. Their ordinary records, including C,
variables and line mappings, are identical to the prior capture. The wrapper's
blocks/operations/values/coverage also remain identical. These are fidelity and
source-volume observations, not model-token or speed results.
The real reference/VM verifier passes in 49.471 wall / 49.130 CPU seconds,
615.8 MiB. The existing cross-function call/input verifier passes in 8.377 /
8.094 seconds, 292.9 MiB; encoded Pragma/parser C/graph checks pass in 12.403 /
12.195 seconds, 335.0 MiB. All verify cleanup and OOM 0. The updated contract
suite passes 47 JS tests, including independent facet failure, cross-facet
conflicts, input-zero identity and boundary-only value reads. `check-spec` passes
in default lenient mode, lint and changed-file formatting pass, and the patch
applies forward to the pinned upstream revision and reverses from the clone.
Full repository typechecking retains its previously recorded resource limitation.
The [boundary question/oracle](boundary-oracle.md) are fixed before model runs.
The subsequent real-model pair passes that oracle in both calling modes. Each
uses one VM analysis and the same retained function record; neither invents a
complete graph from the available call-boundary values. Source digests, target
and preserved-engine pins, selected machine checks, cleanup and OOM-zero receipts
verify. See [whole-task costs](trials.md): the capability survives real model use,
but a single mixed-context-cost pair does not establish general efficiency.
## Compact counts from the validated call owner
The following API-only change keeps the preserved engine and native source
format unchanged. Snapshot call metadata includes counts by recovered opcode
and known/unknown native target, plus call coverage. The owner computes these
once after validation, before the shared CLI/SDK/MCP views. Counts include dead
rows and do not infer target knowledge from CALL versus CALLIND. Available empty
sets have zeros; unavailable sets have no counts. Selected call reads do not
change this whole-facet summary or require a new analysis.
The focused suite passes 49 tests, including known indirect/unknown direct
targets, dead rows, immutable summaries and empty/unavailable distinction.
Both real MCP adapters verify the wrapper's eight direct calls and parser's
28 direct/five unresolved indirect calls while preserving the existing
cross-function checks and validating advertised schemas after SDK conversion.
Code Mode verification takes 29.263 family wall / 21.548 CPU seconds, 283.9 MiB
kernel family peak; direct takes 32.893 / 22.781 seconds, 280.6 MiB. Both have
verified cleanup and OOM 0. These are validation runs, not a controlled speed
comparison with previous verifier timings. An owner replay of the prior
digest-verified VM source yields the expected 395/21 distribution; it is not
relabeled as a fresh provider or model run. The identical boundary question and
oracle are retained for subsequent real-model comparison.
That comparison now passes in both modes. Both consume the compact counts and
read just the two selected calls, reusing one VM analysis. All native VM function
records match the preceding pair and all retained sources/digests verify. Direct
has lower observed task costs than Code Mode in this sample; the before/after
results remain mixed. [trials.md](trials.md) records cumulative/cached/uncached
tokens, model responses, elapsed time, CPU and process-family memory, including
the slower Code Mode result. No native engine or analysis-speed improvement is
claimed for this shared owner metadata change.
## Tagged cleanup ownership regression
Source inspection finds that the experimental owner awaits but ignores
`KunaTargetCommands.close()`'s tagged `Result`. On error it would clear its state
and let `AtomicSession` drop the owner while claiming a successful close. The
SDK verifier reproduces this before the fix: an injected `ProviderCleanupError`
does not reject close. Its fallback cleanup still removes the real owned state;
the original failing result is retained as `cleanup-before.json`.
The owning boundary now uses the existing `requireResult` projection before
closing its cache root or clearing state. The existing session queue therefore
retains the owner on failure. Both close and target replacement report
`cleanup_incomplete`, preserve the staged file identity and original lease, and
succeed on retry; the file is then absent. MCP's open/close error adapter now
preserves context and resource details rather than dropping that evidence. The
CLI already propagates the thrown error as a failed command. No alternate
cleanup owner or downstream retry workaround is added.
`verify-cleanup.mjs` runs against real provider reads and resources, injecting
one tagged failure per close/replacement case. `verify-cleanup-mcp.mjs` injects
one explicit test-only failure in an isolated server, then verifies public
Code Mode and direct error metadata and successful retry. These are controlled
boundary failures, not a claim that the real engine failed to stop. The SDK
check takes 1.730 family wall / 1.567 CPU seconds, 130.4 MiB kernel peak; MCP Code
Mode takes 1.931 / 1.639 seconds, 200.0 MiB; direct takes 1.730 / 1.489 seconds,
192.8 MiB. All verify process cleanup and OOM 0. The original failing verifier
takes 1.226 / 0.985 seconds, 122.7 MiB and also verifies fallback cleanup/OOM 0.
The 49 focused JS tests, lint and formatting pass. This lifecycle-only change
follows the recorded model pairs; no new model token or speed claim is made.
## Callable bounded definition projection
The next native exporter retains a version-1 `atomic_projection` independently
of graph version 3 and call version 1. One checked native membership scan owns
call roots and an optional index of at most 65,536 operation keys; exceeding the
index budget disables the projection without discarding calls. Full-graph row
capacity is checked before rendering its rows. Full and selected facts share
one operation/value normalizer, including exact identities, indexed operands,
outputs, phi predecessor edges, flags and display. Default non-atomic analysis
and C generation are unchanged.
All recovered CALL/CALLIND operations are retained as projection roots, followed
by backward operand definitions in breadth-first order. The projection bounds
4,096 operations, 12,288 values, 16,384 inputs and 2 MiB text. Too many roots or
another admission failure makes the facet explicitly unavailable. Omitted
definitions retain exact IDs and operation-budget/outside-membership reasons.
A fitting full graph omits its redundant projection; an encoded-overflow graph
restores the fitting projection. Facets are moved through bounded alternatives,
and a valid C/call record survives projection failure. There is no repeated
decompilation or clipped collection labeled complete.
The JS boundary shares operand/value validation and query indexes between full
and sparse views. It checks root reachability, exact frontier membership,
call/value agreement and phi metadata without inventing a CFG. In the absence
of a full graph, conflicting projection facts do not erase independently valid
calls. `snapshot.facets.operations` and `facets.values` expose their scopes;
selected definitions/uses and slices work over the retained set. Uses remain
selected-only, CFG/controller queries retain their graph error and Evidence ID,
and slice missing definitions keep their native reasons. A missing projection
preserves the original graph failure instead of hiding it behind a generic
not-captured error. All adapters use this owner.
Coverage returns counts instead of global omitted-ID inventories, at most eight
160-character issue summaries, full issue counts and omission metadata. Complete
native coverage/frontier details remain in source Evidence. Native operation
rows retain `is_dead` with their identities; constant summaries add `value_id`
and `input_index`, preserving exact offset/width semantics. No original-signature,
arbitrary-width computation, memory-alias or runtime proof is introduced.
Preserved engine SHA-256:
`a0685486518e09d3c65f756325a7e9fed8df123a2a988aca2972a72335ce8edc`.
The same one-job/embedded-spec build takes 309.805 family wall / 309.523 CPU
seconds, 2,099.5 MiB kernel family peak. Six focused native JSON tests pass,
including projection restoration and independent overflow (99.752 / 98.662
seconds with test compilation, 626.9 MiB). The final CLI build reuses artifacts
(0.320 / 0.146 seconds, 28.8 MiB), leaving the preserved digest unchanged.
Real SQLite VM public reads expose 4,096 operations, 7,469 values and 326
unexpanded definitions, while the complete graph remains unavailable. Source is
4,008,032 bytes, inside the unchanged 8 MiB public budget. Every selected operation
and value equals the earlier 17.8 MB diagnostic capture; ordinary C/metadata and
the complete call facet also equal it. An independent BFS over that retained
full graph produces exactly the same operation order and frontier. The extended
`measure-native-projection.py --verify-capture` reproduces these comparisons.
This is producer-fidelity evidence, not independent machine/runtime equivalence.
Both public MCP adapters read the selected PHI definitions and slices from one
VM source. Code Mode verifies unavailable controllers preserve the source ID.
The corrected Code Mode verifier takes 52.706 wall / 47.550 CPU seconds,
597.4 MiB peak; direct takes 39.696 / 39.418 seconds, 592.5 MiB. The first
Code Mode verifier incorrectly expected INDIRECT definitions; independent source
inspection shows MULTIEQUAL. Its 37.070 / 36.781 seconds, 593.3 MiB failed
assertion is retained, then the verifier is corrected without changing native
facts. These scripted runs are validation costs, not an adapter speed comparison.
Small-function cross-call checks pass (8.476 / 8.204 seconds, 293.6 MiB); all three
complete function records equal the prior exporter. Encoded Pragma/Parser checks
pass (13.712 / 13.507 seconds, 361.5 MiB): Pragma retains 3,627 projected operations
after graph encoding overflow, while Parser keeps its full 5,164-operation graph
without a duplicate projection. Zlib control/phi regression passes (10.893 /
10.700 seconds, 286.3 MiB). Real CLI reads verify both selected PHIs and repeated
snapshot/source identity (37.367 / 37.174 seconds, 527.1 MiB).
The real VM MCP cache benchmark observes cold snapshot wall 36,448.8 ms / family
CPU 36.425 seconds, then warm 40.2 ms / 0.041 seconds with the identical handle
and source. Cumulative family peak is 590.1 MiB, an upper bound on isolated warm
phase memory. Its complete run is 37.667 / 37.492 seconds. This is same-lease
capture reuse, not cross-session persistence or a model-token result; OS caches
remain uncontrolled. All resource runs above verify cleanup and OOM 0.
The focused JS suite passes 53 tests; lint/format, default lenient `check-spec`,
Python compilation and patch forward/reverse checks pass. Full upstream corpus,
stages and workspace gates remain unexecuted; the patch is not upstream-ready.
No whole-repository typecheck pass is claimed beyond the previously recorded
resource limitation. The [PHI-format task/oracle](projection-oracle.md) are fixed
before real-model launches. No model benefit is assumed from these smaller facts.
## Named reference discovery and input schemas
The first PHI model pair completes correctly but exposes a documentation boundary:
direct help displays `facts_*` names while lookup only recognizes raw method
substrings. A multi-name query returns no matches and causes a full-reference
fallback. Registration and help now share one explicit name map, with canonical
identity separate from presentation. Exact lists preserve caller order,
deduplicate names and retain unmatched terms. Topic/all-contract lookup remain;
ambiguous labels fail instead of choosing by catalog position.
The real client verifier also catches that plain `z.toJSONSchema` defaults to
output semantics, making defaulted `offset`/`limit` falsely required in advertised
input schemas. Reference generation now explicitly selects `io:input`. Converted
schemas are frozen and weakly cached by schema identity; a replacement schema
invalidates the conversion, while description/presentation is read separately.
The documentation module removes the adapter rename pass. No target analysis,
live-result caching or native-engine change is involved.
The shared suite passes 55 tests. `verify-discovery.mjs` checks both real SDK
catalogs and reference responses without opening a target, compiles every catalog
and all fourteen reference schemas with Ajv2020, and validates the same
omitted-default requests against named reference/direct contracts. It proves the
six-name query matches all requested contracts without a miss. The all-schema
verifier takes 1.936 family wall / 1.760 CPU seconds, 138.8 MiB kernel peak,
cleanup verified and OOM 0. The earlier six-schema probe takes 1.628 / 1.449
seconds, 128.9 MiB. Its original 1.730 / 1.487 seconds, 128.1 MiB failed
omitted-default check remains recorded. Six contracts occupy 10,835 Code Mode /
10,360 direct bytes, versus 21,746 / 20,699 for all fourteen. Bytes do not prove
token or time savings. The same PHI question/oracle are retained for the next
actual model pair.
## Wide native operand relations
A retained-source replay exposes a whole-row cost: VM PHI
`0xea998:14649` has 156 inputs and 156 definition edges. Its normalized old
operation is 44,447 JSON bytes, and a default one-node slice returns 44,980 data
bytes. Real QuickJS returns `output_budget` while preserving the source ID.
This replays real producer facts through the shared parser/executor, without
a fresh native analysis or model call (`wide-phi-before.json`). Explicitly
requesting only `inputs` already fits; the gap is default size and lack of
independently selected/paged operands, not inability to obtain the data at all.
`relations kind:operands` now owns slot-level paging and optional input-index
selection. Snapshot + operation + input_index identifies the relationship;
value identity, native definition and exact phi edge are separate fields. It
retains constants, function inputs and nulls that definition edges cannot cover.
Requested out-of-range slots of retained seeds are absent, while unretained
seeds stay explicit/unknown. Seeds and selectors deduplicate in caller order;
total counts filtered rows before paging. Full graph and projection share this
owner; diagnostic SSA rejects the unsupported relation with source context.
Paging counts existing relation groups before materializing selected rows,
avoiding a complete flattened relation copy. Native operation defaults are
compact summaries with exact input/definition/constant counts; detailed fields
remain selectable. Repeated value/block identity lookups deduplicate at their
shared read boundary. A discriminated contract replaces the prior runtime-only
relation refinement, so advertised schemas also enforce seed types and prohibit
input_indices on other relationship kinds. No native rebuild, higher native
capacity, new method or additional authority is involved.
The shared suite passes 57 tests; changed JS lint has zero warnings and formatting
passes. Both real SDK catalogs and all reference schemas compile; selected
operand inputs and invalid selector applicability agree with runtime validation.
That discovery run takes 7.443 family wall / 4.928 CPU seconds, 141.8 MiB peak
including charged file cache. The real Code Mode VM verifier passes ten calls
in 54.327 / 47.069 seconds, 597.6 MiB peak. Its default slice fits, selected
slots preserve exact native facts, and explicit all-input reads still work.
Both runs verify cleanup and OOM 0. This first public run precedes the final
identity-deduplication adjustment; subsequent direct/model reads cover it.
Scripted bytes and costs are not model-token savings or an adapter speed claim.
The subsequent direct verifier passes all ten calls, including duplicate-value
deduplication, in 39.385 wall / 39.163 CPU seconds, 591.3 MiB peak, with cleanup
verified and OOM 0. The different scripted read paths/host state do not isolate
adapter costs. The [wide-operand oracle](operands-oracle.md) fixes the next seeded
real-model task before launch; it is not a before/after of the PHI-format task.
## Static method index
The wide-operand pair exposes a discovery cost: Code Mode asks four times for
help before using the same seven fact requests as direct. `reference view:index`
now returns the same fourteen canonical/display names and descriptions without
constructing schemas, return contracts or examples. `view:contracts` preserves
the existing default and exact-name/topic behavior. Both presentations share one
named documentation contract/owner and the API's registry; no analysis change or
engine rebuild is involved. An index is static declared support, never live
provider capability. Runtime facets remain authoritative.
The shared suite passes 58 tests, including a getter that proves an index does
not access an unrequested input contract. Changed JS lint/format and both real
SDK catalogs/reference schemas pass. The first discovery probe takes 5.284 family
wall / 4.028 CPU seconds, 137.6 MiB peak, cleanup verified and OOM 0. Code Mode's
index is 7,212 JSON bytes versus 24,010 for all contracts; direct is 7,240 versus
22,939. These bytes are static discovery output, not demonstrated token/time
savings. A subsequent focused check and real probe cover moving the input schema
into the documentation owner and unifying presentation construction. The same
wide-operand question/oracle are retained for a new real-model pair.
The final real SDK probe passes in 4.380 wall / 3.807 CPU seconds, 141.4 MiB peak,
cleanup verified and OOM 0. Both subsequent real-model answers satisfy the
unchanged oracle. Code Mode uses index plus one exact contract query, reducing
its discovery lookups from four to two. Whole-task costs remain mixed; all
attempts and limits are recorded in [trials.md](trials.md).
## Fact granularity versus computation granularity
The eight successful real-model VM captures using the preserved `a0685486...`
engine each retain 4,008,032 bytes, including 126,519 bytes of reconstructed C
that the selected-operand models never read. Fresh-lease native request wall
ranges from 36.702 to 53.124 seconds. A separate failed first attempt hits the
120-second timeout before one successful capture; its cause remains unknown.
These are fresh private native caches, not controlled OS-cold samples. Same-lease
warm source reuse remains separately measured above.
Source inspection explains the current computation boundary: the project core
drives whole-function decompilation, renders C and extracts metadata, then
collects independent call/graph/projection facets from the live function. The
new slot atom reduces selected read/serialization scope, but does not implement
selected-slot native analysis. The complete VM CFG is still unavailable and
arbitrary definitions outside the retained call-rooted projection cannot be
expanded by a fact read. Provider parity and general complex-software superiority
remain unestablished.
At that checkpoint, pipeline/render/metadata/export costs were not separately
profiled. The [subsequent native computation study](native-compute-study.md) now
measures them: VM drive about 34 seconds, C rendering 0.22 seconds and projection
0.03 seconds. Skipping C is a small opportunity for this workload. An offline
lossless encoding probe also puts the earlier full 17.8 MB diagnostic record
inside the unchanged 8 MiB transport. The [subsequent codec study](native-graph-transport-study.md)
now implements and verifies this through both public experimental MCP adapters,
including complete decoded Evidence and shared text-budget ownership. Actual
guard/control model behavior is now checked in two real-model pairs. Model
comparisons share the same computation/fact owners, avoiding a capability
difference between adapters. The [switch extension](switch-study.md) adds an
independent native table facet with exact labels and row/edge mapping, selected
queries and a verified 2 MiB fallback that retains cases without a full graph.
Its final engine is `a9ca8a8ac224936afb08a9d4be9c1225feb69473ad9f35764e8d1c4f04875b5b`;
the fixed case/default model question is separate from the earlier guard pairs.
@@ -0,0 +1,50 @@
// One bounded decoded source view; the source owner revalidates bytes per read.
import { createHash } from "node:crypto";
import { readNativeGraphEvidence } from "./native-ir-contract.mjs";
export class NativeEvidenceReads {
#graph;
constructor({ readText, readWindow }) {
Object.assign(this, { readText, readWindow });
}
clear() {
this.#graph = undefined;
}
async read(input) {
if (input.component !== "recovered_ir")
return this.readWindow(input.evidence_id, {
offset: input.offset ?? 0,
limit: input.limit ?? 4096,
});
const { text: original, source } = await this.readText(input.evidence_id);
const key = `${input.evidence_id}:${source.sha256}`;
if (this.#graph?.key !== key) {
const decoded = readNativeGraphEvidence(original);
this.#graph = {
key,
...decoded,
sha256: createHash("sha256").update(decoded.text).digest("hex"),
bytes: Buffer.byteLength(decoded.text),
};
}
const decoded = this.#graph,
text = decoded.text;
const view = {
component: "recovered_ir",
encoding: decoded.encoding,
sha256: decoded.sha256,
bytes: decoded.bytes,
authority:
"uninterpreted retained graph source; fact validity is separate",
};
const offset = input.offset ?? 0,
limit = input.limit ?? 4096;
return {
source,
view,
text: text.slice(offset, offset + limit),
total_code_units: text.length,
next_offset: offset + limit < text.length ? offset + limit : null,
};
}
}
@@ -0,0 +1,94 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createHash } from "node:crypto";
import { gzipSync } from "node:zlib";
import { NativeEvidenceReads } from "./native-evidence-reads.mjs";
const hash = (s) => createHash("sha256").update(s).digest("hex");
function captured(text) {
const bytes = Buffer.from(text);
const wire = JSON.stringify({
binary: "/input",
count: 1,
language: "c",
error: null,
functions: [
{
address_hex: "0x1000",
code: "retained C",
error: null,
atomic_facts: {
schema_version: 4,
encoding: "gzip-base64",
raw_bytes: bytes.length,
data: gzipSync(bytes).toString("base64"),
},
},
],
});
return {
text: wire,
source: {
evidence_id: "ev_owned",
sha256: hash(wire),
bytes: Buffer.byteLength(wire),
},
};
}
test("decoded Evidence pages preserve their own byte identity and raw source provenance", async () => {
const logical = "{malformed JSON with 中文 and 😀",
source = captured(logical);
const reader = new NativeEvidenceReads({
readText: async () => source,
readWindow: async (_id, { offset, limit }) => ({
source: source.source,
text: source.text.slice(offset, offset + limit),
}),
});
const raw = await reader.read({ evidence_id: "ev_owned", limit: 1e5 });
assert.equal(raw.text, source.text);
assert.equal(raw.view, undefined);
const chunks = [];
for (let offset = 0; offset < logical.length; offset += 3) {
const page = await reader.read({
evidence_id: "ev_owned",
component: "recovered_ir",
offset,
limit: 3,
});
chunks.push(page.text);
assert.equal(page.source.sha256, source.source.sha256);
assert.equal(page.view.sha256, hash(logical));
assert.equal(page.view.bytes, Buffer.byteLength(logical));
assert.equal(page.total_code_units, logical.length);
}
assert.equal(chunks.join(""), logical);
});
test("decoded view reuse still requires source-owner validation and follows content identity", async () => {
let source = captured('{"schema_version":3}'),
failure = false,
reads = 0;
const reader = new NativeEvidenceReads({
readText: async () => {
reads++;
if (failure) throw new Error("source_changed");
return source;
},
});
const query = { evidence_id: "ev_owned", component: "recovered_ir" };
await reader.read(query);
failure = true;
await assert.rejects(reader.read(query), /source_changed/);
failure = false;
source = captured('{"schema_version":3,"new":true}');
assert.equal(
(await reader.read(query)).text,
'{"schema_version":3,"new":true}',
);
reader.clear();
assert.equal(
(await reader.read(query)).view.sha256,
hash('{"schema_version":3,"new":true}'),
);
assert.equal(reads, 4);
});
@@ -0,0 +1,77 @@
import assert from "node:assert/strict";
import test from "node:test";
import { parseNativeIR } from "./native-ir.mjs";
import { readNativeGraphEvidence } from "./native-ir-contract.mjs";
// Minimal valid graph: this regression concerns facet admission, not SSA rules.
const document = () => ({
binary: "/fixture",
count: 1,
language: "c",
error: null,
functions: [
{
address_hex: "0x1000",
error: null,
code: "reconstructed C",
atomic_facts: {
schema_version: 3,
blocks: [
{
id: 0,
start: "0x1000",
operations: [],
predecessors: [],
successors: [],
},
],
operations: [],
values: [],
coverage: {
scope: "retained native graph",
machine_semantic_equivalence: "unknown",
indirect_branch_operations: [],
omitted_definition_ids: [],
issues: [],
},
},
},
],
});
test("malformed facet failure values stay local and preserve healthy graph/code/source views", () => {
for (const name of [
"atomic_facts",
"atomic_calls",
"atomic_parameters",
"atomic_switches",
"atomic_projection",
])
for (const reason of [null, 7, false, {}, []]) {
const doc = document();
if (name === "atomic_facts") delete doc.functions[0].atomic_facts;
doc.functions[0][`${name}_error`] = reason;
const text = JSON.stringify(doc),
model = parseNativeIR(text, "0x1000");
assert.equal(model.code, "reconstructed C");
if (name !== "atomic_facts") {
assert.equal(model.facets.recovered_ir.availability, "available");
assert.equal(model.blocks({}).total, 1);
assert.ok(readNativeGraphEvidence(text).text.length);
} else {
assert.equal(
model.facets.recovered_ir.error.code,
"invalid_provider_output",
);
assert.throws(
() => readNativeGraphEvidence(text),
(e) => e.code === "invalid_provider_output",
);
}
if (name === "atomic_parameters")
assert.equal(
model.facets.parameters.error.code,
"invalid_provider_output",
);
}
});
@@ -0,0 +1,36 @@
// The wire owner validates the archive before normal graph-row admission.
import { gunzipSync } from "node:zlib";
import { z } from "zod";
import { requireFact } from "./native-contract.mjs";
import { NATIVE_OUTPUT_BYTES } from "./limits.mjs";
export const MAX_GRAPH_JSON_BYTES = 32 * 1024 * 1024;
const envelope = z.strictObject({
schema_version: z.literal(4),
encoding: z.literal("gzip-base64"),
raw_bytes: z.number().int().min(1).max(MAX_GRAPH_JSON_BYTES),
data: z.string().max(NATIVE_OUTPUT_BYTES),
});
export function decodeGraphArchive(raw) {
if (raw?.schema_version !== 4) return undefined;
const encoded = envelope.parse(raw);
requireFact(
encoded.data.length > 0 &&
encoded.data.length % 4 === 0 &&
/^[A-Za-z0-9+/]*={0,2}$/u.test(encoded.data),
"Native compressed graph has invalid base64",
);
const bytes = Buffer.from(encoded.data, "base64");
requireFact(
bytes.toString("base64") === encoded.data,
"Native compressed graph has noncanonical base64",
);
// The native-declared length is admitted before inflation, not checked only
// after an unbounded allocation. Node also verifies the gzip framing/CRC.
const decoded = gunzipSync(bytes, { maxOutputLength: encoded.raw_bytes });
requireFact(
decoded.length === encoded.raw_bytes,
"Native compressed graph length differs from its declaration",
);
return new TextDecoder("utf-8", { fatal: true }).decode(decoded);
}
@@ -0,0 +1,66 @@
import assert from "node:assert/strict";
import test from "node:test";
import { gzipSync } from "node:zlib";
import {
decodeGraphArchive,
MAX_GRAPH_JSON_BYTES,
} from "./native-graph-encoding.mjs";
const encodeBytes = (bytes) => ({
schema_version: 4,
encoding: "gzip-base64",
raw_bytes: bytes.length,
data: gzipSync(bytes, { level: 1 }).toString("base64"),
});
const encode = (value) => encodeBytes(Buffer.from(JSON.stringify(value)));
test("bounded gzip preserves logical JSON fields and legacy graphs without a second interpretation", () => {
const graph = {
schema_version: 3,
statement: "中文\u0000😀",
offset: "0xffffffffffffffff",
};
assert.equal(decodeGraphArchive(encode(graph)), JSON.stringify(graph));
assert.equal(decodeGraphArchive(graph), undefined);
});
test("admission rejects unsupported envelopes and malformed base64 before inflation", () => {
const good = encode({ schema_version: 3 });
for (const change of [
{ encoding: "deflate" },
{ raw_bytes: 0 },
{ raw_bytes: MAX_GRAPH_JSON_BYTES + 1 },
{ unexpected: true },
{ data: "AAAA\n" },
{ data: "A===" },
{ data: "?AAA" },
{ data: "A".repeat(8 * 1024 * 1024 + 1) },
])
assert.throws(() => decodeGraphArchive({ ...good, ...change }));
assert.throws(
() => decodeGraphArchive({ ...good, data: "AB==" }),
/noncanonical/,
);
});
test("inflation respects declared size and verifies framing without interpreting logical source", () => {
const graph = { schema_version: 3, statement: "x".repeat(1024 * 1024) };
const good = encode(graph);
assert.throws(() => decodeGraphArchive({ ...good, raw_bytes: 64 }), {
code: "ERR_BUFFER_TOO_LARGE",
});
assert.throws(
() => decodeGraphArchive({ ...good, raw_bytes: good.raw_bytes + 1 }),
/differs/,
);
const corrupt = Buffer.from(good.data, "base64");
corrupt[corrupt.length - 8] ^= 1;
assert.throws(() =>
decodeGraphArchive({ ...good, data: corrupt.toString("base64") }),
);
assert.throws(() =>
decodeGraphArchive({
...good,
data: Buffer.from(good.data, "base64").subarray(0, -5).toString("base64"),
}),
);
assert.throws(() => decodeGraphArchive(encodeBytes(Buffer.from([0xff]))));
assert.equal(decodeGraphArchive(encodeBytes(Buffer.from("{"))), "{");
});
@@ -0,0 +1,124 @@
# Bounded full recovered graphs
This implements the preceding native encoding probe as an opt-in experiment,
not stock Kuna support, an integrated release or provider parity.
## Format and owners
Logical graph schema 3 stays unchanged. A fitting ordinary record keeps its
existing representation. Before dropping facts, the writer can encode only the
graph in a schema-4 `{encoding:"gzip-base64",raw_bytes,data}` envelope. Ordinary
C/metadata and independent calls keep their fields. Existing graph/call/
projection/code fallback and explicit failure still apply if encodings do not
fit; no graph is clipped as complete.
Raw serialization stops at 32 MiB. Envelope overhead and base64 expansion are
accounted for before allocation; gzip output and encoded alternatives share the
unchanged caller budget of 8 MiB. Alternatives move ownership instead of cloning
graphs. Construction separately admits 32,000 operations, 36,000 values, 100,000
inputs, 12,000 blocks, 50,000 CFG edges and 4 MiB display/type text. Calls and
projections keep their earlier limits.
Each collector now owns one `TextBudget` for combined display/type charges. The
initial larger graph exposed a hidden second 2 MiB limit in value collection;
the first real VM probe rejected it with `atomic text capacity exceeded` while
preserving calls/C/projection. Passing the collector-owned budget through value
extraction removes this competing policy. Final graph text is 2,345,629 bytes.
`native-graph-encoding.mjs` owns envelope admission, canonical base64, gzip
integrity, exact lengths and fatal UTF-8 decoding. Inflation uses Node's
[`maxOutputLength`](https://github.com/nodejs/node/blob/main/doc/api/zlib.md#class-options)
with an admitted 32 MiB maximum. Logical schema/row/relationship/text admission
and existing native identity/CFG/phi checks then operate on the same graph.
Nested encodings fail logical admission; bad graphs preserve independent calls/C.
`evidence` defaults to the exact source wire record and original hash.
`component:"recovered_ir"` pages decoded graph source with a separate view hash
and byte count. Well-framed malformed logical facts remain inspectable without
being accepted as facts. `NativeEvidenceReads` owns one decoded view up to 32 MiB
per lease; the source owner revalidates bytes on every read. Content identity
keys the view; successful close clears it. All adapters share these owners.
## Real verification
These graph-only engine/patch measurements use commit `e2205313a` and its
version of `kuna-native-ir.patch`. The subsequent [switch extension](switch-study.md)
has its own pinned engine/patch and retains the same logical graph fields.
Kuna upstream: `fe01d6294eb0d1053ce343c8943646df88e143fc`.
Final preserved engine:
`677b9795d49a65e459054ecbd3c0df37d603b541d72df9f74b46778947ed3936`.
Patch SHA-256:
`9f5754a15bd971326d14085f4c515348735d140be3bf36a371e7cf336fc291f3`.
Binaries are copied outside mutable Cargo outputs, not hardlinked or committed.
On the pinned Debian SQLite target, both actual MCP adapters under Node 24.18.0
verify 21,349 operations, 35,755 values, 1,229 blocks and zero omitted definitions.
The complete graph deeply equals the earlier diagnostic golden, and ordinary
C/metadata plus all 416 recovered calls are unchanged. Selected old projection
frontiers now resolve, selected CFG/PHI reads work, both complete Evidence views
verify and repeated snapshots reuse one source. This establishes producer
fidelity, not independent machine/IR equivalence or runtime feasibility.
The actual wire document is **3,788,881 bytes**; decoded graph is **17,008,223
bytes**. The public byte budget remains 8,388,608. Raw receipts/source copies are
`full-graph-codec-*` under `.cache/atomic-codemode/`.
| Executed scope | Family wall seconds | CPU seconds | Kernel peak MiB |
| ---------------------------------------- | ------------------: | ----------: | --------------: |
| Initial build | 441.295 | 391.223 | 2,194.8 |
| Focused native tests, including compile | 98.589 | 98.034 | 632.9 |
| Final budget-version native tests | 176.333 | 175.748 | 644.1 |
| Formatted cached rebuild | 26.999 | 26.749 | 499.3 |
| Collector-budget rebuild | 361.041 | 342.220 | 2,192.9 |
| First probe: hidden text-cap failure | 39.279 | 39.010 | 650.9 |
| Exploratory success under system Node 20 | 44.858 | 44.480 | 576.6 |
| Final Code Mode MCP, pinned Node 24 | 42.422 | 42.111 | 651.0 |
| Final direct MCP, pinned Node 24 | 41.496 | 41.252 | 644.2 |
| CLI: incorrect unique-name assumption | 1.229 | 1.037 | 132.5 |
| CLI: corrected string/xref composition | 43.512 | 43.217 | 584.2 |
| Full-graph cache benchmark | 41.912 | 39.955 | 588.4 |
| Both catalogs/reference schemas | 3.644 | 1.716 | 142.7 |
| Three small functions / call composition | 8.579 | 8.358 | 300.4 |
| Legacy engine / current reader | 39.813 | 39.425 | 642.5 |
All resource runs use one CPU, 4 GiB hard / 3 GiB early-stop bounds, verified
cleanup and OOM 0. Kernel peak includes charged file cache, not RSS. The system
Node probe is outside pinned-toolchain validation; the verifier now rejects a
wrong Node before native analysis. The first failed probe used preserved
pre-fix `fb717dde...`. Native focused tests pass ten cases; shared JS passes 65.
Changed JS lint/format, lenient native `check-spec`, applied-source whitespace
and patch forward/reverse checks pass. Patch-context spaces are format markers.
The three small-function records retain their prior ordinary representations;
the current reader also accepts the old engine's explicit full-graph refusal,
independent calls and 4,096-operation projection through real MCP reads.
The final native test rerun also passes the same ten selected cases after the
collector-budget change. Other CLI integration tests were compiled but filtered
out; they are not additional executed coverage.
Native full corpus/stages/workspace and whole-REA gates remain unexecuted or
previously resource-limited; no upstream/PR/integration readiness is claimed.
Fresh-lease snapshot: 39,677.7 ms / 38.726 family CPU seconds. Same-lease warm:
67.1 ms / 0.068 seconds, identical handle/source. Cumulative peak is 588.4 MiB,
an upper bound on isolated warm memory. OS cache is uncontrolled; no cross-session
cache or model-token benefit is inferred from this scripted benchmark.
## From names/messages to conditions
The inventory has two identical VDBE names (`0x288f0`, `0xea6d0`) without aliases.
The initial CLI assumed uniqueness. Its corrected workflow composes strings,
incoming references and owning-function addresses before one VM snapshot; then
constant producers, uses, derived controllers and selected values/definitions.
It obtains both savepoint guards in sixteen host reads without the C report.
The final example also checks pagination before treating selected facts as a
complete set. A retained-source replay derives the two controller relations in
about 8.9 ms wall; isolated replay CPU/peak memory were not measured.
The [question/oracle](savepoint-control-oracle.md) are fixed before model trials,
with function name/messages but no supplied code addresses. Selected independent
machine evidence checks local guards, load/spill/setup and shared call. Recovered
CFG/use coverage still does not establish full machine flow, memory aliases,
nontermination or feasible execution. The first [real-model pair](savepoint-control-study.md)
now passes the frozen question through both adapters; its whole-task costs are
mixed and include discovery noise and a Code Mode parameter retry. Public
scripted checks alone do not establish those model outcomes.
@@ -0,0 +1,38 @@
// Both the session and diagnostic profiler keep descriptor ownership on failed open.
import {
createKunaFileCloseScope,
inspectKunaInstallation,
} from "../../dist/kuna/KunaInstallation.js";
import { kunaFileCleanupError } from "../../dist/kuna/KunaCommand.js";
import { RegularFileCleanupFailure } from "../../dist/filesystem/OwnedRegularFile.js";
import { requireResult } from "./fact-error.mjs";
export const inspectNativeInstallation = async (
environment,
resources,
signal,
) => {
const files = createKunaFileCloseScope({
retain: (owner, resource) =>
resources.retain({
kind: "lease",
resource,
lease: { release: () => owner.close() },
}),
run: (operation) => resources.run(operation),
});
try {
return requireResult(
await inspectKunaInstallation(environment, {
signal,
fileCloseResources: files.owner,
}),
"provider_unavailable",
);
} catch (cause) {
if (!(cause instanceof RegularFileCleanupFailure)) throw cause;
const error = kunaFileCleanupError(cause, "experiment:atomic-open", signal);
files.bindFailure(cause, error);
return requireResult({ ok: false, error });
}
};
@@ -0,0 +1,266 @@
// Native JSON decoding and resource admission; row-wise validation bounds errors.
import { z } from "zod";
import { FactFailure } from "./fact-error.mjs";
import { NATIVE_OUTPUT_BYTES } from "./limits.mjs";
import { MAX_GRAPH_BLOCKS } from "./graph-limits.mjs";
import { readCallFacet } from "./native-call-contract.mjs";
import { readParameterFacet } from "./native-parameters.mjs";
import { readProjectionFacet } from "./native-projection-contract.mjs";
import { readSwitchFacet } from "./native-switch-contract.mjs";
import { operation, parseOperation } from "./native-operation-contract.mjs";
import {
decodeGraphArchive,
MAX_GRAPH_JSON_BYTES,
} from "./native-graph-encoding.mjs";
import {
hex,
ordinal,
valueId,
operationId,
edgeId,
value,
rowParser,
requireFact,
formatFailure,
readNativeFacet,
} from "./native-contract.mjs";
const edge = z.strictObject({
id: edgeId,
target: ordinal,
index: ordinal,
polarity: z.enum(["true", "false"]).nullable(),
condition_value: valueId.nullable(),
condition_test: z.enum(["eq-zero", "ne-zero"]).nullable(),
});
const factsSchema = z.strictObject({
schema_version: z.literal(3),
blocks: z
.array(
z.strictObject({
id: ordinal,
start: hex,
operations: z.array(operationId),
predecessors: z.array(ordinal),
successors: z.array(edge),
}),
)
.min(1)
.max(MAX_GRAPH_BLOCKS),
operations: z.array(operation).max(32000),
values: z.array(value).max(36000),
coverage: z.strictObject({
scope: z.string(),
machine_semantic_equivalence: z.literal("unknown"),
indirect_branch_operations: z.array(operationId),
omitted_definition_ids: z.array(operationId),
issues: z.array(z.string()),
}),
});
const documentSchema = z.object({
binary: z.string(),
count: z.literal(1),
language: z.string(),
error: z.null(),
functions: z
.array(
z.object({
address_hex: hex,
code: z.string(),
error: z.null(),
atomic_facts: z.unknown().optional(),
atomic_facts_error: z.unknown().optional(),
atomic_calls: z.unknown().optional(),
atomic_calls_error: z.unknown().optional(),
atomic_parameters: z.unknown().optional(),
atomic_parameters_error: z.unknown().optional(),
atomic_switches: z.unknown().optional(),
atomic_switches_error: z.unknown().optional(),
atomic_projection: z.unknown().optional(),
atomic_projection_error: z.unknown().optional(),
}),
)
.length(1),
});
// Parse one row at a time: a bad provider must not expand thousands of malformed
// records into a giant Zod issue list before the caller can reject the source.
const nativeBlock = factsSchema.shape.blocks.element;
const parseBlock = rowParser(nativeBlock, {
operations: (id) => operationId.parse(id),
predecessors: (id) => ordinal.parse(id),
successors: (row) => edge.parse(row),
});
const graphCoverage = factsSchema.shape.coverage;
const parseCoverage = rowParser(graphCoverage, {
indirect_branch_operations: (row) => operationId.parse(row),
omitted_definition_ids: (row) => operationId.parse(row),
issues: (row) => z.string().parse(row),
});
const parseFacts = rowParser(
factsSchema,
{
blocks: parseBlock,
operations: parseOperation,
values: (row) => value.parse(row),
},
{ coverage: parseCoverage },
);
function preflight(facts) {
requireFact(
facts && typeof facts === "object",
"Native atomic facts facet is unavailable; inspect the retained source for its reason and C",
);
requireFact(
facts.schema_version === 3,
"Unsupported native atomic facts schema version; expected 3",
);
requireFact(
facts.blocks?.length > 0,
"Native recovered graph is unavailable",
);
for (const [key, limit] of [
["blocks", 12000],
["operations", 32000],
["values", 36000],
])
requireFact(
Array.isArray(facts[key]) && facts[key].length <= limit,
`Native ${key} exceeds resource capacity or has invalid shape`,
);
for (const [rows, limit] of [
[facts.coverage?.indirect_branch_operations, 32000],
[facts.coverage?.omitted_definition_ids, 36000],
[facts.coverage?.issues, 12000],
])
requireFact(
Array.isArray(rows) && rows.length <= limit,
"Native graph coverage exceeds capacity or has invalid shape",
);
const inputs = facts.operations.reduce(
(sum, op) => sum + (Array.isArray(op?.inputs) ? op.inputs.length : 0),
0,
);
const members = facts.blocks.reduce(
(sum, block) =>
sum + (Array.isArray(block?.operations) ? block.operations.length : 0),
0,
);
const edges = facts.blocks.reduce(
(sum, block) =>
sum +
(Array.isArray(block?.successors) ? block.successors.length : 0) +
(Array.isArray(block?.predecessors) ? block.predecessors.length : 0),
0,
);
requireFact(
inputs <= 100000 && members <= 32000 && edges <= 100000,
"Native relationships exceed resource capacity",
);
const displayBytes =
facts.operations.reduce(
(sum, op) =>
sum +
(typeof op?.statement === "string"
? Buffer.byteLength(op.statement)
: 0),
0,
) +
facts.values.reduce(
(sum, value) =>
sum +
(typeof value?.type_name === "string"
? Buffer.byteLength(value.type_name)
: 0),
0,
);
requireFact(
displayBytes <= 4 * 1024 * 1024,
"Native graph display exceeds resource capacity",
);
}
const readGraph = (fn) =>
readNativeFacet(fn, "atomic_facts", "recovered IR", (raw) => {
const decoded = decodeGraphArchive(raw);
const graph = decoded === undefined ? raw : JSON.parse(decoded);
preflight(graph);
return parseFacts(graph);
});
function readSource(text) {
requireFact(
Buffer.byteLength(text) <= NATIVE_OUTPUT_BYTES,
"Native JSON source exceeds transport budget",
);
return JSON.parse(text);
}
function readFunction(raw, entry, expectedInput) {
requireFact(
Array.isArray(raw?.functions) && raw.functions.length === 1,
"Native source must describe exactly one function",
);
const doc = documentSchema.parse(raw),
fn = doc.functions[0];
if (expectedInput !== undefined && doc.binary !== expectedInput)
throw new FactFailure(
"subject_mismatch",
"Native source names a different command input",
{ expected: expectedInput, observed: doc.binary },
);
if (entry !== undefined && fn.address_hex !== entry)
throw new FactFailure(
"subject_mismatch",
"Native function entry differs from requested subject",
);
return { doc, fn };
}
export function parseNativeFunction(text, entry, expectedInput) {
try {
const { doc, fn } = readFunction(readSource(text), entry, expectedInput);
return {
code: fn.code,
language: doc.language,
facts: readGraph(fn),
calls: readCallFacet(fn),
parameters: readParameterFacet(fn),
switches: readSwitchFacet(fn),
projection: readProjectionFacet(fn),
};
} catch (error) {
throw formatFailure(error);
}
}
export function readNativeGraphEvidence(text) {
try {
const raw = readSource(text);
if (raw?.functions === undefined)
throw new FactFailure(
"capability_unavailable",
"This retained source is not a native function record",
);
const { fn } = readFunction(raw);
if (fn.atomic_facts === undefined) {
const graph = readNativeFacet(
fn,
"atomic_facts",
"recovered IR",
(raw) => raw,
);
if (!graph.ok) throw graph.error;
}
const decoded = decodeGraphArchive(fn.atomic_facts);
const view = decoded ?? JSON.stringify(fn.atomic_facts);
requireFact(
Buffer.byteLength(view) <= MAX_GRAPH_JSON_BYTES,
"Native graph Evidence view exceeds decoded capacity",
);
return {
text: view,
encoding: decoded === undefined ? "json" : "gzip-base64",
};
} catch (error) {
throw formatFailure(error);
}
}
+377
View File
@@ -0,0 +1,377 @@
// The native-format boundary owns validation and indexes; consumers never parse
// diagnostic statements to recover value identity, operand indexes or CFG edges.
import { FactFailure } from "./fact-error.mjs";
import {
indexSwitchFacet,
validateSwitchGraph,
validateSwitchValues,
createSwitchViews,
} from "./native-switch-views.mjs";
import { parseNativeFunction } from "./native-ir-contract.mjs";
import { createControlDependenceIndex } from "./control-dependence.mjs";
import { createGraphPathReader } from "./cfg-path.mjs";
import { createParameterViews } from "./native-parameters.mjs";
import { freezeFacts as freeze } from "./fact-reads.mjs";
import {
indexCallFacet,
validateCallGraph,
createCallViews,
} from "./native-call-views.mjs";
import { requireFact } from "./native-contract.mjs";
import {
indexOperationFacts,
createOperationViews,
coverageIssues,
isNativeOperationRelation,
} from "./native-operation-views.mjs";
import {
indexProjection,
createProjectionViews,
} from "./native-projection-views.mjs";
import {
uniqueNative as unique,
nativePage as page,
readNativeIdentities as readIdentities,
} from "./native-reads.mjs";
function validateBlocks(operations, values, blocks) {
const membership = new Set();
for (const block of blocks.values()) {
for (const id of block.operations) {
requireFact(
operations.get(id)?.block === block.id && !membership.has(id),
"Native operation/block ownership mismatch",
);
membership.add(id);
}
for (const [index, edge] of block.successors.entries()) {
requireFact(
edge.index === index &&
edge.id === `${block.id}:${index}` &&
blocks.get(edge.target)?.predecessors.includes(block.id),
"Native CFG successor/predecessor mismatch",
);
requireFact(
edge.condition_value === null || values.has(edge.condition_value),
"Dangling native branch condition",
);
}
for (const from of block.predecessors)
requireFact(
blocks.get(from)?.successors.some((edge) => edge.target === block.id),
"Dangling native predecessor",
);
}
requireFact(
membership.size === operations.size,
"Native operation omitted from block membership",
);
}
function validatePhiBindings(operations, blocks) {
for (const op of operations.values())
for (const [position, input] of op.inputs.entries()) {
if (input.phi_predecessor !== null)
requireFact(
blocks.get(op.block).predecessors[position] === input.phi_predecessor,
"Native phi/predecessor mismatch",
);
if (input.phi_predecessor_edge !== null)
requireFact(
blocks
.get(input.phi_predecessor)
?.successors.some(
(edge) =>
edge.id === input.phi_predecessor_edge &&
edge.target === op.block,
),
"Native phi incoming-edge identity mismatch",
);
}
}
function indexNative(facts) {
const core = indexOperationFacts(
facts.operations,
facts.values,
facts.coverage.omitted_definition_ids,
);
const blocks = unique(
facts.blocks.map(({ start, ...block }) =>
freeze({ ...block, origin_start: start }),
),
);
validateBlocks(core.operations, core.values, blocks);
validatePhiBindings(core.operations, blocks);
const incoming = new Map(),
outgoing = new Map();
for (const block of blocks.values())
for (const edge of block.successors) {
const row = freeze({
...edge,
from: block.id,
to: edge.target,
operation: block.operations.at(-1) ?? null,
kind: edge.polarity ? "conditional" : "recovered",
});
for (const [map, key] of [
[incoming, edge.target],
[outgoing, block.id],
]) {
if (!map.has(key)) map.set(key, []);
map.get(key).push(row);
}
}
return { ...core, blocks, incoming, outgoing };
}
function createViews(facts, code, indexes) {
const { blocks, incoming, outgoing, normalized } = indexes;
const {
issues,
indirect_branch_operations,
omitted_definition_ids,
...metadata
} = facts.coverage;
const coverage = freeze({
...metadata,
...coverageIssues(issues),
indirect_branch_operation_count: indirect_branch_operations.length,
omitted_definition_count: omitted_definition_ids.length,
operations: normalized.size,
values: indexes.values.size,
blocks: blocks.size,
control_flow: "complete-for-recovered-graph",
representation:
"optimized recovered IR; origins do not establish machine branch targets or block extents",
runtime_successors: "unknown",
memory_alias_dependencies: "unknown",
});
const core = createOperationViews(indexes, coverage);
let controls;
return Object.freeze({
...core,
code,
block: (id) => blocks.get(id) ?? null,
incoming: (id) => incoming.get(id) ?? [],
blocks: (input) => readIdentities(blocks, input),
path: createGraphPathReader(blocks, outgoing),
edges: (input) => {
if (isNativeOperationRelation(input.kind))
return core.operationRelations(input);
const seeds = [...new Set(input.seeds)],
unretained_seeds = seeds.filter((id) => !blocks.has(id));
if (input.kind === "controllers") {
controls ??= createControlDependenceIndex(facts.blocks);
return {
...controls.read({ ...input, seeds }),
unretained_seeds,
};
}
return {
...page(
seeds.flatMap(
(seed) =>
(input.kind === "incoming" ? incoming : outgoing).get(seed) ?? [],
),
input,
),
unretained_seeds,
};
},
});
}
const projectedFailure = (error) => ({
code: error.code ?? "invalid_provider_output",
message: error.message,
details: error.details ?? {},
});
const operationFailure = (projectionError, graphError) =>
projectionError?.details?.availability === "not-captured"
? graphError
: (projectionError ?? graphError);
const captureFacets = ({
graph,
projection,
calls,
graphError,
operationError,
callError,
switches,
switchError,
parameters,
parameterError,
}) =>
freeze({
code: { availability: "available" },
parameters: parameters
? { availability: "available", count: parameters.count }
: { availability: "unavailable", error: parameterError },
recovered_ir: graph
? { availability: "available" }
: { availability: "unavailable", error: graphError },
operations: graph
? {
availability: "available",
scope: "complete-for-recovered-graph",
count: graph.coverage.operations,
}
: projection
? {
availability: "available",
scope: "bounded-call-rooted-definitions",
count: projection.coverage.operations,
root_count: projection.coverage.root_count,
definition_frontier_count:
projection.coverage.definition_frontier_count,
}
: {
availability: "unavailable",
error: operationError,
},
calls: calls
? { availability: "available", ...calls.summary }
: { availability: "unavailable", error: callError },
switches: switches
? { availability: "available", ...switches.summary }
: { availability: "unavailable", error: switchError },
values: graph
? {
availability: "available",
scope: "complete-for-recovered-graph",
count: graph.coverage.values,
}
: projection
? {
availability: "available",
scope: "call-rooted-definitions",
count: projection.coverage.values,
}
: calls
? {
availability: "available",
scope: "call-boundary-only",
count: calls.value_count,
}
: { availability: "unavailable", error: callError },
});
const loadFacet = (result, build) => {
if (!result.ok) return { error: projectedFailure(result.error) };
try {
return build(result.value);
} catch (error) {
return { error: projectedFailure(error) };
}
};
const unavailable =
(facet, error = {}) =>
() => {
throw new FactFailure(error.code, error.message, {
...error.details,
facet,
});
};
export function parseNativeIR(text, entry, expectedInput) {
const capture = parseNativeFunction(text, entry, expectedInput);
const parameters = loadFacet(capture.parameters, (facts) => ({
view: createParameterViews(facts),
}));
const graph = loadFacet(capture.facts, (facts) => {
freeze(facts);
const index = indexNative(facts);
return { index, view: createViews(facts, capture.code, index) };
});
const calls = loadFacet(capture.calls, (facts) => {
const index = indexCallFacet(facts);
if (graph.view) validateCallGraph(index, graph.index);
return { index, view: createCallViews(facts, index) };
});
const unavailableGraph = unavailable("recovered_ir", graph.error);
const projection = graph.view
? {}
: loadFacet(capture.projection, (facts) => {
const index = indexProjection(facts);
// Without a full graph, the independent call owner validates the projection.
if (calls.view) validateCallGraph(calls.index, index);
return {
index,
view: createProjectionViews(
facts,
capture.code,
index,
unavailableGraph,
),
};
});
const unavailableCalls = unavailable("calls", calls.error);
const switches = loadFacet(capture.switches, (facts) => {
const index = indexSwitchFacet(facts);
if (graph.view) validateSwitchGraph(index, graph.index);
else {
validateSwitchValues(index, calls.index?.values);
validateSwitchValues(index, projection.index?.values);
}
return { view: createSwitchViews(facts, index) };
});
const unavailableSwitches = unavailable("switches", switches.error);
const operationError = operationFailure(projection.error, graph.error);
const unavailableOperations = unavailable("operations", operationError);
const fallback = {
code: capture.code,
coverage: freeze({
scope: "native reconstructed code; recovered IR facet unavailable",
operations: null,
blocks: null,
control_flow: "unknown",
machine_semantic_equivalence: "unknown",
issues: [graph.error?.message],
}),
...Object.fromEntries(
["operation", "findConstant", "uses", "select", "slice"].map((name) => [
name,
unavailableOperations,
]),
),
...Object.fromEntries(
["block", "incoming", "blocks"].map((name) => [name, unavailableGraph]),
),
edges: (input) =>
isNativeOperationRelation(input.kind)
? unavailableOperations()
: unavailableGraph(),
};
return Object.freeze({
...(graph.view ?? projection.view ?? fallback),
path: graph.view?.path ?? unavailableGraph,
parameters:
parameters.view?.parameters ??
unavailable("parameters", parameters.error),
edges: (input) =>
input.kind === "cases"
? (switches.view?.cases ?? unavailableSwitches)(input)
: (graph.view ?? projection.view ?? fallback).edges(input),
language: capture.language,
calls: calls.view?.calls ?? unavailableCalls,
switches: switches.view?.switches ?? unavailableSwitches,
values:
graph.view?.values ??
projection.view?.values ??
calls.view?.values ??
unavailableCalls,
facets: captureFacets({
graph: graph.view,
projection: projection.view,
calls: calls.view,
graphError: graph.error,
operationError,
callError: calls.error,
switches: switches.view,
switchError: switches.error,
parameters: parameters.view,
parameterError: parameters.error,
}),
});
}
@@ -0,0 +1,493 @@
import test from "node:test";
import assert from "node:assert/strict";
import { gzipSync } from "node:zlib";
import { parseNativeIR } from "./native-ir.mjs";
import { readNativeGraphEvidence } from "./native-ir-contract.mjs";
import { createControlDependenceIndex } from "./control-dependence.mjs";
import { finiteExitControlOracle } from "./control-path-oracle.mjs";
const id = (n) => `0x${n}:0`;
const val = (n, definition = null) => ({
id: `v${n}`,
space: "register",
offset: "0x0",
size_bytes: 8,
is_constant: false,
is_input: definition === null,
is_annotation: false,
definition,
type_name: "uint64",
});
const input = (n, value_id, phi_predecessor = null) => ({
input_index: n,
value_id,
phi_predecessor,
phi_predecessor_edge:
phi_predecessor === null ? null : `${phi_predecessor}:0`,
});
test("native graph owner exposes paths while malformed graphs keep the facet failure", () => {
const source = diamond();
const model = parseNativeIR(JSON.stringify(source), "0x1000");
const found = model.path({ from: 0, target: { kind: "exit" }, avoid: [1] });
assert.equal(found.status, "found");
assert.deepEqual(
found.items.map((row) => row.id),
["0:1", "2:0"],
);
assert.equal(found.items[0].operation, id(0));
source.functions[0].atomic_facts.blocks[0].successors[0].target = 999;
const malformed = parseNativeIR(JSON.stringify(source), "0x1000");
assert.equal(malformed.code, "reconstructed C");
assert.throws(
() => malformed.path({ from: 0, target: { kind: "exit" } }),
(error) => error.details.facet === "recovered_ir",
);
});
const edge = (from, target, index, polarity = null) => ({
id: `${from}:${index}`,
target,
index,
polarity,
condition_value: polarity ? "v0" : null,
condition_test: polarity ? "ne-zero" : null,
});
const op = (block, opcode, inputs, output = null) => ({
id: id(block),
address: `0x${block}`,
block,
opcode,
inputs,
output,
statement: "display is deliberately unparseable",
is_dead: false,
});
function diamond() {
return {
binary: "/private/input",
count: 1,
language: "c",
error: null,
functions: [
{
address_hex: "0x1000",
error: null,
code: "reconstructed C",
atomic_facts: {
schema_version: 3,
blocks: [
{
id: 0,
start: "0x1000",
operations: [id(0)],
predecessors: [],
successors: [edge(0, 1, 0, "false"), edge(0, 2, 1, "true")],
},
{
id: 1,
start: "0x1001",
operations: [id(1)],
predecessors: [0],
successors: [edge(1, 3, 0)],
},
{
id: 2,
start: "0x1002",
operations: [id(2)],
predecessors: [0],
successors: [edge(2, 3, 0)],
},
{
id: 3,
start: "0x1003",
operations: [id(3)],
predecessors: [1, 2],
successors: [],
},
],
operations: [
op(0, "CPUI_CBRANCH", [input(0, "v0")]),
op(1, "CPUI_COPY", [input(0, "v4")], "v1"),
op(2, "CPUI_COPY", [input(0, "v4")], "v2"),
op(
3,
"CPUI_MULTIEQUAL",
[input(0, "v1", 1), input(1, "v2", 2)],
"v3",
),
],
values: [
val(0),
val(1, id(1)),
val(2, id(2)),
val(3, id(3)),
{
...val(4),
is_constant: true,
is_input: false,
space: "const",
offset: "0xffffffffffffffff",
},
],
coverage: {
scope: "native recovered graph",
machine_semantic_equivalence: "unknown",
indirect_branch_operations: [],
omitted_definition_ids: [],
issues: [],
},
},
},
],
};
}
test("compressed and ordinary graphs have identical parsed facts and malformed archives preserve code", () => {
const doc = diamond(),
raw = Buffer.from(JSON.stringify(doc.functions[0].atomic_facts));
const ordinary = parseNativeIR(JSON.stringify(doc), "0x1000");
doc.functions[0].atomic_facts = {
schema_version: 4,
encoding: "gzip-base64",
raw_bytes: raw.length,
data: gzipSync(raw).toString("base64"),
};
const encoded = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.deepEqual(encoded.coverage, ordinary.coverage);
assert.deepEqual(
encoded.select({ fields: ["inputs", "output", "definitions"] }),
ordinary.select({ fields: ["inputs", "output", "definitions"] }),
);
assert.deepEqual(encoded.blocks({}), ordinary.blocks({}));
assert.deepEqual(readNativeGraphEvidence(JSON.stringify(doc)), {
text: raw.toString(),
encoding: "gzip-base64",
});
for (const change of [
{ raw_bytes: 2 },
{ data: "broken" },
{ raw_bytes: 32 * 1024 * 1024 + 1 },
]) {
const bad = structuredClone(doc);
Object.assign(bad.functions[0].atomic_facts, change);
const model = parseNativeIR(JSON.stringify(bad), "0x1000");
assert.equal(model.code, "reconstructed C");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.throws(() => model.select({}));
}
for (const text of [
"{malformed logical JSON",
JSON.stringify({ schema_version: 4, data: "nested" }),
]) {
const bad = structuredClone(doc),
bytes = Buffer.from(text);
bad.functions[0].atomic_facts = {
schema_version: 4,
encoding: "gzip-base64",
raw_bytes: bytes.length,
data: gzipSync(bytes).toString("base64"),
};
const source = JSON.stringify(bad);
assert.equal(
parseNativeIR(source, "0x1000").facets.recovered_ir.availability,
"unavailable",
);
assert.equal(
readNativeGraphEvidence(source).text,
text,
"Malformed logical facts remain inspectable through owned decoded source",
);
}
assert.throws(
() => readNativeGraphEvidence('{"hex":"0102"}'),
(error) => error.code === "capability_unavailable",
);
});
test("native identity, implicit CFG and operand/phi bindings do not depend on display text", () => {
const model = parseNativeIR(JSON.stringify(diamond()), "0x1000");
assert.equal(model.operation("0x3:0").origin_address, "0x3");
assert.equal(Object.hasOwn(model.operation("0x3:0"), "address"), false);
assert.equal(model.block(1).origin_start, "0x1001");
const operand = model.edges({
kind: "operands",
seeds: ["0x3:0"],
input_indices: [1],
}).items[0];
assert.deepEqual(operand, {
operation: "0x3:0",
input_index: 1,
value_id: "v2",
definition: "0x2:0",
phi_predecessor: 2,
phi_predecessor_edge: "2:0",
});
assert.equal(Object.hasOwn(model.block(1), "start"), false);
assert.equal(model.select({ origin_addresses: ["0x3"] }).total, 1);
assert.deepEqual(model.findConstant("0xffffffffffffffff"), [
"0x1:0",
"0x2:0",
]);
assert.equal(model.edges({ kind: "outgoing", seeds: [1] }).items[0].to, 3);
assert.deepEqual(
model
.operation("0x3:0")
.definitions.map(({ input_index, phi_predecessor }) => [
input_index,
phi_predecessor,
]),
[
[0, 1],
[1, 2],
],
);
assert.equal(
model.values({ ids: ["v4"] }).items[0].offset,
"0xffffffffffffffff",
);
const batch = model.values({ ids: ["v4", "vdead"] });
assert.equal(batch.items.length, 1);
assert.deepEqual(batch.missing, ["vdead"]);
assert.throws(() => {
model.operation("0x3:0").inputs[0].value_id = "foreign";
});
assert.deepEqual(
model
.edges({ kind: "controllers", seeds: [1] })
.items.map((row) => [row.controller, row.edge.polarity]),
[[0, "false"]],
);
assert.equal(model.edges({ kind: "controllers", seeds: [3] }).total, 0);
});
test("malformed identities, dangling relationships, foreign entry and phi reorder fail at the producer boundary", () => {
for (const mutate of [
(facts) => {
facts.values.push(facts.values[0]);
},
(facts) => {
facts.operations[0].inputs[0].value_id = "vdead";
},
(facts) => {
facts.blocks[1].predecessors = [];
},
(facts) => {
facts.operations[3].inputs[0].phi_predecessor = 2;
},
(facts) => {
facts.values[1].definition = "0xf:0";
},
]) {
const doc = diamond();
mutate(doc.functions[0].atomic_facts);
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.equal(model.code, "reconstructed C");
assert.throws(() => model.select({}));
}
assert.throws(
() => parseNativeIR(JSON.stringify(diamond()), "0x2000"),
/subject/u,
);
});
test("CFG relations distinguish unknown seeds from retained blocks with no rows", () => {
const model = parseNativeIR(JSON.stringify(diamond()), "0x1000");
for (const kind of ["incoming", "outgoing", "controllers"]) {
const known = model.edges({ kind, seeds: [1], limit: 128 });
const mixed = model.edges({
kind,
seeds: [1, 999999, 1, 999999],
limit: 128,
});
assert.deepEqual(mixed.items, known.items);
assert.equal(mixed.total, known.total);
assert.deepEqual(mixed.unretained_seeds, [999999]);
const unknown = model.edges({ kind, seeds: [999999] });
assert.equal(unknown.total, 0);
assert.deepEqual(unknown.unretained_seeds, [999999]);
}
const first = model.edges({ kind: "controllers", seeds: [1] });
assert.deepEqual(first.unretained_seeds, []);
assert.throws(
() => first.relation_coverage.exit_unreachable_blocks.push(0),
TypeError,
);
assert.throws(() => {
first.items[0].edge.target = 999999;
}, TypeError);
first.items[0].controller = 999999;
assert.equal(
model.edges({ kind: "controllers", seeds: [1] }).items[0].controller,
0,
);
const none = model.edges({ kind: "controllers", seeds: [3] });
assert.equal(none.total, 0);
assert.deepEqual(none.unretained_seeds, []);
});
test("all three-node directed graphs agree with independent finite-exit path queries", () => {
const key = (row) =>
`${row.controller}|${row.dependent}|${row.edge_id ?? row.edge.id}`;
for (let mask = 0; mask < 512; mask++) {
const blocks = Array.from({ length: 3 }, (_, id) => ({
id,
successors: Array.from({ length: 3 }, (_, target) => target)
.filter((target) => mask & (1 << (id * 3 + target)))
.map((target, index) => ({ id: `${id}:${index}`, target })),
}));
const expected = finiteExitControlOracle(blocks),
index = createControlDependenceIndex(blocks);
const actual = [...index.relations()];
assert.deepEqual(
actual.map(key).sort(),
expected.relations.map(key).sort(),
`graph ${mask}`,
);
assert.deepEqual(
index.coverage.exit_unreachable_blocks,
expected.exit_unreachable_blocks,
);
const pages = [],
total = actual.length;
let offset = 0;
do {
const page = index.read({ seeds: [0, 1, 2], offset, limit: 1 });
assert.equal(page.total, total);
pages.push(...page.items);
offset = page.next_offset;
} while (offset !== null);
assert.deepEqual(pages, actual);
}
});
test("typed slices retain symbolic input frontiers and precise definition bindings", () => {
const model = parseNativeIR(JSON.stringify(diamond()), "0x1000");
const result = model.slice({
seeds: ["0x3:0", "0x0:0"],
max_operations: 10,
stop_at: [],
stop_kinds: [],
});
assert.equal(result.operations.length, 4);
assert.deepEqual(result.value_frontier, [
{ value_id: "v0", reason: "function-input" },
]);
assert.equal(result.coverage.runtime_reachability, "unknown");
});
test("native facet failure preserves C without fabricating an empty graph; source identity still gates both", () => {
const doc = diamond();
delete doc.functions[0].atomic_facts;
doc.functions[0].atomic_facts_error = "atomic operation capacity exceeded";
const model = parseNativeIR(JSON.stringify(doc), "0x1000", "/private/input");
assert.equal(model.code, "reconstructed C");
assert.equal(model.language, "c");
assert.equal(model.coverage.operations, null);
assert.equal(model.facets.code.availability, "available");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.throws(
() => model.select({}),
(error) =>
error.code === "capability_unavailable" &&
error.details.native_error === doc.functions[0].atomic_facts_error,
);
assert.throws(
() => parseNativeIR(JSON.stringify(doc), "0x1000", "/other/input"),
(error) => error.code === "subject_mismatch",
);
});
test("oversized or malformed native arrays fail before diagnostic expansion", () => {
const capacity = diamond();
capacity.functions[0].atomic_facts.operations = Array.from(
{ length: 32001 },
() => ({}),
);
assert.throws(
() => parseNativeIR(JSON.stringify(capacity), "0x1000").select({}),
/capacity/u,
);
const malformed = diamond();
malformed.functions[0].atomic_facts.operations = Array.from(
{ length: 12000 },
() => ({}),
);
assert.throws(
() => parseNativeIR(JSON.stringify(malformed), "0x1000").select({}),
(error) =>
error.code === "invalid_provider_output" &&
error.details.issues.length <= 8 &&
JSON.stringify(error.details).length < 2048,
);
});
test("control dependence handles multiple exits, loops, unreachable exits and bounded work", () => {
const blocks = [
{ id: 0, successors: [{ target: 1 }, { target: 2 }] },
{ id: 1, successors: [] },
{ id: 2, successors: [] },
{ id: 3, successors: [{ target: 3 }] },
];
const result = createControlDependenceIndex(blocks);
assert.deepEqual(
[...result.relations()].map((r) => [r.controller, r.dependent]),
[
[0, 1],
[0, 2],
],
);
assert.deepEqual(result.coverage.exit_unreachable_blocks, [3]);
assert.throws(
() => createControlDependenceIndex(blocks, { workLimit: 1 }),
/budget/u,
);
const linear = Array.from({ length: 12000 }, (_, id) => ({
id,
successors: id < 11999 ? [{ target: id + 1 }] : [],
}));
assert.equal([...createControlDependenceIndex(linear).relations()].length, 0);
});
test("postdominator control dependence agrees with independently enumerated paths for every four-node DAG", () => {
const possible = [
[0, 1],
[0, 2],
[0, 3],
[1, 2],
[1, 3],
[2, 3],
];
for (let mask = 0; mask < 64; mask++) {
const blocks = Array.from({ length: 4 }, (_, id) => ({
id,
successors: possible
.filter(([from], i) => from === id && mask & (1 << i))
.map(([, target]) => ({ target })),
}));
const paths = (node) =>
blocks[node].successors.length
? blocks[node].successors.flatMap(({ target }) =>
paths(target).map((path) => [node, ...path]),
)
: [[node]];
const postdominators = blocks.map(({ id }) =>
paths(id).reduce(
(shared, path) =>
new Set([...shared].filter((node) => path.includes(node))),
new Set([0, 1, 2, 3]),
),
);
const expected = blocks.flatMap((block) =>
block.successors.flatMap((edge) =>
[...postdominators[edge.target]]
.filter((dependent) => !postdominators[block.id].has(dependent))
.map((dependent) => `${block.id}:${edge.target}:${dependent}`),
),
);
const actual = [...createControlDependenceIndex(blocks).relations()].map(
(row) => `${row.controller}:${row.edge.target}:${row.dependent}`,
);
assert.deepEqual(actual.sort(), expected.sort(), `DAG mask ${mask}`);
}
});
@@ -0,0 +1,31 @@
// One native operand/operation schema shared by complete and projected facts.
import { z } from "zod";
import {
hex,
ordinal,
valueId,
operationId,
edgeId,
rowParser,
} from "./native-contract.mjs";
export const operation = z.strictObject({
id: operationId,
address: hex,
block: ordinal,
opcode: z.string(),
statement: z.string(),
is_dead: z.boolean(),
inputs: z.array(
z.strictObject({
input_index: ordinal,
value_id: valueId.nullable(),
phi_predecessor: ordinal.nullable(),
phi_predecessor_edge: edgeId.nullable(),
}),
),
output: valueId.nullable(),
});
export const parseOperation = rowParser(operation, {
inputs: (row) => operation.shape.inputs.element.parse(row),
});
@@ -0,0 +1,322 @@
// Shared immutable SSA operands and queries; no CFG completeness is inferred.
import { backwardSlice } from "../atomic-re-tools/kuna-ssa.mjs";
import { freezeFacts as freeze } from "./fact-reads.mjs";
import { requireFact } from "./native-contract.mjs";
import {
uniqueNative as unique,
nativePage as page,
createNativeValueReader,
} from "./native-reads.mjs";
export const DEFAULT_NATIVE_OPERATION_FIELDS = Object.freeze([
"kind",
"opcode",
"output",
"input_count",
"definition_count",
"constant_count",
]);
export const isNativeOperationRelation = (kind) =>
["definitions", "uses", "operands", "value_uses"].includes(kind);
export const coverageIssues = (issues) => ({
issues: issues.slice(0, 8).map((message) => message.slice(0, 160)),
issue_count: issues.length,
issues_omitted: Math.max(0, issues.length - 8),
issue_messages_truncated: issues.slice(0, 8).some((s) => s.length > 160),
});
const index = (map, key, row) => {
if (!map.has(key)) map.set(key, []);
map.get(key).push(row);
};
const kind = (opcode) =>
({
CPUI_LOAD: "load",
CPUI_STORE: "store",
CPUI_MULTIEQUAL: "phi",
CPUI_CALL: "call",
CPUI_CALLIND: "call",
CPUI_BRANCH: "branch",
CPUI_CBRANCH: "branch",
CPUI_BRANCHIND: "switch",
CPUI_RETURN: "return",
})[opcode] ?? "value";
function validateOperands(operations, values) {
const referenced = new Set();
for (const op of operations.values()) {
requireFact(
op.id.split(":")[0] === op.address,
"Native operation origin/identity mismatch",
);
for (const [position, input] of op.inputs.entries()) {
requireFact(
input.input_index === position &&
(input.value_id === null || values.has(input.value_id)),
"Dangling or misindexed native operand",
);
requireFact(
(input.phi_predecessor === null) ===
(input.phi_predecessor_edge === null) &&
(input.phi_predecessor === null ||
(op.opcode === "CPUI_MULTIEQUAL" &&
input.phi_predecessor_edge.startsWith(
`${input.phi_predecessor}:`,
))),
"Native phi binding is inconsistent",
);
if (input.value_id !== null) referenced.add(input.value_id);
}
requireFact(
op.output === null || values.get(op.output)?.definition === op.id,
"Native output/definition mismatch",
);
if (op.output !== null) referenced.add(op.output);
}
requireFact(
referenced.size === values.size,
"Native operation set contains unrelated values",
);
}
function validateDefinitions(operations, values, omittedIDs) {
const omitted = new Set(omittedIDs),
missing = new Set();
requireFact(
omitted.size === omittedIDs.length,
"Duplicate native definition frontier",
);
for (const value of values.values())
if (value.definition !== null) {
if (!operations.has(value.definition)) missing.add(value.definition);
requireFact(
operations.get(value.definition)?.output === value.id ||
(!operations.has(value.definition) && omitted.has(value.definition)),
"Native value/definition mismatch",
);
}
requireFact(
missing.size === omitted.size,
"Native definition frontier contains unrelated identities",
);
}
export function indexOperationFacts(rows, valueRows, omittedIDs) {
const operations = unique(rows),
values = unique(valueRows);
validateOperands(operations, values);
validateDefinitions(operations, values, omittedIDs);
const users = new Map(),
constants = new Map();
const normalized = new Map();
for (const op of operations.values()) {
const definitions = [],
literals = [];
for (const input of op.inputs) {
const value = values.get(input.value_id);
if (value?.definition) {
const relation = freeze({
definition: value.definition,
use: op.id,
input_index: input.input_index,
value_id: value.id,
phi_predecessor: input.phi_predecessor,
phi_predecessor_edge: input.phi_predecessor_edge,
});
definitions.push(relation);
index(users, value.definition, relation);
}
if (value?.is_constant) {
literals.push({
value_id: value.id,
input_index: input.input_index,
value: value.offset,
printed_size_bytes: value.size_bytes,
is_annotation: value.is_annotation,
});
index(constants, value.offset, op.id);
}
}
const { address: origin_address, ...payload } = op;
normalized.set(
op.id,
freeze({
...payload,
origin_address,
kind: kind(op.opcode),
source_line: null,
definitions,
constants: literals,
input_count: op.inputs.length,
definition_count: definitions.length,
constant_count: literals.length,
}),
);
}
return { operations, values, users, constants, normalized };
}
export function createOperationViews(
indexes,
coverage,
frontierReasons = new Map(),
) {
const { values, users, constants, normalized } = indexes;
let valueUses;
const model = {
coverage,
operation: (id) => normalized.get(id) ?? null,
findConstant: (value) => [...new Set(constants.get(value) ?? [])],
uses: (id) => users.get(id) ?? [],
select: (input = {}) =>
selectOperations(normalized, constants, {
...input,
fields: input.fields ?? DEFAULT_NATIVE_OPERATION_FIELDS,
}),
values: createNativeValueReader(values, coverage),
operationRelations: (input) => {
if (input.kind === "value_uses" && !valueUses) {
valueUses = new Map();
for (const op of normalized.values())
for (const row of op.inputs)
if (row.value_id !== null)
index(
valueUses,
row.value_id,
freeze(operandRow(op.id, row, values)),
);
}
return readOperationRelations(indexes, coverage, input, valueUses);
},
slice: (input) => sliceValues(model, values, input, frontierReasons),
};
return Object.freeze(model);
}
const operandRow = (operation, row, values) => ({
operation,
...row,
definition: values.get(row.value_id)?.definition ?? null,
});
function readOperationRelations(indexes, coverage, input, valueUses) {
const { normalized, values, users } = indexes;
const seeds = [...new Set(input.seeds)];
const operands = input.kind === "operands";
const byValue = input.kind === "value_uses";
const indices = input.input_indices && [...new Set(input.input_indices)];
const groups = seeds.map((seed) => {
const op = normalized.get(seed);
const rows = operands
? indices
? indices.flatMap((index) => op?.inputs[index] ?? [])
: (op?.inputs ?? [])
: byValue
? (valueUses.get(seed) ?? [])
: input.kind === "definitions"
? (op?.definitions ?? [])
: (users.get(seed) ?? []);
return { seed, rows };
});
const offset = input.offset ?? 0,
limit = input.limit ?? 20;
let total = 0;
const items = [];
// Count groups without flattening every relation or copying unselected rows.
for (const { seed, rows } of groups) {
const start = Math.max(0, offset - total);
const end = Math.min(rows.length, offset + limit - total);
for (let i = start; i < end; i++) {
const row = rows[i];
items.push(operands ? operandRow(seed, row, values) : row);
}
total += rows.length;
}
return {
items,
total,
next_offset: offset + limit < total ? offset + limit : null,
unretained_seeds: seeds.filter(
(id) => !(byValue ? values : normalized).has(id),
),
relation_coverage: {
scope: operands
? "all selected native input slots of retained operations; null values remain explicit"
: input.kind === "uses" || byValue
? (coverage.uses_scope ??
"complete-for-retained-recovered-operations")
: "definitions of retained operands; missing defining bodies remain unknown",
...(operands
? {
slot_presence:
"out-of-range slots of retained seeds are absent; unretained seeds remain unknown",
order:
"distinct caller seed order, then distinct requested input-index order or native slot order",
}
: {}),
},
};
}
function selectOperations(normalized, constants, input = {}) {
const ids = input.ids && new Set(input.ids),
addresses = input.origin_addresses && new Set(input.origin_addresses),
blockIds = input.block_ids && new Set(input.block_ids);
const candidates = ids
? [...ids].flatMap((id) => normalized.get(id) ?? [])
: input.constant
? [...new Set(constants.get(input.constant) ?? [])].map((id) =>
normalized.get(id),
)
: normalized.values();
return page(
[...candidates].filter(
(op) =>
(!addresses || addresses.has(op.origin_address)) &&
(!blockIds || blockIds.has(op.block)) &&
(!input.constant ||
op.constants.some((literal) => literal.value === input.constant)) &&
(!input.kind || op.kind === input.kind),
),
input,
["id", "origin_address", "block", "is_dead"],
);
}
function sliceValues(model, values, input, frontierReasons) {
const result = backwardSlice(model, input.seeds, {
maxOperations: input.max_operations,
stopAt: input.stop_at,
stopKinds: input.stop_kinds,
});
const frontier = new Map();
for (const op of result.operations)
for (const input of op.inputs) {
const value = values.get(input.value_id);
if (!value)
frontier.set(`${op.id}:${input.input_index}`, {
operation: op.id,
input_index: input.input_index,
reason: "native-null-input",
});
else if (!value.definition && !value.is_constant && !value.is_annotation)
frontier.set(value.id, {
value_id: value.id,
reason: value.is_input ? "function-input" : "definition-unavailable",
});
}
return {
...result,
value_frontier: [...frontier.values()],
coverage: {
...result.coverage,
status:
result.coverage.status === "complete-for-printed-definitions"
? "complete-for-retained-value-definitions"
: result.coverage.status,
source_scope: model.coverage.scope,
missing_reasons: result.coverage.missing.map((definition) => ({
definition,
reason: frontierReasons.get(definition) ?? "not-retained",
})),
relation_authority: "native SSA value identities and operand indexes",
},
};
}
@@ -0,0 +1,112 @@
// One format owner for recovered formal prototype entries, not raw input flags.
import { z } from "zod";
import { nativeStorage } from "./native-storage.mjs";
import { rowParser, readNativeFacet, requireFact } from "./native-contract.mjs";
import { freezeFacts, projectFact } from "./fact-reads.mjs";
import { nativePage } from "./native-reads.mjs";
const parameter = z.strictObject({
id: z.string(),
native_index: z.number().int().nonnegative().nullable(),
name: z.string(),
type_name: z.string().nullable(),
size_bytes: z.number().int().min(-0x80000000).max(0x7fffffff),
is_void: z.boolean().nullable(),
storage: nativeStorage.nullable(),
type_locked: z.boolean(),
name_locked: z.boolean(),
size_locked: z.boolean(),
this_pointer: z.boolean(),
indirect_storage: z.boolean(),
hidden_return: z.boolean(),
});
const schema = z.strictObject({
schema_version: z.literal(1),
model: z.string().nullable(),
model_unknown: z.boolean().nullable(),
inputs_locked: z.boolean(),
output_locked: z.boolean(),
variadic: z.boolean(),
input_errors: z.boolean(),
output_errors: z.boolean(),
items: z.array(parameter).max(12000),
output: parameter,
});
const parse = rowParser(schema, { items: (row) => parameter.parse(row) });
const validate = (row, index) => {
requireFact(
row.native_index === index &&
row.id === (index === null ? "return" : `parameter:${index}`),
"Native parameter identity/index mismatch",
);
requireFact(
row.storage === null || row.storage.size_bytes === row.size_bytes,
"Native parameter storage/width mismatch",
);
requireFact(
(row.type_name === null) === (row.is_void === null),
"Native parameter type/void knowledge mismatch",
);
requireFact(
row.is_void !== true || (row.size_bytes === 0 && row.storage === null),
"Native void parameter has invented storage",
);
};
export const readParameterFacet = (fn) =>
readNativeFacet(fn, "atomic_parameters", "function parameters", (raw) => {
const facts = parse(raw);
facts.items.forEach(validate);
validate(facts.output, null);
requireFact(
(facts.model === null) === (facts.model_unknown === null),
"Native prototype model knowledge mismatch",
);
return facts;
});
const defaultFields = [
"storage",
"size_bytes",
"is_void",
"type_locked",
"indirect_storage",
"hidden_return",
"this_pointer",
];
const identity = ["id", "native_index"];
export function createParameterViews(facts) {
freezeFacts(facts);
const { schema_version: _version, items, output, ...prototype } = facts;
freezeFacts(prototype);
const coverage = freezeFacts({
scope: "all entries in the captured native recovered function prototype",
source_signature: "unknown",
source_parameter_ordinals: "unknown",
raw_input_values:
"is_input is not formal-parameter membership; globals/stack may also be input varnodes",
ssa_binding:
"not collected here; exact selected storage/width lookup is separate and does not prove aliases",
runtime_binding: "unknown",
machine_semantic_equivalence: "unknown",
input_recovery_errors: prototype.input_errors,
output_recovery_errors: prototype.output_errors,
});
return {
count: items.length,
parameters: (input) => {
const indices =
input.indices === undefined ? null : [...new Set(input.indices)];
const rows = indices
? indices.flatMap((index) => items[index] ?? [])
: items;
const fields = input.fields ?? defaultFields;
return {
...nativePage(rows, { ...input, fields }, identity),
missing_indices:
indices?.filter((index) => index >= items.length) ?? [],
output: projectFact(output, fields, identity),
prototype,
coverage,
};
},
};
}
@@ -0,0 +1,171 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
readParameterFacet,
createParameterViews,
} from "./native-parameters.mjs";
import { parseNativeIR } from "./native-ir.mjs";
import { methods, reference } from "./api.mjs";
import Ajv2020 from "ajv/dist/2020.js";
const parameter = (
index,
storage = { space: "register", offset: "0x38", size_bytes: 8 },
) => ({
id: index === null ? "return" : `parameter:${index}`,
native_index: index,
name: "display",
type_name: "unknown8",
size_bytes: 8,
is_void: false,
storage,
type_locked: false,
name_locked: false,
size_locked: false,
this_pointer: false,
indirect_storage: false,
hidden_return: false,
});
const fixture = () => ({
schema_version: 1,
model: "__stdcall",
model_unknown: false,
inputs_locked: false,
output_locked: false,
variadic: false,
input_errors: false,
output_errors: true,
items: [
parameter(0),
parameter(1, { space: "stack", offset: "0x8", size_bytes: 8 }),
],
output: parameter(null, { space: "register", offset: "0x0", size_bytes: 8 }),
});
const read = (raw) => readParameterFacet({ atomic_parameters: raw });
const model = (fn) =>
parseNativeIR(
JSON.stringify({
binary: "/input",
count: 1,
language: "c",
error: null,
functions: [
{ address_hex: "0x1000", error: null, code: "readable", ...fn },
],
}),
"0x1000",
);
test("formal selection preserves native indices, caller order, unknowns and independently selected output", () => {
const parsed = read(fixture());
assert.equal(parsed.ok, true);
const view = createParameterViews(parsed.value);
const first = view.parameters({
indices: [1, 0, 1, 8],
fields: ["storage", "size_bytes"],
limit: 1,
});
assert.deepEqual(
first.items.map((r) => r.id),
["parameter:1"],
);
assert.equal(first.total, 2);
assert.equal(first.next_offset, 1);
assert.deepEqual(first.missing_indices, [8]);
assert.equal(first.output.id, "return");
assert.equal(first.prototype.output_errors, true);
assert.equal(first.coverage.source_signature, "unknown");
const next = view.parameters({ indices: [1, 0], fields: [], offset: 1 });
assert.deepEqual(next.items, [{ id: "parameter:0", native_index: 0 }]);
assert.deepEqual(next.output, { id: "return", native_index: null });
assert.deepEqual(view.parameters({ indices: [] }).items, []);
assert.equal(Object.hasOwn(view.parameters({}).items[0], "type_name"), false);
});
test("cached metadata/storage cannot be changed by SDK callers", () => {
const view = createParameterViews(read(fixture()).value);
const result = view.parameters({});
assert.throws(() => {
result.prototype.model = "changed";
}, TypeError);
assert.throws(() => {
result.items[0].storage.offset = "0x0";
}, TypeError);
result.items.length = 0;
assert.equal(view.parameters({}).total, 2);
assert.equal(view.parameters({}).prototype.model, "__stdcall");
});
test("unknown type/storage is distinct from native void, malformed identities cannot publish partial formals", () => {
const unknown = fixture();
Object.assign(unknown.output, {
type_name: null,
is_void: null,
storage: null,
});
assert.equal(read(unknown).ok, true);
const empty = fixture();
empty.items = [];
Object.assign(empty.output, {
type_name: "void",
is_void: true,
size_bytes: 0,
storage: null,
});
assert.equal(read(empty).ok, true);
for (const change of [
(x) => (x.items[0].id = "parameter:9"),
(x) => (x.items[1].native_index = 0),
(x) => (x.output.native_index = 0),
(x) => (x.items[0].size_bytes = 4),
(x) => (x.output.is_void = true),
(x) => (x.output.type_name = null),
(x) => (x.model_unknown = null),
]) {
const x = fixture();
change(x);
assert.equal(read(x).ok, false);
}
});
test("prototype facet works without graph/calls; unavailable/invalid prototype retains code and reason", () => {
const available = model({
atomic_parameters: fixture(),
atomic_facts_error: { malformed: "not a failure string" },
atomic_calls_error: "capacity",
});
assert.equal(available.facets.parameters.availability, "available");
assert.equal(available.parameters({}).total, 2);
assert.equal(available.facets.recovered_ir.availability, "unavailable");
assert.equal(available.code, "readable");
for (const fn of [
{},
{
atomic_parameters_error: "native function prototype store is unavailable",
},
{ atomic_parameters: { schema_version: 99 } },
]) {
const unavailable = model(fn);
assert.equal(unavailable.code, "readable");
assert.equal(unavailable.facets.parameters.availability, "unavailable");
assert.throws(
() => unavailable.parameters({}),
(e) => e.details.facet === "parameters",
);
}
});
test("parameter input schema matches advertised JSON Schema and rejects guessed keys/indices", () => {
const validate = new Ajv2020({ strict: false }).compile(
reference("parameters").methods[0].input_schema,
);
for (const [request, valid] of [
[{}, true],
[{ indices: [], fields: [] }, true],
[{ indices: [1, 0, 1], fields: ["storage", "type_name"] }, true],
[{ indices: [-1] }, false],
[{ indices: ["0"] }, false],
[{ fields: ["value_id"] }, false],
[{ signature: true }, false],
]) {
const input = { snapshot: "snap_test", ...request };
assert.equal(methods.parameters.input.safeParse(input).success, valid);
assert.equal(validate(input), valid);
}
});
@@ -0,0 +1,68 @@
// Sparse facts retain their own resource, root and frontier contract.
import { z } from "zod";
import {
operationId,
value,
rowParser,
requireFact,
readNativeFacet,
} from "./native-contract.mjs";
import { operation, parseOperation } from "./native-operation-contract.mjs";
const frontier = z.strictObject({
definition: operationId,
reason: z.enum(["operation-budget", "outside-recovered-membership"]),
});
const coverage = z.strictObject({
scope: z.string(),
operation_budget: z.literal(4096),
frontier: z.array(frontier).max(12288),
issues: z.array(z.string()).max(4096),
machine_semantic_equivalence: z.literal("unknown"),
});
const schema = z.strictObject({
schema_version: z.literal(1),
roots: z.array(operationId).max(4096),
operations: z.array(operation).max(4096),
values: z.array(value).max(12288),
coverage,
});
const parseCoverage = rowParser(coverage, {
frontier: (row) => frontier.parse(row),
issues: (row) => z.string().parse(row),
});
const parseProjection = rowParser(
schema,
{
roots: (row) => operationId.parse(row),
operations: parseOperation,
values: (row) => value.parse(row),
},
{ coverage: parseCoverage },
);
export const readProjectionFacet = (fn) =>
readNativeFacet(fn, "atomic_projection", "operation projection", (raw) => {
requireFact(
raw?.schema_version === 1,
"Unsupported native projection schema",
);
for (const [rows, limit] of [
[raw.roots, 4096],
[raw.operations, 4096],
[raw.values, 12288],
[raw.coverage?.frontier, 12288],
[raw.coverage?.issues, 4096],
])
requireFact(
Array.isArray(rows) && rows.length <= limit,
"Native projection exceeds capacity or has invalid shape",
);
requireFact(
raw.operations.reduce(
(n, op) => n + (Array.isArray(op?.inputs) ? op.inputs.length : 0),
0,
) <= 16384,
"Native projection input capacity exceeded",
);
return parseProjection(raw);
});
@@ -0,0 +1,86 @@
import { requireFact } from "./native-contract.mjs";
import { freezeFacts as freeze } from "./fact-reads.mjs";
import {
indexOperationFacts,
createOperationViews,
coverageIssues,
isNativeOperationRelation,
} from "./native-operation-views.mjs";
export function indexProjection(facts) {
const reasons = new Map();
for (const row of facts.coverage.frontier) {
requireFact(!reasons.has(row.definition), "Duplicate projection frontier");
reasons.set(row.definition, row.reason);
requireFact(
row.reason !== "operation-budget" ||
facts.operations.length === facts.coverage.operation_budget,
"Projection claims an unexhausted operation budget",
);
}
const index = indexOperationFacts(facts.operations, facts.values, [
...reasons.keys(),
]);
const roots = new Set(facts.roots);
requireFact(roots.size === facts.roots.length, "Duplicate projection root");
const callIDs = [...index.operations.values()]
.filter((op) => ["CPUI_CALL", "CPUI_CALLIND"].includes(op.opcode))
.map((op) => op.id);
requireFact(
roots.size === callIDs.length && callIDs.every((id) => roots.has(id)),
"Projection roots differ from retained call operations",
);
const reached = new Set(roots),
queue = [...roots];
for (const id of queue)
for (const edge of index.normalized.get(id).definitions)
if (
index.operations.has(edge.definition) &&
!reached.has(edge.definition)
) {
reached.add(edge.definition);
queue.push(edge.definition);
}
requireFact(
reached.size === index.operations.size,
"Projection contains operations unrelated to its roots",
);
return { ...index, reasons };
}
export function createProjectionViews(facts, code, indexes, unavailableGraph) {
freeze(facts);
const coverage = freeze({
scope: facts.coverage.scope,
operations: indexes.operations.size,
values: indexes.values.size,
blocks: null,
root_count: facts.roots.length,
operation_budget: facts.coverage.operation_budget,
definition_frontier_count: facts.coverage.frontier.length,
...coverageIssues(facts.coverage.issues),
control_flow: "not-collected",
definition_scope:
"retained operand definitions; unexpanded IDs stay unknown",
uses_scope: "selected-operations-only; no complete-use claim",
value_scope:
"operands and outputs of the retained call-rooted operation set",
machine_semantic_equivalence: "unknown",
memory_alias_dependencies: "unknown",
runtime_successors: "unknown",
representation:
"optimized recovered IR; origins and block IDs do not prove machine extents or branch targets",
});
const core = createOperationViews(indexes, coverage, indexes.reasons);
return Object.freeze({
...core,
code,
block: unavailableGraph,
incoming: unavailableGraph,
blocks: unavailableGraph,
edges: (input) =>
isNativeOperationRelation(input.kind)
? core.operationRelations(input)
: unavailableGraph(),
});
}
@@ -0,0 +1,342 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseNativeIR } from "./native-ir.mjs";
const value = (id, definition, extra = {}) => ({
id,
definition,
space: "register",
offset: "0x30",
size_bytes: 8,
is_constant: false,
is_input: false,
is_annotation: false,
type_name: "",
...extra,
});
const input = (input_index, value_id, predecessor = null, edge = null) => ({
input_index,
value_id,
phi_predecessor: predecessor,
phi_predecessor_edge: edge,
});
const op = (id, opcode, inputs, output = null) => ({
id,
address: id.split(":")[0],
block: 9,
opcode,
inputs,
output,
statement: "unparseable display",
is_dead: false,
});
function fixture() {
const operations = [
op("0x1100:1", "CPUI_CALL", [
input(0, "v0"),
input(1, "v3"),
input(2, "v7"),
input(3, "v9"),
]),
op(
"0x1080:2",
"CPUI_MULTIEQUAL",
[input(0, "v1", 7, "7:1"), input(1, "v2", 8, "8:0")],
"v3",
),
op("0x1050:3", "CPUI_PTRSUB", [input(0, "v4"), input(1, "v5")], "v1"),
op("0x1060:4", "CPUI_PTRSUB", [input(0, "v4"), input(1, "v6")], "v2"),
];
const values = [
value("v0", null, {
space: "fspec",
offset: "0x10000",
is_annotation: true,
}),
value("v1", "0x1050:3"),
value("v2", "0x1060:4"),
value("v3", "0x1080:2"),
value("v4", null, { space: "const", offset: "0x0", is_constant: true }),
value("v5", null, { space: "const", offset: "0x2100", is_constant: true }),
value("v6", null, { space: "const", offset: "0x2200", is_constant: true }),
value("v7", null, { is_input: true }),
value("v9", "0x9000:0"),
];
return {
binary: "/input",
count: 1,
language: "c",
error: null,
functions: [
{
address_hex: "0x1000",
code: "retained C",
error: null,
atomic_facts_error: "atomic operation capacity exceeded",
atomic_projection: {
schema_version: 1,
roots: ["0x1100:1"],
operations,
values,
coverage: {
scope: "call-rooted bounded backward SSA definitions",
operation_budget: 4096,
frontier: [
{
definition: "0x9000:0",
reason: "outside-recovered-membership",
},
],
issues: [],
machine_semantic_equivalence: "unknown",
},
},
atomic_calls: {
schema_version: 1,
items: [
{
id: "0x1100:1",
origin_address: "0x1100",
block: 9,
opcode: "CPUI_CALL",
is_dead: false,
target_value_id: "v0",
spec_available: false,
target: null,
target_name: null,
arguments: ["v3", "v7", "v9"].map((value_id, i) => ({
input_index: i + 1,
value_id,
storage: null,
storage_authority: null,
})),
output: null,
prototype: null,
stack_offset: null,
},
],
values: structuredClone(
values.filter((v) => ["v0", "v3", "v7", "v9"].includes(v.id)),
),
coverage: {
scope: "all recovered block-member CALL/CALLIND operations",
blocks_examined: 10,
operations_examined: 100,
value_scope: "call inputs including target and outputs only",
machine_call_equivalence: "unknown",
},
},
},
],
};
}
test("operand relations preserve every slot, page across seeds and select exact caller indices", () => {
const source = fixture();
source.functions[0].atomic_projection.operations[1].inputs.push(
input(2, "v5", 2, "2:0"),
input(3, "v7", 3, "3:0"),
input(4, null, 4, "4:0"),
);
const model = parseNativeIR(JSON.stringify(source), "0x1000");
const read = (extra = {}) =>
model.edges({
kind: "operands",
seeds: ["0x1080:2"],
offset: 0,
limit: 2,
...extra,
});
const first = read();
assert.equal(first.total, 5);
assert.equal(first.next_offset, 2);
assert.deepEqual(
first.items.map((r) => r.input_index),
[0, 1],
);
assert.deepEqual(
read({ offset: 2, limit: 10 }).items.map((r) => r.definition),
[null, null, null],
);
const selected = read({ input_indices: [4, 2, 4, 500], limit: 10 });
assert.equal(selected.total, 2);
assert.equal(selected.items[0].value_id, null);
assert.deepEqual(
selected.items.map((r) => [r.input_index, r.phi_predecessor_edge]),
[
[4, "4:0"],
[2, "2:0"],
],
);
assert.equal(read({ input_indices: [] }).total, 0);
const batch = read({
seeds: ["0x1080:2", "0x1050:3", "0x1050:3", "0x9000:0"],
offset: 4,
limit: 2,
});
assert.equal(batch.total, 7);
assert.equal(batch.next_offset, 6);
assert.deepEqual(
batch.items.map((r) => [r.operation, r.input_index]),
[
["0x1080:2", 4],
["0x1050:3", 0],
],
);
assert.deepEqual(batch.unretained_seeds, ["0x9000:0"]);
assert.equal(
read({ seeds: ["0x1100:1"], input_indices: [3] }).items[0].definition,
"0x9000:0",
);
const summary = model.select({ ids: ["0x1080:2"] }).items[0];
assert.equal(summary.input_count, 5);
assert.equal(summary.definition_count, 2);
assert.equal(summary.constant_count, 1);
assert.equal(Object.hasOwn(summary, "inputs"), false);
const repeatedValues = model.values({ ids: ["v3", "v3", "vbad", "vbad"] });
assert.deepEqual(
repeatedValues.items.map((v) => v.id),
["v3"],
);
assert.deepEqual(repeatedValues.missing, ["vbad"]);
});
test("partial definition facts compose through phi operands without implying a CFG or full uses", () => {
const model = parseNativeIR(JSON.stringify(fixture()), "0x1000");
assert.equal(model.facets.recovered_ir.availability, "unavailable");
assert.equal(
model.facets.operations.scope,
"bounded-call-rooted-definitions",
);
assert.equal(model.facets.values.scope, "call-rooted-definitions");
assert.equal(model.coverage.definition_frontier_count, 1);
assert.equal(JSON.stringify(model.coverage).includes("0x9000:0"), false);
const phi = model.select({
ids: ["0x1080:2"],
fields: ["inputs", "output"],
limit: 1,
}).items[0];
assert.equal(phi.output, "v3");
assert.equal(phi.inputs[0].phi_predecessor_edge, "7:1");
assert.throws(() => {
phi.inputs[0].value_id = "vdead";
}, TypeError);
const sliced = model.slice({
seeds: ["0x1100:1"],
max_operations: 10,
stop_kinds: [],
});
assert.equal(sliced.operations.length, 4);
assert.equal(sliced.coverage.status, "partial");
assert.deepEqual(sliced.coverage.missing_reasons, [
{ definition: "0x9000:0", reason: "outside-recovered-membership" },
]);
assert.deepEqual(sliced.value_frontier, [
{ value_id: "v7", reason: "function-input" },
]);
assert.deepEqual(model.findConstant("0x2100"), ["0x1050:3"]);
const uses = model.edges({
kind: "uses",
seeds: ["0x9000:0"],
offset: 0,
limit: 10,
});
assert.equal(uses.items.length, 1);
assert.deepEqual(uses.unretained_seeds, ["0x9000:0"]);
assert.match(uses.relation_coverage.scope, /selected-operations-only/);
const inputUses = model.edges({ kind: "value_uses", seeds: ["v7"] });
assert.ok(
inputUses.items.some(
(row) =>
row.operation === "0x1100:1" &&
row.input_index === 2 &&
row.definition === null,
),
);
assert.match(inputUses.relation_coverage.scope, /selected-operations-only/);
const inputValue = model.values({ ids: ["v7"] }).items[0];
const located = model.values({
ids: ["v7"],
locations: [
{
space: inputValue.space,
offset: inputValue.offset,
size_bytes: inputValue.size_bytes,
},
],
});
assert.deepEqual(located.items, [inputValue]);
assert.equal(located.coverage.value_scope, model.coverage.value_scope);
for (const read of [
() => model.blocks({}),
() => model.path({ from: 9, target: { kind: "exit" } }),
() => model.edges({ kind: "controllers", seeds: [9] }),
])
assert.throws(read, (e) => e.code === "capability_unavailable");
});
test("bad or contradictory projections preserve independently valid call facts and code", () => {
const changes = [
(p) => {
p.operations[1].inputs[0].value_id = "vdead";
},
(p) => {
p.coverage.frontier = [];
},
(p) => {
p.coverage.frontier[0].reason = "operation-budget";
},
(p) => {
p.roots = ["0x1050:3"];
},
(p) => {
p.roots.push("0x1100:1");
},
(p) => {
p.operations.push(op("0x1070:5", "CPUI_COPY", [input(0, "v7")]));
},
(p) => {
p.values[3].offset = "0xbad";
},
(p) => {
p.coverage.frontier = Array(12289).fill(null);
},
];
for (const change of changes) {
const doc = fixture();
change(doc.functions[0].atomic_projection);
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.code, "retained C");
assert.equal(model.facets.operations.availability, "unavailable");
assert.equal(model.facets.calls.availability, "available");
assert.equal(model.facets.values.scope, "call-boundary-only");
assert.ok(JSON.stringify(model.facets.operations.error).length < 4096);
}
});
test("bad call facets do not erase valid projection definitions", () => {
const doc = fixture();
doc.functions[0].atomic_calls.items[0].arguments[0].value_id = "vdead";
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.facets.calls.availability, "unavailable");
assert.equal(model.facets.operations.availability, "available");
assert.equal(model.values({ ids: ["v5"] }).items[0].offset, "0x2100");
});
test("compact coverage bounds issue text while slices retain the actual issue count", () => {
const doc = fixture();
doc.functions[0].atomic_projection.coverage.issues = Array(10).fill(
"x".repeat(10000),
);
const model = parseNativeIR(JSON.stringify(doc), "0x1000");
assert.equal(model.coverage.issue_count, 10);
assert.equal(model.coverage.issues.length, 8);
assert.equal(model.coverage.issues_omitted, 2);
assert.equal(model.coverage.issue_messages_truncated, true);
assert.ok(JSON.stringify(model.coverage).length < 4096);
assert.equal(
model.slice({ seeds: ["0x1100:1"], max_operations: 10 }).coverage
.source_issues,
10,
);
});
@@ -0,0 +1,93 @@
import { pageFacts } from "./fact-reads.mjs";
import { requireFact, nativeLocationKey } from "./native-contract.mjs";
export const nativePage = (
rows,
input = {},
identity = ["id", "origin_address", "block"],
) => pageFacts(rows, { offset: 0, limit: 20, ...input }, identity);
export const uniqueNative = (rows) => {
const index = new Map();
for (const row of rows) {
requireFact(!index.has(row.id), `Duplicate native identity ${row.id}`);
index.set(row.id, row);
}
return index;
};
export const readNativeIdentities = (index, input, filter = () => true) => ({
...nativePage(
(input.ids
? [...new Set(input.ids)].flatMap((id) => index.get(id) ?? [])
: [...index.values()]
).filter(filter),
input,
),
missing: input.ids
? [...new Set(input.ids)].filter((id) => !index.has(id))
: [],
});
// One owner for graph, projection and call-boundary value selection. The lazy
// index contains only retained facts, never arbitrary caller query/cache keys.
export function createNativeValueReader(values, coverage) {
let locations, unknownSpaces;
const locate = (requested) => {
if (requested.size && !locations) {
locations = new Map();
unknownSpaces = 0;
for (const row of values.values()) {
if (row.space === null) {
unknownSpaces++;
continue;
}
const key = nativeLocationKey(row);
if (!locations.has(key)) locations.set(key, []);
locations.get(key).push(row);
}
}
return [...requested].map(([key, request]) => ({
request,
rows: locations?.get(key) ?? [],
}));
};
return (input) => {
const requested =
input.locations === undefined
? null
: new Map(input.locations.map((row) => [nativeLocationKey(row), row]));
const groups = requested ? locate(requested) : null;
const candidates = input.ids
? [...new Set(input.ids)].flatMap((id) => values.get(id) ?? [])
: groups
? groups.flatMap(({ rows }) => rows)
: [...values.values()];
return {
...nativePage(
candidates.filter(
(row) =>
(!requested ||
!input.ids ||
requested.has(nativeLocationKey(row))) &&
(input.is_input === undefined || row.is_input === input.is_input),
),
input,
),
missing: input.ids
? [...new Set(input.ids)].filter((id) => !values.has(id))
: [],
...(groups
? {
unretained_locations: groups
.filter(({ rows }) => !rows.length)
.map(({ request }) => ({ ...request })),
location_coverage: {
scope:
"exact space/offset/width of retained values; not aliases, pointee contents or machine memory",
unknown_space_count: groups.length ? unknownSpaces : null,
},
}
: {}),
coverage,
};
};
}
@@ -0,0 +1,50 @@
const read = async (name,input) => {
const result=await rea[name](input);
if(!result.ok)throw new Error(JSON.stringify(result.error));
return result.data;
};
const complete=(page)=>{
if(page.next_offset!==null)throw new Error("Continue the selected fact page before drawing a complete conclusion");
return page;
};
const found=await read("functions",{query:"sqlite3VdbeExec",exact:true});
complete(found);
const formats=[];
for(const query of ["cannot open savepoint - SQL statements in progress","cannot release savepoint - SQL statements in progress"]) {
const strings=await read("strings",{query});
complete(strings);
const addresses=[...new Set(strings.items.filter((s)=>s.value===query).map((s)=>s.address))];
if(addresses.length!==1)throw new Error("Ambiguous format: "+JSON.stringify(strings));
const references=await read("references",{addresses,direction:"incoming",fields:["fromFunction","instruction"]});
for(const result of references.results) {
if(!result.ok)throw new Error(JSON.stringify(result.error));
complete(result);
}
formats.push({query,address:addresses[0],string_evidence_id:strings.source.evidence_id,references});
}
const owners=formats.map((f)=>new Set(f.references.results.flatMap((r)=>r.ok?r.items.map((ref)=>ref.fromFunction?.address).filter(Boolean):[])));
const candidates=found.items.filter((f)=>owners.every((set)=>set.has(f.address)));
if(candidates.length!==1)throw new Error("Unresolved format-owning function: "+JSON.stringify({found,formats}));
const capture=await read("snapshot",{entry:candidates[0].address});
const snapshot=capture.snapshot;
for(const format of formats) {
const producers=await read("operations",{snapshot,constant:format.address,fields:["opcode","output"]});
complete(producers);
const setup=producers.items.filter((op)=>op.opcode==="CPUI_PTRSUB");
if(setup.length!==1)throw new Error("Ambiguous format producer: "+JSON.stringify(producers));
const uses=await read("relations",{snapshot,kind:"uses",seeds:[setup[0].id]});
complete(uses);
Object.assign(format,{producer:setup[0],uses});
}
const controls=await read("relations",{snapshot,kind:"controllers",seeds:formats.map((f)=>f.producer.block)});
complete(controls);
const branchIDs=[...new Set(controls.items.flatMap((relation)=>relation.edge.condition_value?[relation.edge.condition_value]:[]))];
const conditions=await read("values",{snapshot,ids:branchIDs});
complete(conditions);
const definitions=await read("operations",{snapshot,ids:conditions.items.map((v)=>v.definition).filter(Boolean),fields:["opcode","inputs","output","constants"]});
complete(definitions);
const values=await read("values",{snapshot,ids:[...new Set(definitions.items.flatMap((op)=>op.inputs.map((i)=>i.value_id).filter(Boolean)))]});
complete(values);
const evidence=await read("evidence",{evidence_id:capture.source.evidence_id,component:"recovered_ir",limit:128});
if((await read("snapshot",{entry:candidates[0].address})).snapshot!==snapshot)throw new Error("Capture was not reused");
return {capture,formats,controls,conditions,definitions,values,evidence};
@@ -0,0 +1,315 @@
// Raw native Evidence has one file/hash owner; reads verify before returning facts.
import { createHash, randomUUID } from "node:crypto";
import { open, rm, writeFile, copyFile, mkdir, stat } from "node:fs/promises";
import { constants } from "node:fs";
import { join } from "node:path";
import { Writable } from "node:stream";
import { StringDecoder } from "node:string_decoder";
import { ArtifactResourceScope } from "../../dist/artifacts/ArtifactResourceScope.js";
import { OwnedFileHandle } from "../../dist/filesystem/OwnedFileHandle.js";
import { FactFailure, projectFactFailure } from "./fact-error.mjs";
import { MAX_RETAINED_SOURCE_BYTES, MAX_NATIVE_SOURCES } from "./limits.mjs";
const cleanupFailure = (cause, primary) => {
const failure = projectFactFailure(
primary === undefined ? cause : primary,
primary === undefined ? "cleanup_incomplete" : "analysis_failed",
);
return new FactFailure(failure.code, failure.message, {
...failure.details,
cleanup_incomplete: String(cause?.message ?? cause),
});
};
export class NativeSourceStore {
#records = new Map();
#retainedBytes = 0;
#copyFailure;
#resources = new ArtifactResourceScope();
constructor({ root, context, captureDirectory }) {
Object.assign(this, { root, context, captureDirectory });
}
get size() {
return this.#records.size;
}
get remainingBytes() {
return MAX_RETAINED_SOURCE_BYTES - this.#retainedBytes;
}
source(id) {
return this.#record(id).source;
}
#record(id) {
const record = this.#records.get(id);
if (!record)
throw new FactFailure(
"unknown_evidence",
"Evidence is not owned by this target lease",
);
return record;
}
async retain(
spool,
{ arguments: actualArguments, input, started, complete },
) {
const size = (await stat(spool.path)).size;
if (size !== spool.bytes) {
await spool.discard();
throw new FactFailure(
"invalid_source",
"Native source size disagrees with acknowledged writes",
{
expected_bytes: spool.bytes,
actual_bytes: size,
source_retained: false,
},
);
}
const id = `ev_${sha256(JSON.stringify([this.context.lease, actualArguments, spool.sha256, complete]))}`;
if (this.#records.has(id)) {
await spool.discard();
return this.#records.get(id).source;
}
const source = Object.freeze({
evidence_id: id,
sha256: spool.sha256,
bytes: spool.bytes,
capture_complete: complete,
arguments: Object.freeze(actualArguments),
display_arguments: Object.freeze(
actualArguments.map((s) => (s === input ? this.context.path : s)),
),
elapsed_ms: performance.now() - started,
});
this.#records.set(id, { source, file: spool.path });
this.#retainedBytes += spool.bytes;
try {
if (this.captureDirectory) {
await mkdir(this.captureDirectory, { recursive: true, mode: 0o700 });
await copyFile(
spool.path,
join(this.captureDirectory, `${id}.txt`),
constants.COPYFILE_EXCL,
);
await writeFile(
join(this.captureDirectory, `${id}.json`),
JSON.stringify({ context: this.context, source }),
{ flag: "wx", mode: 0o600 },
);
}
} catch (cause) {
this.#copyFailure = new FactFailure(
"evidence_copy_failed",
"Native Evidence is retained but the requested external copy failed",
{
evidence_id: id,
source_retained: true,
copy_directory: this.captureDirectory,
reason: String(cause?.message ?? cause),
filesystem_code: cause?.code ?? null,
copy_retry: "new_target_lease",
},
);
throw this.#copyFailure;
}
return source;
}
async #open(path, flags) {
await this.#resources.retryCleanup();
const handle = new OwnedFileHandle(await open(path, flags, 0o600));
const owner = { kind: "file-handle", resource: path, handle };
return {
handle: handle.handle,
close: async (primary) => {
const result = await this.#resources.release(owner);
if (result.kind === "failed")
throw cleanupFailure(result.cause, primary);
},
};
}
async spool(limit, reader) {
if (this.#copyFailure) throw this.#copyFailure;
if (this.size >= MAX_NATIVE_SOURCES)
throw new FactFailure(
"capacity",
"Session source capacity reached; close and reopen the target",
);
limit = Math.min(limit, this.remainingBytes);
if (!Number.isSafeInteger(limit) || limit < 1)
throw new FactFailure("capacity", "Retained-source budget is exhausted");
const path = join(this.root, `source-${randomUUID()}`);
return new NativeSourceSpool({
path,
file: await this.#open(path, "wx"),
limit,
reader,
discard: async () => {
const result = await this.#resources.release({
kind: "lease",
resource: path,
lease: { release: () => rm(path, { force: true }) },
});
if (result.kind === "failed") throw cleanupFailure(result.cause);
},
});
}
async read(id, window) {
const record = this.#record(id);
const file = await this.#open(record.file, "r");
let primary;
try {
return await readVerified(file.handle, record.source, window);
} catch (error) {
primary = error;
throw error;
} finally {
await file.close(primary);
}
}
async close() {
await this.#resources.close();
}
}
class NativeSourceSpool extends Writable {
#hash = createHash("sha256");
#digest;
#pending = Promise.resolve();
#rejected = new AbortController();
bytes = 0;
failure;
constructor({ path, file, limit, reader, discard }) {
super();
Object.assign(this, { path, file, limit, reader, discard });
// The command owns stream failure reporting; never leave a rejected sink unobserved.
reader?.on("error", () => {});
}
get rejected() {
return this.#rejected.signal;
}
get sha256() {
return (this.#digest ??= this.#hash.digest("hex"));
}
_write(chunk, _encoding, callback) {
this.#pending = this.#write(chunk);
this.#pending.then(
() => callback(),
(error) => {
this.failure =
error instanceof FactFailure
? error
: new FactFailure(
"source_write_failed",
"Native Evidence could not be written",
{
reason: String(error?.message ?? error),
filesystem_code: error?.code ?? null,
},
);
this.#rejected.abort(this.failure);
callback(this.failure);
},
);
}
async #write(chunk) {
if (this.bytes + chunk.byteLength > this.limit)
throw new FactFailure(
"resource_constraint",
"Native Evidence exceeds its retained-source budget",
{
scope: "native_source",
limit_bytes: this.limit,
observed_bytes_at_least: this.bytes + chunk.byteLength,
},
);
for (let offset = 0; offset < chunk.byteLength;) {
const written = await this.file.handle.write(
chunk,
offset,
chunk.byteLength - offset,
);
if (written.bytesWritten === 0)
throw new FactFailure(
"source_write_failed",
"Native source write made no progress",
);
this.#hash.update(chunk.subarray(offset, offset + written.bytesWritten));
this.bytes += written.bytesWritten;
offset += written.bytesWritten;
}
if (this.reader)
await new Promise((resolve, reject) =>
this.reader.write(chunk, (error) =>
error ? reject(error) : resolve(),
),
);
}
_final(callback) {
if (this.reader) this.reader.end(callback);
else callback();
}
_destroy(error, callback) {
if (!this.reader?.writableFinished) this.reader?.destroy();
this.#pending.then(
() => callback(error),
() => callback(error),
);
}
async close(primary) {
if (!this.destroyed) this.destroy();
await this.#pending.catch(() => {});
try {
await this.file.close(primary);
} catch (error) {
// Unpublished failed captures must not accumulate outside the source ledger.
try {
await this.discard();
} catch (cause) {
throw cleanupFailure(cause, error);
}
throw error;
}
}
}
async function readVerified(handle, source, window) {
const hash = createHash("sha256"),
decoder = new StringDecoder("utf8"),
chunks = [];
const buffer = Buffer.allocUnsafe(64 * 1024);
let bytes = 0,
units = 0;
const collect = (text) => {
if (window) {
const start = Math.max(0, window.offset - units);
const end = Math.min(text.length, window.offset + window.limit - units);
if (end > start) chunks.push(text.slice(start, end));
} else chunks.push(text);
units += text.length;
};
while (true) {
const { bytesRead } = await handle.read(buffer, 0, buffer.length);
if (!bytesRead) break;
bytes += bytesRead;
if (bytes > source.bytes) throw changed();
const chunk = buffer.subarray(0, bytesRead);
hash.update(chunk);
collect(decoder.write(chunk));
}
collect(decoder.end());
if (bytes !== source.bytes || hash.digest("hex") !== source.sha256)
throw changed();
return {
source,
text: chunks.join(""),
total_code_units: units,
next_offset:
window && window.offset + window.limit < units
? window.offset + window.limit
: null,
};
}
const changed = () =>
new FactFailure("evidence_changed", "Retained source changed");
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
@@ -0,0 +1,310 @@
import assert from "node:assert/strict";
import test from "node:test";
import { createHash } from "node:crypto";
import { readFile, writeFile, stat } from "node:fs/promises";
import { Readable } from "node:stream";
import { pipeline } from "node:stream/promises";
import { PrivateRuntimeRoot } from "../../dist/process/PrivateRuntimeRoot.js";
import { KunaStringInventoryReader } from "../../dist/kuna/KunaStringInventory.js";
import { NativeSourceStore } from "./native-source-store.mjs";
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
async function withFiles(work) {
const root = await PrivateRuntimeRoot.create({ prefix: "rea-source-test-" });
const files = new NativeSourceStore({
root: root.path,
context: { lease: "test", path: "/input" },
});
try {
await work(files);
} finally {
await files.close();
await root.close();
}
}
const retain = (files, spool) =>
files.retain(spool, {
arguments: ["strings", "/input"],
input: "/input",
started: performance.now(),
complete: true,
});
// UTF-8 byte boundaries, UTF-16 unit boundaries and the selected window differ.
test("raw windows preserve slice semantics, exact hashes and complete source lengths", () =>
withFiles(async (files) => {
const text = "x".repeat(65535) + "中文😀" + "y".repeat(65537),
bytes = Buffer.from(text);
const spool = await files.spool(bytes.length);
await pipeline(
Readable.from([bytes.subarray(0, 65536), bytes.subarray(65536)]),
spool,
);
await spool.close();
assert.equal((await stat(spool.path)).mode & 0o777, 0o600);
const source = await retain(files, spool);
assert.equal(source.sha256, hash(bytes));
for (const [offset, limit] of [
[0, 0],
[65534, 2],
[65538, 1],
[65539, 1],
[65540, 3],
[text.length, 5],
[text.length + 9, 2],
]) {
const page = await files.read(source.evidence_id, { offset, limit });
assert.equal(page.text, text.slice(offset, offset + limit));
assert.equal(page.total_code_units, text.length);
assert.equal(
page.next_offset,
offset + limit < text.length ? offset + limit : null,
);
}
assert.equal((await files.read(source.evidence_id)).text, text);
}));
test("a mutation outside the selected window cannot pass source validation", () =>
withFiles(async (files) => {
const spool = await files.spool(32);
await pipeline(Readable.from(["retained evidence"]), spool);
await spool.close();
const source = await retain(files, spool);
for (const value of [
"retained evidencE",
"retained evidenc",
"retained evidence!",
]) {
await writeFile(spool.path, value);
await assert.rejects(
files.read(source.evidence_id, { offset: 0, limit: 1 }),
{ code: "evidence_changed" },
);
}
}));
test("source limits admit the exact boundary and reject before writing an over-budget chunk", () =>
withFiles(async (files) => {
const exact = await files.spool(4);
await pipeline(Readable.from(["abcd"]), exact);
await exact.close();
assert.equal(exact.bytes, 4);
assert.equal(exact.rejected.aborted, false);
const partial = await files.spool(4);
await assert.rejects(pipeline(Readable.from(["abc", "de"]), partial), {
code: "resource_constraint",
});
await partial.close();
assert.equal(partial.bytes, 3);
assert.equal(partial.failure.details.observed_bytes_at_least, 5);
assert.equal(partial.rejected.aborted, true);
assert.equal((await readFile(partial.path)).toString(), "abc");
await partial.discard();
await assert.rejects(stat(partial.path), { code: "ENOENT" });
await assert.rejects(files.spool(0), { code: "capacity" });
}));
const inventory = (overrides = {}) =>
JSON.stringify({
binary: "/input",
encoding: "all",
min_length: 5,
filter: null,
section: null,
termination: "any",
scanned: "sections",
xrefs: false,
count: 1,
strings: [
{
address: 4096,
address_hex: "0x1000",
text: "hello中文",
length: 7,
byte_length: 12,
nul_terminated: true,
encoding: "utf8",
section: ".rodata",
xrefs_count: 0,
functions: [],
},
],
...overrides,
});
test("the production string reader validates streamed rows while original Evidence stays byte-exact", () =>
withFiles(async (files) => {
for (const valid of [true, false]) {
const bytes = Buffer.from(inventory(valid ? {} : { count: 2 })),
reader = new KunaStringInventoryReader();
const spool = await files.spool(bytes.length, reader);
await pipeline(
Readable.from([...bytes].map((byte) => Buffer.from([byte]))),
spool,
);
await spool.close();
const result = reader.finish("/input");
assert.equal(result.ok, valid);
if (result.ok) {
assert.equal(result.value.items[0].string.nul_terminated, true);
assert.equal(result.value.items[0].value, "hello中文");
assert.equal(result.value.sha256, spool.sha256);
} else assert.match(result.error.message, /count/);
assert.deepEqual(await readFile(spool.path), bytes);
}
}));
test("failed descriptor cleanup retains the same owner and preserves the primary failure", () =>
withFiles(async (files) => {
const spool = await files.spool(4),
handle = spool.file.handle,
close = handle.close.bind(handle);
await pipeline(Readable.from(["a"]), spool);
let attempts = 0;
handle.close = async () => {
attempts++;
if (attempts === 1) throw new Error("injected close failure");
return close();
};
await assert.rejects(
spool.close(
Object.assign(new Error("cancelled request"), { code: "cancelled" }),
),
(error) =>
error.code === "cancelled" &&
error.details.cleanup_incomplete === "injected close failure",
);
assert(handle.fd >= 0);
await assert.rejects(stat(spool.path), { code: "ENOENT" });
await files.close();
assert.equal(handle.fd, -1);
assert.equal(attempts, 2);
}));
// This is the existing per-lease retained-source ceiling, independent of paging.
test("the aggregate source budget remains readable at exhaustion without admitting more captures", () =>
withFiles(async (files) => {
const chunk = Buffer.alloc(1024 * 1024, 0x61),
budget = files.remainingBytes;
const spool = await files.spool(budget + 1);
await pipeline(
Readable.from(
(function* () {
for (let i = 0; i < budget / chunk.length; i++) yield chunk;
})(),
),
spool,
);
await spool.close();
const source = await retain(files, spool);
assert.equal(files.remainingBytes, 0);
await assert.rejects(files.spool(1), { code: "capacity" });
const page = await files.read(source.evidence_id, {
offset: source.bytes - 3,
limit: 3,
});
assert.equal(page.text, "aaa");
assert.equal(page.next_offset, null);
assert.equal(page.total_code_units, budget);
}));
test("content deduplication and partial-capture identity preserve the one source owner", () =>
withFiles(async (files) => {
const sources = [];
for (const complete of [true, true, false]) {
const spool = await files.spool(8);
await pipeline(Readable.from(["source"]), spool);
await spool.close();
sources.push(
await files.retain(spool, {
arguments: ["strings", "/input"],
input: "/input",
started: performance.now(),
complete,
}),
);
if (sources.length === 2)
await assert.rejects(stat(spool.path), { code: "ENOENT" });
}
assert.strictEqual(sources[0], sources[1]);
assert.notEqual(sources[0].evidence_id, sources[2].evidence_id);
assert.equal(sources[2].capture_complete, false);
assert.equal(files.size, 2);
assert.equal(files.remainingBytes, 64 * 1024 * 1024 - 12);
await assert.rejects(files.read("foreign", { offset: 0, limit: 1 }), {
code: "unknown_evidence",
});
}));
test("partial writes make progress and a zero-progress write fails explicitly", () =>
withFiles(async (files) => {
const spool = await files.spool(8),
handle = spool.file.handle,
write = handle.write.bind(handle);
handle.write = (buffer, offset, length) =>
write(buffer, offset, Math.min(length, 1));
await pipeline(Readable.from(["source"]), spool);
await spool.close();
assert.equal((await readFile(spool.path)).toString(), "source");
const stuck = await files.spool(8);
stuck.file.handle.write = async () => ({ bytesWritten: 0 });
await assert.rejects(pipeline(Readable.from(["x"]), stuck), {
code: "source_write_failed",
});
await stuck.close();
await stuck.discard();
}));
test("external copy failures preserve the retained observation and caller-selected destination", () =>
withFiles(async (files) => {
const destination = files.root + "/not-a-directory";
await writeFile(destination, "owned test file");
files.captureDirectory = destination;
const spool = await files.spool(8);
await pipeline(Readable.from(["source"]), spool);
await spool.close();
let id;
await assert.rejects(retain(files, spool), (error) => {
id = error.details.evidence_id;
return (
error.code === "evidence_copy_failed" &&
error.details.copy_directory === destination &&
error.details.source_retained
);
});
assert.equal((await files.read(id, { offset: 0, limit: 3 })).text, "sou");
assert.equal(files.size, 1);
await assert.rejects(files.spool(8), { code: "evidence_copy_failed" });
}));
test("a write failure after an acknowledged prefix retains exact partial Evidence", () =>
withFiles(async (files) => {
const spool = await files.spool(8),
handle = spool.file.handle,
write = handle.write.bind(handle);
let calls = 0;
handle.write = (buffer, offset, length) => {
if (calls++)
throw Object.assign(new Error("injected disk failure"), {
code: "ENOSPC",
});
return write(buffer, offset, Math.min(3, length));
};
await assert.rejects(pipeline(Readable.from(["abcdef"]), spool), {
code: "source_write_failed",
});
await spool.close();
assert.equal(spool.bytes, 3);
const source = await files.retain(spool, {
arguments: ["strings", "/input"],
input: "/input",
started: performance.now(),
complete: false,
});
assert.equal(source.sha256, hash("abc"));
assert.equal(source.capture_complete, false);
assert.equal(
(await files.read(source.evidence_id, { offset: 0, limit: 8 })).text,
"abc",
);
}));
@@ -0,0 +1,245 @@
// Parse one bounded native architecture catalog; views never reinterpret names.
import { z } from "zod";
import { NATIVE_OUTPUT_BYTES } from "./limits.mjs";
import {
nativeLocationKey,
hex,
ordinal,
rowParser,
requireFact,
formatFailure,
} from "./native-contract.mjs";
import { freezeFacts } from "./fact-reads.mjs";
import { nativePage } from "./native-reads.mjs";
const u32 = z.number().int().nonnegative().max(0xffffffff);
const space = z.strictObject({
native_index: ordinal,
name: z.string().min(1),
kind: z.string().min(1),
address_size_bytes: u32,
addressable_unit_bytes: u32.positive(),
endianness: z.enum(["big", "little"]),
highest_offset: hex,
});
const register = z.strictObject({
native_row: ordinal,
space: z.string().min(1).nullable(),
offset: hex,
size_bytes: u32.positive(),
name: z.string().nullable(),
name_bytes_hex: z
.string()
.regex(/^(?:[0-9a-f]{2})*$/u)
.nullable(),
});
const schema = z.strictObject({
schema_version: z.literal(1),
binary: z.string(),
architecture: z.strictObject({
native_id: z.string().min(1),
default_code_space: z.string().min(1).nullable(),
}),
space_index_capacity: ordinal,
register_count: ordinal,
spaces: z.array(space),
registers: z.array(register),
coverage: z.strictObject({
scope: z.string(),
native_exact_register_map: z.literal("complete"),
alias_relationships: z.literal("unknown"),
dynamic_join_records: z.literal("not-collected"),
memory_values: z.literal("not-returned"),
listing_discovery: z.literal(false),
functions_decompiled: z.literal(0),
}),
});
// A valid record necessarily occupies at least this many wire bytes. Admit row
// counts before mapping malformed arrays or allocating their parsed rows.
const minSpaceBytes = Buffer.byteLength(
JSON.stringify({
native_index: 0,
name: "x",
kind: "x",
address_size_bytes: 0,
addressable_unit_bytes: 1,
endianness: "big",
highest_offset: "0x0",
}),
);
const minRegisterBytes = Buffer.byteLength(
JSON.stringify({
native_row: 0,
space: "x",
offset: "0x0",
size_bytes: 1,
name: "",
name_bytes_hex: null,
}),
);
const parse = rowParser(schema, {
spaces: (r) => space.parse(r),
registers: (r) => register.parse(r),
});
export function parseNativeStorageMap(text, expectedInput) {
try {
requireFact(
Buffer.byteLength(text) <= NATIVE_OUTPUT_BYTES,
"Native storage map exceeds wire budget",
);
const raw = JSON.parse(text);
for (const [name, minimum] of [
["spaces", minSpaceBytes],
["registers", minRegisterBytes],
])
requireFact(
Array.isArray(raw?.[name]) &&
raw[name].length <= Math.floor(NATIVE_OUTPUT_BYTES / minimum),
`Native storage ${name} exceeds format-derived row capacity`,
);
const facts = parse(raw);
requireFact(
facts.binary === expectedInput,
"Native storage map input differs from requested subject",
);
requireFact(
facts.register_count === facts.registers.length,
"Native register count mismatch",
);
const spacesByName = new Map(),
spacesByIndex = new Map(),
byLocation = new Map(),
byName = new Map();
for (const row of facts.spaces) {
requireFact(
row.native_index < facts.space_index_capacity &&
!spacesByName.has(row.name) &&
!spacesByIndex.has(row.native_index),
"Duplicate or invalid native space identity",
);
spacesByName.set(row.name, row);
spacesByIndex.set(row.native_index, row);
}
requireFact(
facts.architecture.default_code_space === null ||
spacesByName.has(facts.architecture.default_code_space),
"Unretained native default code space",
);
for (const [index, row] of facts.registers.entries()) {
requireFact(
row.native_row === index,
"Native register row identity mismatch",
);
requireFact(
(row.name === null) === (row.name_bytes_hex !== null),
"Native register name/byte knowledge mismatch",
);
requireFact(
row.space === null || spacesByName.has(row.space),
"Register references unretained native space",
);
if (row.space !== null) {
const key = nativeLocationKey(row);
requireFact(!byLocation.has(key), "Duplicate native register location");
byLocation.set(key, row);
}
if (row.name !== null) {
if (!byName.has(row.name)) byName.set(row.name, []);
byName.get(row.name).push(row);
}
}
freezeFacts(facts);
return createViews(facts, {
spacesByName,
spacesByIndex,
byLocation,
byName,
});
} catch (error) {
throw formatFailure(error);
}
}
function createViews(
facts,
{ spacesByName, spacesByIndex, byLocation, byName },
) {
const metadata = freezeFacts({
architecture: facts.architecture,
totals: {
spaces: facts.spaces.length,
space_index_capacity: facts.space_index_capacity,
registers: facts.register_count,
},
coverage: {
...facts.coverage,
unmatched_selectors:
"no retained exact map match; not absence of hardware storage, aliases or runtime values",
names: "native varnode_xref names; not every translator symbol/alias",
unknown_space_register_count: facts.registers.filter(
(r) => r.space === null,
).length,
undecodable_name_count: facts.registers.filter((r) => r.name === null)
.length,
},
});
return Object.freeze({
spaces(input) {
const names = input.names && [...new Set(input.names)],
indices = input.indices && [...new Set(input.indices)];
const rows = (
indices
? indices.flatMap((i) => spacesByIndex.get(i) ?? [])
: names
? names.flatMap((n) => spacesByName.get(n) ?? [])
: facts.spaces
).filter(
(r) =>
(!names || names.includes(r.name)) &&
(!indices || indices.includes(r.native_index)),
);
return {
...metadata,
...nativePage(rows, input, ["native_index", "name"]),
missing_names: names?.filter((n) => !spacesByName.has(n)) ?? [],
missing_indices: indices?.filter((i) => !spacesByIndex.has(i)) ?? [],
};
},
registers(input) {
const names = input.names && new Set(input.names),
locations =
input.locations &&
new Map(input.locations.map((r) => [nativeLocationKey(r), r]));
const normalize = (s) => (input.case_sensitive ? s : s.toLowerCase()),
query = normalize(input.query ?? "");
const rows = locations
? [...locations.keys()].flatMap((k) => byLocation.get(k) ?? [])
: names
? [...names].flatMap((n) => byName.get(n) ?? [])
: facts.registers;
return {
...metadata,
...nativePage(
rows.filter(
(r) =>
(!names || names.has(r.name)) &&
(!query ||
(r.name !== null && normalize(r.name).includes(query))),
),
input,
["native_row", "space", "offset", "size_bytes"],
),
unretained_names: names ? [...names].filter((n) => !byName.has(n)) : [],
...(locations
? {
unretained_locations: [...locations]
.filter(([k]) => !byLocation.has(k))
.map(([, r]) => ({ ...r })),
unretained_space_names: [
...new Set([...locations.values()].map((r) => r.space)),
].filter((n) => !spacesByName.has(n)),
}
: {}),
};
},
});
}
@@ -0,0 +1,393 @@
import test from "node:test";
import assert from "node:assert/strict";
import { parseNativeStorageMap } from "./native-storage-map.mjs";
import { NativeCatalogReads } from "./native-catalog-reads.mjs";
import { FactFailure } from "./fact-error.mjs";
import { methods } from "./api.mjs";
import { NATIVE_OUTPUT_BYTES } from "./limits.mjs";
// Deliberately sparse spaces, duplicate names, one unknown space and raw bytes.
const fixture = () => ({
schema_version: 1,
binary: "/selected/input",
architecture: { native_id: "test:model", default_code_space: "ram" },
space_index_capacity: 9,
register_count: 6,
spaces: [
{
native_index: 3,
name: "ram",
kind: "IPTR_PROCESSOR",
address_size_bytes: 8,
addressable_unit_bytes: 1,
endianness: "big",
highest_offset: "0xffffffffffffffff",
},
{
native_index: 4,
name: "register",
kind: "IPTR_PROCESSOR",
address_size_bytes: 4,
addressable_unit_bytes: 1,
endianness: "little",
highest_offset: "0xffffffff",
},
{
native_index: 8,
name: "stack",
kind: "IPTR_SPACEBASE",
address_size_bytes: 8,
addressable_unit_bytes: 2,
endianness: "big",
highest_offset: "0xffffffffffffffff",
},
],
registers: [
{
native_row: 0,
space: "register",
offset: "0x8",
size_bytes: 8,
name: "RCX",
name_bytes_hex: null,
},
{
native_row: 1,
space: "register",
offset: "0x8",
size_bytes: 2,
name: "CX",
name_bytes_hex: null,
},
{
native_row: 2,
space: "register",
offset: "0x10",
size_bytes: 2,
name: "CX",
name_bytes_hex: null,
},
{
native_row: 3,
space: null,
offset: "0xffffffffffffffff",
size_bytes: 1,
name: "",
name_bytes_hex: null,
},
{
native_row: 4,
space: "register",
offset: "0x0",
size_bytes: 1,
name: null,
name_bytes_hex: "ff00",
},
{
native_row: 5,
space: "register",
offset: "0x1",
size_bytes: 1,
name: "x.y",
name_bytes_hex: null,
},
],
coverage: {
scope: "test exact map",
native_exact_register_map: "complete",
alias_relationships: "unknown",
dynamic_join_records: "not-collected",
memory_values: "not-returned",
listing_discovery: false,
functions_decompiled: 0,
},
});
const parse = (doc = fixture()) =>
parseNativeStorageMap(JSON.stringify(doc), "/selected/input");
const select = (view, method, input = {}) =>
view[method](methods[method].input.parse(input));
test("space identity, sparse indices, caller order, projection and absence before paging", () => {
const view = parse();
const reply = select(view, "spaces", {
indices: [8, 3, 8, 7],
names: ["stack", "ram", "missing"],
fields: ["addressable_unit_bytes"],
limit: 1,
});
assert.deepEqual(reply.items, [
{ native_index: 8, name: "stack", addressable_unit_bytes: 2 },
]);
assert.deepEqual(reply.missing_names, ["missing"]);
assert.deepEqual(reply.missing_indices, [7]);
assert.equal(reply.total, 2);
assert.equal(reply.next_offset, 1);
assert.equal(reply.totals.space_index_capacity, 9);
assert.equal(reply.totals.spaces, 3);
assert.deepEqual(
select(view, "spaces", { names: ["stack", "ram"], fields: [] }).items,
[
{ native_index: 8, name: "stack" },
{ native_index: 3, name: "ram" },
],
);
for (const input of [{ names: [] }, { indices: [] }])
assert.equal(select(view, "spaces", input).total, 0);
});
test("register lookup uses exact space/offset/width, keeps misses before filtering and does not substitute containing registers", () => {
const view = parse(),
locations = [
{ space: "register", offset: "0x8", size_bytes: 2 },
{ space: "register", offset: "0x8", size_bytes: 8 },
{ space: "register", offset: "0x8", size_bytes: 3 },
{ space: "unknown", offset: "0x8", size_bytes: 8 },
{ space: "stack", offset: "0x8", size_bytes: 8 },
];
const reply = select(view, "registers", {
locations: [...locations, locations[0]],
fields: ["name"],
limit: 1,
});
assert.deepEqual(reply.items, [
{ native_row: 1, ...locations[0], name: "CX" },
]);
assert.equal(reply.total, 2);
assert.deepEqual(reply.unretained_locations, locations.slice(2));
assert.deepEqual(reply.unretained_space_names, ["unknown"]);
const intersect = select(view, "registers", {
locations,
names: ["RCX", "rcx"],
query: "cx",
});
assert.equal(intersect.total, 1);
assert.deepEqual(intersect.unretained_names, ["rcx"]);
assert.deepEqual(intersect.unretained_locations, locations.slice(2));
assert.equal(select(view, "registers", { locations: [] }).total, 0);
});
test("register names preserve multiplicity, exact-case names, substring semantics and explicit unknowns", () => {
const view = parse();
assert.deepEqual(
select(view, "registers", {
names: ["CX", "RCX", "CX"],
fields: [],
}).items.map((r) => r.native_row),
[1, 2, 0],
);
assert.equal(select(view, "registers", { query: "cx" }).total, 3);
assert.equal(
select(view, "registers", { query: "cx", case_sensitive: true }).total,
0,
);
assert.equal(select(view, "registers", { query: "." }).total, 1);
assert.equal(select(view, "registers", { names: [] }).total, 0);
const reply = select(view, "registers", { offset: 3 });
assert.deepEqual(reply.items[0], fixture().registers[3]);
assert.deepEqual(reply.items[1], fixture().registers[4]);
assert.equal(reply.coverage.unknown_space_register_count, 1);
assert.equal(reply.coverage.undecodable_name_count, 1);
assert.equal(select(view, "registers", { names: [""] }).items[0].space, null);
});
test("SDK views cannot change retained storage metadata or subsequent queries", () => {
const view = parse(),
reply = select(view, "registers");
for (const change of [
() => {
reply.items[0].name = "foreign";
},
() => {
reply.architecture.native_id = "foreign";
},
() => {
reply.totals.registers = 0;
},
() => {
reply.coverage.functions_decompiled = 1;
},
])
assert.throws(change, TypeError);
reply.items.length = 0;
assert.equal(select(view, "registers").items.length, 6);
});
test("malformed source fails closed at identity, reference and knowledge boundaries", () => {
const mutations = [
(d) => {
d.binary = "/other";
},
(d) => {
d.schema_version = 2;
},
(d) => {
d.register_count++;
},
(d) => {
d.registers[1].native_row = 0;
},
(d) => {
d.spaces[1].native_index = 3;
},
(d) => {
d.spaces[1].name = "ram";
},
(d) => {
d.spaces[0].native_index = 9;
},
(d) => {
d.architecture.default_code_space = "missing";
},
(d) => {
d.registers[1].space = "missing";
},
(d) => {
d.registers[1].size_bytes = 8;
},
(d) => {
d.registers[4].name_bytes_hex = null;
},
(d) => {
d.registers[0].name_bytes_hex = "ff";
},
(d) => {
d.registers[0].offset = "0x08";
},
(d) => {
d.registers[0].size_bytes = 0;
},
(d) => {
d.registers[4].name_bytes_hex = "f";
},
(d) => {
d.coverage.functions_decompiled = 1;
},
(d) => {
d.spaces = null;
},
(d) => {
d.registers = [];
},
];
for (const mutate of mutations) {
const doc = fixture();
mutate(doc);
assert.throws(
() => parse(doc),
(e) => e.code === "invalid_provider_output",
);
}
assert.throws(
() =>
parseNativeStorageMap(
" ".repeat(NATIVE_OUTPUT_BYTES + 1),
"/selected/input",
),
/wire budget/,
);
const doc = fixture();
doc.registers = Array(100000).fill(null);
assert.throws(() => parse(doc), /format-derived row capacity/);
});
test("one immutable storage capture powers both catalog views; clear creates a new lease cache", async () => {
const captures = [],
source = {
evidence_id: "ev_source",
sha256: "digest",
bytes: 10,
elapsed_ms: 1,
};
let guards = 0;
const reader = new NativeCatalogReads(
async (name, args, signal) => {
captures.push({ name, args: args("/selected/input"), signal });
return { input: "/selected/input", source };
},
async (id) => {
assert.equal(id, source.evidence_id);
return JSON.stringify(fixture());
},
() => {
guards++;
},
);
const signal = new AbortController().signal;
const first = await reader.spaces({}, signal);
assert.throws(() => {
first.source.sha256 = "foreign";
}, TypeError);
await reader.registers({ names: ["CX"] }, signal);
await reader.spaces({ names: [] }, signal);
assert.equal(captures.length, 1);
assert.deepEqual(captures[0], {
name: "storage",
args: ["storage-map", "/selected/input", "--json"],
signal,
});
assert.equal(guards, 3);
reader.clear();
await reader.registers({}, signal);
assert.equal(captures.length, 2);
});
test("catalog errors retain source and typed execution failures, never caching a failed parse", async () => {
let text = "invalid",
reads = 0,
captures = 0;
const reader = new NativeCatalogReads(
async () => {
captures++;
return {
input: "/selected/input",
source: { evidence_id: "ev_bad", sha256: "digest" },
};
},
async () => {
reads++;
return text;
},
() => {},
);
await assert.rejects(
reader.spaces({}),
(e) =>
e.code === "invalid_provider_output" &&
e.details.evidence_id === "ev_bad" &&
e.details.source_retained,
);
text = JSON.stringify(fixture());
await reader.registers({});
await reader.spaces({});
assert.equal(reads, 2);
assert.equal(captures, 2);
for (const code of [
"cancelled",
"cleanup_incomplete",
"capacity",
"command_failed",
]) {
const expected = new FactFailure(code, "native failed", {
reason: "actual",
});
const failing = new NativeCatalogReads(
async () => {
throw expected;
},
() => assert.fail("must not read"),
() => {},
);
await assert.rejects(failing.spaces({}), (e) => e === expected);
}
const unavailable = new NativeCatalogReads(
() => assert.fail("must not launch"),
() => assert.fail("must not read"),
() => {
throw new FactFailure("capability_unavailable", "not configured");
},
);
await assert.rejects(
unavailable.registers({}),
(e) => e.code === "capability_unavailable",
);
});
@@ -0,0 +1,10 @@
// Shared native address/storage syntax; caller/callee interpretation stays separate.
import { z } from "zod";
import { hex } from "./native-contract.mjs";
export const nativeLocation = z.strictObject({
space: z.string().min(1),
offset: hex,
});
export const nativeStorage = nativeLocation.extend({
size_bytes: z.number().int().positive().max(0x7fffffff),
});
@@ -0,0 +1,30 @@
# Frozen LLVM native query task
Target: `/usr/lib/x86_64-linux-gnu/libLLVM-16.so.1`, SHA-256 `f62d254b7f2bf42df8c8b07d46ee3bb4c2cafeca436b2e6bc6ccbe4581f58f40`.
Engine: `be6d1882b436c04cb37c73ae30683cd2cce91804930197ece30e2a16a9a31ec9`. Opt-in `REA_ATOMIC_NATIVE_STRING_QUERY=1`.
Independent ELF64 PT_LOAD/file checks in `verify-string-query-machine.py` validate the five selected ASCII spans, preceding NUL, complete text, terminator and exact windows. The complete old native producer golden establishes 602,544 candidates, four objects for `undefined symbol` and one for `Invalid bitcode signature`; it does not prove artifact-wide recognition. All five selected objects contain their query once.
| Address | Bytes incl. NUL | Inclusive end | First 16 bytes | Final 8 bytes |
| --------- | --------------: | ------------- | -------------------------------- | ---------------- |
| 0x40c983e | 48 | 0x40c986d | 756e61626c6520746f206576616c7561 | 796d626f6c202700 |
| 0x4183e47 | 117 | 0x4183ebb | 20456d697474696e6720746865736520 | 727563746f727300 |
| 0x41ece4a | 38 | 0x41ece6f | 696e76616c6964207265666572656e63 | 2073796d626f6c00 |
| 0x420ad6b | 45 | 0x420ad97 | 756e737570706f727465642072656c6f | 796d626f6c202700 |
| 0x40983c8 | 26 | 0x40983e1 | 496e76616c696420626974636f646520 | 676e617475726500 |
Exact selected texts (in the same order):
- "unable to evaluate offset to undefined symbol '".
- " Emitting these undefined symbol references causes us to link the libgcc code that runs our constructors/destructors".
- "invalid reference to undefined symbol".
- "unsupported relocation of undefined symbol '".
- "Invalid bitcode signature".
Both queries share artifact and engine identity, but distinct selected reports, not a raw whole-inventory source. Source IDs and hashes contain a private pathname and vary by lease; report actual complete-capture metadata and verify small Evidence windows from both query sources. Source_row is a native canonical ordinal under the declared scan settings. Different page/detail captures can also have distinct source IDs.
An answer must preserve unknown artifact discovery, not-computed string reference attribution, static loaded-image versus live memory, and absence of target execution. Neither substring presence nor provider candidate counts prove source-object boundaries or runtime use. Retain original model answers, failures and costs; do not repair answers or select a winning retry.
Allow equivalent compositions: exact subwindows can come from a focused covering byte read with truthful capture versus derived lengths. Do not require ten native byte commands or penalize valid reuse. All claimed byte evidence must cover the expected addresses and values in the actual raw captures.
Direct and Code Mode use the same 19 methods and committed runtime, with the same client JavaScript dispatch, question, requested model/reasoning, static authority and resource guard. Code Mode must actually invoke the isolated MCP execution tool. Measure full actual cumulative tokens including cached/uncached input, output/reasoning, catalog/help/retries, calls, wall, local CPU and kernel family peak. Remote computation/cache/model build remain unmeasured. This local static inventory task is not a proof of general complex-software RE superiority or Ghidra/IDA parity.
Loaded 100 of 240 files, more files were not shown because too many files have changed in this diff. Show more