Skip to content

contract: per-class lane layout, chosen at compile time and resolved through ClassView - #1839

Merged
AdaWorldAPI merged 4 commits into
mainfrom
ccr-39105428-bcm2m2-lane-spec
Oct 28, 2026
Merged

AdaWorldAPI merged 4 commits into
mainfrom
ccr-39105428-bcm2m2-lane-spec

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

#1837 made a sparse write skip absent lanes, but over a fixed lab layout. This replaces that layout with one each class declares at compile time. The ClassView resolves it once per class.

Contract: lane_codec (new, zero-dep, additive)

  • EpiLaneSpec holds:
    • width (8 or 9 bits);
    • code space (Sym / Asym);
    • value offset;
    • presence offset;
    • lane count.
  • Compile-time choice. A consumer states the layout as EpiLaneClass::SPEC, built with checked(), so an invalid layout fails to compile (a compile_fail doctest pins this).
  • The presence plane is mandatory. A lane is absent (NaN, $null, UNKNOWN) when its presence bit is 0 and its value is 0. This holds at 8 and 9 bits alike, and it is the only absent code.
    • At 9 bits the presence bit is also the sign, so presence 0 with a nonzero magnitude is a negative value (DR512, matching ndarray codec9).
    • A 9-bit lane must be Sym.
  • ONNX QuantizeLinear / TFLite annotations choose the code space through CodeSpace::from_zero_point (zero point 0 = Sym).
  • ClassView::epi_lanes(class) names the same constant for a classid. The default None means undeclared, and binding refuses, as epistemic_reading already does.

Probe

  • Bind once. ThoughtTables::bind_lanes::<L>(view, class) checks the ClassView once. It returns a LaneBinding<L>, or Refusal::LaneLayout when the class declares no layout or a different one.
  • Writes take the binding. write_epi(&binding, …) does not look the class up again.
  • Sharing a binding. A binding shared across threads belongs in a OnceLock set when the registry loads. LazyLock doesn't fit, because its initializer cannot take the view.
  • 9-bit lanes still go through EpiLane9::never_touched, and a test checks that the contract rule and codec9 agree on all 512 codes.

Tests

  • Contract, 7 unit tests and 2 doc tests:
    • each validation rule refuses;
    • adjacent regions pass;
    • absent is exactly one of the 512 (value, presence) pairs;
    • presence bits past the first byte are read;
    • zero point maps to code space.
  • Probe, 19 tests in all:
    • binding refuses an undeclared or different layout;
    • an absent lane is not written (DR512 and ONNX uint8);
    • the thought's own earlier value is kept;
    • a 9-bit negative is written;
    • a computed −0.499 is written as +0;
    • an absent lane beside a change leaves only the change stored;
    • an asym code 0 is written;
    • a sym int8 code −128 with presence 1 is a value.
  • Eight disables, each red: bind check, keep step, presence-bit copy, presence-only test, value-only test, presence byte offset, overlap check, 9-bit Asym.
  • Other checks:
    • the contract's full suite passes;
    • contract clippy (-D warnings) and cargo fmt --check are clean;
    • clippy reports nothing in the probe.

Open

Mapping the 32-bit row classid to ClassView's u16 ClassId is left to the caller; the probe takes ClassId as an argument instead of doing bit math on the key.

Board: .claude/board/entries/2026-10-28-lane-layout-from-classview.md.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XAqKMPWTwovjYJEUMuGPb4

…es it

lane_codec: EpiLaneSpec (width, code space, never-touched code, value and
presence offsets) declared by the consumer as EpiLaneClass::SPEC, built with
checked() so an invalid layout fails to compile. ONNX/TFLite annotations map
through CodeSpace::from_zero_point. ClassView::epi_lanes names the same
constant for a classid; None = undeclared, and a writer refuses.

thought_layers_probe: write_epi is generic over the class layout and refuses
when the ClassView declares none or another one. 9-bit lanes still use
ndarray codec9's never_touched; a test pins that the contract rule and the
codec agree on all 512 codes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMPWTwovjYJEUMuGPb4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMPWTwovjYJEUMuGPb4
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2dd343e8-d7b7-471e-84fc-4fa989fac0a3
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…; bind once

The presence plane is not optional: every lane has a presence bit, and a
lane is absent when its presence bit is 0 and its value is 0, at 8 and 9
bits alike. NanCode (None, SymMin) is removed and the presence offset is
required. A 9-bit lane must be Sym.

The probe binds a class to its layout once (bind_lanes checks the ClassView
and returns a LaneBinding<L>); writes take the binding and do not look the
class up again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMPWTwovjYJEUMuGPb4
@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review October 28, 2026 17:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T18:01:15.154992Z c393f65 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@AdaWorldAPI
AdaWorldAPI merged commit 694b243 into main Oct 28, 2026
25 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c393f651fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +149 to +150
let v_end = self.values + self.lanes as u16;
let p_end = self.presence + self.presence_bytes();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent offset overflow before validating slab bounds

When validate() is called at runtime with an offset near u16::MAX, these additions overflow before the bounds checks run. For example, a Bits8/Sym spec with values: 65535, presence: 96, and lanes: 16 returns Ok(()) in an optimized build, despite lying outside the 512-byte row; reading a value through that accepted spec then panics. Debug builds instead panic during validation rather than returning SpecError::OutOfSlab. Widen the arithmetic or use checked addition so invalid offsets are consistently refused.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants