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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent/assembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"runtime/debug"
"sync"

Expand Down Expand Up @@ -113,7 +113,7 @@ func (g *guardedTool) AcceptsRawInput() bool {
func (g *guardedTool) Call(ctx context.Context, in json.RawMessage, tc *actool.ToolContext) (res actool.Result, err error) {
defer func() {
if r := recover(); r != nil {
log.Printf("[tools] %s panic: %v\n%s", g.Name(), r, debug.Stack())
slog.Error("[tools] tool handler panicked", "tool", g.Name(), "panic", r, "stack", string(debug.Stack()))
res, err = actool.Errorf(fmt.Sprintf("internal error in tool %s: %v (this call has failed; try different arguments or another tool)", g.Name(), r)), nil
}
}()
Expand Down
10 changes: 5 additions & 5 deletions agent/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (c *Compactor) OnPlannerRound(ctx context.Context, ts *db.ExplorationStore)
}
round, uncompressed, activeDigests, err := c.maintain(ts)
if err != nil {
log.Printf("[compaction] maintain exp=%d: %v", ts.ID(), err)
slog.Warn("[compaction] maintain failed", "exp", ts.ID(), "err", err)
return
}
needMinor := uncompressed >= c.n
Expand Down Expand Up @@ -244,7 +244,7 @@ func (c *Compactor) major(ctx context.Context, ts *db.ExplorationStore) {
}
}
if err := ts.SupersedeDigests(stale); err != nil {
log.Printf("[compaction] supersede exp=%d: %v", ts.ID(), err)
slog.Warn("[compaction] supersede failed", "exp", ts.ID(), "err", err)
}
for _, b := range toCreate {
c.foldBlock(ctx, ts, g, b, nodeByID, cvers, c.generationFor(b, active))
Expand All @@ -258,7 +258,7 @@ func (c *Compactor) major(ctx context.Context, ts *db.ExplorationStore) {
func (c *Compactor) foldBlock(ctx context.Context, ts *db.ExplorationStore, g *coldGraph, b block, nodeByID map[int64]*db.Node, cvers map[int64]int, generation int) {
body, err := c.compress(ctx, g, b, nodeByID)
if err != nil {
log.Printf("[compaction] compress exp=%d block=%v: %v", ts.ID(), b.Members, err)
slog.Warn("[compaction] compress failed", "exp", ts.ID(), "block", b.Members, "err", err)
return
}
// Re-read fresh state and drop any member that revived while we compressed.
Expand All @@ -279,7 +279,7 @@ func (c *Compactor) foldBlock(ctx context.Context, ts *db.ExplorationStore, g *c
final := block{Members: members, Anchors: b.Anchors}
payload := digestPayload(body, final, nodeByID, generation, blockSignature(final, cvers))
if _, err := ts.AddDigest(payload, members); err != nil {
log.Printf("[compaction] add digest exp=%d: %v", ts.ID(), err)
slog.Warn("[compaction] add digest failed", "exp", ts.ID(), "err", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions agent/coverage.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package agent

import (
"log"
"log/slog"

"github.com/Autumn-27/artex/db"
)
Expand All @@ -15,7 +15,7 @@ func coverageOn(as *db.AssetStore, taskID int64) bool {
}
enabled, err := as.CoverageEnabled(taskID)
if err != nil {
log.Printf("[coverage] task %d: reading the coverage flag failed; leaving coverage on: %v", taskID, err)
slog.Warn("[coverage] reading the coverage flag failed; leaving coverage on", "task_id", taskID, "err", err)
return true
}
return enabled
Expand Down
4 changes: 2 additions & 2 deletions agent/noa.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package agent

import (
"log"
"log/slog"
"path/filepath"

"github.com/Autumn-27/norma/agentcore"
Expand All @@ -11,7 +11,7 @@ import (
// noaWarn returns a diagnostics sink tagging non-fatal noa messages with the
// session, routed through the package logger (agents have no per-instance one).
func noaWarn(session string) func(string) {
return func(msg string) { log.Printf("[noa] %s: %s", session, msg) }
return func(msg string) { slog.Warn("[noa] diagnostics", "session", session, "msg", msg) }
}

// noa is the "model-driven context compression" mechanism introduced in norma v0.4.0,
Expand Down
15 changes: 8 additions & 7 deletions agent/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"context"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -616,22 +616,23 @@ func logTestConnection(c Config, capt *llmrec.Capture) {
attempts := capt.Attempts()
if c.Format == FormatBedrockGateway {
if len(attempts) == 0 {
log.Print("[llm-test] bedrock-gateway — no HTTP request was sent")
slog.Warn("[llm-test] bedrock-gateway: no HTTP request was sent")
return
}
for i, a := range attempts {
log.Printf("[llm-test] bedrock-gateway — attempt %d/%d HTTP %d", i+1, len(attempts), a.Status)
slog.Info("[llm-test] bedrock-gateway attempt", "attempt", i+1, "attempts", len(attempts), "status", a.Status)
}
return
}
if len(attempts) == 0 {
log.Printf("[llm-test] %s / %s @ %s — no HTTP request was ever sent (config resolution or connection setup failed)",
c.Provider(), c.Model, c.BaseURL)
slog.Warn("[llm-test] no HTTP request was ever sent (config resolution or connection setup failed)",
"provider", c.Provider(), "model", c.Model, "base_url", c.BaseURL)
return
}
for i, a := range attempts {
log.Printf("[llm-test] %s / %s @ %s — attempt %d/%d HTTP %d\nresponse body: %s",
c.Provider(), c.Model, c.BaseURL, i+1, len(attempts), a.Status, clipBody(a.Body))
slog.Info("[llm-test] connection attempt",
"provider", c.Provider(), "model", c.Model, "base_url", c.BaseURL,
"attempt", i+1, "attempts", len(attempts), "status", a.Status, "response_body", clipBody(a.Body))
}
}

Expand Down
33 changes: 33 additions & 0 deletions agent/slog_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package agent

import (
"bytes"
"context"
"log"
"strings"
"testing"

"github.com/Autumn-27/artex/llmrec"
)

func TestSlogPreservesTagsAndLevels(t *testing.T) {
var buf bytes.Buffer
prev := log.Default().Writer()
log.SetOutput(&buf)
t.Cleanup(func() { log.SetOutput(prev) })

noaWarn("sess-1")("fallback triggered")
_, capt := llmrec.NewCapture(context.Background())
logTestConnection(Config{Format: FormatBedrockGateway}, capt)

lines := strings.Split(strings.TrimSpace(buf.String()), "\n")
if len(lines) != 2 {
t.Fatalf("got %d log lines, want 2:\n%s", len(lines), buf.String())
}
if !strings.Contains(lines[0], "WARN [noa]") || !strings.Contains(lines[0], "session=sess-1") {
t.Fatalf("unexpected noa log line: %q", lines[0])
}
if !strings.Contains(lines[1], "WARN [llm-test]") {
t.Fatalf("unexpected llm-test log line: %q", lines[1])
}
}
6 changes: 3 additions & 3 deletions agent/spill.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agent
import (
"bytes"
"context"
"log"
"log/slog"
"path/filepath"
"strconv"

Expand Down Expand Up @@ -54,7 +54,7 @@ func toolOutputDir(base, runDir, spillDir string) string {
return filepath.Join(runDir, "cmd-output")
}
if err := spillDirMaker(base, spillDir); err != nil {
log.Printf("[agent] spill directory %s: %v", spillDir, err)
slog.Warn("[agent] spill directory creation failed", "dir", spillDir, "err", err)
return ""
}
return spillDir
Expand Down Expand Up @@ -100,7 +100,7 @@ func (h spillHooks) PreToolUse(ctx context.Context, name string, input []byte) (
func (h spillHooks) PostToolUse(ctx context.Context, name string, input, result []byte, isErr bool) {
if bytes.Contains(result, spillMarker) {
if err := h.share(h.dir); err != nil {
log.Printf("[agent] share the spill files in %s: %v", h.dir, err)
slog.Warn("[agent] failed to share spill files", "dir", h.dir, "err", err)
}
}
if h.inner != nil {
Expand Down
8 changes: 4 additions & 4 deletions agent/toolrag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package agent
import (
"context"
"fmt"
"log"
"log/slog"
"math"
"os"
"sort"
Expand Down Expand Up @@ -183,15 +183,15 @@ func applyToolRAG(ctx context.Context, agentKey string, tools []actool.CoreTool,
query, _ := ctx.Value(toolQueryKey{}).(string)
out, projected, err := projectTools(query, tools, toolRAGKeep(deferred), k, score)
if err != nil {
log.Printf("[tool-rag] %s: scoring failed, using full catalog (%d tools): %v", agentKey, len(tools), err)
slog.Warn("[tool-rag] scoring failed, using full catalog", "agent", agentKey, "tools", len(tools), "err", err)
} else if !projected {
log.Printf("[tool-rag] %s: full catalog (%d tools; empty query or under %d)", agentKey, len(tools), toolRAGMinCatalog)
slog.Info("[tool-rag] using full catalog (empty query or under threshold)", "agent", agentKey, "tools", len(tools), "min_catalog", toolRAGMinCatalog)
} else {
names := make([]string, len(out))
for i, t := range out {
names[i] = t.Name()
}
log.Printf("[tool-rag] %s: selected %d/%d tools: %s", agentKey, len(out), len(tools), strings.Join(names, ", "))
slog.Info("[tool-rag] selected tools", "agent", agentKey, "selected", len(out), "total", len(tools), "names", strings.Join(names, ", "))
}
return out
}
4 changes: 2 additions & 2 deletions agent/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -1584,7 +1584,7 @@ func (t *ToolSet) addFinding() actool.CoreTool {
// advice "register it again if it is distinct" is unactionable, because the
// retry hits the same check and is suppressed again.
if a.ForceRegister {
log.Printf("[triage] override: force_register set, registering %q without the duplicate check", a.Name)
slog.Info("[triage] override: force_register set, registering without duplicate check", "candidate", a.Name)
} else if ans, ok := t.triageDuplicate(ctx, input); ok && triageDuplicateHit(ans) {
res := map[string]any{
"duplicate_of_finding_id": ans.DuplicateOf,
Expand Down
4 changes: 2 additions & 2 deletions agent/tools_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"net"
"net/url"
"strconv"
Expand Down Expand Up @@ -129,7 +129,7 @@ func insertAssetsRuleLoadFailure(err error) (actool.Result, bool) {
if err == nil {
return actool.Result{}, false
}
log.Printf("[insert_assets] intercept rules unavailable: %v", err)
slog.Warn("[insert_assets] intercept rules unavailable", "err", err)
return actool.Errorf("asset intercept rules are unavailable; insertion refused"), true
}

Expand Down
22 changes: 13 additions & 9 deletions agent/triage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"log/slog"
"math"
"net/http"
"regexp"
Expand Down Expand Up @@ -323,12 +323,16 @@ func (p *Planner) SetTriageClient(c TriageClient) { p.triage = c }
// bounded: newest findings first (a duplicate of a fresh finding is the common case).
func (t *ToolSet) triageDuplicate(ctx context.Context, in db.RecordFindingInput) (DuplicateAnswer, bool) {
if t.triage == nil || t.ts == nil {
log.Printf("[triage] skip: client=%v store=%v", t.triage != nil, t.ts != nil)
slog.Info("[triage] skip", "client", t.triage != nil, "store", t.ts != nil)
return DuplicateAnswer{}, false
}
nodes, err := t.ts.ListByKindWithSources(db.KindFinding, 500)
if err != nil || len(nodes) == 0 {
log.Printf("[triage] skip: nodes=%d err=%v", len(nodes), err)
if err != nil {
slog.Warn("[triage] skip: failed to list findings", "nodes", len(nodes), "err", err)
return DuplicateAnswer{}, false
}
if len(nodes) == 0 {
slog.Info("[triage] skip: no existing findings", "nodes", 0)
return DuplicateAnswer{}, false
}
// Findings from independently created tasks on the same assets are NOT in the
Expand All @@ -351,26 +355,26 @@ func (t *ToolSet) triageDuplicate(ctx context.Context, in db.RecordFindingInput)
// candidate list is built from nodes whose FindingID is still 0 and every
// entry is dropped (observed live: "nodes=6, no usable existing findings").
if err := t.ts.PopulateFindingTrafficIDs(nodes); err != nil {
log.Printf("[triage] populate finding ids failed: %v", err)
slog.Warn("[triage] populate finding ids failed", "err", err)
}
existing := triageCandidates(nodes, in)
if len(existing) == 0 {
log.Printf("[triage] skip: no usable existing findings (nodes=%d)", len(nodes))
slog.Info("[triage] skip: no usable existing findings", "nodes", len(nodes))
return DuplicateAnswer{}, false
}
log.Printf("[triage] asking: existing=%d candidate=%q", len(existing), in.Name)
slog.Info("[triage] asking", "existing", len(existing), "candidate", in.Name)
ans, err := t.triage.Duplicate(ctx, TriageCandidate{
Name: in.Name, VulnClass: in.VulnClass, Severity: in.Severity, Summary: in.Summary,
}, existing)
if err != nil {
log.Printf("[triage] client error (fail open): %v", err)
slog.Warn("[triage] client error (fail open)", "err", err)
return DuplicateAnswer{}, false
}
// Carry the node id of the matched finding alongside its findings-table id:
// the agent extends a finding through update_finding_report, which takes the
// node id, so an answer that names only the table id sends it to the wrong call.
ans = withNodeID(ans, existing)
log.Printf("[triage] answer: dup=%d node=%d conf=%.2f", ans.DuplicateOf, ans.DuplicateOfNode, ans.Confidence)
slog.Info("[triage] answer", "dup", ans.DuplicateOf, "node", ans.DuplicateOfNode, "conf", fmt.Sprintf("%.2f", ans.Confidence))
return ans, true
}

Expand Down
4 changes: 2 additions & 2 deletions agent/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -343,7 +343,7 @@ func makeRunDir(base, leaf string) {
return
}
if err := runDirMaker(base, leaf); err != nil {
log.Printf("[agent] run directory %s: %v", leaf, err)
slog.Warn("[agent] run directory creation failed", "dir", leaf, "err", err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/artex-archive-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/hex"
"fmt"
"log"
"log/slog"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -47,7 +48,7 @@ func check() error {
cleanup, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := s.Delete(cleanup, uri); err != nil {
log.Printf("test object cleanup failed for %s: %v", uri, err)
slog.Warn("test object cleanup failed", "uri", uri, "err", err)
}
}()
if err := s.Upload(ctx, uri, file, checksum); err != nil {
Expand Down
Loading
Loading