Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/internal/skills/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func run(cmd *skillsCmd, opts *internal.ToolboxOptions) error {
return err
}

opts.Cfg.SkipSourceInitialization = true

if err := os.MkdirAll(cmd.outputDir, 0755); err != nil {
errMsg := fmt.Errorf("error creating output directory: %w", err)
opts.Logger.ErrorContext(ctx, errMsg.Error())
Expand Down
2 changes: 2 additions & 0 deletions internal/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type ServerConfig struct {
UserAgentMetadata []string
// PollInterval sets the polling frequency for configuration file updates.
PollInterval int
// SkipSourceInitialization indicates if the server should skip initializing sources.
SkipSourceInitialization bool
Comment on lines +87 to +88
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.

medium

The pull request title and description do not adhere to the repository's style guide.

  • Title: Should follow the Conventional Commits format (e.g., feat(server): add skip source initialization option). Currently: skip source init exp.
  • Description: The provided description is empty and contains only the template placeholders. Please provide a concise summary of the changes and their impact.
References
  1. PR title must follow the Conventional Commits format: (): . (link)
  2. Every PR must include a description that follows the repository's template. (link)

}

type logFormat string
Expand Down
16 changes: 15 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
// initialize and validate the sources from configs
sourcesMap := make(map[string]sources.Source)
for name, sc := range cfg.SourceConfigs {
if cfg.SkipSourceInitialization {
sourcesMap[name] = &sources.UninitializedSource{
Name: name,
Config: sc,
}
continue
}

s, err := func() (sources.Source, error) {
childCtx, span := instrumentation.Tracer.Start(
ctx,
Expand Down Expand Up @@ -183,14 +191,20 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
defer span.End()
t, err := tc.Initialize(sourcesMap)
if err != nil {
if cfg.SkipSourceInitialization {
l.WarnContext(ctx, fmt.Sprintf("unable to initialize tool %q (source skip enabled): %v", name, err))
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.

medium

Leveraging structured logging by passing the tool name and error as separate attributes is preferred over fmt.Sprintf. This improves log searchability and consistency with other parts of the codebase (e.g., line 465).

Additionally, consider wrapping the tc.Initialize call in a recover() block when SkipSourceInitialization is enabled. This would prevent the server (or CLI tool) from crashing if a tool performs a concrete type assertion on an UninitializedSource and panics.

Suggested change
l.WarnContext(ctx, fmt.Sprintf("unable to initialize tool %q (source skip enabled): %v", name, err))
l.WarnContext(ctx, "unable to initialize tool (source skip enabled)", "tool", name, "error", err)

return nil, nil
}
return nil, fmt.Errorf("unable to initialize tool %q: %w", name, err)
}
return t, nil
}()
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
toolsMap[name] = t
if t != nil {
toolsMap[name] = t
}
}
toolNames := make([]string, 0, len(toolsMap))
for name := range toolsMap {
Expand Down
21 changes: 21 additions & 0 deletions internal/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import (
"context"
"net/http"

"fmt"

Expand Down Expand Up @@ -65,6 +66,26 @@
ToConfig() SourceConfig
}

// UninitializedSource is a placeholder for a source that hasn't been initialized yet.
// It implements many common methods to satisfy type assertions during tool initialization.
type UninitializedSource struct {
Name string
Config SourceConfig
}

func (s *UninitializedSource) SourceType() string { return s.Config.SourceConfigType() }

Check failure on line 76 in internal/sources/sources.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (goimports)
func (s *UninitializedSource) ToConfig() SourceConfig { return s.Config }
func (s *UninitializedSource) HttpDefaultHeaders() map[string]string { return nil }
func (s *UninitializedSource) HttpBaseURL() string { return "" }
func (s *UninitializedSource) HttpQueryParams() map[string]string { return nil }
func (s *UninitializedSource) RunRequest(ctx context.Context, r *http.Request) (any, error) { return nil, nil }
func (s *UninitializedSource) PostgresPool() any { return nil }
func (s *UninitializedSource) SQLiteDB() any { return nil }
func (s *UninitializedSource) BigQueryClient() any { return nil }
func (s *UninitializedSource) RunSQL(ctx context.Context, stmt string, args []any) (any, error) { return nil, nil }
func (s *UninitializedSource) GetDefaultProject() string { return "" }
func (s *UninitializedSource) UseClientAuthorization() bool { return false }

// InitConnectionSpan adds a span for database pool connection initialization
func InitConnectionSpan(ctx context.Context, tracer trace.Tracer, sourceType, sourceName string) (context.Context, trace.Span) {
ctx, span := tracer.Start(
Expand Down
Loading