refactor(logging): log with the caller's context so records carry trace ids
This commit is contained in:
1 parent
0611e00330
commit
656feab2a4
118 files changed
+512
-511
No files matched your search
@@ -120,6 +120,7 @@ linters:
|
||||
sloglint:
|
||||
no-mixed-args: true
|
||||
key-naming-case: snake
|
||||
context: scope
|
||||
|
||||
exclusions:
|
||||
generated: lax
|
||||
|
||||
@@ -345,7 +345,7 @@ func taskMCPProviders(ctx context.Context, req taskrun.Request, deps taskDepende
|
||||
llm := modelloop.NewRuntimeOver(deps.modelTransport, req.Providers, req.Cfg.ModelLimits, nil)
|
||||
set, err := taskmcp.Start(ctx, req.MCPServers, taskmcp.SamplingHandler(llm, req.Cfg, taskmcp.UsageRecorder(deps.store, req.Task, log)), log, storage.MCPNPMCacheMountDir)
|
||||
if err != nil {
|
||||
log.Warn("mcp providers had errors, continuing with available tools", "err", err)
|
||||
log.WarnContext(ctx, "mcp providers had errors, continuing with available tools", "err", err)
|
||||
}
|
||||
return llm, set
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func productionWorkerDependencies() (workerDependencies, error) {
|
||||
bootID: agentboot.TaskID,
|
||||
wait: func(ctx context.Context, log *slog.Logger) {
|
||||
<-ctx.Done()
|
||||
log.Info("archie-agent shutting down")
|
||||
log.InfoContext(ctx, "archie-agent shutting down")
|
||||
},
|
||||
steps: steps,
|
||||
guardrails: tools.NewGuardrailEngine(tools.DefaultGuardrailConfig()),
|
||||
@@ -141,7 +141,7 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
|
||||
// worker logs in as its task, with its run credential.
|
||||
taskID, err := dependencies.bootID(workDir)
|
||||
if err != nil {
|
||||
log.Error("task boot failed", "err", err)
|
||||
log.ErrorContext(ctx, "task boot failed", "err", err)
|
||||
return &StartupError{Operation: "task boot failed", Err: err}
|
||||
}
|
||||
transport, err := dependencies.connect(ctx, agentnats.Config{
|
||||
@@ -154,23 +154,23 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
|
||||
}, log)
|
||||
if err != nil {
|
||||
operation := "nats connect failed"
|
||||
log.Error(operation, "err", err)
|
||||
log.ErrorContext(ctx, operation, "err", err)
|
||||
return &StartupError{Operation: operation, Err: err}
|
||||
}
|
||||
defer transport.Close()
|
||||
log = slog.New(logging.WithTrace(agentexec.NewSystemLogHandler(log.Handler(), transport.LogPublisher(), taskID)))
|
||||
log.Info("system log publisher attached", "task", taskID)
|
||||
log.InfoContext(ctx, "system log publisher attached", "task", taskID)
|
||||
|
||||
subscription, err := transport.SubscribeTasks(ctx, taskID, func(ctx context.Context, request taskrun.Request) (*taskrun.Response, error) {
|
||||
return executeTaskRequest(ctx, request, transport, workDir, log, dependencies.steps, dependencies.guardrails, modelTransport)
|
||||
}, log)
|
||||
if err != nil {
|
||||
log.Error("taskrun subscribe failed", "err", err)
|
||||
log.ErrorContext(ctx, "taskrun subscribe failed", "err", err)
|
||||
return &StartupError{Operation: "taskrun subscribe failed", Err: err}
|
||||
}
|
||||
defer func() {
|
||||
if err := subscription.Close(); err != nil {
|
||||
log.Warn("task run unsubscribe failed", "err", err)
|
||||
log.WarnContext(ctx, "task run unsubscribe failed", "err", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -181,7 +181,7 @@ func run(ctx context.Context, settings Settings, log *slog.Logger, dependencies
|
||||
return nil
|
||||
}))
|
||||
go presence.Run(ctx, presence.Agent, presence.Build{InstanceID: strconv.FormatInt(taskID, 10), Version: Version(), InstallType: installtype.Type()}, transport, registry, log)
|
||||
log.Info("archie-agent ready", "nats", settings.NATSURL)
|
||||
log.InfoContext(ctx, "archie-agent ready", "nats", settings.NATSURL)
|
||||
dependencies.wait(ctx, log)
|
||||
return nil
|
||||
}
|
||||
@@ -195,7 +195,7 @@ type taskServiceTransport interface {
|
||||
}
|
||||
|
||||
func executeTaskRequest(ctx context.Context, request taskrun.Request, transport taskServiceTransport, workDir string, log *slog.Logger, steps *workflow.Manager, guardrails *tools.GuardrailEngine, modelTransport http.RoundTripper) (*taskrun.Response, error) {
|
||||
log.Info("running task", "task", request.Task.ID, "repo", request.Repo.FullName(), "issue", request.Task.IssueNumber)
|
||||
log.InfoContext(ctx, "running task", "task", request.Task.ID, "repo", request.Repo.FullName(), "issue", request.Task.IssueNumber)
|
||||
dependencies := taskDependencies{
|
||||
forge: transport.Forger(request.Task.Identity, request.RunCredential, rpcTimeout),
|
||||
store: transport.Store(rpcTimeout),
|
||||
@@ -209,9 +209,9 @@ func executeTaskRequest(ctx context.Context, request taskrun.Request, transport
|
||||
}
|
||||
response, err := runTask(ctx, request, dependencies, newTaskRunner(modelTransport), workDir, log)
|
||||
if err != nil {
|
||||
log.Error("task run failed", "task", request.Task.ID, "err", err)
|
||||
log.ErrorContext(ctx, "task run failed", "task", request.Task.ID, "err", err)
|
||||
return nil, err
|
||||
}
|
||||
log.Info("task run complete", "task", request.Task.ID, "status", response.Status)
|
||||
log.InfoContext(ctx, "task run complete", "task", request.Task.ID, "status", response.Status)
|
||||
return response, nil
|
||||
}
|
||||
@@ -282,7 +282,7 @@ func (b *boot) deliverAlerts(store alert.Deliverer) func(context.Context) {
|
||||
return func(ctx context.Context) {
|
||||
due, err := store.ClaimAlertDeliveries(ctx, 20)
|
||||
if err != nil {
|
||||
b.log.Warn("alert deliveries not claimed", "err", err)
|
||||
b.log.WarnContext(ctx, "alert deliveries not claimed", "err", err)
|
||||
return
|
||||
}
|
||||
notify := b.cfgHolder.Get().Notify
|
||||
@@ -306,7 +306,7 @@ func (b *boot) deliverAlerts(store alert.Deliverer) func(context.Context) {
|
||||
}
|
||||
}
|
||||
if err := store.RecordAlertAttempt(ctx, outcome); err != nil {
|
||||
b.log.Warn("alert delivery not recorded", "delivery", d.ID, "err", err)
|
||||
b.log.WarnContext(ctx, "alert delivery not recorded", "delivery", d.ID, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ func (b *boot) openStateStoreAdapter(ctx context.Context) error {
|
||||
}
|
||||
client, cleanup, err := servicekit.StateStoreClient(presence.Daemon, b.cfg)
|
||||
if err != nil {
|
||||
b.log.Error("state store adapter", "err", err)
|
||||
b.log.ErrorContext(ctx, "state store adapter", "err", err)
|
||||
return err
|
||||
}
|
||||
b.stateStore = client
|
||||
@@ -331,7 +331,7 @@ func (b *boot) openAccessChain(ctx context.Context) error {
|
||||
}
|
||||
live := infraaccess.NewPending(ctx, source.PoliciesVersion, source.ListPolicies, b.log)
|
||||
if err := live.Reload(ctx); err != nil {
|
||||
b.log.Warn("workflow policies unavailable; execution remains denied", "err", err)
|
||||
b.log.WarnContext(ctx, "workflow policies unavailable; execution remains denied", "err", err)
|
||||
}
|
||||
b.accessChain, b.accessLive = live, live
|
||||
return nil
|
||||
@@ -344,10 +344,10 @@ func (b *boot) handleRequeue(ctx context.Context, requeue int64, once bool) (boo
|
||||
return false, nil
|
||||
}
|
||||
if err := manualRequeueTask(ctx, b.stateStore, requeue); err != nil {
|
||||
b.log.Error("requeue failed", "task", requeue, "err", err)
|
||||
b.log.ErrorContext(ctx, "requeue failed", "task", requeue, "err", err)
|
||||
return false, err
|
||||
}
|
||||
b.log.Info("task requeued", "task", requeue)
|
||||
b.log.InfoContext(ctx, "task requeued", "task", requeue)
|
||||
return !once, nil
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ func (b *boot) connectNATS(ctx context.Context) error { // embedded broker disco
|
||||
var err error
|
||||
natsToken, err = servicekit.NATSToken(cfg.NATS, os.Getenv)
|
||||
if err != nil {
|
||||
log.Error("nats credentials", "err", err)
|
||||
log.ErrorContext(ctx, "nats credentials", "err", err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -417,7 +417,7 @@ func (b *boot) connectNATS(ctx context.Context) error { // embedded broker disco
|
||||
FilterSubject: workintake.SubjectTaskWildcard,
|
||||
}, log)
|
||||
if err != nil {
|
||||
log.Error("nats connect failed", "err", err)
|
||||
log.ErrorContext(ctx, "nats connect failed", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -432,13 +432,13 @@ func (b *boot) connectNATS(ctx context.Context) error { // embedded broker disco
|
||||
MaxAge: &reactionMaxAge,
|
||||
}, log)
|
||||
if err != nil {
|
||||
log.Error("nats reaction stream connect failed", "err", err)
|
||||
log.ErrorContext(ctx, "nats reaction stream connect failed", "err", err)
|
||||
natsClient.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := b.startSpanRelay(ctx, url, natsToken); err != nil {
|
||||
log.Error("span relay failed", "err", err)
|
||||
log.ErrorContext(ctx, "span relay failed", "err", err)
|
||||
natsClient.Close()
|
||||
reactionClient.Close()
|
||||
return err
|
||||
@@ -449,7 +449,7 @@ func (b *boot) connectNATS(ctx context.Context) error { // embedded broker disco
|
||||
b.addCleanup(func() { natsClient.Close() })
|
||||
b.addCleanup(func() { reactionClient.Close() })
|
||||
b.reactionClient = reactionClient
|
||||
log.Info("nats connected", "url", url, "task_stream", nats.DefaultStreamName, "reaction_stream", nats.DefaultReactionStreamName)
|
||||
log.InfoContext(ctx, "nats connected", "url", url, "task_stream", nats.DefaultStreamName, "reaction_stream", nats.DefaultReactionStreamName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -476,16 +476,16 @@ func (b *boot) startEmbeddedNATS(ctx context.Context) (string, string, error) {
|
||||
}
|
||||
srv, err := nats.StartEmbedded(ctx, opts, log)
|
||||
if err != nil && opts.Port != 0 {
|
||||
log.Warn("embedded nats: previous port unavailable; taking a new one", "port", opts.Port, "err", err)
|
||||
log.WarnContext(ctx, "embedded nats: previous port unavailable; taking a new one", "port", opts.Port, "err", err)
|
||||
opts.Port = 0
|
||||
srv, err = nats.StartEmbedded(ctx, opts, log)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("embedded nats start failed", "err", err)
|
||||
log.ErrorContext(ctx, "embedded nats start failed", "err", err)
|
||||
return "", "", err
|
||||
}
|
||||
b.addCleanup(func() { srv.Shutdown() })
|
||||
log.Info("embedded nats started", "url", srv.ClientURL())
|
||||
log.InfoContext(ctx, "embedded nats started", "url", srv.ClientURL())
|
||||
if err := servicekit.WriteNATSEndpoint(cfg.StateDir, srv.ClientURL(), srv.Token()); err != nil {
|
||||
srv.Shutdown()
|
||||
return "", "", err
|
||||
@@ -735,7 +735,7 @@ func (b *boot) publishConfigSnapshot(ctx context.Context) {
|
||||
|
||||
document, err := json.Marshal(webui.BuildConfigView(b.configViewInput()))
|
||||
if err != nil {
|
||||
b.log.Warn("config snapshot not published", "err", err)
|
||||
b.log.WarnContext(ctx, "config snapshot not published", "err", err)
|
||||
return
|
||||
}
|
||||
err = snapshots.PutConfigSnapshot(ctx, storecontract.ConfigSnapshot{
|
||||
@@ -744,7 +744,7 @@ func (b *boot) publishConfigSnapshot(ctx context.Context) {
|
||||
PublishedAt: time.Now().UTC(),
|
||||
})
|
||||
if err != nil {
|
||||
b.log.Warn("config snapshot not published", "err", err)
|
||||
b.log.WarnContext(ctx, "config snapshot not published", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -765,12 +765,12 @@ func (b *boot) wireConfigPublishing(ctx context.Context, cfgPath, overlayPath st
|
||||
func (b *boot) startServices(ctx context.Context) error {
|
||||
log := b.log
|
||||
if err := b.d.Startup(ctx); err != nil {
|
||||
log.Error("startup", "err", err)
|
||||
log.ErrorContext(ctx, "startup", "err", err)
|
||||
return err
|
||||
}
|
||||
if b.schedulingEngine != nil {
|
||||
if err := b.schedulingEngine.Start(ctx); err != nil {
|
||||
log.Error("scheduling engine startup", "err", err)
|
||||
log.ErrorContext(ctx, "scheduling engine startup", "err", err)
|
||||
}
|
||||
}
|
||||
for _, startGateway := range b.startGateways {
|
||||
@@ -806,12 +806,12 @@ func (b *boot) runLoop(ctx context.Context, once bool) error {
|
||||
b.d.RunOnce(ctx)
|
||||
return nil
|
||||
}
|
||||
b.log.Info("archied running", "repos", len(b.cfg.Repos), "poll", b.cfg.PollInterval.Std().String(), "label", b.cfg.Label)
|
||||
b.log.InfoContext(ctx, "archied running", "repos", len(b.cfg.Repos), "poll", b.cfg.PollInterval.Std().String(), "label", b.cfg.Label)
|
||||
b.startDrainMonitor(ctx)
|
||||
b.startWatchdog(ctx)
|
||||
b.startAlerts(ctx)
|
||||
if err := b.d.Run(ctx); err != nil && ctx.Err() == nil {
|
||||
b.log.Error("daemon exited", "err", err)
|
||||
b.log.ErrorContext(ctx, "daemon exited", "err", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -840,13 +840,13 @@ func (b *boot) catalogState() modelcatalog.Snapshot { return b.catalog.State() }
|
||||
func (b *boot) loadCatalog(ctx context.Context) {
|
||||
snapshot, err := b.catalog.Fetch(ctx, b.secrets.Getenv, b.cfgHolder.Get().Providers)
|
||||
if err != nil {
|
||||
b.log.Warn("model catalog unavailable; using configured providers and models", "err", err)
|
||||
b.log.WarnContext(ctx, "model catalog unavailable; using configured providers and models", "err", err)
|
||||
return
|
||||
}
|
||||
models := modelcatalog.Apply(&b.cfg, snapshot)
|
||||
b.cfgHolder.Set(b.cfg.Clone())
|
||||
b.catalog.Set(snapshot)
|
||||
b.log.Info("model catalog loaded", "providers", len(snapshot.Providers), "models", len(models))
|
||||
b.log.InfoContext(ctx, "model catalog loaded", "providers", len(snapshot.Providers), "models", len(models))
|
||||
}
|
||||
|
||||
func (b *boot) refreshModelCatalog(ctx context.Context) error {
|
||||
@@ -862,14 +862,14 @@ func (b *boot) refreshModelCatalog(ctx context.Context) error {
|
||||
}
|
||||
b.catalog.Set(snapshot)
|
||||
b.publishConfig(ctx, cfg)
|
||||
b.log.Info("model catalog refreshed", "providers", len(snapshot.Providers), "models", len(models))
|
||||
b.log.InfoContext(ctx, "model catalog refreshed", "providers", len(snapshot.Providers), "models", len(models))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *boot) startModelCatalogRefresh(ctx context.Context) {
|
||||
modelcatalog.Every(ctx, modelcatalog.RefreshInterval, func() {
|
||||
if err := b.refreshModelCatalog(ctx); err != nil {
|
||||
b.log.Warn("model catalog refresh failed; keeping the loaded catalog", "err", err)
|
||||
b.log.WarnContext(ctx, "model catalog refresh failed; keeping the loaded catalog", "err", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,10 +74,10 @@ func (b *boot) reloadConfig(ctx context.Context, doc *configuration.Document) er
|
||||
// reach it the same way a control-plane update does.
|
||||
b.resizeTaskDispatcher(cfg.Containers.MaxConcurrency)
|
||||
if fields := restartFields; len(fields) > 0 {
|
||||
b.log.Warn("config reloaded; some changes require a restart",
|
||||
b.log.WarnContext(ctx, "config reloaded; some changes require a restart",
|
||||
"fields", fields, "paths", doc.Provenance.Paths())
|
||||
} else {
|
||||
b.log.Info("config reloaded", "paths", doc.Provenance.Paths())
|
||||
b.log.InfoContext(ctx, "config reloaded", "paths", doc.Provenance.Paths())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (b *boot) startWorkflowExecutionSettings(ctx context.Context) error {
|
||||
} else {
|
||||
streamErr = update.Err
|
||||
}
|
||||
b.log.Error("workflow execution settings watch failed", "err", update.Err)
|
||||
b.log.ErrorContext(ctx, "workflow execution settings watch failed", "err", update.Err)
|
||||
return
|
||||
}
|
||||
lastApplyErr = b.applyWorkflowExecutionSettings(ctx, update.Settings, update.Version)
|
||||
@@ -194,15 +194,15 @@ func (b *boot) applyWorkflowExecutionSettings(ctx context.Context, settings work
|
||||
candidate, err := b.buildExecutionSettingsCandidate(settings)
|
||||
if err != nil {
|
||||
b.applyStatus.Report(ctx, controlplanestore.WorkflowExecutionSettingsKind, version, err)
|
||||
b.log.Error("workflow execution settings rejected; the running settings stay", "version", version, "err", err)
|
||||
b.log.ErrorContext(ctx, "workflow execution settings rejected; the running settings stay", "version", version, "err", err)
|
||||
return err
|
||||
}
|
||||
b.executionSettings.Store(&candidate.settings)
|
||||
b.publishConfig(ctx, candidate.cfg)
|
||||
b.applyStatus.Report(ctx, controlplanestore.WorkflowExecutionSettingsKind, version, nil)
|
||||
b.log.Info("workflow execution settings applied", "version", version)
|
||||
b.log.InfoContext(ctx, "workflow execution settings applied", "version", version)
|
||||
if limit, uptime := settings.MaxTaskRuntime, candidate.cfg.Containers.MaxUptime.Std(); uptime > 0 && (limit <= 0 || limit > uptime) {
|
||||
b.log.Warn("containers.max_uptime is shorter than the task time limit; the container is killed first", "max_uptime", uptime, "max_task_runtime", limit)
|
||||
b.log.WarnContext(ctx, "containers.max_uptime is shorter than the task time limit; the container is killed first", "max_uptime", uptime, "max_task_runtime", limit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (b *boot) startRuntimeResourceWatches(ctx context.Context, versions map[str
|
||||
} else {
|
||||
streamErr = update.Err
|
||||
}
|
||||
b.log.Error("runtime settings watch failed", "kind", kind, "err", update.Err)
|
||||
b.log.ErrorContext(ctx, "runtime settings watch failed", "kind", kind, "err", update.Err)
|
||||
return
|
||||
}
|
||||
lastApplyErr = b.applyRuntimeResourceUpdate(ctx, kind, update)
|
||||
@@ -365,7 +365,7 @@ func (b *boot) applyRuntimeResourceUpdate(ctx context.Context, kind string, upda
|
||||
if kind == controlplanestore.PluginSettingsKind {
|
||||
if err := b.refuseSkillsDirChange(ctx); err != nil {
|
||||
b.applyStatus.Report(ctx, kind, update.Version, err)
|
||||
b.log.Error("plugin settings refused; the running settings stay", "version", update.Version, "err", err)
|
||||
b.log.ErrorContext(ctx, "plugin settings refused; the running settings stay", "version", update.Version, "err", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -380,11 +380,11 @@ func (b *boot) applyRuntimeResourceUpdate(ctx context.Context, kind string, upda
|
||||
if err != nil {
|
||||
// runtimeConfig reported the refusal through apply status for every
|
||||
// kind it layers, keeping the version each of them last applied.
|
||||
b.log.Error("runtime settings update rejected; the running settings stay", "kind", kind, "version", update.Version, "err", err)
|
||||
b.log.ErrorContext(ctx, "runtime settings update rejected; the running settings stay", "kind", kind, "version", update.Version, "err", err)
|
||||
return err
|
||||
}
|
||||
b.publishConfig(ctx, cfg)
|
||||
b.log.Info("runtime settings applied", "kind", kind, "version", update.Version)
|
||||
b.log.InfoContext(ctx, "runtime settings applied", "kind", kind, "version", update.Version)
|
||||
if kind == controlplanestore.ContainerRuntimePoliciesKind {
|
||||
// The pool reads the republished config itself; the dispatcher holds
|
||||
// its limit, so a raise must be woken to admit queued work now and a
|
||||
|
||||
@@ -44,13 +44,13 @@ func monitorDrainRequests(
|
||||
decision, err := check()
|
||||
switch {
|
||||
case err != nil:
|
||||
log.Warn("drain request check failed", "err", err)
|
||||
log.WarnContext(ctx, "drain request check failed", "err", err)
|
||||
case decision == drain.DecisionValid:
|
||||
log.Info("drain request accepted; initiating graceful shutdown")
|
||||
log.InfoContext(ctx, "drain request accepted; initiating graceful shutdown")
|
||||
shutdown()
|
||||
return nil
|
||||
case decision == drain.DecisionStale:
|
||||
log.Warn("stale drain request ignored; marker predates current instantiation")
|
||||
log.WarnContext(ctx, "stale drain request ignored; marker predates current instantiation")
|
||||
}
|
||||
|
||||
timer := time.NewTimer(interval)
|
||||
@@ -72,7 +72,7 @@ func monitorDrainRequests(
|
||||
// a single-cycle invocation.
|
||||
func (b *boot) startDrainMonitor(ctx context.Context) {
|
||||
if b.shutdown == nil {
|
||||
b.log.Error("drain monitor not started: no shutdown trigger wired")
|
||||
b.log.ErrorContext(ctx, "drain monitor not started: no shutdown trigger wired")
|
||||
return
|
||||
}
|
||||
reader := drainio.New(DefaultDrainRequestPath(), nil)
|
||||
@@ -85,7 +85,7 @@ func (b *boot) startDrainMonitor(ctx context.Context) {
|
||||
defaultDrainPollInterval,
|
||||
)
|
||||
if err != nil && !errors.Is(err, context.Canceled) {
|
||||
b.log.Error("drain monitor stopped", "err", err)
|
||||
b.log.ErrorContext(ctx, "drain monitor stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -71,7 +71,7 @@ func (e *forgeExtensions) open(ctx context.Context, typ, instance, host, token s
|
||||
}
|
||||
settings, _, err := e.source.Enabled(ctx)
|
||||
if err != nil {
|
||||
e.log.Warn("forge extensions: extension settings unavailable", "err", err)
|
||||
e.log.WarnContext(ctx, "forge extensions: extension settings unavailable", "err", err)
|
||||
return nil, false
|
||||
}
|
||||
setting, ok := settings[typ]
|
||||
@@ -80,7 +80,7 @@ func (e *forgeExtensions) open(ctx context.Context, typ, instance, host, token s
|
||||
}
|
||||
installed, err := e.source.Packages.ListInstalled(ctx)
|
||||
if err != nil {
|
||||
e.log.Warn("forge extensions: installed packages unavailable", "err", err)
|
||||
e.log.WarnContext(ctx, "forge extensions: installed packages unavailable", "err", err)
|
||||
return nil, false
|
||||
}
|
||||
for _, pkg := range installed {
|
||||
@@ -93,7 +93,7 @@ func (e *forgeExtensions) open(ctx context.Context, typ, instance, host, token s
|
||||
}
|
||||
forgeClient, err := e.start(ctx, pkg, pkg.Descriptor.Contributes.Extensions[index].Path, instance, host, token, setting.Settings)
|
||||
if err != nil {
|
||||
e.log.Warn("forge disabled: extension did not start", "forge_type", typ, "instance", instance, "err", err)
|
||||
e.log.WarnContext(ctx, "forge disabled: extension did not start", "forge_type", typ, "instance", instance, "err", err)
|
||||
return forge.NewNoop(e.log), true
|
||||
}
|
||||
return forgeClient, true
|
||||
|
||||
@@ -189,22 +189,22 @@ func (b *boot) setupDaemonRPC(ctx context.Context) {
|
||||
conn := b.cfg.Services.Get(config.ServiceNameDaemon)
|
||||
listen, err := servicekit.ResolveListen(config.ServiceNameDaemon, "", conn.Listen)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
b.log.WarnContext(ctx, "harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
b.log.WarnContext(ctx, "harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
creds, err := id.ServerOption(listen, false)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled", "err", err)
|
||||
b.log.WarnContext(ctx, "harness sessions disabled", "err", err)
|
||||
return
|
||||
}
|
||||
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
|
||||
if err != nil {
|
||||
b.log.Warn("harness sessions disabled: listen", "err", err)
|
||||
b.log.WarnContext(ctx, "harness sessions disabled: listen", "err", err)
|
||||
return
|
||||
}
|
||||
callers := rpcidentity.Callers{Principals: b.d.Principals}
|
||||
@@ -218,7 +218,7 @@ func (b *boot) setupDaemonRPC(ctx context.Context) {
|
||||
|
||||
go func() {
|
||||
if err := srv.Serve(ln); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
|
||||
b.log.Error("harness listener stopped", "err", err)
|
||||
b.log.ErrorContext(ctx, "harness listener stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
b.addCleanup(func() {
|
||||
@@ -230,7 +230,7 @@ func (b *boot) setupDaemonRPC(ctx context.Context) {
|
||||
timer.Stop()
|
||||
_ = ln.Close()
|
||||
})
|
||||
b.log.Info("harness sessions enabled", "addr", ln.Addr().String())
|
||||
b.log.InfoContext(ctx, "harness sessions enabled", "addr", ln.Addr().String())
|
||||
}
|
||||
|
||||
var _ kitrun.GrantRegistry = (*sessionGrants)(nil)
|
||||
|
||||
@@ -99,7 +99,7 @@ func (b *boot) startHealth(ctx context.Context) error {
|
||||
}
|
||||
addr := b.cfg.Health.Listen
|
||||
if err := b.serveHealth(ctx, addr, b.health.handler(), "daemon health"); err != nil {
|
||||
b.log.Error("health listener failed", "addr", addr, "err", err)
|
||||
b.log.ErrorContext(ctx, "health listener failed", "addr", addr, "err", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -44,7 +44,7 @@ func (b *boot) organisations(ctx context.Context) []orgAgents {
|
||||
if directory != nil {
|
||||
agents, err := directory.ListOrgAgents(ctx, owner)
|
||||
if err != nil {
|
||||
b.log.Warn("organisation agents unavailable", "org", owner, "err", err)
|
||||
b.log.WarnContext(ctx, "organisation agents unavailable", "org", owner, "err", err)
|
||||
}
|
||||
for _, agent := range agents {
|
||||
principal, err := directory.PrincipalFor(ctx, agent.IdentityID)
|
||||
@@ -54,7 +54,7 @@ func (b *boot) organisations(ctx context.Context) []orgAgents {
|
||||
}
|
||||
}
|
||||
if owner != org.DefaultOrgID && len(entry.principals) == 0 {
|
||||
b.log.Warn("organisation skipped: no agent to act as", "org", owner)
|
||||
b.log.WarnContext(ctx, "organisation skipped: no agent to act as", "org", owner)
|
||||
continue
|
||||
}
|
||||
out = append(out, entry)
|
||||
@@ -83,18 +83,18 @@ func (b *boot) issueSources(ctx context.Context) []daemon.IssueSource {
|
||||
octx := o.act(ctx)
|
||||
var repos []config.Repo
|
||||
if _, found, err := b.controlPlane.Query(octx, controlplanestore.RepositoryPoliciesKind, func(value []byte) error { return json.Unmarshal(value, &repos) }); err != nil || !found {
|
||||
log.Warn("issue discovery: repositories unavailable", "err", err)
|
||||
log.WarnContext(ctx, "issue discovery: repositories unavailable", "err", err)
|
||||
continue
|
||||
}
|
||||
connections, err := b.repositoryConnections(octx)
|
||||
if err != nil {
|
||||
log.Warn("issue discovery: connections unavailable", "err", err)
|
||||
log.WarnContext(ctx, "issue discovery: connections unavailable", "err", err)
|
||||
continue
|
||||
}
|
||||
byConnection := map[string][]config.Repo{}
|
||||
for _, repo := range repos {
|
||||
if repo.Connection == "" {
|
||||
log.Warn("issue discovery: repository has no connection", "repo", repo.FullName())
|
||||
log.WarnContext(ctx, "issue discovery: repository has no connection", "repo", repo.FullName())
|
||||
continue
|
||||
}
|
||||
byConnection[repo.Connection] = append(byConnection[repo.Connection], repo)
|
||||
@@ -120,7 +120,7 @@ func (b *boot) connectionSource(ctx context.Context, o orgAgents, connection con
|
||||
}
|
||||
resolved, err := b.openRepositoryConnection(ctx, principal, repos[0], connection, config.OperationClone)
|
||||
if err != nil {
|
||||
log.Warn("issue discovery: connection unavailable", "err", err)
|
||||
log.WarnContext(ctx, "issue discovery: connection unavailable", "err", err)
|
||||
return daemon.IssueSource{}, false
|
||||
}
|
||||
user := resolved.Trees.AuthUser
|
||||
@@ -129,6 +129,6 @@ func (b *boot) connectionSource(ctx context.Context, o orgAgents, connection con
|
||||
}
|
||||
return daemon.IssueSource{Identity: principal.IdentityID, Forge: resolved.Forge, BotUser: user, Repos: repos}, true
|
||||
}
|
||||
log.Warn("issue discovery: no agent may clone through this connection")
|
||||
log.WarnContext(ctx, "issue discovery: no agent may clone through this connection")
|
||||
return daemon.IssueSource{}, false
|
||||
}
|
||||
@@ -29,31 +29,31 @@ import (
|
||||
func (b *boot) setupKitLauncher(ctx context.Context) {
|
||||
pool, log := b.containerPool, b.log
|
||||
if pool == nil || pool.HostGateway() == "" {
|
||||
log.Info("kit harness runs disabled: they need the managed container pool on a bridge with a host gateway")
|
||||
log.InfoContext(ctx, "kit harness runs disabled: they need the managed container pool on a bridge with a host gateway")
|
||||
return
|
||||
}
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Warn("kit harness runs disabled", "err", err)
|
||||
log.WarnContext(ctx, "kit harness runs disabled", "err", err)
|
||||
return
|
||||
}
|
||||
agentBinary := filepath.Join(filepath.Dir(exe), "archie-agent")
|
||||
caDir := filepath.Join(b.cfg.StateDir, "egress")
|
||||
ca, err := egress.LoadOrCreateCA(caDir)
|
||||
if err != nil {
|
||||
log.Warn("kit harness runs disabled: egress CA", "err", err)
|
||||
log.WarnContext(ctx, "kit harness runs disabled: egress CA", "err", err)
|
||||
return
|
||||
}
|
||||
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", net.JoinHostPort(pool.HostGateway(), "0"))
|
||||
if err != nil {
|
||||
log.Warn("kit harness runs disabled: egress proxy listener", "err", err)
|
||||
log.WarnContext(ctx, "kit harness runs disabled: egress proxy listener", "err", err)
|
||||
return
|
||||
}
|
||||
endpoints := kitrun.Endpoints{NATS: b.natsURL, StateStore: strings.TrimSpace(b.cfg.Services.Get(config.ServiceNameState).Target)}
|
||||
cmd, err := kitrun.RelayCommand(ln.Addr().String(), endpoints)
|
||||
if err != nil {
|
||||
_ = ln.Close()
|
||||
log.Warn("kit harness runs disabled: egress relay", "err", err)
|
||||
log.WarnContext(ctx, "kit harness runs disabled: egress relay", "err", err)
|
||||
return
|
||||
}
|
||||
// The proxy resolves each credential from the run credential the
|
||||
@@ -67,7 +67,7 @@ func (b *boot) setupKitLauncher(ctx context.Context) {
|
||||
gateway, cleanup, err := b.connectTaskTools()
|
||||
if err != nil {
|
||||
_ = ln.Close()
|
||||
log.Warn("kit task tools unavailable", "err", err)
|
||||
log.WarnContext(ctx, "kit task tools unavailable", "err", err)
|
||||
return
|
||||
}
|
||||
b.addCleanup(cleanup)
|
||||
@@ -84,7 +84,7 @@ func (b *boot) setupKitLauncher(ctx context.Context) {
|
||||
srv := &http.Server{Handler: proxy, ReadHeaderTimeout: 30 * time.Second}
|
||||
go func() {
|
||||
if err := srv.Serve(ln); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Error("egress proxy stopped", "err", err)
|
||||
log.ErrorContext(ctx, "egress proxy stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
// Native tasks need only the proxy for model access, so it serves them
|
||||
@@ -93,7 +93,7 @@ func (b *boot) setupKitLauncher(ctx context.Context) {
|
||||
fetcher, err := fetch.New(fetch.WithDockerCredentials())
|
||||
if err != nil {
|
||||
b.addCleanup(func() { _ = srv.Close() })
|
||||
log.Warn("kit harness runs disabled: kit registry client", "err", err)
|
||||
log.WarnContext(ctx, "kit harness runs disabled: kit registry client", "err", err)
|
||||
return
|
||||
}
|
||||
networks := egress.NewNetworks(pool.Client(), egress.RelaySpec{
|
||||
@@ -108,7 +108,7 @@ func (b *boot) setupKitLauncher(ctx context.Context) {
|
||||
Grants: b.sessionGrants,
|
||||
}
|
||||
b.kitLauncher = kitLauncher
|
||||
log.Info("kit harness runs enabled", "proxy", ln.Addr().String())
|
||||
log.InfoContext(ctx, "kit harness runs enabled", "proxy", ln.Addr().String())
|
||||
}
|
||||
|
||||
// shutdownEgress removes the relay and stops the proxy. It derives its own
|
||||
|
||||
@@ -62,7 +62,7 @@ func resolveForge(ctx context.Context, cfg config.Forge, instance string, secret
|
||||
}
|
||||
token, err := secrets.Resolve(cfg.Token)
|
||||
if err != nil || token == "" {
|
||||
log.Warn("forge disabled: token unavailable",
|
||||
log.WarnContext(ctx, "forge disabled: token unavailable",
|
||||
"forge_type", cfg.Type,
|
||||
"engine", cfg.Token.Engine,
|
||||
"key", cfg.Token.Key,
|
||||
@@ -72,7 +72,7 @@ func resolveForge(ctx context.Context, cfg config.Forge, instance string, secret
|
||||
if client, handled := extensions.open(ctx, cfg.Type, instance, cfg.Host, token); handled {
|
||||
return client, token
|
||||
}
|
||||
log.Warn("forge disabled: no enabled forge extension of that name",
|
||||
log.WarnContext(ctx, "forge disabled: no enabled forge extension of that name",
|
||||
"forge_type", cfg.Type, "instance", instance)
|
||||
return forge.NewNoop(log), ""
|
||||
}
|
||||
@@ -247,7 +247,7 @@ func persistEvents(ctx context.Context, sink *events.Sub, st storecontract.TaskS
|
||||
continue
|
||||
}
|
||||
if _, err := st.InsertEvent(ctx, e); err != nil {
|
||||
log.Error("event sink insert failed", "err", err)
|
||||
log.ErrorContext(ctx, "event sink insert failed", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,12 +410,12 @@ func startContainers(
|
||||
// Single Docker client shared between pool and storage backend.
|
||||
dockerCli, err := client.New(client.FromEnv)
|
||||
if err != nil {
|
||||
log.Error("autonomous workflows unavailable: docker client unavailable", "err", err)
|
||||
log.ErrorContext(ctx, "autonomous workflows unavailable: docker client unavailable", "err", err)
|
||||
return nil, nil, noop
|
||||
}
|
||||
closeDocker := func() {
|
||||
if err := dockerCli.Close(); err != nil {
|
||||
log.Warn("docker client close failed", "err", err)
|
||||
log.WarnContext(ctx, "docker client close failed", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ func startContainers(
|
||||
}, containerLiveSettings(cfgHolder), log)
|
||||
if err != nil {
|
||||
// A missing image is recoverable by hand.
|
||||
log.Error("autonomous workflows unavailable: container pool unavailable", "err", err,
|
||||
log.ErrorContext(ctx, "autonomous workflows unavailable: container pool unavailable", "err", err,
|
||||
"hint", "run `docker compose pull agent` (or `build agent`) so the image is present locally")
|
||||
return nil, storage.NewDockerBackend(dockerCli, cfg.Instance), closeDocker
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func startContainers(
|
||||
//nolint:contextcheck
|
||||
return pool, storage.NewDockerBackend(dockerCli, cfg.Instance), func() {
|
||||
if err := pool.Close(); err != nil {
|
||||
log.Warn("container pool close failed", "err", err)
|
||||
log.WarnContext(ctx, "container pool close failed", "err", err)
|
||||
}
|
||||
closeDocker()
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ func postOutcomes(ctx context.Context, tasks storecontract.OutcomePoster, delive
|
||||
func postPendingOutcomes(ctx context.Context, tasks storecontract.OutcomePoster, deliver outcomeDeliverer, posted func(taskID int64), log *slog.Logger) {
|
||||
pending, err := tasks.UnpostedOutcomes(ctx)
|
||||
if err != nil {
|
||||
log.Warn("list unposted task outcomes", "err", err)
|
||||
log.WarnContext(ctx, "list unposted task outcomes", "err", err)
|
||||
return
|
||||
}
|
||||
for _, t := range pending {
|
||||
@@ -79,14 +79,14 @@ func postPendingOutcomes(ctx context.Context, tasks storecontract.OutcomePoster,
|
||||
case status.Code(err) == codes.NotFound:
|
||||
// No such channel or conversation, so a retry can never
|
||||
// deliver it.
|
||||
log.Info("task outcome has nowhere to go", "task", t.ID, "origin", t.Origin)
|
||||
log.InfoContext(ctx, "task outcome has nowhere to go", "task", t.ID, "origin", t.Origin)
|
||||
case err != nil:
|
||||
log.Warn("post task outcome", "task", t.ID, "err", err)
|
||||
log.WarnContext(ctx, "post task outcome", "task", t.ID, "err", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if err := tasks.MarkOutcomePosted(ctx, t.ID, t.Status); err != nil {
|
||||
log.Warn("mark task outcome posted", "task", t.ID, "err", err)
|
||||
log.WarnContext(ctx, "mark task outcome posted", "task", t.ID, "err", err)
|
||||
}
|
||||
if delivered {
|
||||
posted(t.ID)
|
||||
|
||||
@@ -80,7 +80,7 @@ func reloadLoop(ctx context.Context, ch <-chan os.Signal, c *ReloadController, l
|
||||
return
|
||||
case <-ch:
|
||||
if err := c.Reload(ctx); err != nil {
|
||||
log.Error("config reload failed; keeping running config", "err", err)
|
||||
log.ErrorContext(ctx, "config reload failed; keeping running config", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ func (s scheduleResourceStore) owners(ctx context.Context) []org.OrgID {
|
||||
}
|
||||
list, err := s.orgs.ListOrgs(ctx)
|
||||
if err != nil {
|
||||
s.log.Warn("scheduling: organisations unavailable; running system schedules only", "err", err)
|
||||
s.log.WarnContext(ctx, "scheduling: organisations unavailable; running system schedules only", "err", err)
|
||||
return owners
|
||||
}
|
||||
for _, o := range list {
|
||||
@@ -208,7 +208,7 @@ func (s scheduleResourceStore) Due(ctx context.Context, now time.Time) ([]schedu
|
||||
for _, owner := range s.owners(ctx) {
|
||||
octx, err := s.orgContext(ctx, owner)
|
||||
if err != nil {
|
||||
s.log.Warn("scheduling: skipping organisation", "org", owner, "err", err)
|
||||
s.log.WarnContext(ctx, "scheduling: skipping organisation", "org", owner, "err", err)
|
||||
continue
|
||||
}
|
||||
jobs, _, err := s.client.Schedules(octx)
|
||||
@@ -216,7 +216,7 @@ func (s scheduleResourceStore) Due(ctx context.Context, now time.Time) ([]schedu
|
||||
if owner == org.DefaultOrgID {
|
||||
return nil, err
|
||||
}
|
||||
s.log.Warn("scheduling: organisation schedules unavailable", "org", owner, "err", err)
|
||||
s.log.WarnContext(ctx, "scheduling: organisation schedules unavailable", "org", owner, "err", err)
|
||||
continue
|
||||
}
|
||||
for _, job := range jobs {
|
||||
|
||||
@@ -57,13 +57,13 @@ func (b *boot) startWatchdog(ctx context.Context) {
|
||||
Beat: func() { n.Send(sdnotify.WatchdogState) },
|
||||
Log: b.log,
|
||||
}
|
||||
b.log.Info("systemd watchdog armed",
|
||||
b.log.InfoContext(ctx, "systemd watchdog armed",
|
||||
"heartbeat", interval.String(),
|
||||
"loop_cadence", b.loopCadence().String())
|
||||
|
||||
go func() {
|
||||
if err := sampler.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
||||
b.log.Error("systemd watchdog stopped", "err", err)
|
||||
b.log.ErrorContext(ctx, "systemd watchdog stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (b *boot) openDaemonStateSurfaces(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
if err := b.openDaemonWorkflowDefinitions(); err != nil {
|
||||
b.log.Error("workflow definitions client", "err", err)
|
||||
b.log.ErrorContext(ctx, "workflow definitions client", "err", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -49,9 +49,9 @@ func (b *boot) startUpdateRelay(ctx context.Context, path string) {
|
||||
func (b *boot) relayUpdateReport(ctx context.Context, path string) {
|
||||
report, found, err := releaseupdate.ReadPendingReport(path)
|
||||
if err != nil {
|
||||
b.log.Warn("read pending update report failed; discarding it", "err", err)
|
||||
b.log.WarnContext(ctx, "read pending update report failed; discarding it", "err", err)
|
||||
if clearErr := releaseupdate.ClearPendingReport(path); clearErr != nil {
|
||||
b.log.Warn("clear unreadable update report failed", "err", clearErr)
|
||||
b.log.WarnContext(ctx, "clear unreadable update report failed", "err", clearErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func (b *boot) relayUpdateReport(ctx context.Context, path string) {
|
||||
}
|
||||
b.publishEvent(ctx, releaseupdate.ReportEvent(report, daemonRunningVersions(b.agentStatus)))
|
||||
if err := releaseupdate.ClearPendingReport(path); err != nil {
|
||||
b.log.Warn("clear pending update report failed", "err", err)
|
||||
b.log.WarnContext(ctx, "clear pending update report failed", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func (b *server) openChatSessions(ctx context.Context) error {
|
||||
b.chatSessionStore = chatSessionStore
|
||||
b.addCleanup(func() {
|
||||
if err := chatSessionStore.Close(); err != nil {
|
||||
b.log.Error("close conversation store", "err", err)
|
||||
b.log.ErrorContext(ctx, "close conversation store", "err", err)
|
||||
}
|
||||
})
|
||||
return nil
|
||||
@@ -44,7 +44,7 @@ func (b *server) claimGatewayOwnership(ctx context.Context) error {
|
||||
releaseCtx := context.WithoutCancel(ctx)
|
||||
b.addCleanup(func() {
|
||||
if err := ownership.Release(releaseCtx); err != nil {
|
||||
b.log.Error("release gateway ownership", "err", err)
|
||||
b.log.ErrorContext(ctx, "release gateway ownership", "err", err)
|
||||
}
|
||||
})
|
||||
return nil
|
||||
|
||||
@@ -153,7 +153,7 @@ func newChatTurnRunner(
|
||||
Log: s.Log,
|
||||
})
|
||||
if err := runner.Recover(ctx); err != nil && s.Log != nil {
|
||||
s.Log.Error("recover chat turns", "channel", channel, "err", err)
|
||||
s.Log.ErrorContext(ctx, "recover chat turns", "channel", channel, "err", err)
|
||||
}
|
||||
return runner
|
||||
}
|
||||
@@ -395,12 +395,12 @@ func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, first
|
||||
core.GenerateOptions{Messages: messages, MaxSteps: 1}, nil, nil, g.usage, nil)
|
||||
if err != nil {
|
||||
if g.log != nil {
|
||||
g.log.Error("session title generation failed", "session", sessionID, "err", err)
|
||||
g.log.ErrorContext(ctx, "session title generation failed", "session", sessionID, "err", err)
|
||||
}
|
||||
return "", fmt.Errorf("generate title for session %s: %w", sessionID, err)
|
||||
}
|
||||
if g.log != nil {
|
||||
g.log.Info("session title generated", "session", sessionID)
|
||||
g.log.InfoContext(ctx, "session title generated", "session", sessionID)
|
||||
}
|
||||
return text, nil
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func (b *server) setupCurators(ctx context.Context) bool {
|
||||
log := b.log.With("component", "curator")
|
||||
model, err := b.chatModels.ModelFor(ctx)
|
||||
if err != nil {
|
||||
log.Warn("curators disabled: chat model unavailable; configure a chat model and restart the gateway", "err", err)
|
||||
log.WarnContext(ctx, "curators disabled: chat model unavailable; configure a chat model and restart the gateway", "err", err)
|
||||
return false
|
||||
}
|
||||
skillsRoot := b.cfg.SkillsDir
|
||||
@@ -45,11 +45,11 @@ func (b *server) setupCurators(ctx context.Context) bool {
|
||||
})
|
||||
|
||||
if err := b.curatorRegistry.Register(skillcurator.New(skillcurator.DefaultInterval)); err != nil {
|
||||
log.Error("skill curator registration failed", "err", err)
|
||||
log.ErrorContext(ctx, "skill curator registration failed", "err", err)
|
||||
}
|
||||
|
||||
if err := b.curatorRegistry.Register(sessioncurator.New(sessioncurator.DefaultInterval, infraMemory.EngineName)); err != nil {
|
||||
log.Error("session-memory curator registration failed", "err", err)
|
||||
log.ErrorContext(ctx, "session-memory curator registration failed", "err", err)
|
||||
}
|
||||
|
||||
b.curatorRuntime = curator.NewRuntime(b.curatorRegistry, curator.RuntimeConfig{})
|
||||
@@ -184,7 +184,7 @@ func (b *server) startCurators(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
if err := b.curatorRuntime.Start(ctx); err != nil {
|
||||
b.log.Error("curator runtime startup", "err", err)
|
||||
b.log.ErrorContext(ctx, "curator runtime startup", "err", err)
|
||||
}
|
||||
defs, version, err := b.controlPlane.Curators(ctx)
|
||||
if err == nil {
|
||||
@@ -192,7 +192,7 @@ func (b *server) startCurators(ctx context.Context) error {
|
||||
}
|
||||
b.applyStatus.Report(ctx, controlplanestore.CuratorsKind, version, err)
|
||||
if err != nil {
|
||||
b.log.Error("curator definitions apply failed", "err", err)
|
||||
b.log.ErrorContext(ctx, "curator definitions apply failed", "err", err)
|
||||
}
|
||||
if err := b.watchCurators(ctx, version); err != nil {
|
||||
return fmt.Errorf("watch curators: %w", err)
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
// until ctx ends.
|
||||
func (b *server) serveGatewayListener(ctx context.Context, listener net.Listener, contract gateway.ChatContract, opts []grpc.ServerOption) error {
|
||||
defer listener.Close()
|
||||
b.log.Info("archie-gateway running", "addr", listener.Addr().String(), "tls", b.id != nil)
|
||||
b.log.InfoContext(ctx, "archie-gateway running", "addr", listener.Addr().String(), "tls", b.id != nil)
|
||||
// Boot is over and this listener is about to accept: the same fact
|
||||
// systemd's READY=1 asserts, so the announcement goes out here rather than
|
||||
// from a second notion of "started". Not later: Serve
|
||||
@@ -61,7 +61,7 @@ func (b *server) startGatewayRuntime(ctx context.Context, actor gateway.ChatTask
|
||||
return nil, fmt.Errorf("start gateway tool providers: %w", err)
|
||||
}
|
||||
for _, skipped := range b.providerRegistry.Skipped() {
|
||||
b.log.Warn("gateway tool provider unavailable", "provider", skipped.ID, "err", skipped.Err)
|
||||
b.log.WarnContext(ctx, "gateway tool provider unavailable", "provider", skipped.ID, "err", skipped.Err)
|
||||
}
|
||||
if err := b.startRuntimeWatches(ctx); err != nil {
|
||||
return nil, fmt.Errorf("runtime resource watches: %w", err)
|
||||
|
||||
@@ -133,7 +133,7 @@ func watchStatus[T any](
|
||||
} else {
|
||||
streamErr = err
|
||||
}
|
||||
log.Error("control-plane watch failed", "kind", kind, "err", err)
|
||||
log.ErrorContext(ctx, "control-plane watch failed", "kind", kind, "err", err)
|
||||
return
|
||||
}
|
||||
lastApplyErr = deliver(update)
|
||||
|
||||
@@ -41,7 +41,7 @@ func (b *server) buildMCPProvider(srv config.MCPServer) (toolprovider.Engine, er
|
||||
// registry means this process built no tools, so only the config was layered.
|
||||
func (b *server) reconcileToolSettings(ctx context.Context, cfg config.Config) error {
|
||||
if err := toolLimits(cfg).EnsureSpillDir(); err != nil {
|
||||
b.log.Warn("tool spill directory unavailable; large results will be truncated instead", "err", err)
|
||||
b.log.WarnContext(ctx, "tool spill directory unavailable; large results will be truncated instead", "err", err)
|
||||
}
|
||||
var problems []error
|
||||
if err := b.reconcileMCPServers(ctx, cfg.Tools.MCPServers); err != nil {
|
||||
|
||||
@@ -251,7 +251,7 @@ func (b *server) waitForNATSEndpoint(ctx context.Context) (servicekit.NATSEndpoi
|
||||
if err == nil {
|
||||
return endpoint, nil
|
||||
}
|
||||
b.log.Warn("waiting for the daemon's NATS endpoint", "err", err)
|
||||
b.log.WarnContext(ctx, "waiting for the daemon's NATS endpoint", "err", err)
|
||||
if !servicekit.WaitFor(ctx, 2*time.Second) {
|
||||
return servicekit.NATSEndpoint{}, ctx.Err()
|
||||
}
|
||||
@@ -265,7 +265,7 @@ func (b *server) catalogState() modelcatalog.Snapshot { return b.catalog.State()
|
||||
func (b *server) loadCatalog(ctx context.Context) {
|
||||
snapshot, err := b.catalog.Fetch(ctx, b.secrets.Getenv, b.cfg.Providers)
|
||||
if err != nil {
|
||||
b.log.Warn("model catalog unavailable; using configured providers and models", "err", err)
|
||||
b.log.WarnContext(ctx, "model catalog unavailable; using configured providers and models", "err", err)
|
||||
return
|
||||
}
|
||||
modelcatalog.Apply(&b.cfg, snapshot)
|
||||
@@ -277,14 +277,14 @@ func (b *server) startModelCatalogRefresh(ctx context.Context) {
|
||||
modelcatalog.Every(ctx, modelcatalog.RefreshInterval, func() {
|
||||
snapshot, err := b.catalog.Fetch(ctx, b.secrets.Getenv, b.cfgHolder.Get().Providers)
|
||||
if err != nil {
|
||||
b.log.Warn("model catalog refresh failed; keeping the loaded catalog", "err", err)
|
||||
b.log.WarnContext(ctx, "model catalog refresh failed; keeping the loaded catalog", "err", err)
|
||||
return
|
||||
}
|
||||
base := b.cfgHolder.Get().Clone()
|
||||
modelcatalog.Apply(&base, snapshot)
|
||||
b.catalog.Set(snapshot)
|
||||
if err := b.relayer(ctx, base, ""); err != nil {
|
||||
b.log.Warn("model catalog refresh rejected with the settings; the running settings stay", "err", err)
|
||||
b.log.WarnContext(ctx, "model catalog refresh rejected with the settings; the running settings stay", "err", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func (b *server) startRuntimeWatches(ctx context.Context) error {
|
||||
} else {
|
||||
streamErr = update.Err
|
||||
}
|
||||
b.log.Error("runtime settings watch failed", "kind", kind, "err", update.Err)
|
||||
b.log.ErrorContext(ctx, "runtime settings watch failed", "kind", kind, "err", update.Err)
|
||||
return
|
||||
}
|
||||
base := b.cfgHolder.Get()
|
||||
@@ -370,7 +370,7 @@ func (b *server) startRuntimeWatches(ctx context.Context) error {
|
||||
func (b *server) relayer(ctx context.Context, base config.Config, kind string) error {
|
||||
cfg, versions, err := b.runtimeConfig(ctx, base)
|
||||
if err != nil {
|
||||
b.log.Error("runtime settings update rejected; the running settings stay", "kind", kind, "err", err)
|
||||
b.log.ErrorContext(ctx, "runtime settings update rejected; the running settings stay", "kind", kind, "err", err)
|
||||
return err
|
||||
}
|
||||
b.cfgHolder.Set(cfg)
|
||||
@@ -379,7 +379,7 @@ func (b *server) relayer(ctx context.Context, base config.Config, kind string) e
|
||||
if kind == controlplanestore.ToolSettingsKind {
|
||||
if err := b.reconcileToolSettings(ctx, cfg); err != nil {
|
||||
b.applyStatus.Report(ctx, kind, versions[kind], err)
|
||||
b.log.Error("tool settings reconciled with errors; the running servers stay", "err", err)
|
||||
b.log.ErrorContext(ctx, "tool settings reconciled with errors; the running servers stay", "err", err)
|
||||
problems = append(problems, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (b *server) refreshSkills(ctx context.Context, applied *string) {
|
||||
catalog, err := skill.CatalogRoots(skill.DefaultRoots(cfg.WorkDir, cfg.SkillsDir)...)
|
||||
if err != nil {
|
||||
b.applyStatus.Report(ctx, controlplanestore.SkillsKind, 0, err)
|
||||
log.Warn("skill catalog load failed", "err", err)
|
||||
log.WarnContext(ctx, "skill catalog load failed", "err", err)
|
||||
return
|
||||
}
|
||||
stored, version, err := b.storedSkills(ctx, catalog)
|
||||
@@ -61,10 +61,10 @@ func (b *server) refreshSkills(ctx context.Context, applied *string) {
|
||||
if entry := skill.ActivateTool(cfg.WorkDir, catalog); entry != nil {
|
||||
if err := b.toolReg.Register(*entry); err != nil {
|
||||
applyErr = err
|
||||
log.Warn("skill_activate registration failed", "err", err)
|
||||
log.WarnContext(ctx, "skill_activate registration failed", "err", err)
|
||||
return
|
||||
}
|
||||
log.Info("skill catalog registered", "skills", len(catalog))
|
||||
log.InfoContext(ctx, "skill catalog registered", "skills", len(catalog))
|
||||
}
|
||||
*applied = signature
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func (b *server) storedSkills(ctx context.Context, have []skill.CatalogEntry) ([
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
b.log.Warn("skills resource unavailable", "err", err)
|
||||
b.log.WarnContext(ctx, "skills resource unavailable", "err", err)
|
||||
}
|
||||
return out, version, err
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ func (b *server) registerStandaloneTools(ctx context.Context) {
|
||||
|
||||
if spillDir := cfg.Tools.Policy.SpillDir; spillDir != "" {
|
||||
if err := toolLimits(cfg).EnsureSpillDir(); err != nil {
|
||||
log.Warn("tool spill directory unavailable; large results will be truncated instead", "err", err)
|
||||
log.WarnContext(ctx, "tool spill directory unavailable; large results will be truncated instead", "err", err)
|
||||
} else if ws := cfg.Chat.Workspace; ws != "" && !cfg.Chat.UnrestrictedFilesystem && !isWithin(ws, spillDir) {
|
||||
log.Warn("tool spill directory is outside chat.workspace; the model cannot read back what is spilled there",
|
||||
log.WarnContext(ctx, "tool spill directory is outside chat.workspace; the model cannot read back what is spilled there",
|
||||
"spill_dir", spillDir, "workspace", ws)
|
||||
}
|
||||
}
|
||||
@@ -90,12 +90,12 @@ func (b *server) registerStandaloneTools(ctx context.Context) {
|
||||
|
||||
if entry := sendfile.Tool(cfg.Chat.Workspace); entry != nil {
|
||||
if err := b.toolReg.Register(*entry); err != nil {
|
||||
log.Warn("send_file registration failed", "err", err)
|
||||
log.WarnContext(ctx, "send_file registration failed", "err", err)
|
||||
} else {
|
||||
log.Info("file sending enabled", "workspace", cfg.Chat.Workspace)
|
||||
log.InfoContext(ctx, "file sending enabled", "workspace", cfg.Chat.Workspace)
|
||||
}
|
||||
} else {
|
||||
log.Info("file sending disabled (chat.workspace is unset)")
|
||||
log.InfoContext(ctx, "file sending disabled (chat.workspace is unset)")
|
||||
}
|
||||
|
||||
b.registerMinimaxTool(cfg, log)
|
||||
@@ -111,7 +111,7 @@ func (b *server) registerWorkflowTools(ctx context.Context) {
|
||||
entries := append(gateway.WorkflowTools(workflows, authz), gateway.IntegrationTools(integrationSource{Workflows: workflows, store: b.stateStore}, authz)...)
|
||||
for _, entry := range entries {
|
||||
if err := b.toolReg.Register(entry); err != nil {
|
||||
b.log.Warn("workflow tool registration failed", "tool", entry.Name, "err", err)
|
||||
b.log.WarnContext(ctx, "workflow tool registration failed", "tool", entry.Name, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func shutdownCapabilityHost(ctx context.Context, capabilityHost *plugin.Host, lo
|
||||
stopCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := capabilityHost.Stop(stopCtx); err != nil {
|
||||
log.Error("capability host shutdown", "err", err)
|
||||
log.ErrorContext(ctx, "capability host shutdown", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,6 @@ func (u *usageSink) record(ctx context.Context, source usage.Source, ref string,
|
||||
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), usageWriteTimeout)
|
||||
defer cancel()
|
||||
if err := u.store.RecordUsage(ctx, record); err != nil && u.log != nil {
|
||||
u.log.Warn("record model usage failed", "source", source, "model", ref, "err", err)
|
||||
u.log.WarnContext(ctx, "record model usage failed", "source", source, "model", ref, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (s *Service) publishLoop(ctx context.Context) {
|
||||
return
|
||||
case <-s.publish:
|
||||
if err := s.publishStatus(ctx); err != nil && ctx.Err() == nil {
|
||||
s.log.Warn("publishing channel status failed", "err", err)
|
||||
s.log.WarnContext(ctx, "publishing channel status failed", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func composeChannels(ctx context.Context, d deps) ([]*channelInstance, error) {
|
||||
instances = append(instances, telegramInstance)
|
||||
for _, instance := range d.ExtensionChannels {
|
||||
if slices.ContainsFunc(instances, func(have *channelInstance) bool { return have.name == instance.name }) {
|
||||
d.Log.Warn("channel extension skipped: a built-in channel has the same name", "channel", instance.name)
|
||||
d.Log.WarnContext(ctx, "channel extension skipped: a built-in channel has the same name", "channel", instance.name)
|
||||
continue
|
||||
}
|
||||
instances = append(instances, instance)
|
||||
@@ -187,7 +187,7 @@ func composeTelegram(ctx context.Context, d deps) (*channelInstance, error) {
|
||||
return nil, nil
|
||||
}
|
||||
if len(cfg.Telegram.AllowedUserIDs) == 0 {
|
||||
d.Log.Warn("chat.telegram has no allowed_user_ids: every sender will be rejected. " +
|
||||
d.Log.WarnContext(ctx, "chat.telegram has no allowed_user_ids: every sender will be rejected. "+
|
||||
"Add your Telegram user id to chat.telegram.allowed_user_ids to enable the bot.")
|
||||
}
|
||||
tg := telegram.New(cfg.TelegramToken, cfg.Telegram.AllowedUserIDs, d.Log)
|
||||
@@ -227,7 +227,7 @@ func (s *Service) Start(ctx context.Context) error {
|
||||
s.stop = cancel
|
||||
s.mu.Unlock()
|
||||
|
||||
s.log.Info("messaging service started", "gateway_target", s.cfg.Options.Gateway.Target, "channels", len(s.channels))
|
||||
s.log.InfoContext(ctx, "messaging service started", "gateway_target", s.cfg.Options.Gateway.Target, "channels", len(s.channels))
|
||||
|
||||
if s.statusWriter != nil {
|
||||
go s.publishLoop(ctx)
|
||||
@@ -260,7 +260,7 @@ func (s *Service) Start(ctx context.Context) error {
|
||||
finalCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), s.cfg.Options.ShutdownTimeout)
|
||||
defer cancel()
|
||||
if err := s.publishStatus(finalCtx); err != nil {
|
||||
s.log.Warn("publishing final channel status failed", "err", err)
|
||||
s.log.WarnContext(ctx, "publishing final channel status failed", "err", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -29,17 +29,17 @@ const refSuffix = "_ref"
|
||||
func openExtensionChannels(ctx context.Context, source extension.Source, secrets *secret.Registry, log *slog.Logger) []*channelInstance {
|
||||
cache, err := configuration.DefaultCacheDir()
|
||||
if err != nil {
|
||||
log.Warn("channel extensions unavailable: no cache directory", "err", err)
|
||||
log.WarnContext(ctx, "channel extensions unavailable: no cache directory", "err", err)
|
||||
return nil
|
||||
}
|
||||
settings, _, err := source.Enabled(ctx)
|
||||
if err != nil {
|
||||
log.Warn("channel extensions unavailable: extension settings", "err", err)
|
||||
log.WarnContext(ctx, "channel extensions unavailable: extension settings", "err", err)
|
||||
return nil
|
||||
}
|
||||
installed, err := source.Packages.ListInstalled(ctx)
|
||||
if err != nil {
|
||||
log.Warn("channel extensions unavailable: installed packages", "err", err)
|
||||
log.WarnContext(ctx, "channel extensions unavailable: installed packages", "err", err)
|
||||
return nil
|
||||
}
|
||||
host := extension.NewHost(hclog.New(&hclog.LoggerOptions{Name: "extension", Level: hclog.Warn}))
|
||||
@@ -55,7 +55,7 @@ func openExtensionChannels(ctx context.Context, source extension.Source, secrets
|
||||
}
|
||||
ch, err := buildExtensionChannel(ctx, host, source, filepath.Join(cache, "extensions", "channels"), pkg, pkg.Descriptor.Contributes.Extensions[index].Path, setting.Settings, secrets)
|
||||
if err != nil {
|
||||
log.Warn("channel extension not started", "channel", pkg.Name, "err", err)
|
||||
log.WarnContext(ctx, "channel extension not started", "channel", pkg.Name, "err", err)
|
||||
continue
|
||||
}
|
||||
instances = append(instances, &channelInstance{
|
||||
|
||||
@@ -61,7 +61,7 @@ func (s *Service) announceReady(ctx context.Context, awaited map[string]bool) {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-timeout.C:
|
||||
s.log.Warn("announcing readiness before every channel bound", "waiting_for", len(awaited))
|
||||
s.log.WarnContext(ctx, "announcing readiness before every channel bound", "waiting_for", len(awaited))
|
||||
sdnotify.Ready(s.log)
|
||||
return
|
||||
case id := <-s.runningSignal:
|
||||
|
||||
@@ -31,7 +31,7 @@ func (s *Service) reconcileLoop(ctx context.Context) {
|
||||
return
|
||||
case <-ticker.C:
|
||||
if err := s.reconcileOnce(ctx); err != nil {
|
||||
s.log.Warn("channel settings reconcile failed", "err", err)
|
||||
s.log.WarnContext(ctx, "channel settings reconcile failed", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ func serve(ctx context.Context, listen string, id *rpctls.Identity, srv *Service
|
||||
serveErr <- servicekit.Serve(ctx, server, listener)
|
||||
cancel()
|
||||
}()
|
||||
log.Info("messaging service listening", "listen", listen)
|
||||
log.InfoContext(ctx, "messaging service listening", "listen", listen)
|
||||
startErr := srv.Start(ctx)
|
||||
cancel()
|
||||
if err := <-serveErr; err != nil {
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *Service) runChannel(ctx context.Context, c *channelInstance) {
|
||||
c.cancel = cancel
|
||||
c.mu.Unlock()
|
||||
|
||||
s.log.Info("starting channel", "name", c.name)
|
||||
s.log.InfoContext(ctx, "starting channel", "name", c.name)
|
||||
err := ch.Start(runCtx, s.chat, s.lifecycleFor(c.name))
|
||||
attempts++
|
||||
|
||||
@@ -368,7 +368,7 @@ func (s *Service) stopChannel(ctx context.Context, name string, ch channels.Chan
|
||||
stopCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), timeout)
|
||||
defer cancel()
|
||||
if err := ch.Stop(stopCtx); err != nil {
|
||||
s.log.Warn("channel stop failed", "name", name, "err", err)
|
||||
s.log.WarnContext(ctx, "channel stop failed", "name", name, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ func captureArrivalPublisher(d deps) func(context.Context, events.Event) {
|
||||
ctx, cancel := context.WithTimeout(ctx, captureEventTimeout)
|
||||
defer cancel()
|
||||
if _, err := d.Store.InsertEvent(ctx, e); err != nil {
|
||||
d.Log.Warn("capture arrival event not published", "err", err)
|
||||
d.Log.WarnContext(ctx, "capture arrival event not published", "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func Run(ctx context.Context, options Options) error {
|
||||
"gateway", opts.Gateway.Target,
|
||||
"state", opts.State.Target,
|
||||
}
|
||||
log.Info("archie-ui running", attrs...)
|
||||
log.InfoContext(ctx, "archie-ui running", attrs...)
|
||||
return serve(ctx, listener, srv.Handler(), opts)
|
||||
}
|
||||
|
||||
@@ -195,6 +195,6 @@ func serve(ctx context.Context, listener net.Listener, handler http.Handler, opt
|
||||
|
||||
func pumpEvents(ctx context.Context, srv *webui.Server, interval time.Duration, log *slog.Logger) {
|
||||
if err := srv.PumpEvents(ctx, interval); err != nil {
|
||||
log.Error("event pump stopped; the activity feed will only show history", "err", err)
|
||||
log.ErrorContext(ctx, "event pump stopped; the activity feed will only show history", "err", err)
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ func (r *liveReviewer) Review(ctx context.Context, p bench.Problem) (bench.Revie
|
||||
if err != nil {
|
||||
return bench.Review{}, err
|
||||
}
|
||||
slog.Info("benchmark review started", "problem", p.ID)
|
||||
slog.InfoContext(ctx, "benchmark review started", "problem", p.ID)
|
||||
tc := &workflow.TaskContext{
|
||||
Task: &workflow.Task{ID: r.nextID.Add(1), Attempt: 1, Owner: owner, Repo: repo, PRNumber: number, Workflow: "pr-review", Inputs: map[string]any{"depth": "deep"}},
|
||||
Cfg: r.cfg, Agent: r.agent, PRSource: r.source, Log: slog.Default(),
|
||||
@@ -48,7 +48,7 @@ func (r *liveReviewer) Review(ctx context.Context, p bench.Problem) (bench.Revie
|
||||
if decision.Comments == nil {
|
||||
decision.Comments = []prreview.ScoredFinding{}
|
||||
}
|
||||
slog.Info("benchmark review completed", "problem", p.ID, "comments", len(decision.Comments), "skipped_phases", decision.SkippedPhases)
|
||||
slog.InfoContext(ctx, "benchmark review completed", "problem", p.ID, "comments", len(decision.Comments), "skipped_phases", decision.SkippedPhases)
|
||||
return bench.Review{Comments: decision.Comments, SkippedPhases: decision.SkippedPhases}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ func Logging(ctx context.Context, cfg config.Config, component string) (Logs, er
|
||||
})
|
||||
log := fileLog.With("component", component)
|
||||
if err != nil {
|
||||
log.Error("file logging disabled", "err", err)
|
||||
log.ErrorContext(ctx, "file logging disabled", "err", err)
|
||||
} else if cfg.Log.File != "" {
|
||||
log.Info("logging to file", "path", cfg.Log.File)
|
||||
log.InfoContext(ctx, "logging to file", "path", cfg.Log.File)
|
||||
}
|
||||
closer := closerFunc(func() error {
|
||||
stopTracing()
|
||||
|
||||
@@ -20,10 +20,10 @@ func ServeHealth(ctx context.Context, addr string, mux http.Handler, label strin
|
||||
srv := &http.Server{Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
go func() {
|
||||
if err := srv.Serve(listener); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Error(label+" server stopped", "err", err)
|
||||
log.ErrorContext(ctx, label+" server stopped", "err", err)
|
||||
}
|
||||
}()
|
||||
log.Info(label+" listening", "addr", "http://"+listener.Addr().String())
|
||||
log.InfoContext(ctx, label+" listening", "addr", "http://"+listener.Addr().String())
|
||||
return func() {
|
||||
shutdownCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
@@ -144,7 +144,7 @@ func KeepWatch[T any](
|
||||
onEnded[0]()
|
||||
}
|
||||
backoff = retryDelay(backoff, attemptHealthy(progressed, time.Since(started), backoff))
|
||||
log.Warn("control plane watch stream ended; reconnecting",
|
||||
log.WarnContext(ctx, "control plane watch stream ended; reconnecting",
|
||||
"kind", kind, "after_version", after, "retry_in", backoff)
|
||||
for {
|
||||
if !wait(ctx, backoff) {
|
||||
@@ -159,7 +159,7 @@ func KeepWatch[T any](
|
||||
// answering, and is charged exactly as any other attempt that ends
|
||||
// that way.
|
||||
backoff = retryDelay(backoff, false)
|
||||
log.Warn("control plane watch could not be re-established",
|
||||
log.WarnContext(ctx, "control plane watch could not be re-established",
|
||||
"kind", kind, "after_version", after, "retry_in", backoff, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func (b *server) sweepAlerts(ctx context.Context, store alert.Store) {
|
||||
b.checkPolicies(ctx, reporter, store)
|
||||
if pruner != nil {
|
||||
if _, err := pruner.PruneAlerts(ctx, time.Now().Add(-alertRetention)); err != nil && ctx.Err() == nil {
|
||||
b.log.Warn("prune alerts", "err", err)
|
||||
b.log.WarnContext(ctx, "prune alerts", "err", err)
|
||||
}
|
||||
}
|
||||
select {
|
||||
@@ -120,7 +120,7 @@ func (b *server) checkServices(ctx context.Context, reporter alert.Reporter, rec
|
||||
list, err := records.ListPresence(ctx)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
b.log.Warn("service health not checked", "err", err)
|
||||
b.log.WarnContext(ctx, "service health not checked", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func (b *server) checkPolicies(ctx context.Context, reporter alert.Reporter, sto
|
||||
stored, err := policies.ListPolicies(ctx)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
b.log.Warn("policies not checked", "err", err)
|
||||
b.log.WarnContext(ctx, "policies not checked", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,14 +141,14 @@ func (b *server) pruneAuditEvents(ctx context.Context) {
|
||||
resource, err := resources.Resource(ctx, storecontract.DefaultOrgID, controlplanestore.AuditRetentionKind)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
b.log.Warn("audit retention not applied: setting unreadable, sweep skipped", "err", err)
|
||||
b.log.WarnContext(ctx, "audit retention not applied: setting unreadable, sweep skipped", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
retention, err := controlplanestore.RuntimeEventRetention(resource.Value)
|
||||
if err != nil {
|
||||
if ctx.Err() == nil {
|
||||
b.log.Warn("audit retention not applied: setting invalid, sweep skipped", "err", err)
|
||||
b.log.WarnContext(ctx, "audit retention not applied: setting invalid, sweep skipped", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -164,12 +164,12 @@ func (b *server) pruneAuditEvents(ctx context.Context) {
|
||||
rows, err := pruner.PruneAuditEvents(ctx, prunableEventKinds(), cutoff)
|
||||
switch {
|
||||
case errors.Is(err, postgres.ErrAuditPruneBusy):
|
||||
b.log.Debug("audit retention sweep skipped: another sweep holds the lock")
|
||||
b.log.DebugContext(ctx, "audit retention sweep skipped: another sweep holds the lock")
|
||||
case err != nil:
|
||||
if ctx.Err() == nil {
|
||||
b.log.Warn("prune audit events", "err", err)
|
||||
b.log.WarnContext(ctx, "prune audit events", "err", err)
|
||||
}
|
||||
default:
|
||||
b.log.Info("pruned audit observability events", "rows", rows, "cutoff", cutoff.UTC())
|
||||
b.log.InfoContext(ctx, "pruned audit observability events", "rows", rows, "cutoff", cutoff.UTC())
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ func (b *server) autoUpdatePackages(ctx context.Context, packages storepkg.Manag
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
if err := packages.UpdateAuto(ctx); err != nil && ctx.Err() == nil {
|
||||
b.log.Error("auto-update packages", "err", err)
|
||||
b.log.ErrorContext(ctx, "auto-update packages", "err", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
@@ -17,13 +17,13 @@ import (
|
||||
func (b *server) openStateStorePool(ctx context.Context) error {
|
||||
pool, err := postgres.OpenMigrated(ctx, b.cfg.DatabaseURL, "the State Store")
|
||||
if err != nil {
|
||||
b.log.Error("open state store postgres pool", "err", err)
|
||||
b.log.ErrorContext(ctx, "open state store postgres pool", "err", err)
|
||||
return err
|
||||
}
|
||||
ownership, err := postgres.AcquireOwnership(ctx, pool, postgres.OwnerStateStore)
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
b.log.Error("claim state store ownership", "err", err)
|
||||
b.log.ErrorContext(ctx, "claim state store ownership", "err", err)
|
||||
return err
|
||||
}
|
||||
b.pg = pool
|
||||
|
||||
@@ -123,7 +123,7 @@ func Run(ctx context.Context, options Options) error { //nolint:cyclop // the co
|
||||
return fmt.Errorf("listen for state store: %w", err)
|
||||
}
|
||||
defer listener.Close()
|
||||
b.log.Info("archie-state-store running", "addr", listener.Addr().String(), "tls", b.cfg.TLS.CertDir != "")
|
||||
b.log.InfoContext(ctx, "archie-state-store running", "addr", listener.Addr().String(), "tls", b.cfg.TLS.CertDir != "")
|
||||
|
||||
if err := b.startOptionalSurfaces(ctx, options); err != nil {
|
||||
return err
|
||||
@@ -179,7 +179,7 @@ func (b *server) seedAndValidatePolicies(ctx context.Context) error {
|
||||
}
|
||||
engine := infraaccess.New(stored)
|
||||
for _, problem := range engine.Problems() {
|
||||
b.log.Error("stored access policy is invalid and denies its level",
|
||||
b.log.ErrorContext(ctx, "stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
return nil
|
||||
@@ -240,7 +240,7 @@ func (b *server) openStateStore(ctx context.Context) error {
|
||||
b.secrets = secrets
|
||||
bindingCipher, err := bindingCipherFromConfig(cfg, secrets)
|
||||
if err != nil {
|
||||
log.Error("configure bindings cipher", "err", err)
|
||||
log.ErrorContext(ctx, "configure bindings cipher", "err", err)
|
||||
return err
|
||||
}
|
||||
// Open the PostgreSQL pool and apply the schema before anything else: the
|
||||
|
||||
@@ -47,7 +47,7 @@ func (s *toolCallProjectingTaskStore) InsertEvent(ctx context.Context, e events.
|
||||
}
|
||||
if perr := s.toolCalls.InsertToolCall(ctx, toolCallFromEvent(e)); perr != nil {
|
||||
failures := s.projectionFailures.Add(1)
|
||||
s.log.Error("tool_call projection failed; the event persisted but the tool_calls row did not",
|
||||
s.log.ErrorContext(ctx, "tool_call projection failed; the event persisted but the tool_calls row did not",
|
||||
"err", perr, "task_id", e.TaskID, "attempt", e.Attempt,
|
||||
"tool", e.Data["tool"], "projection_failures", failures)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func (e *EphemeralSender) Send(ctx context.Context, sender any, reply messaging.
|
||||
|
||||
deleter, ok := messaging.DeleterOf(sender)
|
||||
if !ok {
|
||||
e.log.Debug("channel cannot retract an ephemeral reply; leaving it in place",
|
||||
e.log.DebugContext(ctx, "channel cannot retract an ephemeral reply; leaving it in place",
|
||||
"platform", reply.Event.Platform, "type", reply.Event.Type)
|
||||
return sent, nil
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (e *EphemeralSender) Send(ctx context.Context, sender any, reply messaging.
|
||||
delCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), e.timeout)
|
||||
defer cancel()
|
||||
if err := deleter.DeleteMessage(delCtx, sent); err != nil {
|
||||
e.log.Warn("ephemeral reply retraction failed",
|
||||
e.log.WarnContext(ctx, "ephemeral reply retraction failed",
|
||||
"platform", reply.Event.Platform, "error", err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -113,7 +113,7 @@ func (a *telegramApprover) RequestApproval(ctx context.Context, action, descript
|
||||
if approvalCtx.Err() != nil {
|
||||
return messaging.ApprovalDenied, approvalCtx.Err()
|
||||
}
|
||||
a.gw.log.Error("send approval prompt failed", "error", err)
|
||||
a.gw.log.ErrorContext(ctx, "send approval prompt failed", "error", err)
|
||||
return messaging.ApprovalDenied, fmt.Errorf("send approval prompt: %w", err)
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ func (g *Gateway) handleApprovalCallback(ctx context.Context, b *bot.Bot, update
|
||||
return
|
||||
}
|
||||
if !g.isSenderAllowed(query.From.ID) {
|
||||
g.log.Warn("approval callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.log.WarnContext(ctx, "approval callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.answerCallback(ctx, b, query.ID, "You are not authorised to use this bot.", true)
|
||||
return
|
||||
}
|
||||
@@ -245,7 +245,7 @@ func (g *Gateway) handleApprovalCallback(ctx context.Context, b *bot.Bot, update
|
||||
return
|
||||
}
|
||||
|
||||
g.log.Info(
|
||||
g.log.InfoContext(ctx,
|
||||
"tool approval decision",
|
||||
"action", pa.action, "decision", decision,
|
||||
"recipient", query.From.ID, "username", query.From.Username,
|
||||
@@ -299,7 +299,7 @@ func (g *Gateway) answerCallback(ctx context.Context, b *bot.Bot, queryID, text
|
||||
Text: text,
|
||||
ShowAlert: alert,
|
||||
}); err != nil {
|
||||
g.log.Warn("answer callback failed", "error", err)
|
||||
g.log.WarnContext(ctx, "answer callback failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (g *Gateway) editCallbackMessage(ctx context.Context, b *bot.Bot, query *mo
|
||||
MessageID: message.ID,
|
||||
Text: text,
|
||||
}); err != nil {
|
||||
g.log.Warn("edit callback message failed", "error", err)
|
||||
g.log.WarnContext(ctx, "edit callback message failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ func (g *Gateway) registerCommands(ctx context.Context, b *bot.Bot) {
|
||||
Commands: gatewayCommands,
|
||||
Scope: scope,
|
||||
}); err != nil {
|
||||
g.log.Warn("set command menu failed", "scope", fmt.Sprintf("%T", scope), "error", err)
|
||||
g.log.WarnContext(ctx, "set command menu failed", "scope", fmt.Sprintf("%T", scope), "error", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
g.log.Info("command menu registered",
|
||||
g.log.InfoContext(ctx, "command menu registered",
|
||||
"commands", len(gatewayCommands), "scopes", len(commandScopes))
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func (g *Gateway) sendEphemeral(ctx context.Context, b *bot.Bot, chatID int64, m
|
||||
return event, nil
|
||||
})
|
||||
if err != nil {
|
||||
g.log.Error("ephemeral notice send failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "ephemeral notice send failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ func (g *Gateway) abandonAllLive(ctx context.Context) {
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(timeout):
|
||||
g.log.Warn("gateway stop: gave up waiting for in-flight replies to be marked as restarted",
|
||||
g.log.WarnContext(ctx, "gateway stop: gave up waiting for in-flight replies to be marked as restarted",
|
||||
"pending", len(live), "timeout", timeout)
|
||||
}
|
||||
}
|
||||
@@ -300,7 +300,7 @@ func (l *liveReply) Media(ctx context.Context, event messaging.MediaEvent) {
|
||||
// -- a sender that already knows it cannot deliver a given media
|
||||
// kind should never cost a doomed network round trip to find out.
|
||||
if !messaging.CapabilitiesOf(sender).Media {
|
||||
l.g.log.Debug("channel cannot deliver media inline, falling back to a link",
|
||||
l.g.log.DebugContext(ctx, "channel cannot deliver media inline, falling back to a link",
|
||||
"tool", event.ToolName, "type", event.Attachment.Type)
|
||||
l.appendFallbackLine(ctx, event.Attachment)
|
||||
return
|
||||
@@ -316,7 +316,7 @@ func (l *liveReply) Media(ctx context.Context, event messaging.MediaEvent) {
|
||||
return
|
||||
}
|
||||
|
||||
l.g.log.Warn("media delivery failed, falling back to a link",
|
||||
l.g.log.WarnContext(ctx, "media delivery failed, falling back to a link",
|
||||
"tool", event.ToolName, "type", event.Attachment.Type, "error", err)
|
||||
l.appendFallbackLine(ctx, event.Attachment)
|
||||
}()
|
||||
@@ -610,14 +610,14 @@ func (l *liveReply) open(ctx context.Context, blocks []models.InputRichBlock) {
|
||||
}
|
||||
msg, err := l.b.SendRichMessage(ctx, params)
|
||||
if err != nil {
|
||||
l.g.log.Debug("live reply rich send failed, retrying unformatted", "error", err)
|
||||
l.g.log.DebugContext(ctx, "live reply rich send failed, retrying unformatted", "error", err)
|
||||
plain := &bot.SendMessageParams{ChatID: l.chatID, Text: strings.Join(blocksToPlainText(blocks), "\n\n")}
|
||||
if l.messageThreadID != 0 {
|
||||
plain.MessageThreadID = l.messageThreadID
|
||||
}
|
||||
msg, err = l.b.SendMessage(ctx, plain)
|
||||
if err != nil {
|
||||
l.g.log.Debug("live reply send failed", "error", err)
|
||||
l.g.log.DebugContext(ctx, "live reply send failed", "error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -639,14 +639,14 @@ func (l *liveReply) edit(ctx context.Context, messageID int, blocks []models.Inp
|
||||
if richErr == nil {
|
||||
return nil
|
||||
}
|
||||
l.g.log.Debug("live reply rich edit failed, retrying unformatted", "error", richErr)
|
||||
l.g.log.DebugContext(ctx, "live reply rich edit failed, retrying unformatted", "error", richErr)
|
||||
|
||||
if _, plainErr := l.b.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: l.chatID,
|
||||
MessageID: messageID,
|
||||
Text: strings.Join(blocksToPlainText(blocks), "\n\n"),
|
||||
}); plainErr != nil {
|
||||
l.g.log.Debug("live reply edit failed", "error", plainErr)
|
||||
l.g.log.DebugContext(ctx, "live reply edit failed", "error", plainErr)
|
||||
return errors.Join(
|
||||
fmt.Errorf("rich edit: %w", richErr),
|
||||
fmt.Errorf("plain edit: %w", plainErr),
|
||||
|
||||
@@ -199,7 +199,7 @@ func (g *Gateway) sendModelSelector(
|
||||
Message: messaging.Message{Role: messaging.RoleUser, Text: "/model"},
|
||||
})
|
||||
if err != nil {
|
||||
g.log.Error("model selector fallback failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "model selector fallback failed", "error", err)
|
||||
return
|
||||
}
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, reply.Text)
|
||||
@@ -215,7 +215,7 @@ func (g *Gateway) sendModelSelector(
|
||||
params.MessageThreadID = msg.MessageThreadID
|
||||
}
|
||||
if _, err := b.SendMessage(ctx, params); err != nil {
|
||||
g.log.Error("send model selector failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "send model selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ func (g *Gateway) handleModelCallback(
|
||||
return
|
||||
}
|
||||
if !g.isSenderAllowed(query.From.ID) {
|
||||
g.log.Warn("model callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.log.WarnContext(ctx, "model callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.answerModelCallback(ctx, b, query.ID, "You are not authorised to use this bot.", true)
|
||||
return
|
||||
}
|
||||
@@ -506,7 +506,7 @@ func (g *Gateway) handleModelCancelCallback(ctx context.Context, b *bot.Bot, upd
|
||||
return
|
||||
}
|
||||
if _, err := b.EditMessageText(ctx, params); err != nil {
|
||||
g.log.Warn("cancel model selector failed", "error", err)
|
||||
g.log.WarnContext(ctx, "cancel model selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ func (g *Gateway) answerModelCallback(ctx context.Context, b *bot.Bot, queryID,
|
||||
ShowAlert: alert,
|
||||
}
|
||||
if _, err := b.AnswerCallbackQuery(ctx, params); err != nil {
|
||||
g.log.Warn("answer model callback query failed", "error", err)
|
||||
g.log.WarnContext(ctx, "answer model callback query failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -552,6 +552,6 @@ func (g *Gateway) editModelPicker(
|
||||
return
|
||||
}
|
||||
if _, err := b.EditMessageText(ctx, params); err != nil {
|
||||
g.log.Warn("edit model picker failed", "error", err)
|
||||
g.log.WarnContext(ctx, "edit model picker failed", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func (g *Gateway) sendProviderSelector(
|
||||
params.MessageThreadID = msg.MessageThreadID
|
||||
}
|
||||
if _, err := b.SendMessage(ctx, params); err != nil {
|
||||
g.log.Error("send provider selector failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "send provider selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func (g *Gateway) handleProviderCallback(
|
||||
return
|
||||
}
|
||||
if !g.isSenderAllowed(query.From.ID) {
|
||||
g.log.Warn("provider callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.log.WarnContext(ctx, "provider callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.answerModelCallback(ctx, b, query.ID, "You are not authorised to use this bot.", true)
|
||||
return
|
||||
}
|
||||
@@ -160,6 +160,6 @@ func (g *Gateway) updateModelSelectorForProvider(
|
||||
return
|
||||
}
|
||||
if _, err := b.EditMessageText(ctx, params); err != nil {
|
||||
g.log.Warn("update provider selector failed", "error", err)
|
||||
g.log.WarnContext(ctx, "update provider selector failed", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
)
|
||||
|
||||
// pipelineErrorHandler logs update-loop failures.
|
||||
func (g *Gateway) pipelineErrorHandler(_ context.Context) func(error) {
|
||||
func (g *Gateway) pipelineErrorHandler(ctx context.Context) func(error) {
|
||||
return func(err error) {
|
||||
if tooMany, ok := errors.AsType[*bot.TooManyRequestsError](err); ok {
|
||||
g.log.Warn("telegram rate limited", "retry_after", tooMany.RetryAfter,
|
||||
g.log.WarnContext(ctx, "telegram rate limited", "retry_after", tooMany.RetryAfter,
|
||||
"component", "gateway-telegram")
|
||||
return
|
||||
}
|
||||
g.log.Error("telegram pipeline error", "error", err)
|
||||
g.log.ErrorContext(ctx, "telegram pipeline error", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (g *Gateway) restartHandler() bot.HandlerFunc {
|
||||
select {
|
||||
case g.restartCh <- restartRequest{chatID: msg.Chat.ID, threadID: msg.MessageThreadID}:
|
||||
default:
|
||||
g.log.Warn("restart already in progress, ignoring duplicate request")
|
||||
g.log.WarnContext(ctx, "restart already in progress, ignoring duplicate request")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ func (g *Gateway) stopConversation(ctx context.Context, msg *models.Message, cli
|
||||
session := conversationID(msg).String()
|
||||
if g.turns != nil {
|
||||
cancelled, dropped = g.turns.Stop(session)
|
||||
g.log.Info("stop requested", "session", session, "cancelled", cancelled, "dropped", dropped)
|
||||
g.log.InfoContext(ctx, "stop requested", "session", session, "cancelled", cancelled, "dropped", dropped)
|
||||
}
|
||||
if client == nil {
|
||||
return stopReport(cancelled, dropped, nil)
|
||||
|
||||
@@ -194,7 +194,7 @@ func (g *Gateway) Start(ctx context.Context, client messaging.ChatContract, life
|
||||
if g.Token == "" {
|
||||
return fmt.Errorf("telegram bot token is required")
|
||||
}
|
||||
g.log.Info("starting telegram gateway")
|
||||
g.log.InfoContext(ctx, "starting telegram gateway")
|
||||
|
||||
for {
|
||||
lifecycle.ReportStarting()
|
||||
@@ -217,16 +217,16 @@ func (g *Gateway) Start(ctx context.Context, client messaging.ChatContract, life
|
||||
cancel()
|
||||
return g.Stop(context.WithoutCancel(ctx))
|
||||
case req := <-g.restartCh:
|
||||
g.log.Info("restarting telegram gateway", "requested_by", req.chatID)
|
||||
g.log.InfoContext(ctx, "restarting telegram gateway", "requested_by", req.chatID)
|
||||
cancel()
|
||||
if err := g.Stop(context.WithoutCancel(ctx)); err != nil {
|
||||
g.log.Warn("stop during restart failed", "error", err)
|
||||
g.log.WarnContext(ctx, "stop during restart failed", "error", err)
|
||||
}
|
||||
if g.Reload != nil {
|
||||
if err := g.Reload(g); err != nil {
|
||||
// Keep the previous settings rather than dying: a bad
|
||||
// config edit must not take the gateway down for good.
|
||||
g.log.Error("config reload failed, restarting with previous settings", "error", err)
|
||||
g.log.ErrorContext(ctx, "config reload failed, restarting with previous settings", "error", err)
|
||||
}
|
||||
}
|
||||
g.pendingRestart = &req
|
||||
@@ -286,7 +286,7 @@ func (g *Gateway) launch(ctx context.Context, client messaging.ChatContract, lif
|
||||
opts := []bot.Option{
|
||||
bot.WithErrorsHandler(g.pipelineErrorHandler(ctx)),
|
||||
bot.WithDebugHandler(func(format string, args ...any) {
|
||||
g.log.Debug("telegram debug", "message", fmt.Sprintf(format, args...))
|
||||
g.log.DebugContext(ctx, "telegram debug", "message", fmt.Sprintf(format, args...))
|
||||
}),
|
||||
bot.WithDefaultHandler(g.defaultHandler(client)),
|
||||
bot.WithMiddlewares(g.panicRecoveryMiddleware(), g.updateLoggingMiddleware()),
|
||||
@@ -365,7 +365,7 @@ func (g *Gateway) announceRelease(ctx context.Context, b *bot.Bot) {
|
||||
if err != nil {
|
||||
// Notifications are ancillary to chat availability. Keep the gateway
|
||||
// running and let the announcer retry unrecorded recipients next time.
|
||||
g.log.Warn("release announcement failed", "error", err)
|
||||
g.log.WarnContext(ctx, "release announcement failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ func (g *Gateway) Stop(ctx context.Context) error {
|
||||
if !g.running {
|
||||
return nil
|
||||
}
|
||||
g.log.Info("stopping telegram gateway")
|
||||
g.log.InfoContext(ctx, "stopping telegram gateway")
|
||||
g.running = false
|
||||
g.outbound.Store(nil)
|
||||
|
||||
@@ -418,7 +418,7 @@ func (g *Gateway) resumeHandler(client messaging.ChatContract) bot.HandlerFunc {
|
||||
Text: msg.Text,
|
||||
}})
|
||||
if err != nil {
|
||||
g.log.Error("resume handler failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "resume handler failed", "error", err)
|
||||
return
|
||||
}
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, reply.Text)
|
||||
@@ -440,7 +440,7 @@ func (g *Gateway) routeCmdHandler(client messaging.ChatContract, cmd string) bot
|
||||
Text: cmd,
|
||||
}})
|
||||
if err != nil {
|
||||
g.log.Error("command handler failed", "command", cmd, "error", err)
|
||||
g.log.ErrorContext(ctx, "command handler failed", "command", cmd, "error", err)
|
||||
return
|
||||
}
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, reply.Text)
|
||||
@@ -625,10 +625,10 @@ func (g *Gateway) submitTurn(ctx context.Context, b *bot.Bot, msg *models.Messag
|
||||
if err != nil {
|
||||
stopTyping()
|
||||
if errors.Is(err, context.Canceled) || errors.Is(turnCtx.Err(), context.Canceled) {
|
||||
g.log.Info("chat turn stopped", "session", session)
|
||||
g.log.InfoContext(ctx, "chat turn stopped", "session", session)
|
||||
live.abandon(turnCtx)
|
||||
} else {
|
||||
g.log.Error("stream failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "stream failed", "error", err)
|
||||
live.abandonFailed(turnCtx)
|
||||
}
|
||||
return
|
||||
@@ -669,10 +669,10 @@ func (g *Gateway) drainTurnEvents(
|
||||
|
||||
if streamErr != nil || turnCtx.Err() != nil {
|
||||
if errors.Is(turnCtx.Err(), context.Canceled) || (streamErr != nil && errors.Is(streamErr, context.Canceled)) {
|
||||
g.log.Info("chat turn stopped", "session", session)
|
||||
g.log.InfoContext(turnCtx, "chat turn stopped", "session", session)
|
||||
live.abandon(turnCtx)
|
||||
} else {
|
||||
g.log.Error("stream turn failed", "error", streamErr)
|
||||
g.log.ErrorContext(turnCtx, "stream turn failed", "error", streamErr)
|
||||
live.abandonFailed(turnCtx)
|
||||
}
|
||||
return "", true
|
||||
@@ -689,14 +689,14 @@ func (g *Gateway) fetchTurnMedia(ctx context.Context, b *bot.Bot, gm *messaging.
|
||||
// Before the download, so a file whose declared type contradicts itself is
|
||||
// refused rather than fetched and acted on.
|
||||
if err := messaging.ValidateInbound(gm.Media[0]); err != nil {
|
||||
g.log.Warn("inbound media refused", "media_type", gm.Media[0].Type, "error", err)
|
||||
g.log.WarnContext(ctx, "inbound media refused", "media_type", gm.Media[0].Type, "error", err)
|
||||
g.sendMessage(ctx, b, chatID, threadID,
|
||||
mediaReplyLabel(gm.Media[0])+"but I can't use that file — try sending it again.")
|
||||
return false
|
||||
}
|
||||
data, err := g.downloadMedia(ctx, b, gm.Media[0])
|
||||
if err != nil {
|
||||
g.log.Warn("inbound media download failed", "media_type", gm.Media[0].Type, "error", err)
|
||||
g.log.WarnContext(ctx, "inbound media download failed", "media_type", gm.Media[0].Type, "error", err)
|
||||
g.sendMessage(ctx, b, chatID, threadID,
|
||||
mediaReplyLabel(gm.Media[0])+"but I couldn't download it — try sending it again.")
|
||||
return false
|
||||
@@ -734,7 +734,7 @@ func (g *Gateway) authorizedMessage(ctx context.Context, b *bot.Bot, update *mod
|
||||
if g.isSenderAllowed(update.Message.From.ID) {
|
||||
return update.Message, true
|
||||
}
|
||||
g.log.Warn(
|
||||
g.log.WarnContext(ctx,
|
||||
"message from unauthorized sender",
|
||||
"user_id", update.Message.From.ID,
|
||||
"username", update.Message.From.Username,
|
||||
@@ -765,7 +765,7 @@ func (g *Gateway) startTyping(ctx context.Context, b *bot.Bot, chatID int64, mes
|
||||
params.MessageThreadID = messageThreadID
|
||||
}
|
||||
if _, err := b.SendChatAction(ctx, params); err != nil {
|
||||
g.log.Debug("send chat action failed", "error", err)
|
||||
g.log.DebugContext(ctx, "send chat action failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -847,10 +847,10 @@ func (g *Gateway) sendBlocks(ctx context.Context, b *bot.Bot, chatID int64, mess
|
||||
rich.MessageThreadID = messageThreadID
|
||||
}
|
||||
if msg, err := b.SendRichMessage(ctx, rich); err == nil {
|
||||
g.log.Debug("telegram message sent", "renderer", telegramRenderVersion, "mode", "rich")
|
||||
g.log.DebugContext(ctx, "telegram message sent", "renderer", telegramRenderVersion, "mode", "rich")
|
||||
return msg.ID
|
||||
} else {
|
||||
g.log.Warn("rich send failed, retrying unformatted", "error", err)
|
||||
g.log.WarnContext(ctx, "rich send failed, retrying unformatted", "error", err)
|
||||
}
|
||||
|
||||
plain := &bot.SendMessageParams{ChatID: chatID, Text: strings.Join(blocksToPlainText(blocks), "\n\n")}
|
||||
@@ -858,10 +858,10 @@ func (g *Gateway) sendBlocks(ctx context.Context, b *bot.Bot, chatID int64, mess
|
||||
plain.MessageThreadID = messageThreadID
|
||||
}
|
||||
if msg, err := b.SendMessage(ctx, plain); err != nil {
|
||||
g.log.Error(errMsg, "error", err)
|
||||
g.log.ErrorContext(ctx, errMsg, "error", err)
|
||||
return 0
|
||||
} else {
|
||||
g.log.Warn("telegram message sent via plain fallback", "renderer", telegramRenderVersion, "mode", "plain")
|
||||
g.log.WarnContext(ctx, "telegram message sent via plain fallback", "renderer", telegramRenderVersion, "mode", "plain")
|
||||
return msg.ID
|
||||
}
|
||||
}
|
||||
@@ -888,7 +888,7 @@ func (g *Gateway) panicRecoveryMiddleware() bot.Middleware {
|
||||
if hasChat {
|
||||
attrs = append(attrs, "chat_id", chatID)
|
||||
}
|
||||
g.log.Error("panic in telegram middleware", attrs...)
|
||||
g.log.ErrorContext(ctx, "panic in telegram middleware", attrs...)
|
||||
}
|
||||
}()
|
||||
next(ctx, b, update)
|
||||
@@ -907,7 +907,7 @@ func (g *Gateway) updateLoggingMiddleware() bot.Middleware {
|
||||
if threadID := updateThreadID(update); threadID != 0 {
|
||||
attrs = append(attrs, "thread_id", threadID)
|
||||
}
|
||||
g.log.Debug("telegram update", attrs...)
|
||||
g.log.DebugContext(ctx, "telegram update", attrs...)
|
||||
next(ctx, b, update)
|
||||
}
|
||||
}
|
||||
@@ -983,6 +983,6 @@ func (g *Gateway) dropPendingUpdates(ctx context.Context, b *bot.Bot) {
|
||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
if _, err := b.DeleteWebhook(ctx, &bot.DeleteWebhookParams{DropPendingUpdates: true}); err != nil {
|
||||
g.log.Warn("could not drop pending telegram updates, backlog may be replayed", "error", err)
|
||||
g.log.WarnContext(ctx, "could not drop pending telegram updates, backlog may be replayed", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (g *Gateway) updateHandler() bot.HandlerFunc {
|
||||
}
|
||||
snapshot, err := g.Updates.Check(ctx, msg.From.ID)
|
||||
if err != nil {
|
||||
g.log.Warn("check updates failed", "error", err)
|
||||
g.log.WarnContext(ctx, "check updates failed", "error", err)
|
||||
g.sendMessage(ctx, b, msg.Chat.ID, msg.MessageThreadID, "I couldn't check for updates right now.")
|
||||
return
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (g *Gateway) sendUpdateMessage(ctx context.Context, b *bot.Bot, chatID int6
|
||||
params.MessageThreadID = threadID
|
||||
}
|
||||
if _, err := b.SendMessage(ctx, params); err != nil {
|
||||
g.log.Error("send update status failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "send update status failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ func (g *Gateway) handleUpdateCallback(ctx context.Context, b *bot.Bot, update *
|
||||
return
|
||||
}
|
||||
if !g.isSenderAllowed(query.From.ID) {
|
||||
g.log.Warn("update callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.log.WarnContext(ctx, "update callback from unauthorized sender", "user_id", query.From.ID)
|
||||
g.answerModelCallback(ctx, b, query.ID, "You are not authorised to use this bot.", true)
|
||||
return
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (g *Gateway) dispatchUpdateAction(ctx context.Context, b *bot.Bot, query *m
|
||||
switch {
|
||||
case strings.HasPrefix(query.Data, updateDeferCallback):
|
||||
if err := g.Updates.Defer(ctx, query.From.ID, action.snapshot); err != nil {
|
||||
g.log.Warn("defer update failed", "error", err)
|
||||
g.log.WarnContext(ctx, "defer update failed", "error", err)
|
||||
g.answerModelCallback(ctx, b, query.ID, "Couldn't defer the update.", true)
|
||||
return
|
||||
}
|
||||
@@ -188,14 +188,14 @@ func (g *Gateway) installUpdate(ctx context.Context, b *bot.Bot, query *models.C
|
||||
if _, err := b.EditMessageText(ctx, &bot.EditMessageTextParams{
|
||||
ChatID: message.Chat.ID, MessageID: message.ID, Text: progressText(lines),
|
||||
}); err != nil {
|
||||
g.log.Warn("update progress message failed", "error", err)
|
||||
g.log.WarnContext(ctx, "update progress message failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
installCtx := context.WithoutCancel(ctx)
|
||||
result, err := g.Updates.Install(installCtx, snapshot, meta, progress)
|
||||
if err != nil {
|
||||
g.log.Error("approved update failed", "error", err)
|
||||
g.log.ErrorContext(ctx, "approved update failed", "error", err)
|
||||
lines = append(lines, formatInstallFailure(err))
|
||||
g.editUpdateMessage(ctx, b, query, progressText(lines))
|
||||
return
|
||||
@@ -337,9 +337,9 @@ func (g *Gateway) reportPendingUpdate(ctx context.Context, b *bot.Bot) {
|
||||
}
|
||||
report, found, err := releaseupdate.ReadPendingReport(g.UpdateReportPath)
|
||||
if err != nil {
|
||||
g.log.Warn("read pending update report failed; discarding it", "error", err)
|
||||
g.log.WarnContext(ctx, "read pending update report failed; discarding it", "error", err)
|
||||
if clearErr := releaseupdate.ClearPendingReport(g.UpdateReportPath); clearErr != nil {
|
||||
g.log.Warn("clear unreadable update report failed", "error", clearErr)
|
||||
g.log.WarnContext(ctx, "clear unreadable update report failed", "error", clearErr)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func (g *Gateway) reportPendingUpdate(ctx context.Context, b *bot.Bot) {
|
||||
}
|
||||
g.SendPendingReport(ctx, b, report)
|
||||
if err := releaseupdate.ClearPendingReport(g.UpdateReportPath); err != nil {
|
||||
g.log.Warn("clear pending update report failed", "error", err)
|
||||
g.log.WarnContext(ctx, "clear pending update report failed", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,6 +375,6 @@ func (g *Gateway) editUpdateMessage(ctx context.Context, b *bot.Bot, query *mode
|
||||
}
|
||||
message := query.Message.Message
|
||||
if _, err := b.EditMessageText(ctx, &bot.EditMessageTextParams{ChatID: message.Chat.ID, MessageID: message.ID, Text: text}); err != nil {
|
||||
g.log.Warn("update update message failed", "error", err)
|
||||
g.log.WarnContext(ctx, "update update message failed", "error", err)
|
||||
}
|
||||
}
|
||||
+21
-21
@@ -227,7 +227,7 @@ func NewPool(ctx context.Context, cfg Config, live func() Config, log *slog.Logg
|
||||
if cfg.PullPolicy == "always" || cfg.PullPolicy == "missing" {
|
||||
if err := p.pullImage(ctx, cfg.Image); err != nil {
|
||||
if err := cli.Close(); err != nil {
|
||||
log.Warn("docker client close failed during pull error", "err", err)
|
||||
log.WarnContext(ctx, "docker client close failed during pull error", "err", err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -305,7 +305,7 @@ func (p *Pool) Acquire(ctx context.Context, image string, mounts []storage.Mount
|
||||
if _, err := p.cli.ContainerStart(ctx, resp.ID, client.ContainerStartOptions{}); err != nil {
|
||||
// Best-effort cleanup.
|
||||
if _, rmErr := p.cli.ContainerRemove(context.WithoutCancel(ctx), resp.ID, client.ContainerRemoveOptions{Force: true}); rmErr != nil {
|
||||
p.log.Warn("container remove after start failure", "id", resp.ID[:12], "err", rmErr)
|
||||
p.log.WarnContext(ctx, "container remove after start failure", "id", resp.ID[:12], "err", rmErr)
|
||||
}
|
||||
p.unreserve()
|
||||
return nil, fmt.Errorf("container start: %w", err)
|
||||
@@ -356,7 +356,7 @@ func (p *Pool) started(ctx context.Context, maxUptime time.Duration, id, name st
|
||||
if maxUptime > 0 {
|
||||
p.armMaxUptime(ctx, maxUptime, id)
|
||||
}
|
||||
p.log.Info("container started", "id", id[:12], "name", name)
|
||||
p.log.InfoContext(ctx, "container started", "id", id[:12], "name", name)
|
||||
detail := new(string)
|
||||
return &Container{ID: id, exited: p.watchExit(ctx, id, detail), detail: detail}
|
||||
}
|
||||
@@ -421,10 +421,10 @@ func (p *Pool) reapMaxUptime(ctx context.Context, id string) {
|
||||
stopCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
if _, err := p.cli.ContainerStop(stopCtx, id, client.ContainerStopOptions{Timeout: &zero}); err != nil {
|
||||
p.log.Warn("max uptime stop failed", "id", id[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "max uptime stop failed", "id", id[:12], "err", err)
|
||||
}
|
||||
if _, err := p.cli.ContainerRemove(context.WithoutCancel(ctx), id, client.ContainerRemoveOptions{Force: true}); err != nil {
|
||||
p.log.Warn("max uptime remove failed", "id", id[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "max uptime remove failed", "id", id[:12], "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,7 +505,7 @@ func (p *Pool) Release(ctx context.Context, c *Container) {
|
||||
}
|
||||
honorGrace, stopTimeout := releaseDecision(ctx, p.cfg.GracePeriod)
|
||||
if honorGrace {
|
||||
p.log.Info("container keeping alive for grace period", "id", c.ID[:12], "grace", p.cfg.GracePeriod)
|
||||
p.log.InfoContext(ctx, "container keeping alive for grace period", "id", c.ID[:12], "grace", p.cfg.GracePeriod)
|
||||
time.Sleep(p.cfg.GracePeriod)
|
||||
}
|
||||
|
||||
@@ -516,10 +516,10 @@ func (p *Pool) Release(ctx context.Context, c *Container) {
|
||||
defer cancel()
|
||||
|
||||
if _, err := p.cli.ContainerStop(stopCtx, c.ID, client.ContainerStopOptions{Timeout: stopTimeout}); err != nil {
|
||||
p.log.Warn("container stop failed", "id", c.ID[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "container stop failed", "id", c.ID[:12], "err", err)
|
||||
}
|
||||
if _, err := p.cli.ContainerRemove(context.WithoutCancel(ctx), c.ID, client.ContainerRemoveOptions{Force: true}); err != nil {
|
||||
p.log.Warn("container remove failed", "id", c.ID[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "container remove failed", "id", c.ID[:12], "err", err)
|
||||
}
|
||||
}
|
||||
p.forgetTeardown(c.ID)
|
||||
@@ -527,7 +527,7 @@ func (p *Pool) Release(ctx context.Context, c *Container) {
|
||||
p.mu.Lock()
|
||||
p.active--
|
||||
p.mu.Unlock()
|
||||
p.log.Info("container released", "id", c.ID[:12])
|
||||
p.log.InfoContext(ctx, "container released", "id", c.ID[:12])
|
||||
}
|
||||
|
||||
// Close stops and removes all active containers. If the pool created its
|
||||
@@ -606,25 +606,25 @@ func (p *Pool) pullImage(ctx context.Context, ref string) error {
|
||||
if cfg.PullPolicy == "missing" {
|
||||
_, err := p.cli.ImageInspect(ctx, ref)
|
||||
if err == nil {
|
||||
p.log.Info("image already present", "image", ref)
|
||||
p.log.InfoContext(ctx, "image already present", "image", ref)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
p.log.Info("pulling image", "image", ref)
|
||||
p.log.InfoContext(ctx, "pulling image", "image", ref)
|
||||
rc, err := p.cli.ImagePull(ctx, ref, client.ImagePullOptions{RegistryAuth: p.registryAuthHeader(cfg, ref)})
|
||||
if err != nil {
|
||||
return fmt.Errorf("pull %s: %w", ref, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := rc.Close(); err != nil {
|
||||
p.log.Warn("image pull reader close failed", "err", err)
|
||||
p.log.WarnContext(ctx, "image pull reader close failed", "err", err)
|
||||
}
|
||||
}()
|
||||
if _, err := io.Copy(io.Discard, rc); err != nil {
|
||||
return fmt.Errorf("pull %s: discard: %w", ref, err)
|
||||
}
|
||||
p.log.Info("image pulled", "image", ref)
|
||||
p.log.InfoContext(ctx, "image pulled", "image", ref)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -666,21 +666,21 @@ func encodeRegistryAuth(credential string) (string, error) {
|
||||
func selfNetwork(ctx context.Context, cli *client.Client, log *slog.Logger) string {
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
log.Warn("container network auto-detect: os.Hostname failed, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "err", err)
|
||||
log.WarnContext(ctx, "container network auto-detect: os.Hostname failed, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "err", err)
|
||||
return ""
|
||||
}
|
||||
self, err := cli.ContainerInspect(ctx, hostname, client.ContainerInspectOptions{})
|
||||
if err != nil {
|
||||
log.Warn("container network auto-detect: could not inspect self by hostname, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "hostname", hostname, "err", err)
|
||||
log.WarnContext(ctx, "container network auto-detect: could not inspect self by hostname, spawned containers will use the default bridge network and won't resolve sibling services by name — set containers.network explicitly", "hostname", hostname, "err", err)
|
||||
return ""
|
||||
}
|
||||
if self.Container.NetworkSettings == nil {
|
||||
log.Warn("container network auto-detect: self container has no NetworkSettings, spawned containers will use the default bridge network — set containers.network explicitly", "hostname", hostname)
|
||||
log.WarnContext(ctx, "container network auto-detect: self container has no NetworkSettings, spawned containers will use the default bridge network — set containers.network explicitly", "hostname", hostname)
|
||||
return ""
|
||||
}
|
||||
for name := range self.Container.NetworkSettings.Networks {
|
||||
if name != "bridge" {
|
||||
log.Info("spawned containers will join daemon's network", "network", name)
|
||||
log.InfoContext(ctx, "spawned containers will join daemon's network", "network", name)
|
||||
return name
|
||||
}
|
||||
}
|
||||
@@ -697,16 +697,16 @@ func (p *Pool) recoverOrphans(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
for _, c := range list.Items {
|
||||
p.log.Info("recovering orphaned container", "id", c.ID[:12])
|
||||
p.log.InfoContext(ctx, "recovering orphaned container", "id", c.ID[:12])
|
||||
if _, err := p.cli.ContainerStop(ctx, c.ID, client.ContainerStopOptions{}); err != nil {
|
||||
p.log.Warn("container stop during orphan recovery", "id", c.ID[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "container stop during orphan recovery", "id", c.ID[:12], "err", err)
|
||||
}
|
||||
if _, err := p.cli.ContainerRemove(ctx, c.ID, client.ContainerRemoveOptions{Force: true}); err != nil {
|
||||
p.log.Warn("container remove during orphan recovery", "id", c.ID[:12], "err", err)
|
||||
p.log.WarnContext(ctx, "container remove during orphan recovery", "id", c.ID[:12], "err", err)
|
||||
}
|
||||
}
|
||||
if len(list.Items) > 0 {
|
||||
p.log.Info("orphan recovery complete", "count", len(list.Items))
|
||||
p.log.InfoContext(ctx, "orphan recovery complete", "count", len(list.Items))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func (d *Daemon) reconcileCallWaits(ctx context.Context, dispatcher *taskDispatc
|
||||
steps, err := reader.ListSteps(readCtx, hold.id, hold.attempt)
|
||||
cancel()
|
||||
if err != nil {
|
||||
d.Log.Warn("read call waits", "task", hold.id, "err", err)
|
||||
d.Log.WarnContext(ctx, "read call waits", "task", hold.id, "err", err)
|
||||
continue
|
||||
}
|
||||
waits := 0
|
||||
|
||||
+88
-88
@@ -286,7 +286,7 @@ func (d *Daemon) Startup(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
if n > 0 {
|
||||
d.Log.Info("re-queued tasks left running by a previous daemon", "count", n)
|
||||
d.Log.InfoContext(ctx, "re-queued tasks left running by a previous daemon", "count", n)
|
||||
}
|
||||
|
||||
d.sweepAccess(ctx)
|
||||
@@ -306,7 +306,7 @@ func (d *Daemon) sweepAccess(ctx context.Context) {
|
||||
ctx, cancel := context.WithTimeout(ctx, sweepTimeout)
|
||||
defer cancel()
|
||||
if err := source.Forge.AcceptInvitations(ctx); err != nil {
|
||||
log.Warn("invitation sweep failed", "err", err)
|
||||
log.WarnContext(ctx, "invitation sweep failed", "err", err)
|
||||
}
|
||||
for _, r := range source.Repos {
|
||||
if err := source.Forge.VerifyPush(ctx, r.Owner, r.Name); err != nil {
|
||||
@@ -315,12 +315,12 @@ func (d *Daemon) sweepAccess(ctx context.Context) {
|
||||
switch {
|
||||
case errors.Is(ctx.Err(), context.DeadlineExceeded):
|
||||
// Every later call would return the same error, so say it once.
|
||||
log.Warn("push check abandoned: sweep budget exhausted", "repo", r.FullName(), "err", err)
|
||||
log.WarnContext(ctx, "push check abandoned: sweep budget exhausted", "repo", r.FullName(), "err", err)
|
||||
return
|
||||
case ctx.Err() != nil:
|
||||
return
|
||||
}
|
||||
log.Warn("repo not pushable -- tasks from it will fail", "repo", r.FullName(), "err", err)
|
||||
log.WarnContext(ctx, "repo not pushable -- tasks from it will fail", "repo", r.FullName(), "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -396,24 +396,24 @@ func (d *Daemon) pollIssuesWithConfig(ctx context.Context, fg forge.Forge, cfg c
|
||||
// Empty-label rule shared with workintake.MatchesDispatch: a label
|
||||
// trigger needs a non-empty label or it would match every open issue.
|
||||
if cfg.Label == "" {
|
||||
d.Log.Error("label trigger configured with an empty label; refusing to poll (an empty label matches every open issue)", "repo", repo.FullName())
|
||||
d.Log.ErrorContext(ctx, "label trigger configured with an empty label; refusing to poll (an empty label matches every open issue)", "repo", repo.FullName())
|
||||
return nil, false
|
||||
}
|
||||
issues, err := fg.IssuesWithLabel(ctx, repo.Owner, repo.Name, cfg.Label)
|
||||
if err != nil {
|
||||
d.Log.Error("label poll failed", "repo", repo.FullName(), "err", err)
|
||||
d.Log.ErrorContext(ctx, "label poll failed", "repo", repo.FullName(), "err", err)
|
||||
return nil, false
|
||||
}
|
||||
return issues, true
|
||||
}
|
||||
assigned := func() ([]forge.Issue, bool) {
|
||||
if cfg.BotUser == "" {
|
||||
d.Log.Error("assignee trigger needs the connection's account; refusing to poll", "repo", repo.FullName())
|
||||
d.Log.ErrorContext(ctx, "assignee trigger needs the connection's account; refusing to poll", "repo", repo.FullName())
|
||||
return nil, false
|
||||
}
|
||||
issues, err := fg.AssignedIssues(ctx, repo.Owner, repo.Name, cfg.BotUser)
|
||||
if err != nil {
|
||||
d.Log.Error("assigned poll failed", "repo", repo.FullName(), "err", err)
|
||||
d.Log.ErrorContext(ctx, "assigned poll failed", "repo", repo.FullName(), "err", err)
|
||||
return nil, false
|
||||
}
|
||||
return issues, true
|
||||
@@ -483,10 +483,10 @@ func (d *Daemon) cleanupExpiredStorage(ctx context.Context) {
|
||||
if d.Storage != nil {
|
||||
n, err := d.Storage.CleanupExpired(ctx, ttl)
|
||||
if err != nil {
|
||||
d.Log.Warn("persistent volume cleanup failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "persistent volume cleanup failed", "err", err)
|
||||
}
|
||||
if n > 0 {
|
||||
d.Log.Info("expired persistent volumes removed", "count", n)
|
||||
d.Log.InfoContext(ctx, "expired persistent volumes removed", "count", n)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,7 +514,7 @@ func (d *Daemon) dispatchBindings(ctx context.Context) {
|
||||
} else {
|
||||
principal, err := d.Principals.PrincipalFor(ctx, d.RootIdentityID)
|
||||
if err != nil {
|
||||
d.Log.Warn("binding dispatch: principal unavailable", "identity", d.RootIdentityID, "err", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: principal unavailable", "identity", d.RootIdentityID, "err", err)
|
||||
return
|
||||
}
|
||||
principals = []access.Principal{principal}
|
||||
@@ -535,12 +535,12 @@ func (d *Daemon) dispatchOrgBindings(ctx context.Context) {
|
||||
// on a disabled workflow would take.
|
||||
bindings, err := d.Bindings.ListBindings(ctx)
|
||||
if err != nil {
|
||||
d.Log.Warn("list bindings failed", "error", err)
|
||||
d.Log.WarnContext(ctx, "list bindings failed", "error", err)
|
||||
return
|
||||
}
|
||||
enablement, err := d.workflowEnablement(ctx)
|
||||
if err != nil {
|
||||
d.Log.Warn("binding dispatch: workflow enablement unavailable", "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: workflow enablement unavailable", "error", err)
|
||||
return
|
||||
}
|
||||
enabled := make([]string, 0, len(bindings))
|
||||
@@ -555,12 +555,12 @@ func (d *Daemon) dispatchOrgBindings(ctx context.Context) {
|
||||
|
||||
captures, err := d.BindingDispatcher.ListUndispatchedCaptures(ctx, enabled, bindingDispatchBatchLimit)
|
||||
if err != nil {
|
||||
d.Log.Warn("list undispatched captures failed", "error", err)
|
||||
d.Log.WarnContext(ctx, "list undispatched captures failed", "error", err)
|
||||
return
|
||||
}
|
||||
workflows, err := d.activeWorkflows(ctx)
|
||||
if err != nil {
|
||||
d.Log.Warn("binding dispatch: workflow definitions unavailable", "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: workflow definitions unavailable", "error", err)
|
||||
return
|
||||
}
|
||||
for _, c := range captures {
|
||||
@@ -574,7 +574,7 @@ func (d *Daemon) dispatchOrgBindings(ctx context.Context) {
|
||||
func (d *Daemon) dispatchCapture(ctx context.Context, c storecontract.CapturedEvent, workflows workflow.WorkflowDefinitionCollection, enablement workflowtask.WorkflowEnablement) {
|
||||
armed, err := d.BindingDispatcher.ArmedBindingsForSource(ctx, c.Source)
|
||||
if err != nil {
|
||||
d.Log.Warn("armed bindings lookup", "source", c.Source, "error", err)
|
||||
d.Log.WarnContext(ctx, "armed bindings lookup", "source", c.Source, "error", err)
|
||||
return
|
||||
}
|
||||
for _, b := range armed {
|
||||
@@ -588,12 +588,12 @@ func (d *Daemon) dispatchCapture(ctx context.Context, c storecontract.CapturedEv
|
||||
// unavailable. A mapping that no longer exists is a terminal outcome.
|
||||
func (d *Daemon) bindingMapping(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent) *mapping.Mapping {
|
||||
if d.Mappings == nil {
|
||||
d.Log.Warn("binding dispatch: mapping store unavailable", "binding", b.ID)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: mapping store unavailable", "binding", b.ID)
|
||||
return nil
|
||||
}
|
||||
m, err := d.Mappings.GetMapping(ctx, b.MappingID)
|
||||
if err != nil {
|
||||
d.Log.Warn("binding dispatch: get mapping", "binding", b.ID, "mapping", b.MappingID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: get mapping", "binding", b.ID, "mapping", b.MappingID, "error", err)
|
||||
return nil
|
||||
}
|
||||
if m == nil {
|
||||
@@ -619,7 +619,7 @@ func (d *Daemon) dispatchOneBinding(ctx context.Context, b binding.Binding, c st
|
||||
}
|
||||
if d.MappingMatches != nil {
|
||||
if err := d.MappingMatches.RecordMappingMatch(ctx, m.ID, c.ID); err != nil {
|
||||
d.Log.Warn("binding dispatch: record mapping match", "mapping", m.ID, "capture", c.ID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: record mapping match", "mapping", m.ID, "capture", c.ID, "error", err)
|
||||
}
|
||||
}
|
||||
filter, err := binding.CompileFilter(b.Filter, m.Fields)
|
||||
@@ -663,7 +663,7 @@ func (d *Daemon) claimAndEnqueue(ctx context.Context, b binding.Binding, c store
|
||||
task, err := d.BindingTaskCreator.EnqueueBindingTask(ctx, target.owner, target.repo, title, body, b.Workflow, taskIdentity, b.ID, b.Version, c.ID, target.inputs)
|
||||
if err != nil {
|
||||
if !errors.Is(err, storecontract.ErrAlreadyDispatched) {
|
||||
d.Log.Warn("binding dispatch: enqueue", "binding", b.ID, "capture", c.ID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: enqueue", "binding", b.ID, "capture", c.ID, "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -680,7 +680,7 @@ func (d *Daemon) authorizeDispatch(ctx context.Context, b binding.Binding, c sto
|
||||
}
|
||||
principal, ok := access.PrincipalFromContext(ctx)
|
||||
if !ok {
|
||||
d.Log.Warn("binding dispatch: no principal; dispatch left for the next cycle", "binding", b.ID, "capture", c.ID)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: no principal; dispatch left for the next cycle", "binding", b.ID, "capture", c.ID)
|
||||
return false
|
||||
}
|
||||
resource := access.Resource{
|
||||
@@ -695,7 +695,7 @@ func (d *Daemon) authorizeDispatch(ctx context.Context, b binding.Binding, c sto
|
||||
// Nothing was evaluated. Recording it would mark the pair evaluated for
|
||||
// good, so a State Store blip would drop the capture instead of leaving
|
||||
// it for the next cycle.
|
||||
d.Log.Warn("binding dispatch: access chain unavailable; dispatch left for the next cycle", "binding", b.ID, "capture", c.ID, "err", decision.Err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: access chain unavailable; dispatch left for the next cycle", "binding", b.ID, "capture", c.ID, "err", decision.Err)
|
||||
return false
|
||||
}
|
||||
if d.Denials != nil {
|
||||
@@ -705,7 +705,7 @@ func (d *Daemon) authorizeDispatch(ctx context.Context, b binding.Binding, c sto
|
||||
Policies: decision.Policies,
|
||||
}
|
||||
if err := d.Denials.RecordDenial(ctx, denial); err != nil {
|
||||
d.Log.Warn("binding dispatch: record denial", "binding", b.ID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: record denial", "binding", b.ID, "error", err)
|
||||
}
|
||||
}
|
||||
d.recordDispatchFailure(ctx, b, c, "access denied", map[string]any{
|
||||
@@ -739,7 +739,7 @@ func (d *Daemon) markBindingStart(ctx context.Context, taskID int64, b binding.B
|
||||
"capture_id": c.ID, "source": c.Source, "unsigned": c.Unsigned,
|
||||
},
|
||||
}); err != nil {
|
||||
d.Log.Warn("binding dispatch: start marker", "task", taskID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: start marker", "task", taskID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,7 +766,7 @@ func (d *Daemon) recordDispatchFailure(ctx context.Context, b binding.Binding, c
|
||||
func (d *Daemon) recordEvaluated(ctx context.Context, b binding.Binding, c storecontract.CapturedEvent, reason string) {
|
||||
err := d.BindingDispatcher.RecordDispatch(ctx, b.ID, int64(b.Version), c.ID, 0, reason)
|
||||
if err != nil && !errors.Is(err, storecontract.ErrAlreadyDispatched) {
|
||||
d.Log.Warn("binding dispatch: record evaluation", "binding", b.ID, "capture", c.ID, "error", err)
|
||||
d.Log.WarnContext(ctx, "binding dispatch: record evaluation", "binding", b.ID, "capture", c.ID, "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -838,7 +838,7 @@ func (d *Daemon) drainReactions(ctx context.Context) {
|
||||
)
|
||||
}
|
||||
if _, err := d.reactionConsumer.drain(ctx, d.Reactions, maxReactionsPerCycle); err != nil {
|
||||
d.Log.Error("reaction drain failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "reaction drain failed", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ func (d *Daemon) drainNATS(ctx context.Context) {
|
||||
for ctx.Err() == nil {
|
||||
msg, err := d.Tasks.Fetch(ctx)
|
||||
if err != nil && !errors.Is(err, eventbus.ErrNoMessage) {
|
||||
d.Log.Error("nats fetch failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "nats fetch failed", "err", err)
|
||||
break
|
||||
}
|
||||
if err == nil {
|
||||
@@ -877,7 +877,7 @@ func (d *Daemon) drainNATS(ctx context.Context) {
|
||||
// nothing will ever arrive on the stream to trigger them.
|
||||
task, claimErr := d.Store.ClaimNext(ctx)
|
||||
if claimErr != nil {
|
||||
d.Log.Error("sqlite claim failed", "err", claimErr)
|
||||
d.Log.ErrorContext(ctx, "sqlite claim failed", "err", claimErr)
|
||||
break
|
||||
}
|
||||
if task == nil {
|
||||
@@ -918,7 +918,7 @@ func (d *Daemon) ResizeTaskDispatcher(maxConcurrency int) {
|
||||
func (d *Daemon) submitNATSTask(ctx context.Context, dispatcher *taskDispatcher, msg eventbus.Message) {
|
||||
envelope, err := workintake.DecodeTask(msg.Data())
|
||||
if err != nil {
|
||||
d.Log.Error("nats decode failed", "subject", msg.Subject(), "err", err)
|
||||
d.Log.ErrorContext(ctx, "nats decode failed", "subject", msg.Subject(), "err", err)
|
||||
_ = msg.Ack()
|
||||
return
|
||||
}
|
||||
@@ -1257,7 +1257,7 @@ func (d *Daemon) withdrawUnpolled(ctx context.Context, repo config.Repo, identit
|
||||
Statuses: []string{taskstate.Queued, taskstate.Running}, Limit: 500,
|
||||
})
|
||||
if err != nil {
|
||||
d.Log.Warn("withdrawal check: active tasks unavailable", "repo", repo.FullName(), "err", err)
|
||||
d.Log.WarnContext(ctx, "withdrawal check: active tasks unavailable", "repo", repo.FullName(), "err", err)
|
||||
return
|
||||
}
|
||||
for _, t := range active {
|
||||
@@ -1266,7 +1266,7 @@ func (d *Daemon) withdrawUnpolled(ctx context.Context, repo config.Repo, identit
|
||||
continue
|
||||
}
|
||||
if err := d.WithdrawTask(ctx, t.ID, "the issue is no longer assigned, labelled or open"); err != nil {
|
||||
d.Log.Warn("withdraw task", "task", t.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "withdraw task", "task", t.ID, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1276,7 +1276,7 @@ func (d *Daemon) pollNATS(ctx context.Context, fg forge.Forge, cfg config.Config
|
||||
// Read-only existence check prevents rediscovering an existing task.
|
||||
existing, err := d.Store.TaskByIssue(ctx, repo.Owner, repo.Name, is.Number)
|
||||
if err != nil {
|
||||
d.Log.Error("task lookup failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
|
||||
d.Log.ErrorContext(ctx, "task lookup failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
|
||||
return
|
||||
}
|
||||
if existing != nil {
|
||||
@@ -1296,7 +1296,7 @@ func (d *Daemon) pollNATS(ctx context.Context, fg forge.Forge, cfg config.Config
|
||||
Kind: workintake.KindForLabels(parsed),
|
||||
}
|
||||
if err := d.PublishTask(ctx, task); err != nil {
|
||||
d.Log.Error("task publish failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
|
||||
d.Log.ErrorContext(ctx, "task publish failed", "repo", repo.FullName(), "issue", is.Number, "err", err)
|
||||
return
|
||||
}
|
||||
d.acknowledge(ctx, fg, cfg, repo, is)
|
||||
@@ -1369,10 +1369,10 @@ func (d *Daemon) identityOrg(ctx context.Context, id identity.IdentityID) (org.O
|
||||
// using fg -- the forge client that owns repo (identity-scoped or root) --
|
||||
// and the ack reaction from cfg, the dispatch config that owns this poll.
|
||||
func (d *Daemon) acknowledge(ctx context.Context, fg forge.Forge, cfg config.Config, repo config.Repo, is forge.Issue) {
|
||||
d.Log.Info("issue queued", "repo", repo.FullName(), "issue", is.Number, "title", is.Title)
|
||||
d.Log.InfoContext(ctx, "issue queued", "repo", repo.FullName(), "issue", is.Number, "title", is.Title)
|
||||
if ack := cfg.Dispatch.AckReaction; ack != "" {
|
||||
if err := fg.React(ctx, repo.Owner, repo.Name, is.Number, ack); err != nil {
|
||||
d.Log.Warn("ack reaction failed", "issue", is.Number, "err", err)
|
||||
d.Log.WarnContext(ctx, "ack reaction failed", "issue", is.Number, "err", err)
|
||||
}
|
||||
}
|
||||
d.emit(ctx, events.Event{
|
||||
@@ -1383,15 +1383,15 @@ func (d *Daemon) acknowledge(ctx context.Context, fg forge.Forge, cfg config.Con
|
||||
|
||||
func (d *Daemon) acceptTaskPublisher(ctx context.Context, msg eventbus.Message, name string) bool {
|
||||
if ok, reason, class := d.identityMayAct(ctx, name); !ok {
|
||||
d.Log.Error("nats intake rejected: "+reason, "subject", msg.Subject())
|
||||
d.Log.ErrorContext(ctx, "nats intake rejected: "+reason, "subject", msg.Subject())
|
||||
if class == taskstate.ParkTransient {
|
||||
if err := msg.Nak(); err != nil {
|
||||
d.Log.Warn("nak failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "nak failed", "err", err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
if err := msg.Ack(); err != nil {
|
||||
d.Log.Warn("ack failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "ack failed", "err", err)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1407,9 +1407,9 @@ func (d *Daemon) processNATSTask(ctx context.Context, msg eventbus.Message, hold
|
||||
defer span.End()
|
||||
tm, err := workintake.DecodeTask(msg.Data())
|
||||
if err != nil {
|
||||
d.Log.Error("nats decode failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "nats decode failed", "err", err)
|
||||
if err := msg.Ack(); err != nil {
|
||||
d.Log.Warn("ack failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "ack failed", "err", err)
|
||||
}
|
||||
// bad message, don't retry
|
||||
return
|
||||
@@ -1421,39 +1421,39 @@ func (d *Daemon) processNATSTask(ctx context.Context, msg eventbus.Message, hold
|
||||
|
||||
inserted, err := d.Store.EnqueueIssue(ctx, tm.Owner, tm.Repo, tm.Number, tm.Title, tm.Body, strings.Join(tm.Labels, ","), tm.Identity)
|
||||
if err != nil {
|
||||
d.Log.Error("nats enqueue failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "nats enqueue failed", "err", err)
|
||||
if err := msg.Nak(); err != nil {
|
||||
d.Log.Warn("nats nak failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "nats nak failed", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !inserted {
|
||||
// Already tracked -- dedup. Ack and move on.
|
||||
if err := msg.Ack(); err != nil {
|
||||
d.Log.Warn("ack failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "ack failed", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
task, err := d.Store.ClaimByIssue(ctx, tm.Owner, tm.Repo, tm.Number)
|
||||
if err != nil {
|
||||
d.Log.Error("nats claim failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "nats claim failed", "err", err)
|
||||
if err := msg.Nak(); err != nil {
|
||||
d.Log.Warn("nats nak failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "nats nak failed", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if task == nil {
|
||||
// Claimed by another consumer, or task is not queued. Ack.
|
||||
if err := msg.Ack(); err != nil {
|
||||
d.Log.Warn("ack failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "ack failed", "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
d.process(ctx, task, hold)
|
||||
if err := msg.Ack(); err != nil {
|
||||
d.Log.Warn("ack failed", "err", err)
|
||||
d.Log.WarnContext(ctx, "ack failed", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1466,13 +1466,13 @@ func (d *Daemon) closeResolvedIssue(ctx context.Context, fg forge.Forge, task *w
|
||||
if d.ResolveRepository != nil {
|
||||
resolved, err := d.Repository(ctx, task, config.OperationPR)
|
||||
if err != nil {
|
||||
d.Log.Warn("issue closure not permitted", "task", task.ID)
|
||||
d.Log.WarnContext(ctx, "issue closure not permitted", "task", task.ID)
|
||||
return
|
||||
}
|
||||
fg = resolved.Forge
|
||||
}
|
||||
if err := fg.CloseIssue(ctx, task.Owner, task.Repo, task.IssueNumber, comment); err != nil {
|
||||
d.Log.Warn("closing resolved issue failed; it stays open and will be re-polled",
|
||||
d.Log.WarnContext(ctx, "closing resolved issue failed; it stays open and will be re-polled",
|
||||
"repo", task.Owner+"/"+task.Repo, "issue", task.IssueNumber, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -1482,7 +1482,7 @@ func (d *Daemon) closeResolvedIssue(ctx context.Context, fg forge.Forge, task *w
|
||||
func (d *Daemon) reconcilePRs(ctx context.Context) {
|
||||
tasks, err := d.Store.OpenPRs(ctx)
|
||||
if err != nil {
|
||||
d.Log.Error("reconcile query failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "reconcile query failed", "err", err)
|
||||
return
|
||||
}
|
||||
for _, t := range tasks {
|
||||
@@ -1497,7 +1497,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
|
||||
// issue number) is forge-only.
|
||||
state, err := fg.PRState(ctx, t.Owner, t.Repo, t.PRNumber)
|
||||
if err != nil {
|
||||
d.Log.Warn("PR state check failed", "pr", t.PRNumber, "err", err)
|
||||
d.Log.WarnContext(ctx, "PR state check failed", "pr", t.PRNumber, "err", err)
|
||||
continue
|
||||
}
|
||||
attempt := t.Attempt
|
||||
@@ -1509,7 +1509,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
|
||||
d.closeResolvedIssue(ctx, fg, &t, fmt.Sprintf(
|
||||
"Closed by #%d, merged by archie.", t.PRNumber,
|
||||
))
|
||||
d.Log.Info("PR merged", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber)
|
||||
d.Log.InfoContext(ctx, "PR merged", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber)
|
||||
d.emit(ctx, events.Event{
|
||||
Kind: events.KindPRMerged, TaskID: t.ID, Attempt: attempt,
|
||||
Repo: t.Owner + "/" + t.Repo, Issue: t.IssueNumber,
|
||||
@@ -1518,7 +1518,7 @@ func (d *Daemon) reconcilePRs(ctx context.Context) {
|
||||
case "closed":
|
||||
_ = d.Store.Transition(ctx, t.ID, workflow.StatusPROpen, workflow.StatusRejected, "PR closed without merge")
|
||||
_ = trees.Cleanup(t.Owner, t.Repo, t.IssueNumber)
|
||||
d.Log.Info("PR rejected", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber)
|
||||
d.Log.InfoContext(ctx, "PR rejected", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber)
|
||||
d.emit(ctx, events.Event{
|
||||
Kind: events.KindPRRejected, TaskID: t.ID, Attempt: attempt,
|
||||
Repo: t.Owner + "/" + t.Repo, Issue: t.IssueNumber,
|
||||
@@ -1557,7 +1557,7 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task, hold *taskHol
|
||||
return
|
||||
}
|
||||
|
||||
d.Log.Info("processing task", "repo", repo.FullName(), "issue", task.IssueNumber, "attempt", task.Attempt)
|
||||
d.Log.InfoContext(ctx, "processing task", "repo", repo.FullName(), "issue", task.IssueNumber, "attempt", task.Attempt)
|
||||
workDir, ok := d.prepareWorkspace(ctx, task, trees, repo)
|
||||
if !ok {
|
||||
return
|
||||
@@ -1565,7 +1565,7 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task, hold *taskHol
|
||||
if !task.HasRepository() {
|
||||
defer func() {
|
||||
if err := trees.RemoveScratch(task.ID); err != nil {
|
||||
d.Log.Warn("scratch workspace cleanup failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "scratch workspace cleanup failed", "task", task.ID, "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -1614,7 +1614,7 @@ func (d *Daemon) teardownStorage(ctx context.Context, task *workflow.Task, repo
|
||||
Owner: task.Owner,
|
||||
Repo: task.Repo,
|
||||
}); err != nil {
|
||||
d.Log.Warn("storage teardown failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "storage teardown failed", "task", task.ID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1644,7 +1644,7 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
if !task.HasRepository() {
|
||||
dir, err := trees.PrepareScratch(task.ID)
|
||||
if err != nil {
|
||||
d.Log.Error("scratch workspace prepare failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "scratch workspace prepare failed", "err", err)
|
||||
d.parkRunningTask(ctx, task, "scratch workspace prepare failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return "", false
|
||||
}
|
||||
@@ -1657,7 +1657,7 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
if task.Branch == "" {
|
||||
// The action refuses this combination, so an empty branch here is a
|
||||
// dispatch bug upstream and no retry can fix it.
|
||||
d.Log.Error("task has no persisted branch to continue", "task", task.ID)
|
||||
d.Log.ErrorContext(ctx, "task has no persisted branch to continue", "task", task.ID)
|
||||
d.parkRunningTask(ctx, task, "worktree resume failed: task has no branch to continue", taskstate.ParkNeedsDecision)
|
||||
return "", false
|
||||
}
|
||||
@@ -1676,13 +1676,13 @@ func (d *Daemon) prepareWorkspace(ctx context.Context, task *workflow.Task, tree
|
||||
if target != worktree.Fresh {
|
||||
reason = "worktree resume failed: " + err.Error()
|
||||
}
|
||||
d.Log.Error("worktree prepare failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "worktree prepare failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, reason, taskstate.ParkTransient)
|
||||
return "", false
|
||||
}
|
||||
task.Branch = branch
|
||||
if err := d.Store.Update(ctx, task); err != nil {
|
||||
d.Log.Warn("task branch not persisted", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "task branch not persisted", "task", task.ID, "err", err)
|
||||
}
|
||||
return dir, true
|
||||
}
|
||||
@@ -1698,7 +1698,7 @@ func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *workflow
|
||||
|
||||
latest, err := d.Store.TaskByID(cleanupCtx, task.ID)
|
||||
if err != nil {
|
||||
d.Log.Warn("terminal worktree cleanup task lookup failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "terminal worktree cleanup task lookup failed", "task", task.ID, "err", err)
|
||||
return
|
||||
}
|
||||
if latest == nil {
|
||||
@@ -1714,7 +1714,7 @@ func (d *Daemon) cleanupTerminalTaskWorktree(ctx context.Context, task *workflow
|
||||
return
|
||||
}
|
||||
if err := d.cleanupWorktree(cleanupCtx, trees, task.Owner, task.Repo, task.IssueNumber); err != nil {
|
||||
d.Log.Warn("terminal worktree cleanup failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "terminal worktree cleanup failed", "task", task.ID, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1729,16 +1729,16 @@ func (d *Daemon) worktreeHoldsUncapturedWork(ctx context.Context, trees *worktre
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return false
|
||||
}
|
||||
d.Log.Warn("terminal worktree kept: it could not be read; archive the task to remove it", "task", task.ID, "dir", dir, "err", err)
|
||||
d.Log.WarnContext(ctx, "terminal worktree kept: it could not be read; archive the task to remove it", "task", task.ID, "dir", dir, "err", err)
|
||||
return true
|
||||
}
|
||||
uncommitted, err := trees.HasUncommittedChanges(ctx, dir)
|
||||
if err != nil {
|
||||
d.Log.Warn("terminal worktree kept: uncommitted work could not be read; archive the task to remove it", "task", task.ID, "dir", dir, "err", err)
|
||||
d.Log.WarnContext(ctx, "terminal worktree kept: uncommitted work could not be read; archive the task to remove it", "task", task.ID, "dir", dir, "err", err)
|
||||
return true
|
||||
}
|
||||
if uncommitted {
|
||||
d.Log.Info("terminal worktree kept: it holds uncommitted work; archive the task to remove it", "task", task.ID, "dir", dir)
|
||||
d.Log.InfoContext(ctx, "terminal worktree kept: it holds uncommitted work; archive the task to remove it", "task", task.ID, "dir", dir)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -1768,7 +1768,7 @@ func (d *Daemon) acquireTaskContainer(
|
||||
image string,
|
||||
) (*container.Container, string, func(), bool) {
|
||||
park := func(reason string, err error) {
|
||||
d.Log.Error(reason, "err", err)
|
||||
d.Log.ErrorContext(ctx, reason, "err", err)
|
||||
d.parkRunningTask(ctx, task, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
}
|
||||
|
||||
@@ -1794,7 +1794,7 @@ func (d *Daemon) acquireTaskContainer(
|
||||
// Guard: Storage may be nil if the daemon was wired incorrectly. In
|
||||
// normal operation, Storage is always set when ContainerPool is set.
|
||||
if d.Storage == nil {
|
||||
d.Log.Error("storage backend is nil -- cannot acquire container")
|
||||
d.Log.ErrorContext(ctx, "storage backend is nil -- cannot acquire container")
|
||||
d.parkRunningTask(ctx, task, "storage backend not configured", taskstate.ParkTransient)
|
||||
return nil, "", nil, false
|
||||
}
|
||||
@@ -1874,11 +1874,11 @@ func (d *Daemon) parkCapabilityUnavailable(ctx context.Context, task *workflow.T
|
||||
var reason string
|
||||
if d.ContainerPool == nil {
|
||||
reason = "managed agent container pool is unavailable; refusing to run this task on the host"
|
||||
d.Log.Error("task parked: managed worker unavailable", "task", task.ID,
|
||||
d.Log.ErrorContext(ctx, "task parked: managed worker unavailable", "task", task.ID,
|
||||
"hint", "enable containers and make the archie-agent image available, then retry the task")
|
||||
} else {
|
||||
reason = "agent task transport is unavailable; refusing to run this task on the host"
|
||||
d.Log.Error("task parked: agent task transport unavailable", "task", task.ID)
|
||||
d.Log.ErrorContext(ctx, "task parked: agent task transport unavailable", "task", task.ID)
|
||||
}
|
||||
d.parkRunningTask(ctx, task, reason, taskstate.ParkTransient)
|
||||
}
|
||||
@@ -1901,7 +1901,7 @@ func (d *Daemon) parkBlockedTask(ctx context.Context, task *workflow.Task, reaso
|
||||
|
||||
if err := d.Store.ParkTask(writeCtx, task.ID, workflow.StatusRunning, reason, class, blocker); err != nil {
|
||||
if !errors.Is(err, storecontract.ErrStaleTransition) {
|
||||
d.Log.Warn("terminal park transition failed", "task", task.ID, "reason", reason, "err", err)
|
||||
d.Log.WarnContext(ctx, "terminal park transition failed", "task", task.ID, "reason", reason, "err", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1965,7 +1965,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
otel.GetTextMapPropagator().Inject(ctx, propagation.MapCarrier(req.Trace))
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
d.Log.Error("taskrun encode failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "taskrun encode failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "taskrun encode failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
@@ -1973,23 +1973,23 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
reply, err := d.requestTaskRun(ctx, task.ID, data)
|
||||
if err != nil {
|
||||
if stoppingOnly(ctx) {
|
||||
d.Log.Info("daemon stopping; task left running for the next daemon to re-queue", "task", task.ID)
|
||||
d.Log.InfoContext(ctx, "daemon stopping; task left running for the next daemon to re-queue", "task", task.ID)
|
||||
return
|
||||
}
|
||||
err = runFailure(ctx, err)
|
||||
d.Log.Error("taskrun request failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "taskrun request failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "taskrun request failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
|
||||
var resp taskrun.Response
|
||||
if err := json.Unmarshal(reply, &resp); err != nil {
|
||||
d.Log.Error("taskrun decode response failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "taskrun decode response failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "taskrun decode response failed: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
if resp.Error != "" {
|
||||
d.Log.Error("taskrun run failed", "task", task.ID, "err", resp.Error)
|
||||
d.Log.ErrorContext(ctx, "taskrun run failed", "task", task.ID, "err", resp.Error)
|
||||
d.parkRunningTask(ctx, task, "taskrun run failed: "+resp.Error, taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
@@ -1999,7 +1999,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
// Store that refused the transition -- and a retry can record one.
|
||||
if !taskstate.CanTransition(taskstate.Running, resp.Status) {
|
||||
reason := noOutcomeReason(resp.Status)
|
||||
d.Log.Error("taskrun run recorded no outcome", "task", task.ID, "status", resp.Status)
|
||||
d.Log.ErrorContext(ctx, "taskrun run recorded no outcome", "task", task.ID, "status", resp.Status)
|
||||
d.parkRunningTask(ctx, task, reason, taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
@@ -2012,7 +2012,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
d.AgentStatus.Observe(resp.AgentVersion, resp.AgentInstallType)
|
||||
}
|
||||
|
||||
d.Log.Info("taskrun complete", "task", task.ID, "status", resp.Status)
|
||||
d.Log.InfoContext(ctx, "taskrun complete", "task", task.ID, "status", resp.Status)
|
||||
}
|
||||
|
||||
// noOutcomeReason names why a taskrun reply left the task without an outcome,
|
||||
@@ -2028,7 +2028,7 @@ func noOutcomeReason(status string) string {
|
||||
// profile, parking the task on failure.
|
||||
func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (config.AgentProfile, bool) {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkBlockedTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return config.AgentProfile{}, false
|
||||
}
|
||||
@@ -2047,7 +2047,7 @@ func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (confi
|
||||
}
|
||||
}
|
||||
}
|
||||
d.Log.Error("agent profile unavailable", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "agent profile unavailable", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsDecision)
|
||||
return config.AgentProfile{}, false
|
||||
}
|
||||
@@ -2175,7 +2175,7 @@ func (d *Daemon) runActionPlaybooks(ctx context.Context, task *workflow.Task) {
|
||||
return
|
||||
}
|
||||
if err := d.Playbooks.Run(ctx, d.PlaybookLedger, d.Log, playbookInput(task)); err != nil {
|
||||
d.Log.Warn("action playbook run failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "action playbook run failed", "task", task.ID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2195,7 +2195,7 @@ func (d *Daemon) resolveWorkflowID(ctx context.Context, task *workflow.Task, ava
|
||||
// different one under their rule is worse than parking the task.
|
||||
return "", fmt.Errorf("playbook %q binds this trigger to workflow %q, which is not defined", decision.PlaybookID, decision.Workflow)
|
||||
}
|
||||
d.Log.Info("playbook selected workflow",
|
||||
d.Log.InfoContext(ctx, "playbook selected workflow",
|
||||
"task", task.ID, "playbook", decision.PlaybookID,
|
||||
"playbook_version", decision.Version, "workflow", decision.Workflow)
|
||||
return decision.Workflow, nil
|
||||
@@ -2323,7 +2323,7 @@ func (d *Daemon) admitToRelay(ctx context.Context, relay *stateStoreRelay, task
|
||||
}
|
||||
addrs, err := d.ContainerPool.ContainerAddrs(ctx, ctr.ID)
|
||||
if err != nil {
|
||||
d.Log.Warn("state store relay: container addresses unknown, refusing its connections", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "state store relay: container addresses unknown, refusing its connections", "task", task.ID, "err", err)
|
||||
}
|
||||
relay.Admit(addrs)
|
||||
}
|
||||
@@ -2343,7 +2343,7 @@ func (d *Daemon) openTaskStateStoreRelay(ctx context.Context) (*stateStoreRelay,
|
||||
gateway = d.ContainerPool.HostGateway()
|
||||
}
|
||||
if gateway == "" {
|
||||
d.Log.Warn("state store target is loopback and the container pool has no host bridge address; task containers cannot reach it",
|
||||
d.Log.WarnContext(ctx, "state store target is loopback and the container pool has no host bridge address; task containers cannot reach it",
|
||||
"target", d.ConnectedStateStore.URL)
|
||||
return nil, nil
|
||||
}
|
||||
@@ -2411,7 +2411,7 @@ func (d *Daemon) captureAttemptConfig(ctx context.Context, task *workflow.Task,
|
||||
}
|
||||
document, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
d.Log.Warn("attempt configuration not captured", "task", task.ID, "attempt", task.Attempt, "err", err)
|
||||
d.Log.WarnContext(ctx, "attempt configuration not captured", "task", task.ID, "attempt", task.Attempt, "err", err)
|
||||
return
|
||||
}
|
||||
event := events.Event{
|
||||
@@ -2431,7 +2431,7 @@ func (d *Daemon) captureAttemptConfig(ctx context.Context, task *workflow.Task,
|
||||
}
|
||||
id, err := d.Store.InsertEvent(ctx, event)
|
||||
if err != nil {
|
||||
d.Log.Warn("attempt configuration not captured", "task", task.ID, "attempt", task.Attempt, "err", err)
|
||||
d.Log.WarnContext(ctx, "attempt configuration not captured", "task", task.ID, "attempt", task.Attempt, "err", err)
|
||||
return
|
||||
}
|
||||
// The assigned ID tells the event sink to broadcast without inserting a
|
||||
@@ -2478,12 +2478,12 @@ func (d *Daemon) identityActive(ctx context.Context, id identity.IdentityID) boo
|
||||
return true
|
||||
}
|
||||
if id == "" {
|
||||
d.Log.Error("identity lifecycle check failed", "err", "identity ID is empty")
|
||||
d.Log.ErrorContext(ctx, "identity lifecycle check failed", "err", "identity ID is empty")
|
||||
return false
|
||||
}
|
||||
value, err := d.IdentityRepository.Get(ctx, id)
|
||||
if err != nil {
|
||||
d.Log.Error("identity lifecycle check failed", "identity", id, "err", err)
|
||||
d.Log.ErrorContext(ctx, "identity lifecycle check failed", "identity", id, "err", err)
|
||||
return false
|
||||
}
|
||||
return value.Lifecycle == identity.LifecycleActive
|
||||
@@ -2650,7 +2650,7 @@ func (d *Daemon) reownDenied(ctx context.Context, dir string, err error) bool {
|
||||
return false
|
||||
}
|
||||
if rerr := d.ContainerPool.Reown(ctx, dir, os.Getuid(), os.Getgid()); rerr != nil {
|
||||
d.Log.Warn("worktree ownership repair failed", "dir", dir, "err", rerr)
|
||||
d.Log.WarnContext(ctx, "worktree ownership repair failed", "dir", dir, "err", rerr)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -29,7 +29,7 @@ type KitLauncher interface {
|
||||
// the egress relay, and its environment carries no model provider key.
|
||||
func (d *Daemon) runKitTask(ctx context.Context, task *workflow.Task, repo config.Repo, workDir string, profile config.AgentProfile) {
|
||||
park := func(reason string, err error) {
|
||||
d.Log.Error(reason, "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, reason, "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, reason+": "+err.Error(), taskstate.ParkTransient)
|
||||
}
|
||||
if d.KitLauncher == nil {
|
||||
@@ -98,7 +98,7 @@ func (d *Daemon) runKitTask(ctx context.Context, task *workflow.Task, repo confi
|
||||
stopLimit()
|
||||
|
||||
if err := d.KitLauncher.Release(ctx, run); err != nil {
|
||||
d.Log.Warn("kit release failed", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "kit release failed", "task", task.ID, "err", err)
|
||||
}
|
||||
d.removeEndedKitVolumes(ctx, task.ID, run.Volumes)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (d *Daemon) removeEndedKitVolumes(ctx context.Context, taskID int64, volume
|
||||
return
|
||||
}
|
||||
if err := d.KitLauncher.RemoveVolumes(lookupCtx, volumes); err != nil {
|
||||
d.Log.Warn("kit volume removal failed", "task", taskID, "err", err)
|
||||
d.Log.WarnContext(ctx, "kit volume removal failed", "task", taskID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ func (d *Daemon) toolAllowlist(ctx context.Context, task *workflow.Task, profile
|
||||
if d.PackageAuthorities != nil {
|
||||
authority, err := d.PackageAuthorities.AcceptedAuthority(ctx, name)
|
||||
if err != nil {
|
||||
d.Log.Warn("package authority unavailable; offering no tools", "task", task.ID, "package", name, "err", err)
|
||||
d.Log.WarnContext(ctx, "package authority unavailable; offering no tools", "task", task.ID, "package", name, "err", err)
|
||||
} else {
|
||||
accepted = authority.Tools
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ func (c *reactionConsumer) handle(ctx context.Context, msg eventbus.Message) {
|
||||
defer span.End()
|
||||
envelope, err := workintake.DecodeReviewComment(msg.Data())
|
||||
if err != nil {
|
||||
c.log.Error("review reaction decode failed", "subject", msg.Subject(), "err", err)
|
||||
c.log.ErrorContext(ctx, "review reaction decode failed", "subject", msg.Subject(), "err", err)
|
||||
_ = msg.Ack() // it will never decode on redelivery
|
||||
return
|
||||
}
|
||||
|
||||
task, err := c.lookup.OpenTaskByPR(ctx, envelope.Owner, envelope.Repo, envelope.PRNumber)
|
||||
if err != nil {
|
||||
c.log.Error("review reaction lookup failed", "owner", envelope.Owner, "repo", envelope.Repo, "pr", envelope.PRNumber, "err", err)
|
||||
c.log.ErrorContext(ctx, "review reaction lookup failed", "owner", envelope.Owner, "repo", envelope.Repo, "pr", envelope.PRNumber, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -140,7 +140,7 @@ func (c *reactionConsumer) handleReview(ctx context.Context, msg eventbus.Messag
|
||||
unit := workflow.ReviewUnit{ReviewID: e.ReviewID, Author: e.Author, State: e.State, Body: e.Body}
|
||||
payload, err := workflow.EncodeReviewUnit(unit)
|
||||
if err != nil {
|
||||
c.log.Error("review unit encode failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "review unit encode failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -149,15 +149,15 @@ func (c *reactionConsumer) handleReview(ctx context.Context, msg eventbus.Messag
|
||||
// The task left the states a remediation can start or queue
|
||||
// behind, so the reaction resolves to no work. A review that
|
||||
// arrives mid-run is absorbed by the store, not dropped here.
|
||||
c.log.Debug("task does not accept remediation", "task", task.ID, "review", e.ReviewID)
|
||||
c.log.DebugContext(ctx, "task does not accept remediation", "task", task.ID, "review", e.ReviewID)
|
||||
_ = msg.Ack()
|
||||
return
|
||||
}
|
||||
c.log.Error("BeginRemediation failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "BeginRemediation failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
c.log.Info("review reaction queued a remediation", "task", task.ID, "pr", fmt.Sprintf("%s/%s#%d", e.Owner, e.Repo, e.PRNumber), "review", e.ReviewID, "state", e.State)
|
||||
c.log.InfoContext(ctx, "review reaction queued a remediation", "task", task.ID, "pr", fmt.Sprintf("%s/%s#%d", e.Owner, e.Repo, e.PRNumber), "review", e.ReviewID, "state", e.State)
|
||||
_ = msg.Ack()
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (c *reactionConsumer) handleComment(ctx context.Context, msg eventbus.Messa
|
||||
}}}
|
||||
payload, err := workflow.EncodeReviewUnit(unit)
|
||||
if err != nil {
|
||||
c.log.Error("review unit encode failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "review unit encode failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (c *reactionConsumer) handleComment(ctx context.Context, msg eventbus.Messa
|
||||
_ = msg.Ack()
|
||||
return
|
||||
}
|
||||
c.log.Error("BeginRemediation failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "BeginRemediation failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (c *reactionConsumer) handleComment(ctx context.Context, msg eventbus.Messa
|
||||
Comments: []workflow.ReviewUnitComment{{CommentID: e.CommentID, Path: e.Path, Line: e.Line, Body: e.Body}},
|
||||
})
|
||||
if err != nil {
|
||||
c.log.Error("review unit encode failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "review unit encode failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -206,7 +206,7 @@ func (c *reactionConsumer) handleComment(ctx context.Context, msg eventbus.Messa
|
||||
c.drop(msg, "parent review's unit is no longer pending")
|
||||
return
|
||||
}
|
||||
c.log.Error("UpdateReviewPayload failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "UpdateReviewPayload failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
@@ -219,7 +219,7 @@ func (c *reactionConsumer) recordApproval(ctx context.Context, msg eventbus.Mess
|
||||
Detail: fmt.Sprintf("%s approved pull request #%d", e.Author, e.PRNumber),
|
||||
Data: map[string]any{"review_id": e.ReviewID, "author": e.Author, "pr_number": e.PRNumber},
|
||||
}); err != nil {
|
||||
c.log.Error("record approval failed", "task", task.ID, "err", err)
|
||||
c.log.ErrorContext(ctx, "record approval failed", "task", task.ID, "err", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func (d *Daemon) scanPRReviews(ctx context.Context) {
|
||||
}
|
||||
tasks, err := d.Store.OpenPRs(ctx)
|
||||
if err != nil {
|
||||
d.Log.Error("review scan query failed", "err", err)
|
||||
d.Log.ErrorContext(ctx, "review scan query failed", "err", err)
|
||||
return
|
||||
}
|
||||
if d.reactionPublisher == nil {
|
||||
@@ -106,7 +106,7 @@ func (d *Daemon) scanOnePR(ctx context.Context, reader forge.PullRequestReviewRe
|
||||
if t.Org == "" {
|
||||
resolved, err := d.identityOrg(ctx, d.publisherIdentity(t.Identity))
|
||||
if err != nil {
|
||||
d.Log.Warn("review scan org resolve failed", "task", t.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "review scan org resolve failed", "task", t.ID, "err", err)
|
||||
return
|
||||
}
|
||||
t.Org = resolved
|
||||
@@ -118,7 +118,7 @@ func (d *Daemon) scanOnePR(ctx context.Context, reader forge.PullRequestReviewRe
|
||||
ctx, reader, t, d.botUserForTask(t),
|
||||
t.ReviewCursor, t.WatchCommentID, d.reactionPublisher)
|
||||
if err != nil {
|
||||
d.Log.Warn("review scan failed", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber, "err", err)
|
||||
d.Log.WarnContext(ctx, "review scan failed", "repo", t.Owner+"/"+t.Repo, "pr", t.PRNumber, "err", err)
|
||||
return
|
||||
}
|
||||
if reviewCursor == t.ReviewCursor && commentCursor == t.WatchCommentID {
|
||||
@@ -128,6 +128,6 @@ func (d *Daemon) scanOnePR(ctx context.Context, reader forge.PullRequestReviewRe
|
||||
// A stale guard here means the task was claimed between the scan and
|
||||
// the write; the next scan re-reads and re-lists from the old cursor,
|
||||
// and PublishUnique plus the consumer's dedup absorb the repeats.
|
||||
d.Log.Warn("review cursor persist failed", "task", t.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "review cursor persist failed", "task", t.ID, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
// task.
|
||||
func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task) bool {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.Log.ErrorContext(ctx, "pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkBlockedTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return false
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (d *Daemon) mayRunWorkflow(ctx context.Context, task *workflow.Task, id ide
|
||||
}
|
||||
principal, err := d.Principals.PrincipalFor(ctx, id)
|
||||
if err != nil {
|
||||
d.Log.Warn("workflow identity: principal unavailable", "task", task.ID, "identity", id, "err", err)
|
||||
d.Log.WarnContext(ctx, "workflow identity: principal unavailable", "task", task.ID, "identity", id, "err", err)
|
||||
return false, nil
|
||||
}
|
||||
resource := access.Resource{Kind: access.KindWorkflow, ID: task.Workflow, Org: task.Org, Workspace: task.Workspace}
|
||||
@@ -155,7 +155,7 @@ func (d *Daemon) mayRunWorkflow(ctx context.Context, task *workflow.Task, id ide
|
||||
Kind: resource.Kind, ResourceID: resource.ID, Level: decision.Level, Policies: decision.Policies,
|
||||
}
|
||||
if err := d.Denials.RecordDenial(ctx, denial); err != nil {
|
||||
d.Log.Warn("workflow identity: record denial", "task", task.ID, "err", err)
|
||||
d.Log.WarnContext(ctx, "workflow identity: record denial", "task", task.ID, "err", err)
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
|
||||
@@ -158,6 +158,6 @@ func (r *Reporter) restamp(ctx context.Context) {
|
||||
|
||||
func (r *Reporter) write(ctx context.Context, status storecontract.ApplyStatus) {
|
||||
if err := r.store.PutApplyStatus(ctx, status); err != nil {
|
||||
r.log.Warn("apply status not reported", "kind", status.Kind, "err", err)
|
||||
r.log.WarnContext(ctx, "apply status not reported", "kind", status.Kind, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -105,9 +105,9 @@ func (rt *Runtime) Start(ctx context.Context) error {
|
||||
startErr := rt.registry.Start(ctx)
|
||||
if log := rt.registry.Host().Log; log != nil {
|
||||
if startErr != nil {
|
||||
log.Error("curator runtime start completed with failures", "err", startErr)
|
||||
log.ErrorContext(ctx, "curator runtime start completed with failures", "err", startErr)
|
||||
} else {
|
||||
log.Info("curator runtime started", "curators", len(rt.registry.Names()))
|
||||
log.InfoContext(ctx, "curator runtime started", "curators", len(rt.registry.Names()))
|
||||
}
|
||||
}
|
||||
for _, name := range rt.registry.Names() {
|
||||
@@ -239,16 +239,16 @@ func (rt *Runtime) Stop(ctx context.Context) error {
|
||||
|
||||
if err := waitLoops(ctx, loops...); err != nil {
|
||||
if log := rt.registry.Host().Log; log != nil {
|
||||
log.Error("curator runtime shutdown timed out", "err", err)
|
||||
log.ErrorContext(ctx, "curator runtime shutdown timed out", "err", err)
|
||||
}
|
||||
return fmt.Errorf("curator runtime shutdown: %w", errors.Join(err, rt.registry.Stop(ctx)))
|
||||
}
|
||||
err := rt.registry.Stop(ctx)
|
||||
if log := rt.registry.Host().Log; log != nil {
|
||||
if err != nil {
|
||||
log.Error("curator runtime stopped with failures", "err", err)
|
||||
log.ErrorContext(ctx, "curator runtime stopped with failures", "err", err)
|
||||
} else {
|
||||
log.Info("curator runtime stopped")
|
||||
log.InfoContext(ctx, "curator runtime stopped")
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -291,7 +291,7 @@ func (rt *Runtime) runLoop(ctx context.Context, name string, c CuratorEngine, wa
|
||||
if !due {
|
||||
next = clock.Now().Add(m.Interval)
|
||||
if log := rt.registry.Host().Log; log != nil {
|
||||
log.Debug("curator not due", "curator", name, "next", next)
|
||||
log.DebugContext(ctx, "curator not due", "curator", name, "next", next)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func InvokeOnce(ctx context.Context, ledger storecontract.PlaybookDispatcher, lo
|
||||
if err != nil {
|
||||
if errors.Is(err, storecontract.ErrAlreadyDispatched) {
|
||||
if log != nil {
|
||||
log.Debug("playbook action already dispatched; skipping", "playbook", decision.PlaybookID, "version", decision.Version, "event_id", input.TaskID, "action_id", actionID)
|
||||
log.DebugContext(ctx, "playbook action already dispatched; skipping", "playbook", decision.PlaybookID, "version", decision.Version, "event_id", input.TaskID, "action_id", actionID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func (t *Turns) Submit(ctx context.Context, session string, run func(context.Con
|
||||
go t.serve(session, l)
|
||||
}
|
||||
if depth > 1 {
|
||||
t.log.Info("chat turn queued", "session", session, "queue_depth", depth)
|
||||
t.log.InfoContext(ctx, "chat turn queued", "session", session, "queue_depth", depth)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func Run(ctx context.Context, service string, build Build, store interface {
|
||||
record.Ready, record.Detail, record.Checks = summarise(ctx, registry)
|
||||
record.ReportedAt = time.Now().UTC()
|
||||
if err := store.PutPresence(ctx, record); err != nil && ctx.Err() == nil {
|
||||
log.Warn("presence not reported", "service", service, "err", err)
|
||||
log.WarnContext(ctx, "presence not reported", "service", service, "err", err)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
@@ -92,7 +92,7 @@ func newCommandRunStage(settings yaml.Node) (Stage, error) {
|
||||
}
|
||||
if advisory {
|
||||
if tc.Log != nil {
|
||||
tc.Log.Warn("command.run step failed; advisory, so the run continues", "detail", detail, "err", err)
|
||||
tc.Log.WarnContext(ctx, "command.run step failed; advisory, so the run continues", "detail", detail, "err", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ func runDiffRules(ctx context.Context, tc *TaskContext, rules []compiledDiffRule
|
||||
// The count is the run's own evidence of what the rules read: without it, a
|
||||
// step that read nothing and a step whose rules matched nothing leave the
|
||||
// same trace.
|
||||
tc.Log.Info("diff rules read the committed change", "base", base, "added_lines", len(added), "rules", len(rules))
|
||||
tc.Log.InfoContext(ctx, "diff rules read the committed change", "base", base, "added_lines", len(added), "rules", len(rules))
|
||||
if diff == "" {
|
||||
if err := refuseAChangeThatIsNotCommitted(ctx, tc); err != nil {
|
||||
return err
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func notify(ctx context.Context, tc *TaskContext, kind string) {
|
||||
if tc.Task.IsForgeBacked() {
|
||||
if _, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, deliveryNotice(tc, kind)); err != nil {
|
||||
tc.Log.Warn("delivery notice not posted",
|
||||
tc.Log.WarnContext(ctx, "delivery notice not posted",
|
||||
"kind", kind, "issue", tc.Task.IssueNumber, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func stageBaselineGateRun(ctx context.Context, tc *TaskContext) error {
|
||||
if cause := gateEnvironmentCause(string(out), err); cause != "" {
|
||||
return baselineEnvironmentError(argv, string(out), cause)
|
||||
}
|
||||
tc.Log.Warn("baseline red -- auto-fixing pre-existing gate failure",
|
||||
tc.Log.WarnContext(ctx, "baseline red -- auto-fixing pre-existing gate failure",
|
||||
"cmd", strings.Join(argv, " "),
|
||||
"err", clipTail(string(out), baselineWarnLogBytes))
|
||||
if fixErr := runBaselineFix(ctx, tc, argv, out); fixErr != nil {
|
||||
@@ -119,7 +119,7 @@ func runBaselineFix(ctx context.Context, tc *TaskContext, argv []string, out []b
|
||||
changed, commitErr := tc.Trees.CommitAll(ctx, tc.Dir,
|
||||
fmt.Sprintf("fix: baseline gate repair (%s)", strings.Join(argv, " ")))
|
||||
if commitErr != nil {
|
||||
tc.Log.Warn("baseline fix commit failed", "err", commitErr)
|
||||
tc.Log.WarnContext(ctx, "baseline fix commit failed", "err", commitErr)
|
||||
}
|
||||
if changed {
|
||||
tc.BuildSummary = res.Summary
|
||||
|
||||
@@ -115,7 +115,7 @@ func stagePRReviewAndOpenPR(decisionStages []Stage, body func(*TaskContext) stri
|
||||
}
|
||||
|
||||
if _, err := runPROutputPhase(ctx, tc); err != nil {
|
||||
tc.Log.Error("pr-review findings not posted; the pull request is open regardless", "err", err,
|
||||
tc.Log.ErrorContext(ctx, "pr-review findings not posted; the pull request is open regardless", "err", err,
|
||||
"pr", tc.Task.PRNumber)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -749,7 +749,7 @@ func postReview(ctx context.Context, tc *TaskContext, owner, repo string, number
|
||||
for _, c := range review.Comments {
|
||||
places = append(places, fmt.Sprintf("%s:%d", c.Path, c.Line))
|
||||
}
|
||||
tc.Log.Info("posting review", "inline", places, "body_bytes", len(review.Body), "diff_files", len(tc.prReview.files))
|
||||
tc.Log.InfoContext(ctx, "posting review", "inline", places, "body_bytes", len(review.Body), "diff_files", len(tc.prReview.files))
|
||||
err := tc.Forge.CreateReviewComments(ctx, owner, repo, number, headSHA, review)
|
||||
if err == nil {
|
||||
return nil
|
||||
@@ -757,7 +757,7 @@ func postReview(ctx context.Context, tc *TaskContext, owner, repo string, number
|
||||
if len(review.Comments) == 0 {
|
||||
return fmt.Errorf("%w (no inline comments; %d diff files)", err, len(tc.prReview.files))
|
||||
}
|
||||
tc.Log.Warn("forge refused inline review comments; posting them in the body", "err", err, "inline", places)
|
||||
tc.Log.WarnContext(ctx, "forge refused inline review comments; posting them in the body", "err", err, "inline", places)
|
||||
if retry := tc.Forge.CreateReviewComments(ctx, owner, repo, number, headSHA, forgeReview(findings, nil, tc.prReview.ownPR)); retry != nil {
|
||||
// The same refusal twice was never about placement; say it once.
|
||||
if retry.Error() == err.Error() {
|
||||
|
||||
@@ -126,7 +126,7 @@ func StageRemediationRoundCap() Stage {
|
||||
if err := tc.EmitDurable(ctx, events.KindRemediationRound, "round-cap",
|
||||
fmt.Sprintf("remediation round %d answers review %d by %s", tc.Task.RemediationRounds, unit.ReviewID, unit.Author),
|
||||
map[string]any{"round": tc.Task.RemediationRounds, "of": maxRounds, "review_id": unit.ReviewID, "author": unit.Author}); err != nil {
|
||||
tc.Log.Warn("remediation round not recorded", "err", err)
|
||||
tc.Log.WarnContext(ctx, "remediation round not recorded", "err", err)
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
@@ -140,7 +140,7 @@ func postRemediationComment(ctx context.Context, tc *TaskContext, body string) {
|
||||
return
|
||||
}
|
||||
if _, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, body); err != nil {
|
||||
tc.Log.Warn("remediation comment not posted", "pr", tc.Task.PRNumber, "err", err)
|
||||
tc.Log.WarnContext(ctx, "remediation comment not posted", "pr", tc.Task.PRNumber, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func newReviewReplyStage(settings yaml.Node) (Stage, error) {
|
||||
reply := fmt.Sprintf("%s\n\n---\n*archie remediation, round %d*", s.Body, tc.Task.RemediationRounds)
|
||||
if id, ok := tc.reviewUnit.replyTarget(); ok {
|
||||
if err := tc.Forge.ReplyToReview(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, id, reply); err != nil {
|
||||
tc.Log.Warn("remediation reply not posted", "pr", tc.Task.PRNumber, "comment", id, "err", err)
|
||||
tc.Log.WarnContext(ctx, "remediation reply not posted", "pr", tc.Task.PRNumber, "comment", id, "err", err)
|
||||
}
|
||||
} else {
|
||||
postRemediationComment(ctx, tc, reply)
|
||||
|
||||
@@ -275,7 +275,7 @@ func wrapStep(step StepRecord, body func(context.Context, *TaskContext) error) S
|
||||
tc.stepResult = StepResult{}
|
||||
tc.skippedWhen = ""
|
||||
if step.When != "" && !when.holds(tc) {
|
||||
tc.Log.Info("step skipped", "step", name, "when", step.When)
|
||||
tc.Log.InfoContext(ctx, "step skipped", "step", name, "when", step.When)
|
||||
tc.skippedWhen = step.When
|
||||
return nil
|
||||
}
|
||||
@@ -305,11 +305,11 @@ func runAttempts(ctx context.Context, tc *TaskContext, name string, attempts int
|
||||
if err = body(ctx, tc); err == nil || attempt == attempts {
|
||||
return err
|
||||
}
|
||||
tc.Log.Warn("step failed; retrying", "step", name, "attempt", attempt, "of", attempts, "err", err)
|
||||
tc.Log.WarnContext(ctx, "step failed; retrying", "step", name, "attempt", attempt, "of", attempts, "err", err)
|
||||
if emitErr := tc.EmitDurable(ctx, events.KindStepRetried, name,
|
||||
fmt.Sprintf("attempt %d of %d failed: %v", attempt, attempts, err),
|
||||
map[string]any{"attempt": attempt, "of": attempts, "error": err.Error()}); emitErr != nil {
|
||||
tc.Log.Warn("step retry not recorded", "step", name, "err", emitErr)
|
||||
tc.Log.WarnContext(ctx, "step retry not recorded", "step", name, "err", emitErr)
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -374,7 +374,7 @@ func compileSwitch(step StepRecord, registry StepRegistry) (Stage, error) {
|
||||
if !ok {
|
||||
name, stages = switchDefault, arms[switchDefault]
|
||||
}
|
||||
tc.Log.Info("switch case chosen", "step", step.StageName(), "value", name)
|
||||
tc.Log.InfoContext(ctx, "switch case chosen", "step", step.StageName(), "value", name)
|
||||
if stages == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,25 +36,25 @@ type changeStatsReader interface {
|
||||
// an empty HeadSHA means not measured.
|
||||
func (tc *TaskContext) captureChanges(ctx context.Context, after string) task.ChangeStats {
|
||||
if tc.Dir == "" {
|
||||
tc.Log.Warn("change capture skipped: no worktree to read", "captured_after", after)
|
||||
tc.Log.WarnContext(ctx, "change capture skipped: no worktree to read", "captured_after", after)
|
||||
return task.ChangeStats{}
|
||||
}
|
||||
reader, ok := tc.Trees.(changeStatsReader)
|
||||
if !ok {
|
||||
tc.Log.Warn("change capture unavailable: this worktree implementation cannot report a diffstat",
|
||||
tc.Log.WarnContext(ctx, "change capture unavailable: this worktree implementation cannot report a diffstat",
|
||||
"captured_after", after)
|
||||
return task.ChangeStats{}
|
||||
}
|
||||
stats, err := reader.ChangedFileStats(ctx, tc.Dir, tc.Repo.BaseBranch())
|
||||
if err != nil {
|
||||
tc.Log.Warn("change capture failed", "captured_after", after, "err", err)
|
||||
tc.Log.WarnContext(ctx, "change capture failed", "captured_after", after, "err", err)
|
||||
return task.ChangeStats{}
|
||||
}
|
||||
// Durable, never bus-only: the worktree this was measured from is gone by
|
||||
// the time anyone reads it, so a capture that only reached the live feed
|
||||
// would be lost with the process.
|
||||
if err := tc.EmitDurable(ctx, events.KindChangesCaptured, tc.Stage, "", changeCaptureData(tc, after, stats)); err != nil {
|
||||
tc.Log.Warn("change capture not persisted", "captured_after", after, "err", err)
|
||||
tc.Log.WarnContext(ctx, "change capture not persisted", "captured_after", after, "err", err)
|
||||
}
|
||||
return stats
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func OpenPR(ctx context.Context, tc *TaskContext, body string) error {
|
||||
// Best-effort: the link is cosmetic.
|
||||
if err := tc.Forge.LinkBranch(ctx, t.Owner, t.Repo, t.IssueNumber, tc.Branch); err != nil {
|
||||
if tc.Log != nil {
|
||||
tc.Log.Warn("link branch to issue failed; opening the PR anyway",
|
||||
tc.Log.WarnContext(ctx, "link branch to issue failed; opening the PR anyway",
|
||||
"repo", t.Owner+"/"+t.Repo, "issue", t.IssueNumber,
|
||||
"branch", tc.Branch, "err", err)
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
||||
previousLog := tc.Log
|
||||
stageLog := previousLog.With("stage", stage.Name)
|
||||
tc.Log = stageLog
|
||||
stageLog.Info("stage starting")
|
||||
stageLog.InfoContext(ctx, "stage starting")
|
||||
|
||||
err = stage.Run(ctx, tc)
|
||||
tc.Log = previousLog
|
||||
@@ -372,11 +372,11 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
||||
})
|
||||
cancel()
|
||||
if recordErr != nil {
|
||||
stageLog.Warn("interrupted step finish could not be recorded", "stage", stage.Name, "err", recordErr)
|
||||
stageLog.WarnContext(ctx, "interrupted step finish could not be recorded", "stage", stage.Name, "err", recordErr)
|
||||
} else {
|
||||
publishEvent(ctx, tc, finishEvent)
|
||||
}
|
||||
stageLog.Info("stage interrupted", "err", err)
|
||||
stageLog.InfoContext(ctx, "stage interrupted", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ func Run(ctx context.Context, wf Workflow, tc *TaskContext) {
|
||||
From: taskstate.StepRunning, To: finishTo, Detail: finishDetail, Results: tc.resultsAfter(stage, err),
|
||||
})
|
||||
if recordErr != nil {
|
||||
stageLog.Error("stage finish could not be recorded", "stage", stage.Name, "err", recordErr)
|
||||
stageLog.ErrorContext(ctx, "stage finish could not be recorded", "stage", stage.Name, "err", recordErr)
|
||||
park(ctx, tc, fmt.Sprintf("stage %s could not be recorded: %v", stage.Name, recordErr))
|
||||
return
|
||||
}
|
||||
@@ -455,7 +455,7 @@ func (tc *TaskContext) resumeStages(stages []Stage) ([]Stage, error) {
|
||||
// continues on failure, and an outcome finishes the run.
|
||||
func endsRun(ctx context.Context, tc *TaskContext, stage Stage, err error, log, stageLog *slog.Logger) bool {
|
||||
if err != nil && stage.ContinueOnFailure {
|
||||
stageLog.Warn("stage failed; continuing", "err", err)
|
||||
stageLog.WarnContext(ctx, "stage failed; continuing", "err", err)
|
||||
return false
|
||||
}
|
||||
if err != nil {
|
||||
@@ -501,21 +501,21 @@ func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
|
||||
return
|
||||
}
|
||||
if err := tc.Store.Transition(ctx, t.ID, StatusRunning, tc.Outcome.Status, tc.Outcome.Detail); err != nil {
|
||||
log.Error("workflow outcome transition failed", "err", err)
|
||||
log.ErrorContext(ctx, "workflow outcome transition failed", "err", err)
|
||||
return
|
||||
}
|
||||
tc.Emit(ctx, events.KindOutcome, tc.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
|
||||
log.Info("workflow finished", "status", tc.Outcome.Status)
|
||||
log.InfoContext(ctx, "workflow finished", "status", tc.Outcome.Status)
|
||||
}
|
||||
|
||||
func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
t := tc.Task
|
||||
t.ParkReason = reason
|
||||
if err := tc.Store.Update(ctx, t); err != nil {
|
||||
tc.Log.Error("task fields could not be persisted while parking", "err", err)
|
||||
tc.Log.ErrorContext(ctx, "task fields could not be persisted while parking", "err", err)
|
||||
}
|
||||
if err := tc.Store.Transition(ctx, t.ID, StatusRunning, StatusParked, reason); err != nil {
|
||||
tc.Log.Error("task park transition failed", "err", err)
|
||||
tc.Log.ErrorContext(ctx, "task park transition failed", "err", err)
|
||||
return
|
||||
}
|
||||
tc.Emit(ctx, events.KindParked, tc.Stage, reason, nil)
|
||||
@@ -523,7 +523,7 @@ func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
// this park?", and the event above lands on the timeline, which the log
|
||||
// never carries. This is the one place a park's reason is final, so it is
|
||||
// the one place that records it -- the stage names itself in the reason.
|
||||
tc.Log.Error("task parked", "stage", tc.Stage, "reason", reason)
|
||||
tc.Log.ErrorContext(ctx, "task parked", "stage", tc.Stage, "reason", reason)
|
||||
}
|
||||
|
||||
const clipMarker = "\n…(truncated)"
|
||||
@@ -671,6 +671,6 @@ func (tc *TaskContext) recordUsage(ctx context.Context, step, alias, modelRef st
|
||||
CachedTokens: int64(u.CachedTokens), At: time.Now().UTC(),
|
||||
}.WithRef(modelRef)
|
||||
if err := tc.Store.RecordUsage(ctx, record); err != nil && tc.Log != nil {
|
||||
tc.Log.Warn("record model usage failed", "step", step, "model", modelRef, "err", err)
|
||||
tc.Log.WarnContext(ctx, "record model usage failed", "step", step, "model", modelRef, "err", err)
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func runWorkflowCall(ctx context.Context, s workflowCallSettings, tc *TaskContex
|
||||
started := map[string]any{"callee_task_id": callee.ID, "workflow": s.Workflow, "wait": s.Wait}
|
||||
if err := tc.EmitDurable(ctx, events.KindWorkflowCallStarted, path,
|
||||
fmt.Sprintf("started %q as task %d", s.Workflow, callee.ID), started); err != nil {
|
||||
tc.Log.Warn("workflow call start not persisted", "err", err)
|
||||
tc.Log.WarnContext(ctx, "workflow call start not persisted", "err", err)
|
||||
}
|
||||
// Record the call as a step holding the callee's execution ID, named for
|
||||
// the call site -- the path, not the key that also carries the callee --
|
||||
@@ -280,7 +280,7 @@ func awaitCallee(ctx context.Context, s workflowCallSettings, tc *TaskContext, p
|
||||
}
|
||||
retries++
|
||||
wait := callReadBackoffFor(retries)
|
||||
tc.Log.Warn("callee status read failed; retrying",
|
||||
tc.Log.WarnContext(ctx, "callee status read failed; retrying",
|
||||
"callee_task_id", callTaskID, "attempt", retries, "in", wait, "err", err)
|
||||
if !sleepOrDone(ctx, wait) {
|
||||
return nil, ctx.Err()
|
||||
@@ -293,7 +293,7 @@ func awaitCallee(ctx context.Context, s workflowCallSettings, tc *TaskContext, p
|
||||
if err := tc.EmitDurable(ctx, events.KindWorkflowCallFinished, path,
|
||||
fmt.Sprintf("%q (task %d) finished: %s", s.Workflow, callTaskID, detail),
|
||||
map[string]any{"callee_task_id": callTaskID, "workflow": s.Workflow, "status": status, "detail": detail}); err != nil {
|
||||
tc.Log.Warn("workflow call finish not persisted", "err", err)
|
||||
tc.Log.WarnContext(ctx, "workflow call finish not persisted", "err", err)
|
||||
}
|
||||
return outputs, nil
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(req.Body, maxBodyBytes))
|
||||
if err != nil {
|
||||
r.log.Error("read body", "err", err)
|
||||
r.log.ErrorContext(req.Context(), "read body", "err", err)
|
||||
http.Error(w, "read error", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
// logged, never silently accepted.
|
||||
sig := req.Header.Get("X-Hub-Signature-256")
|
||||
if !webhookguard.VerifyHMAC(body, sig, r.secret) {
|
||||
r.log.Warn("invalid signature", "remote", req.RemoteAddr)
|
||||
r.log.WarnContext(req.Context(), "invalid signature", "remote", req.RemoteAddr)
|
||||
http.Error(w, "invalid signature", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@@ -183,12 +183,12 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
event, err := r.parser.ParseWebhook(req.Context(), headers, body)
|
||||
if errors.Is(err, forge.ErrBadWebhook) {
|
||||
r.log.Warn("parse webhook", "err", err)
|
||||
r.log.WarnContext(req.Context(), "parse webhook", "err", err)
|
||||
http.Error(w, "bad payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
r.log.Error("parse webhook", "err", err)
|
||||
r.log.ErrorContext(req.Context(), "parse webhook", "err", err)
|
||||
http.Error(w, "parse unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func (r *Receiver) serveIssueEvent(w http.ResponseWriter, req *http.Request, iss
|
||||
// anything else is acknowledged without publishing.
|
||||
if reason, withdrawn := r.withdrawal(issueEvent); withdrawn && r.withdraw != nil {
|
||||
if err := r.withdraw(req.Context(), issueEvent.Owner, issueEvent.Repo, issueEvent.Number, reason); err != nil {
|
||||
r.log.Error("withdraw task", "repo", issueEvent.Owner+"/"+issueEvent.Repo, "issue", issueEvent.Number, "err", err)
|
||||
r.log.ErrorContext(req.Context(), "withdraw task", "repo", issueEvent.Owner+"/"+issueEvent.Repo, "issue", issueEvent.Number, "err", err)
|
||||
http.Error(w, "withdraw failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -230,12 +230,12 @@ func (r *Receiver) serveIssueEvent(w http.ResponseWriter, req *http.Request, iss
|
||||
}
|
||||
|
||||
if err := r.publish(req.Context(), task); err != nil {
|
||||
r.log.Error("publish task", "task", task.Ref(), "err", err)
|
||||
r.log.ErrorContext(req.Context(), "publish task", "task", task.Ref(), "err", err)
|
||||
http.Error(w, "publish failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
r.recordPublish()
|
||||
r.log.Info("published", "task", task.Ref())
|
||||
r.log.InfoContext(req.Context(), "published", "task", task.Ref())
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func (r *Receiver) serveReviewEvent(w http.ResponseWriter, req *http.Request, e
|
||||
return
|
||||
}
|
||||
if !r.allowReactionDelivery(req.RemoteAddr) {
|
||||
r.log.Warn("reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
r.log.WarnContext(req.Context(), "reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
http.Error(w, "rate limited", http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
@@ -280,7 +280,7 @@ func (r *Receiver) serveReviewCommentEvent(w http.ResponseWriter, req *http.Requ
|
||||
return
|
||||
}
|
||||
if !r.allowReactionDelivery(req.RemoteAddr) {
|
||||
r.log.Warn("reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
r.log.WarnContext(req.Context(), "reaction rate limit exceeded", "remote", req.RemoteAddr)
|
||||
http.Error(w, "rate limited", http.StatusTooManyRequests)
|
||||
return
|
||||
}
|
||||
@@ -305,7 +305,7 @@ func (r *Receiver) serveReviewCommentEvent(w http.ResponseWriter, req *http.Requ
|
||||
|
||||
func (r *Receiver) deliverReaction(w http.ResponseWriter, req *http.Request, reaction workintake.ReviewCommentEnvelope) {
|
||||
if err := r.reactionPublish(req.Context(), reaction); err != nil {
|
||||
r.log.Error("publish reaction", "key", reaction.IdempotencyKey(), "err", err)
|
||||
r.log.ErrorContext(req.Context(), "publish reaction", "key", reaction.IdempotencyKey(), "err", err)
|
||||
http.Error(w, "publish failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ func (r *Router) generateTitle(ctx context.Context, sessionID, firstMessage stri
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
if r.Log != nil {
|
||||
r.Log.Error("session title generation panicked", "session", sessionID, "panic", p)
|
||||
r.Log.ErrorContext(ctx, "session title generation panicked", "session", sessionID, "panic", p)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -134,11 +134,11 @@ func (r *Router) checkSlashAccess(ctx context.Context, in Inbound, cmd string) (
|
||||
denial := SlashDenial{Sender: sender, Command: cmd, Role: decision.Role, Reason: decision.Reason}
|
||||
if r.SlashDenials != nil {
|
||||
if err := r.SlashDenials.RecordSlashDenial(ctx, denial); err != nil && r.Log != nil {
|
||||
r.Log.Error("record slash denial", "err", err)
|
||||
r.Log.ErrorContext(ctx, "record slash denial", "err", err)
|
||||
}
|
||||
}
|
||||
if r.Log != nil {
|
||||
r.Log.Warn("slash command refused",
|
||||
r.Log.WarnContext(ctx, "slash command refused",
|
||||
"sender", sender, "command", cmd, "role", string(decision.Role), "reason", decision.Reason)
|
||||
}
|
||||
return fmt.Sprintf("You are not permitted to run %s.", cmd), true
|
||||
|
||||
@@ -213,7 +213,7 @@ func (r *TurnRunner) replayPriorReply(
|
||||
return "", true, r.failTurn(ctx, turn, fmt.Errorf("save replayed chat turn: %w", err))
|
||||
}
|
||||
if r.Log != nil {
|
||||
r.Log.Info("replaying the reply to a redelivered message",
|
||||
r.Log.InfoContext(ctx, "replaying the reply to a redelivered message",
|
||||
"session", sessionID, "source_id", msg.SourceID)
|
||||
}
|
||||
if stream != nil {
|
||||
@@ -355,7 +355,7 @@ func (r *TurnRunner) prepareTurn(ctx context.Context, sessionID string, in Inbou
|
||||
return preparedTurn{}, fmt.Errorf("derive chat context budget: %w", err)
|
||||
}
|
||||
if r.Log != nil && modelDetails.ContextWindow <= 0 {
|
||||
r.Log.Warn("chat model has no context metadata; using compatibility compression budget",
|
||||
r.Log.WarnContext(ctx, "chat model has no context metadata; using compatibility compression budget",
|
||||
"model", modelName)
|
||||
}
|
||||
// The trigger runs before the request is assembled, so a session that has
|
||||
@@ -367,7 +367,7 @@ func (r *TurnRunner) prepareTurn(ctx context.Context, sessionID string, in Inbou
|
||||
}
|
||||
view := CompressHistory(compressTurnHistory(history), compression)
|
||||
if r.Log != nil {
|
||||
r.Log.Info("chat turn",
|
||||
r.Log.InfoContext(ctx, "chat turn",
|
||||
"session", sessionID,
|
||||
"channel", in.Message.ConversationID.ChannelID,
|
||||
"thread", in.Message.ConversationID.ThreadID,
|
||||
@@ -403,7 +403,7 @@ func (r *TurnRunner) compressSessionAtBudget(
|
||||
return history, nil
|
||||
}
|
||||
if r.Log != nil {
|
||||
r.Log.Info("compressed the chat session at its context budget",
|
||||
r.Log.InfoContext(ctx, "compressed the chat session at its context budget",
|
||||
"session", sessionID,
|
||||
"channel", r.Channel,
|
||||
"messages_before", len(history),
|
||||
@@ -491,13 +491,13 @@ func (r *TurnRunner) transcribeSpeech(ctx context.Context, in Inbound) messaging
|
||||
transcript, err := r.Transcriber.Transcribe(ctx, att.Data)
|
||||
if err != nil {
|
||||
if r.Log != nil {
|
||||
r.Log.Warn("voice transcription failed; keeping the media note", "error", err)
|
||||
r.Log.WarnContext(ctx, "voice transcription failed; keeping the media note", "error", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.TrimSpace(transcript) == "" {
|
||||
if r.Log != nil {
|
||||
r.Log.Info("voice transcription produced no text; keeping the media note")
|
||||
r.Log.InfoContext(ctx, "voice transcription produced no text; keeping the media note")
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func renderMemory(ctx context.Context, store MemoryStore, subject domainmemory.S
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
if log != nil {
|
||||
log.Warn("chat memory read panicked; continuing without a memory block", "panic", p)
|
||||
log.WarnContext(ctx, "chat memory read panicked; continuing without a memory block", "panic", p)
|
||||
}
|
||||
block = ""
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func renderMemory(ctx context.Context, store MemoryStore, subject domainmemory.S
|
||||
})
|
||||
if err != nil {
|
||||
if log != nil {
|
||||
log.Warn("chat memory read failed; continuing without a memory block", "err", err)
|
||||
log.WarnContext(ctx, "chat memory read failed; continuing without a memory block", "err", err)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ func (l *Live) apply(ctx context.Context, version int64) error {
|
||||
}
|
||||
engine := New(stored)
|
||||
for _, problem := range engine.Problems() {
|
||||
l.log.Error("stored access policy is invalid and denies its level",
|
||||
l.log.ErrorContext(ctx, "stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
// The engine before the stamp: a check that reads the stamp must find the
|
||||
@@ -149,7 +149,7 @@ func (l *Live) Problems() []Problem { return l.engine.Load().Problems() }
|
||||
func StartLive(ctx context.Context, list func(context.Context) ([]access.Policy, error), version func(context.Context) (int64, error), log *slog.Logger) *Live {
|
||||
live := NewPending(ctx, version, list, log)
|
||||
if err := live.Reload(ctx); err != nil {
|
||||
log.Warn("access policies not loaded; requests are refused until they load", "err", err)
|
||||
log.WarnContext(ctx, "access policies not loaded; requests are refused until they load", "err", err)
|
||||
}
|
||||
return live
|
||||
}
|
||||
@@ -27,13 +27,13 @@ func MarkSafe(ctx context.Context, mountDir string, log *slog.Logger) bool {
|
||||
func markSafe(ctx context.Context, mountDir string, run gitRunner, log *slog.Logger) bool {
|
||||
info, err := os.Stat(mountDir)
|
||||
if err != nil || !info.IsDir() {
|
||||
log.Debug("git safe.directory skipped: mountDir does not exist", "dir", mountDir)
|
||||
log.DebugContext(ctx, "git safe.directory skipped: mountDir does not exist", "dir", mountDir)
|
||||
return false
|
||||
}
|
||||
|
||||
out, err := run(ctx, "config", "--global", "--add", "safe.directory", mountDir)
|
||||
if err != nil {
|
||||
log.Warn(
|
||||
log.WarnContext(ctx,
|
||||
"git safe.directory config failed -- gates that shell out to git may fail",
|
||||
"dir", mountDir,
|
||||
"err", err,
|
||||
@@ -42,6 +42,6 @@ func markSafe(ctx context.Context, mountDir string, run gitRunner, log *slog.Log
|
||||
return false
|
||||
}
|
||||
|
||||
log.Info("git safe.directory configured", "dir", mountDir)
|
||||
log.InfoContext(ctx, "git safe.directory configured", "dir", mountDir)
|
||||
return true
|
||||
}
|
||||
@@ -22,7 +22,7 @@ func (t *Transport) startTracing(ctx context.Context, request taskrun.Request, l
|
||||
client := spanrelay.NewExporter(t.conn, request.Task.ID)
|
||||
stop, err := telemetry.StartWithClient(ctx, client, 1, "agent", buildinfo.Version)
|
||||
if err != nil {
|
||||
log.Warn("container tracing disabled", "err", err)
|
||||
log.WarnContext(ctx, "container tracing disabled", "err", err)
|
||||
return
|
||||
}
|
||||
t.stopTracing = stop
|
||||
|
||||
@@ -98,7 +98,7 @@ func Connect(ctx context.Context, config Config, log *slog.Logger) (*Transport,
|
||||
conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
log.Info("worker transport connected", "url", conn.ConnectedUrl())
|
||||
log.InfoContext(ctx, "worker transport connected", "url", conn.ConnectedUrl())
|
||||
|
||||
// The agent is fully on gRPC for its store calls; the legacy NATS storerpc
|
||||
// path is deleted. A missing StateStoreURL fails fast rather than letting
|
||||
@@ -112,7 +112,7 @@ func Connect(ctx context.Context, config Config, log *slog.Logger) (*Transport,
|
||||
conn.Close()
|
||||
return nil, fmt.Errorf("connect state store: %w", err)
|
||||
}
|
||||
log.Info("worker state store transport connected", "url", config.StateStoreURL)
|
||||
log.InfoContext(ctx, "worker state store transport connected", "url", config.StateStoreURL)
|
||||
|
||||
return &Transport{
|
||||
conn: conn,
|
||||
@@ -291,14 +291,14 @@ func (t *Transport) SubscribeTasks(ctx context.Context, taskID int64, handler Ta
|
||||
flush = t.conn.FlushTimeout
|
||||
}
|
||||
|
||||
log.Info("taskrun: dedicated per-task subscription", "task", taskID)
|
||||
log.InfoContext(ctx, "taskrun: dedicated per-task subscription", "task", taskID)
|
||||
sub, err := subscribe(SubjectForTask(taskID), callback)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := flush(taskSubscriptionFlushTimeout); err != nil {
|
||||
if cleanupErr := sub.Unsubscribe(); cleanupErr != nil {
|
||||
log.Warn("task subscription cleanup failed after flush failure", "err", cleanupErr)
|
||||
log.WarnContext(ctx, "task subscription cleanup failed after flush failure", "err", cleanupErr)
|
||||
}
|
||||
return nil, fmt.Errorf("flush task subscription: %w", err)
|
||||
}
|
||||
@@ -314,12 +314,12 @@ func (t *Transport) handleTask(
|
||||
) {
|
||||
var request taskrun.Request
|
||||
if err := json.Unmarshal(msg.Data, &request); err != nil {
|
||||
log.Error("taskrun decode failed", "err", err)
|
||||
log.ErrorContext(ctx, "taskrun decode failed", "err", err)
|
||||
t.respondTask(msg, nil, fmt.Errorf("decode taskrun request: %w", err), log)
|
||||
return
|
||||
}
|
||||
if err := validateTaskRequest(msg.Subject, request, bootTaskID); err != nil {
|
||||
log.Error("taskrun validation failed", "subject", msg.Subject, "err", err)
|
||||
log.ErrorContext(ctx, "taskrun validation failed", "subject", msg.Subject, "err", err)
|
||||
t.respondTask(msg, nil, fmt.Errorf("validate taskrun request: %w", err), log)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func (rc *Receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
id, err := rc.Captures.InsertCapture(r.Context(), c, rc.Retention, rc.MaxEvents)
|
||||
if err != nil {
|
||||
rc.logger().Error("capture insert", "err", err, "source", path)
|
||||
rc.logger().ErrorContext(r.Context(), "capture insert", "err", err, "source", path)
|
||||
http.Error(w, "capture failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -178,7 +178,7 @@ func (rc *Receiver) refusal(r *http.Request, path string, owner org.OrgID) int {
|
||||
}
|
||||
if rc.Refusals != nil {
|
||||
if err := rc.Refusals.RecordCaptureRefusal(r.Context(), path, addr, time.Now()); err != nil {
|
||||
rc.logger().Warn("capture refusal not counted", "source", path, "err", err)
|
||||
rc.logger().WarnContext(r.Context(), "capture refusal not counted", "source", path, "err", err)
|
||||
}
|
||||
}
|
||||
return http.StatusForbidden
|
||||
@@ -203,7 +203,7 @@ func (rc *Receiver) resolveSource(r *http.Request, path string) *source.Source {
|
||||
}
|
||||
src, err := rc.Sources.GetSource(r.Context(), path)
|
||||
if err != nil {
|
||||
rc.logger().Warn("source lookup", "source", path, "err", err)
|
||||
rc.logger().WarnContext(r.Context(), "source lookup", "source", path, "err", err)
|
||||
return nil
|
||||
}
|
||||
return src
|
||||
|
||||
@@ -80,7 +80,7 @@ func (l *LivePlaybooks) current(ctx context.Context) *playbook.Store {
|
||||
response, err := l.rpc.Query(ctx, &pb.QueryRequest{Kind: PlaybooksKind})
|
||||
if err != nil {
|
||||
l.ApplyStatus.Report(ctx, PlaybooksKind, 0, err)
|
||||
l.log.Warn("eda playbooks unavailable; keeping the last good set", "err", controlplanerpc.ClientError(err))
|
||||
l.log.WarnContext(ctx, "eda playbooks unavailable; keeping the last good set", "err", controlplanerpc.ClientError(err))
|
||||
return held.store
|
||||
}
|
||||
if held.store != nil && response.Resource.Version == held.version {
|
||||
@@ -90,18 +90,18 @@ func (l *LivePlaybooks) current(ctx context.Context) *playbook.Store {
|
||||
var collection PlaybookCollection
|
||||
if err := json.Unmarshal(response.Resource.ValueJson, &collection); err != nil {
|
||||
l.ApplyStatus.Report(ctx, PlaybooksKind, response.Resource.Version, err)
|
||||
l.log.Error("eda playbooks undecodable; keeping the last good set", "err", err)
|
||||
l.log.ErrorContext(ctx, "eda playbooks undecodable; keeping the last good set", "err", err)
|
||||
return held.store
|
||||
}
|
||||
store, err := CompilePlaybooks(collection)
|
||||
if err != nil {
|
||||
l.ApplyStatus.Report(ctx, PlaybooksKind, response.Resource.Version, err)
|
||||
l.log.Error("eda playbooks do not compile; keeping the last good set", "err", err)
|
||||
l.log.ErrorContext(ctx, "eda playbooks do not compile; keeping the last good set", "err", err)
|
||||
return held.store
|
||||
}
|
||||
held.version, held.store = response.Resource.Version, store
|
||||
l.ApplyStatus.Report(ctx, PlaybooksKind, held.version, nil)
|
||||
l.log.Info("eda playbooks loaded", "org", id, "version", held.version, "playbooks", len(store.Playbooks))
|
||||
l.log.InfoContext(ctx, "eda playbooks loaded", "org", id, "version", held.version, "playbooks", len(store.Playbooks))
|
||||
return store
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func Connect(ctx context.Context, cfg Config, log *slog.Logger) (*Client, error)
|
||||
}
|
||||
|
||||
closeOnFail = nil
|
||||
log.Info("nats connected",
|
||||
log.InfoContext(ctx, "nats connected",
|
||||
"stream", cfg.StreamName,
|
||||
"consumer", cfg.ConsumerName,
|
||||
"url", conn.ConnectedUrl())
|
||||
|
||||
@@ -64,13 +64,13 @@ func (c *Client) Subscribe(ctx context.Context, filterSubject string, handle fun
|
||||
defer span.End()
|
||||
if err := handle(message{msg: msg}); err != nil {
|
||||
span.RecordError(err)
|
||||
c.log.Error("message handler failed",
|
||||
c.log.ErrorContext(ctx, "message handler failed",
|
||||
"subject", msg.Subject(), "error", err)
|
||||
_ = msg.Nak()
|
||||
return
|
||||
}
|
||||
if err := msg.Ack(); err != nil {
|
||||
c.log.Error("ack failed", "subject", msg.Subject(), "error", err)
|
||||
c.log.ErrorContext(ctx, "ack failed", "subject", msg.Subject(), "error", err)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -85,7 +85,7 @@ func StartEmbedded(ctx context.Context, opts EmbeddedOptions, log *slog.Logger)
|
||||
return nil, fmt.Errorf("embedded nats server did not become ready")
|
||||
}
|
||||
|
||||
log.Info("embedded nats ready", "url", srv.ClientURL())
|
||||
log.InfoContext(ctx, "embedded nats ready", "url", srv.ClientURL())
|
||||
return &EmbeddedServer{srv: srv, log: log, token: token}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func (c *Client) publish(ctx context.Context, msg *nats.Msg) error {
|
||||
if _, err := c.js.PublishMsg(ctx, msg); err != nil {
|
||||
return fmt.Errorf("publish to %s: %w", msg.Subject, err)
|
||||
}
|
||||
c.log.Debug("published", "subject", msg.Subject, "bytes", len(msg.Data))
|
||||
c.log.DebugContext(ctx, "published", "subject", msg.Subject, "bytes", len(msg.Data))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user