Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

CodeLevelMeaning
BOOT-001INFOKernel booted
BOOT-002INFOFramebuffer console initialized
BOOT-003WARNNo framebuffer provided; serial output only
BOOT-004INFOBoot complete
SER-001INFOSerial port COM1 initialized
INT-001INFOGDT, TSS and IDT loaded
INT-002INFOHardware interrupts enabled
MEM-001ERRORMemory initialization failed (kernel continues without a heap)
MEM-003ERROR / PANICHeap allocation failed (diagnostic)
MEM-010INFOMemory map summary
MEM-011INFOPaging initialized
MEM-012INFOKernel heap initialized
INPUT-001INFOKeyboard and serial input ready
SHELL-001INFOShell started
CMD-001WARNInvalid or unknown command
CMD-002WARNWrong number of command arguments
CMD-003WARNCommand reported an error
CMD-004INFOCommand cancelled at the confirmation prompt
CMD-010INFOCommand executed
COMM-001ERRORMessage did not fit into a protocol frame and was not sent
COMM-002WARNFrame received from the AI Bridge was rejected (malformed or invalid)
AI-001WARNAI Bridge reported an error for a request
AI-002WARNAI Bridge did not answer before the timeout
AI-003WARNAI answer rejected by validation
AI-010INFOAI-suggested command run by the user with run
AI-011WARNAI-suggested command blocked by the safety checks
AI-012INFOAI-suggested command declined at the confirmation prompt
EXC-000PANICDivide error (diagnostic)
EXC-003INFOBreakpoint; execution continues (diagnostic)
EXC-006PANICInvalid opcode (diagnostic)
EXC-008PANICDouble fault, typically a kernel stack overflow (diagnostic)
EXC-013PANICGeneral protection fault (diagnostic)
EXC-014PANICPage fault (diagnostic)
PANIC-001PANICKernel 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

IDScenarioExpected ResultPriority
OBS-001Kernel bootBoot event loggedHigh
OBS-002Serial initializationSerial status loggedHigh
OBS-003Memory initializationMemory event loggedHigh
OBS-004Shell commandCommand event loggedHigh
OBS-005Kernel errorERROR log generatedHigh
OBS-006Kernel panicPANIC diagnostic generatedHigh
OBS-007Diagnostic sentCommunication event loggedHigh
OBS-008AI requestRequest ID recordedHigh
OBS-009AI responseResponse validation event recordedHigh
OBS-010AI timeoutAI timeout error recordedHigh
OBS-011Invalid protocol messageValidation failure recordedHigh
OBS-012Provider failureExternal-service error distinguished from kernel failureHigh
OBS-013Repeated failuresRepeated failure is visible in logs/metricsMedium
OBS-014Secret exposure testSensitive credentials absent from logsHigh

30. Observability requirements

IDRequirementPriority
OBS-REQ-001Kernel shall provide structured log levels.Must
OBS-REQ-002Kernel errors shall produce diagnostic information.Must
OBS-REQ-003Panic paths shall attempt to emit diagnostics.Must
OBS-REQ-004Communication events shall be traceable.Must
OBS-REQ-005AI requests shall have identifiers.Should
OBS-REQ-006AI latency shall be measurable.Should
OBS-REQ-007AI errors shall be distinguishable from kernel errors.Must
OBS-REQ-008Sensitive credentials shall not be logged.Must
OBS-REQ-009Diagnostic records shall contain subsystem and severity information.Must
OBS-REQ-010Core observability shall function without the external AI service.Must
OBS-REQ-011External provider/model information should be recorded for AI evaluation.Should
OBS-REQ-012Observability 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.