Skip to content

feat: support guest log level overrides for initialized snapshots - #1833

Open
jprendes wants to merge 9 commits into
hyperlight-dev:mainfrom
jprendes:guest-log-level-initialized-snapshots
Open

jprendes wants to merge 9 commits into
hyperlight-dev:mainfrom
jprendes:guest-log-level-initialized-snapshots

Conversation

@jprendes

Copy link
Copy Markdown
Contributor

Closes #1698

Adds guest log-level overrides for initialized snapshots.

Changes

  • Adds a host-to-guest runtime log-level update protocol.
  • Updates guest log and tracing filters before guest calls.
  • Supports log-level overrides when restoring snapshots.
  • Adds MultiUseSandbox::log_level.
  • Reapplies the configured level after restore().
  • Adds coverage for initialized snapshots and restore persistence.
  • Update documentation comments.

Validation

  • Focused snapshot and log-level tests

Copilot AI lite review requested due to automatic review settings September 15, 2026 16:03
@jprendes jprendes added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Sep 15, 2026

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

Copilot AI 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.

🟡 Changes recommended

Snapshot compatibility, tracing cache invalidation, guest protocol support, and test/documentation follow-ups remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

Justfile:246

  • The new ignored test is added to test-isolated, but coverage-run has its own explicit isolated-test list and still only invokes max_guest_log_level_is_honored_from_snapshot. Since ignored tests are not selected by the broad test commands, the initialized-snapshot override behavior is omitted from coverage. Add the corresponding command to the coverage recipe.
    {{ cargo-cmd }} test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" { "dev" } else { target } }} {{ target-triple-flag }} -p hyperlight-host --lib -- sandbox::initialized_multi_use::tests::from_snapshot::max_guest_log_level_overrides_initialized_snapshot --exact --ignored

src/hyperlight_host/src/sandbox/initialized_multi_use.rs:633

  • The pending value is consumed only by refresh_guest_log_level in the guest binary. An initialized snapshot contains the guest code that was captured, so snapshots made before this protocol, or with a guest build that lacks it, never consume this slot. Because the snapshot ABI and loader acceptance are unchanged, this path silently reports success while the override has no effect. Add a compatibility/version gate or another mechanism that guarantees the restored guest supports the protocol.
        if let Some(log_level) = self.max_guest_log_level {
            self.mem_mgr.request_guest_log_level_update(log_level)?;

src/hyperlight_host/src/sandbox/initialized_multi_use.rs:151

  • This adds the public MultiUseSandbox::log_level API and changes snapshot-builder behavior, but CHANGELOG.md has no entry for the feature under Unreleased. Add a concise user-facing changelog entry before merging.
    /// Sets the maximum log level used by future guest calls.
    ///
    /// The setting is reapplied after restoring a snapshot.
    pub fn log_level(&mut self, log_level: LevelFilter) -> Result<()> {
  • Files reviewed: 12/12 changed files
  • Comments generated: 4
  • Review effort level: Lite

Comment thread src/hyperlight_common/src/layout.rs
Comment thread src/hyperlight_guest_tracing/src/subscriber.rs
Comment thread Justfile
Comment thread src/hyperlight_host/src/sandbox/builder.rs

Copilot AI 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.

🟡 Changes recommended

Critical logging and snapshot-golden compatibility issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

src/hyperlight_guest_tracing/src/lib.rs:77

  • When the requested level is OFF and no subscriber exists, this fallback still initializes guest tracing. generic_init deliberately skips tracing for OFF (hyperlight_guest_bin/src/lib.rs:300-306), while GuestHandle::log_message uses is_trace_enabled() to choose the direct output path. Initializing an OFF subscriber makes that check true and causes direct guest_logger::log_message calls to be dropped by GuestSubscriber::enabled instead of sent to the host. Keep tracing uninitialized for OFF when there is no existing subscriber, while still updating an existing subscriber to OFF.
        } else {
            init_guest_tracing(guest_start_tsc, max_log_level);
  • Files reviewed: 15/15 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread src/hyperlight_guest_tracing/src/subscriber.rs
Comment thread src/hyperlight_host/src/sandbox/snapshot/file/media_types.rs

@ludfjig ludfjig 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.

Looks great. I think we can update docs/hyperlight-metrics-logs-and-traces.md as well

Comment thread src/hyperlight_guest_tracing/src/subscriber.rs
Comment thread src/hyperlight_host/src/sandbox/initialized_multi_use.rs
Comment thread src/hyperlight_host/src/sandbox/builder.rs
Comment thread src/hyperlight_host/src/sandbox/initialized_multi_use.rs
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@jprendes
jprendes force-pushed the guest-log-level-initialized-snapshots branch from 568c1be to 2f4e5d0 Compare September 16, 2026 11:05

@ludfjig ludfjig 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.

looks good the only thing I'm uncertain about is whether bumping the snapshot version is really necessary. What could go wrong if we don't bump any versions, and load an old snapshot with these changes?

@jprendes

Copy link
Copy Markdown
Contributor Author

I think on that case we could risk overriding the exception stack with log level information, right?
But then, the exception stack shouldn't have any valuable information IIUC. Not sure.

@jprendes

Copy link
Copy Markdown
Contributor Author

Here's the comment that resulted in the version bump: #1833 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. regen-goldens Regenerate snapshot golden fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max_guest_log_level is not plumbed through snapshot load

3 participants