Skip to content

Core correctness and API ergonomics - #3

Merged
scrogson merged 7 commits into
mainfrom
core-correctness-and-api-ergonomics
Feb 20, 2026
Merged

scrogson merged 7 commits into
mainfrom
core-correctness-and-api-ergonomics

Conversation

@scrogson

Copy link
Copy Markdown
Owner

Summary

  • Phase 1 - Process API Surface: Expose link, unlink, monitor, demonitor, flag, send_after as top-level ambitious:: convenience functions, plus new ProcessFlag enum
  • Phase 2 - GenServer Ergonomics: Add ServerRef type (address GenServers by PID or registered name), update call/cast to accept impl Into<ServerRef>, add public reply() for deferred replies and stop() for graceful shutdown
  • Phase 3 - Supervisor Completeness: Replace terminate_child/delete_child stubs with real implementations using OTP-faithful command message pattern; add new restart_child function
  • Phase 4 - Application Fixes: Remove unsafe block from AppController by switching from Box to Arc function pointers; fix stop_all to use reverse dependency ordering
  • Phase 5 - Documentation Sync: Update CLAUDE.md and README.md to match the actual codebase (single-crate structure, &mut self GenServer handlers, Reply<T>/Status/Init<Self> return types, correct trait signatures)

Test plan

  • All 298 tests pass (just ci green: fmt, clippy, tests)
  • Zero warnings with #[deny(warnings)]
  • No unsafe code remaining in application module
  • Backward-compatible: existing Pid arguments still work via From<Pid> for ServerRef
  • New supervisor commands tested: terminate (success, idempotent, not-found), delete (running error, success after terminate, not-found), restart (already-running error, success after terminate, start count verification)

Covers 5 phases: Process API surface, GenServer ergonomics (ServerRef,
reply, stop), Supervisor completeness (terminate/delete/restart_child),
Application fixes (remove unsafe, fix stop_all ordering), and
documentation sync.
…_after

Expose Erlang/OTP-style process primitives as top-level convenience
functions that delegate to task-local context, matching the existing
pattern used by current_pid(), send(), recv(), and exit().

- Add ProcessFlag enum (TrapExit variant) in core module
- Add link/unlink for bidirectional failure propagation
- Add monitor/demonitor for unidirectional process observation
- Add flag() for setting process flags (returns previous value)
- Add send_after() convenience wrapper with OTP argument order
- Export all new functions from runtime, lib.rs, and prelude
- Add integration test verifying all new functions work in process context
Phase 2 of the core correctness and API ergonomics plan:

- Add ServerRef type for addressing GenServers by Pid or registered name
- Update call() and cast() to accept impl Into<ServerRef> instead of Pid
- Add public reply() function for deferred reply pattern (NoReply + later reply)
- Add public stop() function for graceful GenServer shutdown
- Update lib.rs prelude re-exports to include ServerRef, reply, stop
- Remove #[allow(dead_code)] from encode_stop (now used by stop())
- Add tests for ServerRef conversions, resolve, call with ServerRef, and stop
…start)

Replace stub implementations of terminate_child and delete_child with real
message-passing command pattern using TaggedEnvelope protocol. Add new
restart_child public API. Fix wait_for_termination to use task-local
context instead of global runtime.
Replace raw pointer extraction with Arc::clone for safe access to
application start functions across RwLock boundaries. The previous
approach extracted a raw pointer from a Box behind a RwLock guard
and used it after the guard was dropped via an unsafe block.

Also fix stop_all to properly stop applications in reverse dependency
order using visit_deps, rather than relying on arbitrary HashMap
iteration order.
Sync documentation with the real code after Phases 1-4 consolidated the
project into a single crate with updated APIs:

- Crate structure: single `crates/ambitious/` crate, not multi-crate
- GenServer: self-as-state pattern with &mut self handlers, Init/Reply/Status return types
- Supervisor: SupervisorInit with SupervisorFlags, RuntimeHandle-based client API
- Term/Message: separate traits (Term for serialization, Message for tagged dispatch)
- Process API: updated signatures (SendError, Result returns, current_pid)
- Build commands: cargo test -p ambitious (not ambitious-process)
@scrogson
scrogson merged commit be9f4e1 into main Feb 20, 2026
4 checks passed
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.

1 participant