Skip to content

test: add Thalamic → corpus-ipc → Brainstem CPU smoke harness - #56

Merged
rmems merged 12 commits into
mainfrom
cursor/thalamic-corpus-ipc-smoke-368b
Sep 17, 2026
Merged

rmems merged 12 commits into
mainfrom
cursor/thalamic-corpus-ipc-smoke-368b

Conversation

@rmems

@rmems rmems commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

User description

User description

Closes #43 (LIM-1135).

Adds a CPU-only integration smoke that proves a representative telemetry frame can cross the published corpus-ipc 0.1 contract into a loaded Brainstem runtime without Thalamic owning an SNN.

Merged onto current main after #53 (liveness / readiness / degraded health). Distill sidecar restore, neuromod 0.6, crates.io corpus-ipc 0.1, bounded ingress queues, the deterministic restart/fault-injection harness, and the health reporter from #53 are kept from main. This PR adds typed JSON IpcMessage ingress, run_for_ticks / RuntimeStats, and the Thalamic fixture.

What landed

  • tests/thalamic_brainstem_smoke.rs plus tests/fixtures/thalamic_producer.rs (no neuromod / SpikingNetwork).
  • Typed ingress validation (src/ingress/corpus.rs, --features corpus-ipc) over IpcMessage::Stimuli(StimulusBatch): width, freshness, future timestamps, valid_mask, session_id, schema token corpus-ipc.stimulus.v1.
  • ZMQ SUB decodes JSON IpcMessage frames; modulator-only frames are drained in the same tick; rejected frames still advance the network and increment rejected_batches.
  • BrainstemDaemon::run_for_ticks for bounded, signal-free ticks (always shuts down the source, even if sink flush fails). It calls StimulusSource::initialize the same way run does after feat(runtime): separate liveness, readiness, and degraded health #53.
  • Live restore still uses Distill sidecar JSON (restore_network); the smoke writes a sidecar fixture rather than a neuromod serde envelope.

Review follow-up

Addressed CodeAnt, Codex, cubic, Cursor Bugbot, DeepSource, and Codacy findings: future timestamps, zero-width new(), safety_healthy clobber, try_exists, clone_from/reuse of modulator buffers, ephemeral ZMQ bind via get_last_endpoint, RAII temp dirs under CARGO_TARGET_TMPDIR, Default for ThalamicProducer (explicit healthy fields; new() calls Default), rejected-frame tick accounting, idle-tick modulator hold, splitting schema/freshness checks out of accept_stimulus_batch, and Option::map_or_else for the smoke fixture scratch root.

How to test

cargo fmt --check
cargo clippy --locked --all-targets -- -D warnings
cargo test --locked
CC=gcc CXX=g++ cargo clippy --locked --all-targets --all-features -- -D warnings
CC=gcc CXX=g++ cargo test --locked --all-features

Linear Issue: LIM-1135

Open in Web Open in Cursor 

Summary by cubic

Closes #43 (LIM-1135). Adds a CPU-only smoke harness where a Thalamic fixture with no spiking network publishes a typed IpcMessage::Stimuli(StimulusBatch) frame through the corpus-ipc contract into a loaded Brainstem runtime, gated behind --features corpus-ipc so default stub builds don't need libzmq. The runtime loads model_path as a JSON checkpoint instead of silently building a blank network, and ZMQ ingress decodes and validates typed JSON frames instead of the legacy binary readout packet. The smoke runs through BrainstemDaemon::run_for_ticks.

Bug Fixes

  • Ingress rejects wrong widths, stale or future timestamps, bad schema tokens, and unexpected IpcMessage variants; rejected frames are counted but the tick loop still advances the network.
  • Idle ZMQ ticks hold the last neuromodulator snapshot so dopamine, cortisol, acetylcholine, and tempo don't reset.
  • Checkpoint loading fails closed on wrong schema, dimension mismatch, non-finite parameters, or blank weights; missing files fall back to a blank network, and try_exists errors fail loudly.
  • session_id and valid_mask survive the wire, and modulator-only frames are drained within the same tick.
  • run and run_for_ticks share source initialization and checkpoint boot through boot_network, so a ZMQ source is not double-connected and health events stay in lockstep.

Dependencies

  • Uses corpus-ipc 0.1.0 from crates.io with its IpcMessage / StimulusBatch types; the ZMQ SUB source connects via CORPUS_IPC_ZMQ_READOUT_IPC.
  • Bumps MSRV to 1.98.1 so corpus-ipc 0.1.0 compiles.

Written for commit 25f22e4. Summary will update on new commits.

Review in cubic


CodeAnt-AI Description

Validate typed stimulus ingress and run bounded Thalamic-to-Brainstem CPU smoke tests

What Changed

  • Brainstem now accepts typed corpus-ipc JSON stimulus batches with schema, channel width, timestamp freshness, future-time, and payload validation.
  • Stimulus metadata such as validity masks, batch IDs, timestamps, and producer sessions is preserved; invalid channels are excluded from network input.
  • Rejected frames no longer stop the tick loop, and runtime statistics report accepted, rejected, and processed batches.
  • Neuromodulator-only frames are drained without delaying sensory input, while idle ticks retain the latest neuromodulator values.
  • Added a CPU-only integration smoke covering Thalamic telemetry, checkpoint loading, IPC round-tripping, rejection handling, and safety behavior when Brainstem is unavailable.

Impact

✅ Fewer tick-loop interruptions from invalid IPC frames
✅ Clearer rejection of stale, incompatible, or malformed stimuli
✅ Preserved missing-channel and neuromodulator state across idle ticks

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

LIM-1135 / GH#43. Load an explicit JSON checkpoint, decode published
IpcMessage::Stimuli frames (valid_mask included), reject schema
incompatibility, and keep the Thalamic fixture healthy when Brainstem
is unavailable. Pin corpus-ipc 0.1.0 and MSRV 1.98.1.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
@linear-code

linear-code Bot commented Sep 15, 2026

Copy link
Copy Markdown

LIM-1135

@rmems
rmems marked this pull request as ready for review September 15, 2026 05:22
@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Essentials

Run ID: 0f249e7c-ce78-44f7-b741-14c155111b9c

📥 Commits

Reviewing files that changed from the base of the PR and between 57ff758 and be808bc.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • Cargo.toml
  • README.md
  • docs/ci.md
  • src/backend.rs
  • src/checkpoint/mod.rs
  • src/daemon.rs
  • src/ingress/corpus.rs
  • src/ingress/mod.rs
  • src/ingress/tests.rs
  • src/lib.rs
  • tests/fixtures/thalamic_producer.rs
  • tests/thalamic_brainstem_smoke.rs
 ______________________________________________________________
< Ad Astra Per Codicem Fixis. To the stars through code fixes. >
 --------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
✨ Simplify code
  • Commit to this branch
  • Create a new PR

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

@codeant-ai

codeant-ai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Incremental review completed a4f8a06 Sep 17, 2026 · 21:14 21:14
✅ Reviewed your PR 22ad7e2 Sep 15, 2026 · 05:22 05:24

@codeant-ai

codeant-ai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 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-09-15T05:33:29.681026Z 22ad7e2 Draft marked ready
🔒 Security Review ✅ Completed 2026-09-15T05:31:35.023763Z 22ad7e2 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.

@codeant-ai codeant-ai Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files label Sep 15, 2026

@amazon-q-developer amazon-q-developer 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.

This PR successfully adds a CPU-only integration smoke test harness proving that telemetry frames can cross the published corpus-ipc contract into Brainstem runtime without Thalamic owning an SNN. The implementation is comprehensive and well-tested.

Key changes reviewed:

  • ✅ New checkpoint loading with explicit validation (schema version, dimensions, finite parameters, non-blank weights)
  • ✅ Typed ingress validation for corpus-ipc messages with proper width, freshness, and schema checks
  • ✅ Runtime stats tracking for bounded tick runs in test harnesses
  • ✅ Comprehensive test coverage including round-trip validation, error handling, and edge cases

Security & Quality:

  • ✅ No hardcoded credentials or sensitive data
  • ✅ Proper input validation throughout
  • ✅ Error handling follows fail-fast principles
  • ✅ Test coverage validates all acceptance criteria

No blocking defects found. The code is production-ready and well-architected.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@deepsource-io

deepsource-io Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 57ff758...25f22e4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Sep 17, 2026 9:39p.m. Review ↗
Secrets Sep 17, 2026 9:39p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@codacy-production

codacy-production Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 106 complexity · 12 duplication

Metric Results
Complexity 106
Duplication 12

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Comment thread src/checkpoint.rs Outdated
Comment thread src/backend.rs Outdated
Comment thread src/daemon.rs Outdated
Comment thread tests/fixtures/thalamic_producer.rs Outdated
Comment thread tests/thalamic_brainstem_smoke.rs Outdated
Comment thread src/backend.rs
Comment thread src/checkpoint.rs Outdated
Comment thread src/checkpoint.rs Outdated
Comment thread src/daemon.rs Outdated
Comment thread src/ingress.rs Outdated

@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: 22ad7e2099

ℹ️ 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 thread src/ingress/corpus.rs
Comment thread src/ingress/corpus.rs
Comment thread src/checkpoint.rs Outdated
Comment thread src/backend.rs
Comment thread tests/fixtures/thalamic_producer.rs Outdated
Comment thread src/ingress.rs Outdated
Comment thread src/daemon.rs Outdated
Comment thread src/ingress/corpus.rs
Comment thread tests/thalamic_brainstem_smoke.rs
Comment thread src/checkpoint.rs Outdated

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 18 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/checkpoint.rs Outdated
Comment thread src/backend.rs
Comment thread src/ingress.rs Outdated
Comment thread src/daemon.rs Outdated
Comment thread tests/fixtures/thalamic_producer.rs Outdated
Comment thread src/checkpoint.rs Outdated
Comment thread src/ingress.rs Outdated
Comment thread src/ingress.rs Outdated
Comment thread src/backend.rs Outdated
Comment thread src/checkpoint.rs Outdated

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Rejected frames skip network ticks
    • Typed ingress rejects now return skip-ingress Ok(None) instead of Err, so run_tick still advances the network on zeroed stimuli.
  • ✅ Fixed: Idle ticks drop held modulators
    • EAGAIN and rejected-frame ticks now return the last neuromodulator snapshot so idle steps keep dopamine/cortisol/acetylcholine/tempo.

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 22ad7e2. Configure here.

Comment thread src/daemon.rs
Comment thread src/backend.rs Outdated
Protocol validation failures (Ping, stale, width, other IpcMessage
variants) now skip ingress with Ok(None) instead of Err, so run_tick
still advances the SNN. Idle EAGAIN ticks return the last neuromodulator
snapshot so dopamine/cortisol/acetylcholine/tempo no longer reset.
Comment thread src/backend.rs Outdated

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Re-trigger cubic

Comment thread src/backend.rs Outdated
@rmems rmems added ci Continuous Integration testing labels Sep 17, 2026
@rmems rmems self-assigned this Sep 17, 2026
Bring the Thalamic smoke onto current main: Distill sidecar restore
(#52/#59), crates.io corpus-ipc 0.1 / neuromod 0.6 (#58), and bounded
ingress queues (#51). Keep typed JSON IpcMessage ingress and run_for_ticks.

Review fixes: reject future timestamps, count skipped-invalid frames,
drain modulator-only ZMQ frames, shutdown the source after a failed
flush, try_exists on live checkpoints, preserve session_id/valid_mask,
and RAII temp dirs in the smoke harness.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
Comment thread tests/fixtures/thalamic_producer.rs Outdated
cursoragent and others added 3 commits September 17, 2026 21:19
Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
…ingress

Implement ThalamicProducer::default with explicit healthy fields and have new()
call Default so RS-A1008 does not treat default() as a recursive Self constructor.
Reuse last_modulators via clone_from in skip_ingress.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
Split stimulus schema and freshness checks out of accept_stimulus_batch so
the function stays under the 50-line limit. Write smoke fixtures under
CARGO_TARGET_TMPDIR (or crate target/) instead of the shared system temp dir.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
Comment thread tests/thalamic_brainstem_smoke.rs Outdated
cursoragent and others added 5 commits September 17, 2026 21:30
Bring in #53 liveness/readiness/degraded health. Keep typed ingress,
run_for_ticks/RuntimeStats, valid_mask decoding, and the Codacy fixture
temp-dir plus accept_stimulus_batch split. run_tick now reports both
health events and smoke counters; run_for_ticks initializes the source
the same way as run so ZMQ is not double-connected from the binary.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
DeepSource RS antipattern: replace map + unwrap_or_else with map_or_else.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
run_tick would exceed clippy::too-many-arguments after merging #53
health reporting with RuntimeStats. Bundle those observers in TickReport.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
run and run_for_ticks both connect the stimulus source then validate
the restored network. Extract boot_network so health events stay in
lockstep and Codacy duplication from the merge stays down.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
@coderabbitai coderabbitai Bot added the documentation Improvements or additions to documentation label Sep 17, 2026
Extract drive_ticks and finish_bounded_run so the bounded smoke entry
stays under 50 lines without changing shutdown-on-flush-error behavior.

Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
@rmems
rmems merged commit 4158c6e into main Sep 17, 2026
9 checks passed
@rmems
rmems deleted the cursor/thalamic-corpus-ipc-smoke-368b branch September 17, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration documentation Improvements or additions to documentation size:XXL This PR changes 1000+ lines, ignoring generated files testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[brainstem-daemon] GH#43 — integration: add end-to-end Thalamic → corpus-ipc → Brainstem runtime smoke test

2 participants