Skip to content

refactor(sentinel): port sentinel/escalate to pure Rust — kill the TS round-trip (task #225, Stage B PR 1/3) - #1570

Merged
joelteply merged 1 commit into
canaryfrom
refactor/migrate-ts-commands-stage-b
Jun 9, 2026
Merged

joelteply merged 1 commit into
canaryfrom
refactor/migrate-ts-commands-stage-b

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Squash from branch. See commit for full body.

… round-trip (task #225, Stage B PR 1/3)

First migration in the Stage B push Joel asked for: "port commands
next, as we clean them up with our idealism." `sentinel/escalate` was
the smallest, most self-contained call site that Stage A made
visible — pure substrate plumbing (no external integrations), two
call sites in one module, zero TS-side callers, easy to validate.

## What this kills

- `src/commands/sentinel/escalate/` (whole command dir — receiver
  that only Rust ever called)
- `src/system/sentinel/SentinelEscalationService.ts` (handler service)
- The re-export in `src/system/sentinel/index.ts`
- The `SENTINEL_ESCALATE` constant in `generated-command-constants.ts`
- The two entries in `src/server/generated.ts` + `src/browser/generated.ts`

After this, no TS source references the escalate command. The
substrate has one fewer round-trip on every sentinel completion.

## What replaces it

`core/continuum-core/src/modules/sentinel/escalation.rs` — a
substrate-pure dispatcher with the same three-stage pipeline the TS
service had, but compressed:

1. **Persist** the `SentinelExecutionResult` into the `sentinels`
   entity via `data/list` + `data/update`.
2. **Escalate** an `InboxTaskRecord` into the `tasks` collection
   via `data/create`. The TS version branched on
   `getPersonaInbox(...)` for online vs offline personas; the Rust
   version unifies on `data/create` because `ChannelModule::tick`
   already polls the `tasks` collection and routes pending tasks
   into the live `PersonaInbox`. **One path, not two.**
3. **Store** the terminal event as a `SentinelMemoryRecord` in
   the persona's `memories` collection.

Each downstream collection has its own private struct
(`SentinelExecutionResult`, `InboxTaskRecord`, `SentinelMemoryRecord`)
with `#[serde(rename_all = "camelCase")]`, so the field set is
enforced at the type level. Per Joel's mid-flight reminder on the
escalate work ("use good structs, well formulated"): no
`serde_json::json!` blobs at the call site, no `Value` pass-through.
Everything that crosses a serialization boundary is a typed record.

## Typed escalation primitives

Promoted the `SentinelEscalation.escalation_rules` field from
`Option<Value>` (TS pass-through) to `Option<Vec<EscalationRule>>`
now that Rust owns the schema. The wire enums
(`EscalationCondition` / `EscalationAction` / `EscalationPriority`)
get ts-rs exports so the TS side still has a typed view. New
helper `EscalationPriority::inbox_priority()` mirrors the TS
`PRIORITY_MAP` literal — covered by a unit test so a future
rename can't silently drift.

## New typed event surface

`SentinelEscalationEvent` bundles the terminal-status fields the
two completion paths already had locally (`handle`, status,
duration, error, escalation metadata). The two call sites in
`SentinelModule` now build the event from in-process Rust values
and call `escalation::dispatch(&executor, event).await` instead of
`executor.execute_ts_json("sentinel/escalate", json!(...))`.

`SentinelTerminalStatus` encodes the Completed / Failed / Cancelled
trichotomy with named helpers for the slug-to-string mappings
(inbox `taskType`, matched `EscalationCondition`, memory
importance) — so the slug taxonomy lives in one place instead of
duplicated TS ternaries.

## Substrate-pure unification

The TS service had two branches in `escalateToPersonaInbox`:
- Online persona -> in-memory `inbox.enqueue(task)`
- Offline persona -> `DataCreate.execute({collection: 'tasks', data: task})`

The Rust dispatcher does only the second. Why: `ChannelModule::tick`
already polls the `tasks` collection on every tick and routes pending
tasks through the per-persona `PersonaInbox`. The channel tick IS
the online/offline rendezvous. Two TS code paths become one Rust
code path — the channel routing layer was already doing the
work, the TS service was duplicating it.

## Verified

  cargo check -p continuum-core --lib --features metal,accelerate                 -> clean
  cargo test  -p continuum-core --lib --features metal,accelerate modules::sentinel:: -> 138/138
  cargo test  -p continuum-core --lib --features metal,accelerate escalation::    -> 5/5

The 5 new escalation unit tests pin the TS-contract surface:
- inbox priority scalars match the TS `PRIORITY_MAP` literal
- failed + cancelled both route through the `Error` condition
- task-type slugs match the TS literal set (`sentinel-complete` /
  `sentinel-failed` / `sentinel-escalation`)
- default escalation rules include `Complete=Notify+Low`
- `InboxTaskRecord` serializes to camelCase so
  `ChannelModule::data_to_task_queue_item` keeps parsing it

## Doctrinal alignment

- `[[no-fallbacks-ever]]` — escalation is no longer a TS-bridge
  fallthrough; failure surfaces as a typed `String` from each
  stage and is logged via `tracing::warn!`.
- `[[rust-is-the-core-node-is-the-shell]]` — every collection
  the dispatcher touches (`sentinels`, `tasks`, `memories`) is
  Rust-owned. The TS bridge for this command is dead.
- `[[rethink-dont-port-commands-to-rust]]` — the online/offline
  branch in the TS version was redundant with the channel tick;
  the Rust port removes it.

## What's next (Stage B PRs 2 + 3)

- Task #226: delete the feature-gated legacy `livekit_agent.rs`
  `execute_ts_json("collaboration/live/transcription")` call —
  pure deletion, dead surface (bridge_client is the active LiveKit
  path).
- Task #227: migrate `genome/job-create` — channel tick's LoRA
  training trigger. Bigger than escalate; genome is substantial
  Rust-side already.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@joelteply
joelteply merged commit e46671a into canary Jun 9, 2026
4 of 6 checks passed
@joelteply
joelteply deleted the refactor/migrate-ts-commands-stage-b branch June 9, 2026 06:23
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