Skip to content

fix(logging): harden lifecycle capture and console recovery - #1268

Merged
ndizazzo merged 3 commits into
mainfrom
codex/harden-logging-lifecycle
Aug 13, 2026
Merged

ndizazzo merged 3 commits into
mainfrom
codex/harden-logging-lifecycle

Conversation

@ndizazzo

@ndizazzo ndizazzo commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Corrective follow-up to the merged logging stack

This PR follows the logging stack merged into main:

The initial stack was validated end-to-end with the embedded console and a local Qwen3.5-4B inference run. A follow-up review then checked every supplied finding against the current code. All six inline findings and the outside-diff SSE projection finding were still valid; none were skipped.

Needed corrections

  1. Typed audit context now applies the established path → URL → generic redaction sequence before storage. URL userinfo is also redacted so credential-bearing URLs cannot leak credentials without a query string. Regression coverage verifies URL credentials and query secrets are absent.

  2. Terminal lifecycle events now carry bounded duration_ms values:

    • runtime shutdown completion;
    • per-instance and managed-model shutdown;
    • runtime-model resolution, capacity, and launch failures;
    • startup preparation/launch failures.
      Operation start times are propagated through all listed completion and failure branches.
  3. Startup emits exactly one runtime_model_load_started for the initial attempt before preparation, so preparation failures have a matching start event. Split-model relaunches emit one new start per relaunch. A regression test covers preparation-failure ordering.

  4. Audit row context search retains the legacy entryId; the request-row branch is unchanged.

  5. CLI parse-family detection derives value-taking options from Clap and skips their operands before classifying positional command tokens. --config runtime --bad-flag therefore remains unknown, while explicit runtime surfaces and existing family mappings are preserved.

  6. SSE audit projection now reuses the typed audit contract: closed subject kinds, valid static reason/outcome codes, and valid numeric-summary keys. Invalid fields are omitted, and numeric summaries are filtered before the eight-entry bound.

The store, REST API, SSE, and UI remain an allowlisted typed projection; arbitrary detail_json stays private.

Scope boundary

This PR does not change mesh protocol fields, Skippy ABI/native callbacks, topology/session/prefill/decode/KV/device/resource hooks, or other underlying elements merely to add events. Event families needing new authoritative hooks remain deferred to .omo/specs/event-system.md.

Invite-token policy

Mesh invite tokens are intentionally public, shareable connection descriptors. They are not credentials and should not be flagged for redaction. Owner keys, authorization headers, API keys, private URLs, and other authentication material remain protected.

Validation

  • just release-host-build
  • cargo clippy -p mesh-llm --all-targets -- -D warnings
  • cargo fmt --all -- --check and git diff --check
  • full mesh-llm-host-runtime library tests: 2,458 passed, 8 ignored, 0 failed
  • focused audit-context, SSE-projection, startup-ordering, runtime-audit, and CLI regression tests
  • affected Logs ledger UI tests: 16 passed; UI typecheck, ESLint, and Prettier passed
  • embedded-console Playwright validation with Qwen3.5-4B non-stream and stream inference, including payload capture, lifecycle rows, stale-cursor recovery, responsive dark UI, and no serious/critical axe violations

Summary by CodeRabbit

  • New Features

    • Added richer audit context, including subjects, operations, outcomes, durations, and bounded numeric summaries.
    • Added payload-capture status indicators and sanitized streaming artifact capture.
    • CLI help, version, and parse-failure events now retain appropriate outcomes and audit details.
    • Logs display expanded audit metadata and continuously reconcile live updates.
    • Runtime and model lifecycle events now include contextual audit records.
  • Bug Fixes

    • Improved recovery from live-stream hydration gaps and incomplete captures.
    • Improved credential redaction in captured URLs and artifacts.
  • Documentation

    • Updated logging guidance, event coverage, and invite-token handling.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request is currently a draft. Reviews will not take place until the PR is marked as ready for review.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9af1c18-145d-4c18-bcfa-be9fcdb4d139

📥 Commits

Reviewing files that changed from the base of the PR and between 600228d and 53864fc.

📒 Files selected for processing (1)
  • crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs

📝 Walkthrough

Walkthrough

The change adds typed operational audit context, early CLI lifecycle logging, runtime lifecycle coverage, bounded OpenAI stream artifacts, persistence and API projections, capture-status reporting, and log UI metadata and recovery support.

Changes

Operational logging

Layer / File(s) Summary
CLI lifecycle auditing
crates/mesh-llm-commands/..., crates/mesh-llm-events/..., crates/mesh-llm/...
CLI families and parse outcomes now support pre-parse audit events, preserved exit codes, and external command classification.
Typed audit context and projections
crates/mesh-llm-host-runtime/src/logging/..., crates/mesh-llm-log-store/..., crates/mesh-llm-host-runtime/src/api/routes/logs/...
Audit records now carry bounded typed context. The context is validated, persisted, projected, redacted, and tested without exposing arbitrary detail data.
Runtime lifecycle events
crates/mesh-llm-host-runtime/src/runtime/...
Startup, shutdown, model load, unload, failure, and unexpected-exit events now include contextual subjects, outcomes, reason codes, and durations.
Bounded stream artifacts
crates/mesh-llm-host-runtime/src/logging/openai_lifecycle.rs, crates/mesh-llm-host-runtime/src/network/openai/...
Normalized and translated SSE streams now capture bounded redacted bodies and report incomplete or oversized captures as unavailable.
Log API and UI integration
crates/mesh-llm-ui/src/features/logs/..., crates/mesh-llm-ui/src/lib/api/types.ts
Audit metadata, capture status, search fields, replay-gap recovery, and continuous audit reconciliation are now represented in the log interface.

Estimated code review effort: 5 (Critical) | ~120 minutes

Mergeability Score: ⚪ Minimal · up to 53864

The PR hardens lifecycle logging, redaction, startup ordering, CLI parsing, and typed SSE projections; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • Mesh-LLM/mesh-llm#1133: Extends the runtime logging foundation used by the contextual audit and artifact changes.
  • Mesh-LLM/mesh-llm#1175: Directly relates to the CLI lifecycle logging and command dispatch changes.
  • Mesh-LLM/mesh-llm#1176: Directly relates to the log schemas, ledger, inspector, recovery, and CLI logging projections.

Suggested reviewers: i386, michaelneale

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.30% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes to lifecycle logging, artifact capture, and console recovery.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/harden-logging-lifecycle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ndizazzo
ndizazzo marked this pull request as ready for review August 12, 2026 23:09
@github-actions
github-actions Bot requested a review from i386 August 12, 2026 23:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs (1)

182-255: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Validate every projected context field.

Line 202 accepts arbitrary numeric-summary keys. Lines 244-249 also project arbitrary subject_kind, reason_code, and outcome values from persisted payloads.

A malformed or legacy audit payload can then send unbounded-vocabulary metadata to the live SSE client. Validate subject_kind against the closed subject set. Validate reason, outcome, and numeric keys with the same static-code rules as OperationalAuditContext. Apply the eight-entry limit after key validation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs` around
lines 182 - 255, Update the context projection around the AuditEntryData
construction to reuse the static-code validation rules from
OperationalAuditContext: restrict subject_kind to the closed subject set,
validate reason_code and outcome, and accept only valid numeric-summary keys.
Filter numeric_summaries by key before applying the existing eight-entry limit,
and ensure invalid projected fields are omitted rather than sent to the SSE
client.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/mesh-llm-host-runtime/src/logging/service/operational_audit.rs`:
- Around line 145-152: Update bounded_context_value to apply redact_urls_in_text
in the established logging-policy sequence, alongside path sanitization and
generic redaction, before trimming and storing the value. Add a regression test
covering a credential-bearing URL and verify the resulting context value
contains no URL credentials or query secrets.

In `@crates/mesh-llm-host-runtime/src/runtime/control_loop.rs`:
- Around line 349-354: Extend terminal lifecycle audit events to include elapsed
duration in milliseconds. In
crates/mesh-llm-host-runtime/src/runtime/control_loop.rs:349-354, capture the
start time at ShutdownStarted and add elapsed time to ShutdownCompleted; apply
the corresponding per-instance and managed-model shutdown timing in
model_lifecycle.rs:326-329 and 364-368. In model_lifecycle/load.rs:4-14 and
unload.rs:14-33, propagate each operation’s start time through all failure and
completion branches, including resolution and capacity failures. In
startup_handles.rs:1497-1500, pass the current load attempt start time to
record_startup_terminal_failure and include elapsed time in ModelLoadFailed.

In `@crates/mesh-llm-host-runtime/src/runtime/startup_handles.rs`:
- Around line 1215-1219: Move the initial ModelLoadStarted recording ahead of
prepare_startup_local_model_task in the startup flow, ensuring preparation
failures still have a matching start event. Preserve exactly one start event for
each split-model relaunch, and add a regression test covering preparation
failure event ordering.

In `@crates/mesh-llm-ui/src/features/logs/components/LogEventLedgerColumns.tsx`:
- Around line 173-175: Update the audit branch of the context accessor to append
row.audit.entryId after the existing audit fields, while leaving the request
branch unchanged so legacy audit entry IDs remain searchable and filterable.

In `@crates/mesh-llm/src/lib.rs`:
- Around line 201-235: Update parse_failure_family to skip operands belonging to
global options before matching positional command tokens, so values such as
“runtime” after “--config” cannot determine the family; preserve
explicit_surface behavior and existing family mappings. Add a regression test
covering “--config runtime --bad-flag” and assert it does not classify as
Runtime.

---

Outside diff comments:
In `@crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs`:
- Around line 182-255: Update the context projection around the AuditEntryData
construction to reuse the static-code validation rules from
OperationalAuditContext: restrict subject_kind to the closed subject set,
validate reason_code and outcome, and accept only valid numeric-summary keys.
Filter numeric_summaries by key before applying the existing eight-entry limit,
and ensure invalid projected fields are omitted rather than sent to the SSE
client.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 902dd98b-ffb0-43ff-bac7-d2b6a24127d9

📥 Commits

Reviewing files that changed from the base of the PR and between 4890efd and c3435a6.

📒 Files selected for processing (46)
  • crates/mesh-llm-commands/src/operational_logging.rs
  • crates/mesh-llm-events/src/command_lifecycle.rs
  • crates/mesh-llm-host-runtime/src/api/routes/logs/dto.rs
  • crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs
  • crates/mesh-llm-host-runtime/src/api/routes/logs/mod.rs
  • crates/mesh-llm-host-runtime/src/api/routes/logs/tests.rs
  • crates/mesh-llm-host-runtime/src/api/status.rs
  • crates/mesh-llm-host-runtime/src/lib.rs
  • crates/mesh-llm-host-runtime/src/logging/mod.rs
  • crates/mesh-llm-host-runtime/src/logging/openai_lifecycle.rs
  • crates/mesh-llm-host-runtime/src/logging/persistence.rs
  • crates/mesh-llm-host-runtime/src/logging/policy.rs
  • crates/mesh-llm-host-runtime/src/logging/policy/artifact_redaction.rs
  • crates/mesh-llm-host-runtime/src/logging/runtime_state.rs
  • crates/mesh-llm-host-runtime/src/logging/runtime_state/tests.rs
  • crates/mesh-llm-host-runtime/src/logging/service.rs
  • crates/mesh-llm-host-runtime/src/logging/service/operational_audit.rs
  • crates/mesh-llm-host-runtime/src/network/openai/response/stream_translation.rs
  • crates/mesh-llm-host-runtime/src/network/openai/response_adapter.rs
  • crates/mesh-llm-host-runtime/src/runtime/control_loop.rs
  • crates/mesh-llm-host-runtime/src/runtime/mod.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/load.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/unload.rs
  • crates/mesh-llm-host-runtime/src/runtime/operational_logging.rs
  • crates/mesh-llm-host-runtime/src/runtime/operational_logging/tests.rs
  • crates/mesh-llm-host-runtime/src/runtime/startup_handles.rs
  • crates/mesh-llm-log-store/src/api_acceptance_tests/summary_audit.rs
  • crates/mesh-llm-log-store/src/repositories.rs
  • crates/mesh-llm-ui/src/features/logs/api/schemas.test.ts
  • crates/mesh-llm-ui/src/features/logs/api/schemas.ts
  • crates/mesh-llm-ui/src/features/logs/api/use-logs-live-recovery.test.tsx
  • crates/mesh-llm-ui/src/features/logs/api/use-logs-live-recovery.ts
  • crates/mesh-llm-ui/src/features/logs/components/LogEventInspector.test.tsx
  • crates/mesh-llm-ui/src/features/logs/components/LogEventInspector.tsx
  • crates/mesh-llm-ui/src/features/logs/components/LogEventLedgerColumns.tsx
  • crates/mesh-llm-ui/src/features/logs/components/LogsLedger.test.tsx
  • crates/mesh-llm-ui/src/features/logs/components/LogsLedger.tsx
  • crates/mesh-llm-ui/src/features/logs/pages/LogMaintenanceInvalidation.test.tsx
  • crates/mesh-llm-ui/src/features/logs/pages/LogsLedgerPage.tsx
  • crates/mesh-llm-ui/src/lib/api/types.ts
  • crates/mesh-llm/src/commands/mod.rs
  • crates/mesh-llm/src/commands/plugin_cli.rs
  • crates/mesh-llm/src/lib.rs
  • docs/EXO_COMPARISON.md
  • docs/LOGGING.md

Comment thread crates/mesh-llm-host-runtime/src/runtime/control_loop.rs
Comment thread crates/mesh-llm-host-runtime/src/runtime/startup_handles.rs Outdated
Comment thread crates/mesh-llm-ui/src/features/logs/components/LogEventLedgerColumns.tsx Outdated
Comment thread crates/mesh-llm/src/lib.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs`:
- Around line 363-387: Add a ninth valid numeric summary key to the audit entry
fixture used by the numeric summaries test, then assert the serialized data
under numericSummaries contains only eight entries and does not include that
ninth key. Keep the existing filtering assertion for “bad-key” and verify the
cap enforced by audit_entry_frame.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 667feccc-10a1-48e9-8577-cc19a97ba175

📥 Commits

Reviewing files that changed from the base of the PR and between c3435a6 and e307cf3.

📒 Files selected for processing (10)
  • crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs
  • crates/mesh-llm-host-runtime/src/logging/policy.rs
  • crates/mesh-llm-host-runtime/src/logging/service/operational_audit.rs
  • crates/mesh-llm-host-runtime/src/runtime/control_loop.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/load.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/unload.rs
  • crates/mesh-llm-host-runtime/src/runtime/startup_handles.rs
  • crates/mesh-llm-ui/src/features/logs/components/LogEventLedgerColumns.tsx
  • crates/mesh-llm/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/mesh-llm-host-runtime/src/runtime/control_loop.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/load.rs
  • crates/mesh-llm-ui/src/features/logs/components/LogEventLedgerColumns.tsx
  • crates/mesh-llm-host-runtime/src/logging/policy.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle/unload.rs
  • crates/mesh-llm/src/lib.rs
  • crates/mesh-llm-host-runtime/src/runtime/startup_handles.rs
  • crates/mesh-llm-host-runtime/src/logging/service/operational_audit.rs
  • crates/mesh-llm-host-runtime/src/runtime/model_lifecycle.rs

Comment thread crates/mesh-llm-host-runtime/src/api/routes/logs/events/protocol.rs
@ndizazzo
ndizazzo force-pushed the codex/harden-logging-lifecycle branch 3 times, most recently from 600228d to 53864fc Compare August 13, 2026 09:43
@ndizazzo
ndizazzo force-pushed the codex/harden-logging-lifecycle branch from 53864fc to 801d412 Compare August 13, 2026 10:41
@ndizazzo
ndizazzo merged commit 5022e09 into main Aug 13, 2026
51 checks passed
@ndizazzo
ndizazzo deleted the codex/harden-logging-lifecycle branch August 13, 2026 15:58
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