Observability
1. Purpose
Observability in PsyDian is the ability to understand the internal state and behavior of the operating-system prototype through logs, diagnostics, metrics, and traceable events.
Because PsyDian contains a bare-metal kernel, a host-side AI Bridge, and an external AI service, observability must cover all three layers while keeping their boundaries clear.
The primary goals are:
- Understand kernel boot and initialization behavior.
- Detect and diagnose kernel failures.
- Track shell and command-processing events.
- Observe diagnostic generation.
- Track kernel-to-host communication.
- Monitor AI Bridge processing.
- Measure external AI latency and failures.
- Correlate a diagnostic request with its resulting AI response.
- Distinguish kernel failures from host/AI failures.
- Provide useful evidence during development, testing, and demonstration.
2. Observability architecture
PsyDian Kernel
│
┌──────────────┼──────────────┐
│ │ │
Kernel Logs Diagnostics Events
│ │ │
└──────────────┼──────────────┘
↓
Serial / Diagnostic Channel
↓
Host AI Bridge
│
┌──────────────┼──────────────┐
│ │ │
Bridge Logs Metrics Errors
│ │ │
└──────────────┼──────────────┘
↓
External AI Service
│
Provider/API Response
↓
AI Bridge Logs
↓
PsyDian Response
The architecture deliberately keeps observability separate from command authority.
3. Observability layers
PsyDian observability is divided into:
Layer 1 → Kernel Observability
Layer 2 → Communication Observability
Layer 3 → AI Bridge Observability
Layer 4 → External AI Dependency Observability
Layer 5 → End-to-End Observability
4. Kernel observability
The kernel shall provide low-level logging through the available serial output mechanism.
Examples:
[INFO] PsyDian kernel booted.
[INFO] Serial initialized.
[INFO] Memory initialized.
[INFO] Interrupt subsystem initialized.
[INFO] Keyboard initialized.
[INFO] Shell initialized.
Errors:
[ERROR] Heap allocation failed.
[ERROR] Keyboard initialization failed.
Warnings:
[WARN] Memory region unavailable.
Panic:
[PANIC] Kernel encountered an unrecoverable error.
Kernel logs are primarily intended for:
- Development.
- Debugging.
- Testing.
- Panic analysis.
- System diagnostics.
5. Log levels
PsyDian shall use consistent log levels.
INFO
Normal system events.
Example:
[INFO] Kernel initialized.
WARN
Unexpected but non-fatal conditions.
Example:
[WARN] Optional feature unavailable.
ERROR
A failure that affects a component but may not stop the whole system.
Example:
[ERROR] AI Bridge communication failed.
PANIC
An unrecoverable kernel condition.
Example:
[PANIC] Page fault during kernel execution.
6. Structured log format
Logs should remain consistent and machine-readable where practical.
Conceptual structure:
[TIMESTAMP][LEVEL][SUBSYSTEM][EVENT_ID] MESSAGE
Example:
[INFO][BOOT][BOOT-001] PsyDian kernel booted.
Another example:
[ERROR][MEMORY][MEM-003] Heap allocation failed.
During early development, timestamps may be omitted if reliable timekeeping has not yet been implemented.
The project should not require a full timestamp subsystem merely for logging.
7. Event categories
Important observability events include:
Boot events
KERNEL_BOOT
BOOT_COMPLETE
SUBSYSTEM_INIT
BOOT_FAILURE
Memory events
MEMORY_INIT
PAGE_TABLE_INIT
HEAP_INIT
ALLOC_SUCCESS
ALLOC_FAILURE
Interrupt events
EXCEPTION
HARDWARE_INTERRUPT
HANDLER_FAILURE
Shell events
COMMAND_RECEIVED
COMMAND_VALIDATED
COMMAND_EXECUTED
COMMAND_FAILED
Diagnostic events
DIAGNOSTIC_CREATED
DIAGNOSTIC_SENT
DIAGNOSTIC_RECEIVED
AI events
AI_REQUEST_STARTED
AI_REQUEST_SENT
AI_RESPONSE_RECEIVED
AI_RESPONSE_VALIDATED
AI_REQUEST_FAILED
8. Diagnostic observability
Diagnostics should contain enough contextual information to identify:
- What happened.
- Which subsystem was affected.
- Severity.
- Relevant message.
- Correlation/request identifier where available.
- Additional context when safely available.
Conceptual structure:
{
"type": "diagnostic",
"version": 1,
"id": "diag-001",
"severity": "error",
"subsystem": "memory",
"message": "Heap allocation failed"
}
9. Request IDs and correlation IDs
PsyDian should use identifiers to correlate related events.
Example:
Diagnostic ID:
diag-001
The corresponding AI request may use:
Request ID:
req-001
Conceptual relationship:
diag-001
↓
req-001
↓
AI Provider Request
↓
req-001
↓
AI Response
This makes it easier to determine which AI response corresponds to which diagnostic.
10. AI Bridge logging
The AI Bridge should log operational metadata such as:
Request ID
Message Type
Processing State
Provider
Model
Response Status
Validation Result
Latency
Error Code
Example:
[INFO] req-001 DIAGNOSTIC_RECEIVED
[INFO] req-001 AI_REQUEST_STARTED
[INFO] req-001 AI_RESPONSE_RECEIVED latency=1840ms
[INFO] req-001 RESPONSE_VALIDATED
Sensitive request payloads should not be logged by default.
11. Error codes
Stable internal error codes should be used.
Examples:
COMM-001 Communication failure
COMM-002 Invalid message
AI-001 AI service unavailable
AI-002 AI timeout
AI-003 Invalid AI response
AI-004 Authentication failure
CMD-001 Invalid command
MEM-001 Memory initialization failure
MEM-003 Heap allocation failure
PANIC-001 Kernel panic
The exact code registry will be finalized as the implementation grows.
Codes implemented in the kernel
Log lines use the format [LEVEL][SUBSYSTEM][CODE] message. Codes marked diagnostic also produce a structured diagnostic record and a protocol frame.
| Code | Level | Meaning |
|---|---|---|
BOOT-001 | INFO | Kernel booted |
BOOT-002 | INFO | Framebuffer console initialized |
BOOT-003 | WARN | No framebuffer provided; serial output only |
BOOT-004 | INFO | Boot complete |
SER-001 | INFO | Serial port COM1 initialized |
INT-001 | INFO | GDT, TSS and IDT loaded |
INT-002 | INFO | Hardware interrupts enabled |
MEM-001 | ERROR | Memory initialization failed (kernel continues without a heap) |
MEM-003 | ERROR / PANIC | Heap allocation failed (diagnostic) |
MEM-010 | INFO | Memory map summary |
MEM-011 | INFO | Paging initialized |
MEM-012 | INFO | Kernel heap initialized |
INPUT-001 | INFO | Keyboard and serial input ready |
SHELL-001 | INFO | Shell started |
CMD-001 | WARN | Invalid or unknown command |
CMD-002 | WARN | Wrong number of command arguments |
CMD-003 | WARN | Command reported an error |
CMD-004 | INFO | Command cancelled at the confirmation prompt |
CMD-010 | INFO | Command executed |
COMM-001 | ERROR | Message did not fit into a protocol frame and was not sent |
COMM-002 | WARN | Frame received from the AI Bridge was rejected (malformed or invalid) |
AI-001 | WARN | AI Bridge reported an error for a request |
AI-002 | WARN | AI Bridge did not answer before the timeout |
AI-003 | WARN | AI answer rejected by validation |
AI-010 | INFO | AI-suggested command run by the user with run |
AI-011 | WARN | AI-suggested command blocked by the safety checks |
AI-012 | INFO | AI-suggested command declined at the confirmation prompt |
EXC-000 | PANIC | Divide error (diagnostic) |
EXC-003 | INFO | Breakpoint; execution continues (diagnostic) |
EXC-006 | PANIC | Invalid opcode (diagnostic) |
EXC-008 | PANIC | Double fault, typically a kernel stack overflow (diagnostic) |
EXC-013 | PANIC | General protection fault (diagnostic) |
EXC-014 | PANIC | Page fault (diagnostic) |
PANIC-001 | PANIC | Kernel panic (diagnostic) |
CMD-* events are stored in the log history (shown by the logs command) without being printed, because the shell already shows its own message for them.
12. Metrics
Metrics should focus on measurable system behavior rather than collecting unnecessary information.
Kernel metrics
Potential metrics:
- Boot success/failure count.
- Kernel initialization duration.
- Exception count.
- Panic count.
- Heap allocation failures.
- Shell command processing time.
- Keyboard input processing rate.
Communication metrics
Potential metrics:
- Messages sent.
- Messages received.
- Invalid messages.
- Communication failures.
- Average message processing time.
- Communication latency.
AI Bridge metrics
Potential metrics:
- AI requests.
- Successful AI requests.
- Failed AI requests.
- AI timeout count.
- Response validation failures.
- AI request latency.
- AI response latency.
- Retry count.
- Provider error rate.
AI cost metrics
When supported by the selected provider:
- Input token usage.
- Output token usage.
- Estimated request cost.
13. Recommended performance metrics
The MVP should prioritize:
Boot Time
Local Command Latency
Diagnostic Processing Latency
Communication Latency
AI Request Latency
AI Response Latency
End-to-End Diagnostic Latency
The end-to-end AI latency can be represented as:
Kernel
↓
Diagnostic Creation
↓
Communication
↓
AI Bridge
↓
External AI
↓
Response Validation
↓
Communication
↓
PsyDian
14. AI latency breakdown
The AI Bridge should ideally measure separate stages:
Request Queue Time
+
Prompt Construction Time
+
Network/API Time
+
Response Parsing Time
+
Validation Time
=
AI Processing Time
This allows the team to identify whether delays are caused by:
- Local processing.
- Network.
- Provider latency.
- Validation.
15. Tracing
The complete AI-assisted diagnostic path should be traceable.
Conceptual trace:
User Request
↓
PsyDian Shell
↓
Kernel Diagnostic
↓
Diagnostic Message
↓
AI Bridge
↓
AI Provider
↓
AI Response
↓
Response Validation
↓
PsyDian Shell
↓
User
A request identifier should be retained throughout the flow where practical.
16. Kernel-to-host trace
For a diagnostic event:
Kernel Event
↓
Diagnostic ID
↓
Serial Transmission
↓
Bridge Receive
↓
Bridge Processing
This helps determine whether a problem occurred in:
Kernel
or
Communication
or
AI Bridge
17. External AI trace
The AI Bridge should distinguish between:
Request Created
Request Sent
Provider Response Received
Response Parsed
Response Validated
Response Returned
This provides enough information to diagnose provider/API failures without logging sensitive content.
18. Error observability
Errors shall receive stable internal codes and, where applicable, request/diagnostic identifiers.
User-facing error messages should remain safe and understandable.
Do not expose:
- API credentials.
- Internal secrets.
- Unnecessary stack traces.
- Sensitive diagnostic information.
Example:
[ERROR] AI assistance unavailable.
Request: req-001
Reason: AI request timeout.
19. Panic observability
Kernel panics are particularly important because the kernel may no longer be able to perform normal processing.
The panic path should attempt to emit:
[PANIC]
Subsystem
Message
Relevant context
Diagnostic ID
Example:
[PANIC][MEMORY][PANIC-001]
Heap allocator entered unrecoverable state.
The panic handler should avoid depending on complex functionality that may itself be unavailable during a severe failure.
20. Failure classification
Observability should make it possible to distinguish:
Kernel Failure
↓
Kernel diagnostic
Communication Failure
↓
Protocol / transport error
AI Bridge Failure
↓
Bridge error
External AI Failure
↓
Provider/API error
This distinction is essential for debugging the complete system.
21. Alerting
PsyDian is an academic prototype rather than a production cloud service, so a full enterprise alerting system is not required.
However, important failure conditions should be clearly surfaced.
Potential alert conditions:
- Repeated kernel initialization failures.
- Repeated communication failures.
- AI provider unavailable.
- High AI timeout rate.
- Repeated malformed AI responses.
- Unexpected increase in panic events.
- Repeated allocation failures.
- Repeated protocol validation failures.
In the MVP, these can be represented through terminal/serial logs rather than a separate alert-management service.
22. Observability during development
During development, the primary observability interface will be:
PsyDian
↓
Serial Output
↓
QEMU
↓
Host Terminal
Example:
[INFO][BOOT] PsyDian kernel booted.
[INFO][SERIAL] UART initialized.
[INFO][MEMORY] Memory subsystem initialized.
[INFO][INT] Interrupt subsystem initialized.
[INFO][INPUT] Keyboard initialized.
[INFO][SHELL] Shell initialized.
This provides immediate feedback during subsystem development.
23. Observability during AI diagnostics
An AI-assisted diagnostic session may produce:
[ERROR][MEMORY][MEM-003]
Heap allocation failed.
[INFO][AI][req-001]
Diagnostic sent to AI Bridge.
[INFO][AI][req-001]
AI analysis received.
[INFO][AI][req-001]
Response validated.
The shell can then display:
AI Analysis:
The heap allocation request could not be satisfied.
Suggested Investigation:
1. Inspect allocator state.
2. Check available heap memory.
24. Privacy and logging rules
Observability must not become a source of unnecessary data exposure.
Do not log:
API keys
Authentication tokens
Secrets
Unnecessary personal data
Unnecessary complete AI payloads
Where sensitive information may appear in user input or diagnostics, the bridge should filter or avoid persistent logging.
25. Observability data retention
For the MVP:
- Kernel logs may primarily remain in serial output.
- AI Bridge logs may be stored locally during development.
- Persistent long-term telemetry is not required.
- Diagnostic history storage is optional.
Future versions may add persistent diagnostic storage when a filesystem is available.
26. AI observability
AI-specific metadata should include:
Request ID
Provider
Model
Latency
Status
Validation Result
Error Code
Token Usage (if available)
The project should record model/provider information so AI behavior can be compared between versions.
27. Observability for AI evaluation
Observability data can support GenAI evaluation.
For example:
Request ID
↓
Diagnostic Input
↓
Model
↓
Latency
↓
Response
↓
Validation Result
↓
Human Evaluation
This allows the team to associate model behavior with a specific test scenario.
28. Development dashboard / visualization
A dedicated dashboard is not required for the MVP.
For the initial implementation, structured serial/terminal output is sufficient.
A future monitoring interface could display:
Kernel Status
Memory Usage
Exception Count
Panic Count
Shell Commands
AI Requests
AI Latency
AI Errors
Diagnostic History
This is future scope.
29. Observability test cases
| ID | Scenario | Expected Result | Priority |
|---|---|---|---|
| OBS-001 | Kernel boot | Boot event logged | High |
| OBS-002 | Serial initialization | Serial status logged | High |
| OBS-003 | Memory initialization | Memory event logged | High |
| OBS-004 | Shell command | Command event logged | High |
| OBS-005 | Kernel error | ERROR log generated | High |
| OBS-006 | Kernel panic | PANIC diagnostic generated | High |
| OBS-007 | Diagnostic sent | Communication event logged | High |
| OBS-008 | AI request | Request ID recorded | High |
| OBS-009 | AI response | Response validation event recorded | High |
| OBS-010 | AI timeout | AI timeout error recorded | High |
| OBS-011 | Invalid protocol message | Validation failure recorded | High |
| OBS-012 | Provider failure | External-service error distinguished from kernel failure | High |
| OBS-013 | Repeated failures | Repeated failure is visible in logs/metrics | Medium |
| OBS-014 | Secret exposure test | Sensitive credentials absent from logs | High |
30. Observability requirements
| ID | Requirement | Priority |
|---|---|---|
| OBS-REQ-001 | Kernel shall provide structured log levels. | Must |
| OBS-REQ-002 | Kernel errors shall produce diagnostic information. | Must |
| OBS-REQ-003 | Panic paths shall attempt to emit diagnostics. | Must |
| OBS-REQ-004 | Communication events shall be traceable. | Must |
| OBS-REQ-005 | AI requests shall have identifiers. | Should |
| OBS-REQ-006 | AI latency shall be measurable. | Should |
| OBS-REQ-007 | AI errors shall be distinguishable from kernel errors. | Must |
| OBS-REQ-008 | Sensitive credentials shall not be logged. | Must |
| OBS-REQ-009 | Diagnostic records shall contain subsystem and severity information. | Must |
| OBS-REQ-010 | Core observability shall function without the external AI service. | Must |
| OBS-REQ-011 | External provider/model information should be recorded for AI evaluation. | Should |
| OBS-REQ-012 | Observability data should support debugging of end-to-end AI diagnostics. | Must |
31. MVP observability scope
Required
- Kernel serial logging.
- INFO/WARN/ERROR/PANIC log levels.
- Boot and initialization logs.
- Exception/panic diagnostics.
- Shell operation logs where useful.
- Structured diagnostic records.
- Communication error logging.
- AI Bridge operational logging.
- Request/diagnostic identifiers where practical.
- AI latency measurement.
- AI failure reporting.
- Secret-safe logging.
- End-to-end diagnostic traceability.
Optional
- Persistent diagnostic history.
- Metrics dashboard.
- Distributed tracing.
- Advanced telemetry storage.
- Automated alerting infrastructure.
- Remote monitoring.
- Log aggregation service.
- OpenTelemetry integration.
Optional observability infrastructure must not delay core PsyDian development.
32. Final observability flow
Kernel Event
↓
Structured Log / Diagnostic
↓
Serial Channel
↓
Host AI Bridge
↓
Request ID / Processing State
↓
External AI Service
↓
Response / Latency / Status
↓
Response Validation
↓
Diagnostic Result
↓
PsyDian Shell
↓
User
33. Observability principles
Visibility
Important system behavior should produce observable evidence.
Correlation
Related events should be traceable through identifiers.
Separation
Kernel, communication, bridge, and external AI failures should be distinguishable.
Security
Observability must not expose credentials or unnecessary sensitive information.
Low overhead
Logging and measurement should not excessively interfere with kernel operation.
Determinism
Development and testing output should remain predictable and reproducible.
AI transparency
AI-generated information should remain distinguishable from original kernel evidence.
Graceful degradation
Core observability should continue even when the AI service is unavailable.