Skip to content
Merged
16 changes: 16 additions & 0 deletions crates/goose-server/src/commands/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use goose_server::tls::setup_tls;
use tower_http::cors::{Any, CorsLayer};
use tracing::info;

fn boot_marker(message: &str) {
eprintln!("GOOSED_BOOT: {message}");
}

#[cfg(unix)]
async fn shutdown_signal() {
use tokio::signal::unix::{signal, SignalKind};
Expand All @@ -35,14 +39,20 @@ pub async fn run() -> Result<()> {
#[cfg(feature = "rustls-tls")]
let _ = rustls::crypto::ring::default_provider().install_default();

boot_marker("logging init start");
crate::logging::setup_logging(Some("goosed"))?;
boot_marker("logging init done");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Gate boot markers behind debug logging

This commit adds boot_marker(...) calls on the normal success path, so goosed now writes many GOOSED_BOOT lines to stderr even when nothing is wrong. That violates the logging rule in /workspace/goose/AGENTS.md (only add logs for errors/security), and it also degrades desktop triage because ui/desktop/src/goosed.ts collects stderr into startup error diagnostics. Please guard these markers behind an explicit debug flag or a trace-level logger so production stderr stays signal-only.

Useful? React with 👍 / 👎.


boot_marker("config load start");
let settings = configuration::Settings::new()?;
boot_marker("config load done");

let secret_key = std::env::var("GOOSE_SERVER__SECRET_KEY")
.unwrap_or_else(|_| hex::encode(rand::random::<[u8; 32]>()));

boot_marker("appstate init start");
let app_state = state::AppState::new(settings.tls).await?;
boot_marker("appstate init done");

// Share the server secret with the tunnel manager so it uses the same
// key for forwarded requests, without mutating the process environment.
Expand Down Expand Up @@ -78,11 +88,13 @@ pub async fn run() -> Result<()> {
if settings.tls {
#[cfg(any(feature = "rustls-tls", feature = "native-tls"))]
{
boot_marker("tls setup start");
let tls_setup = setup_tls(
settings.tls_cert_path.as_deref(),
settings.tls_key_path.as_deref(),
)
.await?;
boot_marker("tls setup done");

let handle = Handle::new();
let shutdown_handle = handle.clone();
Expand All @@ -92,6 +104,7 @@ pub async fn run() -> Result<()> {
});

info!("listening on https://{}", addr);
boot_marker("listening");

#[cfg(feature = "rustls-tls")]
axum_server::bind_rustls(addr, tls_setup.config)
Expand All @@ -114,9 +127,12 @@ pub async fn run() -> Result<()> {
);
}
} else {
boot_marker("tcp bind start");
let listener = tokio::net::TcpListener::bind(addr).await?;
boot_marker("tcp bind done");

info!("listening on http://{}", addr);
boot_marker("listening");

axum::serve(listener, app)
.with_graceful_shutdown(async { shutdown_signal().await })
Expand Down
34 changes: 34 additions & 0 deletions crates/goose-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod state;
mod tunnel;

use std::path::PathBuf;
use std::{backtrace::Backtrace, panic::PanicHookInfo};

use clap::{Parser, Subcommand};
use goose::agents::validate_extensions;
Expand Down Expand Up @@ -42,9 +43,42 @@ enum Commands {
},
}

fn boot_marker(message: &str) {
eprintln!("GOOSED_BOOT: {message}");
}

fn install_panic_hook() {
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info: &PanicHookInfo<'_>| {
let location = panic_info
.location()
.map(|location| format!("{}:{}", location.file(), location.line()))
.unwrap_or_else(|| "unknown".to_string());

let payload = panic_info
.payload()
.downcast_ref::<&str>()
.map(|msg| (*msg).to_string())
.or_else(|| panic_info.payload().downcast_ref::<String>().cloned())
.unwrap_or_else(|| "unknown panic payload".to_string());

eprintln!("GOOSED_BOOT: panic at {location}: {payload}");
eprintln!("GOOSED_BOOT: backtrace:\n{}", Backtrace::force_capture());

default_hook(panic_info);
}));
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
install_panic_hook();
boot_marker("main entered");

let cli = Cli::parse();
boot_marker(&format!(
"command parsed: {:?}",
std::mem::discriminant(&cli.command)
));

match cli.command {
Commands::Agent => {
Expand Down
Loading
Loading