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

Closed
tim.lingo wants to merge 1 commits from fix/cgi-identity-emission-clean 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 1 commit 2026-08-09 18:49:21 +00:00
fix(codegen): emit the declared cgi identity — it was searched for in a list that cannot contain it
El SDK Release / build-and-release (pull_request) Failing after 13m58s
El SDK CI - dev / build-and-test (pull_request) Failing after 10m32s
866c75e5e2
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 19:13:02 +00:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.