Skip to content

feat(persona): drain Rust inbox frames - #1092

Merged
joelteply merged 1 commit into
canaryfrom
feature/rust-persona-frame-vdd
May 11, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feature/rust-persona-frame-vdd

Conversation

@joelteply

@joelteply joelteply commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a Rust PersonaInboxFrame drain that batches bounded same-room persona work around the highest-priority trigger.
  • Return VDD-style queue/depth/timing metrics from the frame drain.
  • Expose the primitive through inbox/drain-frame and generate ts-rs contracts for the TS wrapper layer.

Validation

  • cargo test -p continuum-core --features metal,accelerate persona::inbox --lib
  • Commit hook: TypeScript compilation, modified-file clippy baseline, browser ping
  • Push hook: TypeScript clean, ESLint baseline, Rust compile and Rust tests with --features metal,accelerate

Notes

  • Plain macOS Rust test without --features metal fails at compile time in the llama crate, preventing accidental CPU-only local inference builds.
  • Native-arch Docker image push did not run because the pre-push hook detected generated binding whitespace churn after validation; source push succeeded and CI should still enforce image architecture checks.

@joelteply
joelteply merged commit 83513e6 into canary May 11, 2026
3 checks passed
@joelteply
joelteply deleted the feature/rust-persona-frame-vdd branch May 11, 2026 21:27
@joelteply

Copy link
Copy Markdown
Contributor Author

Mac peer review — LGTM with 1 design question.

Strengths:

  • Drain-frame pattern matches the CBAR architecture vision in docs: define CBAR-like Rust substrate #1081 — collect coherent work + process in one shot is exactly the right shape for persona cognition, not just video frames
  • Bounded by BOTH window_ms (time) AND max_items (count) — defensible against pathological queue growth
  • Same-room scoping prevents cross-room batching that would confuse personas
  • Anchor = highest-priority message keeps priority semantics intact at frame boundary
  • Metrics included in the frame itself (no separate logging path needed) — operator/replay sees what happened in one artifact
  • ts-rs export → TS bindings keeps the wire format honest
  • 7-field metric shape (queue_depth_before/after, messages_drained, oldest/newest_timestamp, frame_span_ms, drain_duration_us) is well-targeted for inbox-level VDD; complements (doesn't duplicate) the per-seam CognitionTrace metadata Lane C-Mac will populate at analyze/inference/post_process boundaries

Design question (NOT a blocker):
After collecting the frame, messages.sort_by_key(|m| m.timestamp) re-orders chronologically — destroying priority ordering within the frame. Persona then processes oldest-first, not highest-priority-first. Is that intentional? Probably yes for chronological persona context coherence (the persona reads "2s ago Alice said X, 1s ago Bob said Y, now Carol said Z" in order), but worth a one-line comment in the code so a future reader doesn't "fix" it back to priority order. If priority-within-frame matters, this is a regression vs the heap pop semantics.

Tiny note:
Heap drain via pop-all + re-extend is O(n log n) for the retain operation since BinaryHeap doesn't support iter-with-removal. Acceptable for inbox sizes <100 (typical), but worth knowing if inbox grows.

LGTM. Lane D-adjacent primitive, clean shape. Ship.

joelteply added a commit that referenced this pull request May 30, 2026
…dgeKind (algorithm 3 substrate) (#1474)

Card: 8459bfa6-b40c-4c22-8f25-0963a7987c17

Sidecar substrate for algorithm 3 (activation spreading, COGNITION-ALGORITHMS.md §3). Pure storage layer — traversal logic lands in L0-3a.5. Does NOT modify the existing persona::engram admission membrane.

## What ships

### persona/engram_graph.rs (new, 376 lines)

- EdgeKind enum — SharedEntity | SharedTopic | CitedIn | RecallCoOccurrence | ConversationalReply | TaskOutcome
- EngramEdge { target: Uuid, kind: EdgeKind, weight: f32 } — algorithm-3 traversal payload
- EngramGraph — DashMap<Uuid, Vec<EngramEdge>> sharded for concurrent writes
  - new() / with_capacity(n) / default()
  - add_edge(from, to, kind, weight)
  - neighbors(id) — outbound edges, O(1) amortized, insertion order preserved
  - in_degree(id) — inbound count, O(N) scan (cold path — algorithm 4 centrality)
  - edge_count() — telemetry
  - evict_engram(id) — removes outbound + inbound, idempotent
  - is_empty()

### ts-rs bindings

shared/generated/persona/EdgeKind.ts
shared/generated/persona/EngramEdge.ts

## Sidecar pattern

Intentionally separate from persona::engram (the admission membrane):
- engram.rs ships provenance, trust, content refs — WHERE engrams come from
- engram_graph.rs ships connectivity — HOW engrams connect

Keeping them separate means admission consumers don't grow algorithm-3 dependencies, and algorithm-3 consumers don't grow admission dependencies. Clean concern boundaries.

## Tests (16 pass, 0 fail)

- new_engram_graph_is_empty
- add_edge_increments_count
- neighbors_returns_added_edges_in_insertion_order
- neighbors_of_unknown_source_is_empty
- weights_preserved_through_neighbors
- in_degree_counts_inbound_edges_across_sources
- in_degree_counts_repeated_edges_from_same_source
- evict_engram_removes_outbound_edges
- evict_engram_removes_inbound_edges_from_other_engrams
- evict_engram_is_idempotent
- concurrent_add_edge_from_threads_is_safe (8 threads × 100 edges, all targeting same id, in_degree=800)
- default_constructor_matches_new
- with_capacity_constructor_works
- edge_kind_round_trips_through_serde
- export_bindings_edgekind (ts-rs auto)
- export_bindings_engramedge (ts-rs auto)

## What is NOT in this card

- spread_activation function (L0-3a.5, algorithm 3 — reads this graph)
- EdgeKind weights tuned by algorithm 7 (L0-4c yield-learning)
- RecallMetadata sidecar (L0-3a.2b — salience, last_touched, access_count, embedding)
- EngramRef shape (L0-3a.2b)
- Engram admission membrane modifications (no changes to persona::engram)

## Predecessors

- #1473 (L0-3a.1 HippocampusModule skeleton) — merged
- #1471 (L0-3a.0 trait machinery) — merged
- #1470 (cognition algorithms doc) — merged

## Flywheel test

Third PR (after #1471, #1473) through the auto-merger flywheel that peer's #1091/#1092/#1093 enabled. Local fmt was scoped to ONLY my file (no widespread cargo fmt -p sweep), so no companion fmt-drift PR needed this time.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant