Updated: 2025-01-26
This document describes the Self-Improvement API endpoints exposed by the Aetherra Hub, which enable manual approval and application of autonomously generated improvement proposals. These endpoints integrate with the Lyrixa GUI Self-Improve tab and support both Hot Module Reload (HMR) and manual OS restart workflows.
- Define the REST API contract for applying self-improvement proposals
- Document harmonized HTTP status codes and response schemas
- Explain the
restart_requiredflag semantics and HMR integration - Provide guidance for UI integration and error handling
- Document batch operations and approval workflows
The Self-Improvement API is part of the Aetherra Maintenance System autonomous feedback loop:
- Homeostasis System monitors OS health and detects performance issues
- Self-Improvement Engine generates optimization proposals based on metrics
- Self-Improvement API (this document) enables manual review and approval via GUI
- Hot Module Reload (HMR) Controller applies approved proposals at runtime when enabled
- Self-Incorporation Service integrates changes and reports outcomes back to metrics
The API provides a human-in-the-loop gate for proposal application, ensuring safe evolution with user oversight.
Apply a single improvement proposal with optional HMR-based hot reload.
Request body:
{
"proposal_id": "string", // Required: Unique ID of proposal to apply
"force": false, // Optional: Skip safety checks (default: false)
"user": "string" // Optional: User ID for audit trail
}Success response (HTTP 200):
{
"ok": true,
"status": "approved", // Proposal approved
"message": "Proposal applied successfully via HMR",
"restart_required": false, // HMR applied, no restart needed
"proposal_id": "string"
}Success response (HTTP 200 - HMR unavailable):
{
"ok": true,
"status": "approved",
"message": "Proposal approved - HMR not available, OS restart required",
"restart_required": true, // Manual OS restart needed
"proposal_id": "string"
}Error response (HTTP 400):
{
"ok": false,
"error": "string", // Error description
"details": "string" // Optional: Additional error context
}Response codes:
- 200 OK: Proposal approved (may require restart based on
restart_requiredflag) - 400 Bad Request: Invalid request, proposal application failed, or HMR error
Restart required semantics:
| HMR Status | Applied | restart_required | HTTP Code | UI Behavior |
|---|---|---|---|---|
| Enabled & available | Yes | false |
200 | Show success, no restart badge |
| Unavailable | No | true |
200 | Show "OS Restart Required" badge |
| Error during apply | No | true |
400 | Show error message |
| Disabled | No | true |
200 | Show "OS Restart Required" badge |
Apply multiple improvement proposals in a single operation.
Request body:
{
"proposal_ids": ["string", ...], // Required: Array of proposal IDs
"force": false, // Optional: Skip safety checks (default: false)
"user": "string" // Optional: User ID for audit trail
}Success response (HTTP 200):
{
"ok": true,
"applied": 3, // Count of successfully applied proposals
"failed": 1, // Count of failed proposals
"restart_required": true, // Any proposal requiring restart?
"results": [
{
"proposal_id": "string",
"ok": true,
"status": "approved",
"message": "Applied via HMR",
"restart_required": false
},
{
"proposal_id": "string",
"ok": false,
"error": "Application failed",
"restart_required": true
}
]
}Response codes:
- 200 OK: Batch operation completed (check individual results for per-proposal status)
- 400 Bad Request: Invalid request format or critical error
Batch semantics:
- Batch operation continues even if individual proposals fail
- Global
restart_requiredistrueif any proposal requires restart - Individual results include per-proposal
restart_requiredflags - Empty
proposal_idsarray returns 400 Bad Request
Prior to 2025-01-26, the Self-Improvement API used multiple HTTP status codes to signal different outcomes (503 for HMR unavailable, 502 for selfinc failure, 500 for HMR errors). This created complexity in client logic and violated REST conventions.
Current harmonized approach:
- HTTP 200: Proposal approved (check
restart_requiredflag to determine if OS restart needed) - HTTP 400: Request invalid or proposal application failed
Benefits:
- Simplified client logic: Check
body.okandrestart_requiredflag only - RESTful semantics: 2xx for success, 4xx for client errors
- Single source of truth:
restart_requiredflag drives UI behavior
Migration note: Clients previously checking res.status === 503 should now check body.restart_required === true.
HMR enables runtime application of approved proposals without OS restart. When HMR is enabled and available, the Self-Improvement API will attempt to apply proposals via the HMR Controller.
Set these environment variables before launching Aetherra OS:
export AETHERRA_HMR_ENABLED=1 # Enable HMR system
export AETHERRA_HMR_MODE=safe # Use safe reload mode
export AETHERRA_HMR_AUTO_RELOAD=1 # Auto-reload on file changesOr in PowerShell:
$env:AETHERRA_HMR_ENABLED = "1"
$env:AETHERRA_HMR_MODE = "safe"
$env:AETHERRA_HMR_AUTO_RELOAD = "1"The API checks HMR availability before applying proposals:
- HMR enabled:
restart_required: falsewhen successfully applied - HMR unavailable:
restart_required: true, user must manually restart OS - HMR error: HTTP 400 with error details
- Safe mode: Only applies proposals passing safety validation
- Rollback: Automatic rollback on application errors
- Audit trail: All HMR operations logged to kernel metrics
- SLO monitoring: Homeostasis monitors post-application health
The Lyrixa GUI Self-Improve tab integrates with this API to provide manual proposal review and approval.
- Fetch proposals: UI calls
GET /api/selfimprove/proposalsto list pending proposals - User review: Proposals displayed with title, description, and metrics
- Approval: User clicks "Approve" button on selected proposal
- Apply: UI calls
POST /api/selfimprove/applywith proposal ID - Check result:
- If
ok: trueandrestart_required: false: Show success (HMR applied) - If
ok: trueandrestart_required: true: Show "OS Restart Required" badge - If
ok: false: Show error message
- If
const approveSuggestion = async (proposalId: string) => {
try {
const res = await fetch('/api/selfimprove/apply', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proposal_id: proposalId })
});
const body = await res.json();
if (body && body.ok === true) {
// Proposal approved successfully
if (body.restart_required) {
// Show "OS Restart Required" badge
showRestartBadge(proposalId);
} else {
// HMR applied, no restart needed
showSuccess("Proposal applied successfully");
}
} else {
// Application failed
showError(body.error || "Application failed");
}
} catch (err) {
showError("Network error: " + err.message);
}
};const approveMultiple = async (proposalIds: string[]) => {
const res = await fetch('/api/selfimprove/batch-apply', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ proposal_ids: proposalIds })
});
const body = await res.json();
if (body.ok) {
console.log(`Applied: ${body.applied}, Failed: ${body.failed}`);
if (body.restart_required) {
showRestartBadge("multiple");
}
// Process individual results
body.results.forEach(result => {
if (result.ok) {
updateProposalStatus(result.proposal_id, "approved");
} else {
showProposalError(result.proposal_id, result.error);
}
});
}
};Invalid proposal ID:
{
"ok": false,
"error": "Proposal not found",
"details": "proposal_id 'invalid-id' does not exist"
}HMR application error:
{
"ok": false,
"error": "HMR application failed",
"details": "Module reload failed: ImportError in target module"
}Self-Incorporation service unavailable:
{
"ok": false,
"error": "Self-Incorporation service not available",
"details": "Cannot apply proposal without selfinc service"
}- 400 Bad Request: Do not retry (client error)
- 500 Internal Server Error: Retry with exponential backoff
- Network errors: Retry up to 3 times with exponential backoff
- Proposals require manual user approval via GUI
- Batch operations limited to 10 proposals per request
forceflag requires elevated privileges (planned)
All proposal applications are logged with:
- Timestamp
- User ID (if provided)
- Proposal ID
- Application outcome
- HMR status
- Restart required flag
Audit logs available via kernel metrics and Homeostasis reporting.
AETHERRA_HMR_ENABLED: Enable HMR system (default: 0)AETHERRA_HMR_MODE: HMR mode (safe/aggressive, default: safe)AETHERRA_HMR_AUTO_RELOAD: Auto-reload on file changes (default: 0)AETHERRA_SELFINC_STRICT: Require signed proposals (default: 0)
Configuration available via config.json:
{
"self_improvement": {
"enabled": true,
"hmr_enabled": true,
"hmr_mode": "safe",
"batch_limit": 10,
"require_approval": true
}
}Self-Improvement API metrics exposed via /metrics endpoint:
aetherra_selfimprove_apply_total: Total apply attempts (labels: status, restart_required)aetherra_selfimprove_apply_duration_seconds: Apply operation durationaetherra_selfimprove_hmr_success_total: Successful HMR applicationsaetherra_selfimprove_hmr_error_total: Failed HMR applications
Check Self-Improvement Engine status:
GET /api/statsResponse includes:
{
"self_improvement_engine": {
"enabled": true,
"status": "idle",
"proposals_pending": 3
}
}- AETHERRA_MAINTENANCE_SYSTEM.md: Overall maintenance architecture
- AETHERRA_LYRIXA_SYSTEM.md: Lyrixa UI integration
- AETHERRA_AGENT_SYSTEM.md: Agent orchestration and task lifecycle
ApplyResponse:
interface ApplyResponse {
ok: boolean; // Operation success
status?: string; // "approved" | "rejected" | "error"
message: string; // Human-readable outcome
restart_required: boolean; // OS restart needed?
proposal_id: string; // Applied proposal ID
error?: string; // Error message if ok: false
details?: string; // Additional error context
}BatchApplyResponse:
interface BatchApplyResponse {
ok: boolean; // Overall operation success
applied: number; // Count of successful applications
failed: number; // Count of failures
restart_required: boolean; // Any proposal requiring restart?
results: ApplyResponse[]; // Per-proposal results
}Apply single proposal:
curl -X POST http://localhost:3001/api/selfimprove/apply \
-H "Content-Type: application/json" \
-d '{"proposal_id": "prop-123", "user": "admin"}'Batch apply:
curl -X POST http://localhost:3001/api/selfimprove/batch-apply \
-H "Content-Type: application/json" \
-d '{"proposal_ids": ["prop-123", "prop-456"], "user": "admin"}'Status: ✅ Implemented (harmonized status codes, restart_required flag, HMR integration, batch operations)