logging: errors logged through the slog JSON handler serialize to {}, losing all diagnostic detail #976

Closed
opened 2026-10-27 13:38:31 +00:00 by sam · 0 comments
Owner

Problem

Every log.Error(..., "err", err) call site logs through slog.NewJSONHandler (internal/logging/logging.go:56,61,69, internal/logging/tasksink.go:63). Go's stdlib error types (fmt.Errorf, errors.New) are structs with unexported fields (*fmt.wrapError{msg, err}, *errors.errorString{s}). encoding/json cannot see unexported fields, and neither type implements MarshalJSON, MarshalText, or slog.LogValuer — so any error value passed to a JSON-handled logger serializes to the empty object {}, discarding the actual failure reason.

This is not one call site: grep -rn '"err", err)' across internal/ and cmd/ returns 160 matches across 25 files.

Evidence

Live on the dashboard /logs page (task #1000000000000001, 2026-08-15 08:51:28–08:51:31), captured via Playwright:

08:51:28 ERROR handle failed err={}
08:51:28 ERROR handle failed err={}
... (996 identical lines across a 3-second window)

The message comes from internal/app/agentworker/stage_loop.go:42:

log.Error("handle failed", "err", err)

where err is fmt.Errorf("handle: %w", err) (internal/app/agentworker/single_stage_request.go:82). The real underlying failure is completely unrecoverable from the logs — there is no way to tell, after the fact, why 996 consecutive stage handles failed.

Fix

Any of:

  • Log the string form explicitly: log.Error("handle failed", "err", err.Error())
  • Add a small slog.Attr helper (logging.Err(err) → slog.String("err", err.Error())) and require its use at all 160 call sites, or
  • Set HandlerOptions.ReplaceAttr on the JSON handlers to stringify any error-typed attribute value centrally, fixing every call site without touching them individually.

The last option is the smallest, single-point fix and should be preferred — it also protects any future log.Error(..., "err", err) call site from reintroducing the bug.

Close reason

Fixed in 6a23f8d (archied/archie v1.9.3). Root cause was more specific than the bead's hypothesis: slog.NewJSONHandler itself resolves an error attr correctly (verified live) -- the actual bug is that SystemLogHandler and FeedHandler both json.Marshal Entry.Fields directly via encoding/json, bypassing slog's value formatting entirely, which has no Error()-aware case. Fixed at the single choke point both handlers share: internal/logging/feed.go's addAttr/attrValue now resolves error attrs to .Error() before they reach the map, plus a guard against the typed-nil-pointer panic footgun. Regression test: internal/logging/attrs_test.go.


Imported from beads archie-core-1786749700482-2-ea056b07 · GitHub #516 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-15

## Problem Every `log.Error(..., "err", err)` call site logs through `slog.NewJSONHandler` (`internal/logging/logging.go:56,61,69`, `internal/logging/tasksink.go:63`). Go's stdlib error types (`fmt.Errorf`, `errors.New`) are structs with unexported fields (`*fmt.wrapError{msg, err}`, `*errors.errorString{s}`). `encoding/json` cannot see unexported fields, and neither type implements `MarshalJSON`, `MarshalText`, or `slog.LogValuer` — so any error value passed to a JSON-handled logger serializes to the empty object `{}`, discarding the actual failure reason. This is not one call site: `grep -rn '"err", err)'` across `internal/` and `cmd/` returns **160 matches across 25 files**. ## Evidence Live on the dashboard `/logs` page (task `#1000000000000001`, 2026-08-15 08:51:28–08:51:31), captured via Playwright: ``` 08:51:28 ERROR handle failed err={} 08:51:28 ERROR handle failed err={} ... (996 identical lines across a 3-second window) ``` The message comes from `internal/app/agentworker/stage_loop.go:42`: ```go log.Error("handle failed", "err", err) ``` where `err` is `fmt.Errorf("handle: %w", err)` (`internal/app/agentworker/single_stage_request.go:82`). The real underlying failure is completely unrecoverable from the logs — there is no way to tell, after the fact, why 996 consecutive stage handles failed. ## Fix Any of: - Log the string form explicitly: `log.Error("handle failed", "err", err.Error())` - Add a small `slog.Attr` helper (`logging.Err(err)` → `slog.String("err", err.Error())`) and require its use at all 160 call sites, or - Set `HandlerOptions.ReplaceAttr` on the JSON handlers to stringify any `error`-typed attribute value centrally, fixing every call site without touching them individually. The last option is the smallest, single-point fix and should be preferred — it also protects any future `log.Error(..., "err", err)` call site from reintroducing the bug. ### Close reason Fixed in 6a23f8d (archied/archie v1.9.3). Root cause was more specific than the bead's hypothesis: slog.NewJSONHandler itself resolves an error attr correctly (verified live) -- the actual bug is that SystemLogHandler and FeedHandler both json.Marshal Entry.Fields directly via encoding/json, bypassing slog's value formatting entirely, which has no Error()-aware case. Fixed at the single choke point both handlers share: internal/logging/feed.go's addAttr/attrValue now resolves error attrs to .Error() before they reach the map, plus a guard against the typed-nil-pointer panic footgun. Regression test: internal/logging/attrs_test.go. --- _Imported from beads `archie-core-1786749700482-2-ea056b07` · GitHub #516 · type bug · priority P1 · created 2026-08-14 · closed 2026-08-15_
sam added the highbug labels 2026-10-27 13:38:31 +00:00
sam self-assigned this 2026-10-27 13:38:31 +00:00
sam closed this issue 2026-10-27 13:38:32 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#976