fix(codegen): emit the declared cgi identity — it was searched for in a list that cannot contain it #87

Closed
tim.lingo wants to merge 2 commits from fix/cgi-identity-emission into main
Member

A cgi block declares an agent's compound identity — name, dharma_id, principal, network, engram. None of it reaches the compiled output. Every binary built with this compiler carries no declared identity at all, which is what IDPROTO claims 1-2 require it to carry.

The bug

A cgi block is a top-level declaration, so codegen_streaming classifies it with is_top_level_decl and calls el_release(stmt) — correctly; it isn't executable. The identity emission then searched toplevel_exec_stmts for that same block. Declarations are excluded from that list by construction, so the search could never succeed.

A probe printing what the search actually sees, for a program whose first statement is a cgi block:

[TES] toplevel_exec_stmts length=2
[TES]   stmt=Let
[TES]   stmt=Expr

The code documented its own assumption — "Since cgi blocks are rare and small, they end up in toplevel_exec_stmts" — and that assumption was false. It emitted nothing, silently, with no diagnostic on any channel.

The fix

Capture the declared values before the release (they're strings, so no dangling reference) and emit from those. The search is deleted rather than repaired, so the failure mode is removed rather than relocated.

Proven discriminating — old fails, new passes

old compiler this branch
minimal cgi program 0 el_cgi_init el_cgi_init with all four declared values
neuron soul binary principal absent principal present
boot 2s
interface 110 routes in, 110 out

And at runtime, first line of stdout before the soul boots:

[cgi] identity: name=neuron-soul dharma_id=ntn-genesis@http://localhost:7770 principal=william-christopher-anderson network=dharma-mainnet engram=http://localhost:8742

Notes for whoever builds this

  • compiler.el imports lexer/parser/codegen, so the existing elc bootstraps it directly. lang/elc-combined.el is stale (Jun 5) and was not used.
  • lang/elc.c does not build against the pinned v1.0.0-20260501 release runtime — it needs lang/el-compiler/runtime (missing stdout_to_file / stdout_restore). That cost an afternoon; worth documenting.

Rung: E2E-VERIFIED in an isolated lab. The rebuilt compiler is not installed anywhere.

Companion: neuron-technologies/neuron branch feat/cgi-identity-accessors, which adds read-only accessors so a consumer can actually read the compiled constant. Without this codegen fix those accessors return empty.

A `cgi` block declares an agent's compound identity — name, dharma_id, principal, network, engram. **None of it reaches the compiled output.** Every binary built with this compiler carries no declared identity at all, which is what IDPROTO claims 1-2 require it to carry. ## The bug A `cgi` block is a top-level *declaration*, so `codegen_streaming` classifies it with `is_top_level_decl` and calls `el_release(stmt)` — correctly; it isn't executable. The identity emission then searched `toplevel_exec_stmts` for that same block. Declarations are excluded from that list by construction, so the search could never succeed. A probe printing what the search actually sees, for a program whose first statement is a `cgi` block: ``` [TES] toplevel_exec_stmts length=2 [TES] stmt=Let [TES] stmt=Expr ``` The code documented its own assumption — *"Since cgi blocks are rare and small, they end up in toplevel_exec_stmts"* — and that assumption was false. It emitted nothing, silently, with no diagnostic on any channel. ## The fix Capture the declared values before the release (they're strings, so no dangling reference) and emit from those. The search is deleted rather than repaired, so the failure mode is removed rather than relocated. ## Proven discriminating — old fails, new passes | | old compiler | this branch | |---|---|---| | minimal `cgi` program | 0 `el_cgi_init` | `el_cgi_init` with **all four declared values** | | neuron soul binary | principal **absent** | principal **present** | | boot | — | 2s | | interface | — | 110 routes in, 110 out | And at runtime, first line of stdout before the soul boots: ``` [cgi] identity: name=neuron-soul dharma_id=ntn-genesis@http://localhost:7770 principal=william-christopher-anderson network=dharma-mainnet engram=http://localhost:8742 ``` ## Notes for whoever builds this - `compiler.el` imports lexer/parser/codegen, so the existing `elc` bootstraps it directly. `lang/elc-combined.el` is stale (Jun 5) and was not used. - `lang/elc.c` does **not** build against the pinned `v1.0.0-20260501` release runtime — it needs `lang/el-compiler/runtime` (missing `stdout_to_file` / `stdout_restore`). That cost an afternoon; worth documenting. Rung: E2E-VERIFIED in an isolated lab. The rebuilt compiler is **not** installed anywhere. Companion: `neuron-technologies/neuron` branch `feat/cgi-identity-accessors`, which adds read-only accessors so a consumer can actually read the compiled constant. Without this codegen fix those accessors return empty.
tim.lingo added 2 commits 2026-08-09 18:47:33 +00:00
Measured on the live container mind (pinned 40-query eval, judged): substring
2/40=5% hit@5 -> ranked 35/40=88%. Multi-word queries stop returning zero; new
memories stop losing to storage order (created_at tiebreak). Transparent-layer
identity filter preserved in both passes; jb_finish (#64) tail preserved.
query_param now url_decode()s values - %XX arrived literal before (pre-existing
GET defect, masked while multi-word substring returned nothing anyway).
E2E-verified in Tim's container deployment 2026-07-14/15; eval harness:
docs repo research-archive/p0-prototypes/eval_pinned_40q_20260715.py.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A cgi block is a top-level declaration, so codegen_streaming classifies it via
is_top_level_decl and releases it. The identity emission then searched
toplevel_exec_stmts for that same block. Declarations are excluded from that list by
construction, so the search could never succeed. A probe printed what it actually
saw for a program whose first statement is a cgi block: [Let, Expr]. It emitted
nothing, silently, with no diagnostic on any channel.

The code documented its own assumption — 'Since cgi blocks are rare and small, they
end up in toplevel_exec_stmts' — and that assumption was false.

Capture the declared values before the release and emit from them. The search is
deleted rather than repaired, so the failure mode is removed rather than relocated.

Proven discriminating (old fails, new passes):
  minimal cgi program, old   -> 0 el_cgi_init
  minimal cgi program, fixed -> el_cgi_init with all four declared values
  neuron soul, fixed         -> principal present in the compiled binary (0 before),
                                boots in 2s, interface 110 routes in / 110 out

Consequence: a binary now carries its declared identity as a compiled constant,
which is what the identity protocol requires. Whether the runtime surfaces it to
state_get("soul_principal") is unverified and separate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tim.lingo closed this pull request 2026-08-09 18:49:01 +00:00
This repo is archived. You cannot comment on pull requests.