Task logs serialise errors to an empty object, destroying diagnostics #1500

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

Error values in task logs sometimes render as an empty JSON object, so the one field that says WHY something failed carries no information. Observed in production task logs 2026-08-24, in the same stream:

{"time":"...","level":"ERROR","message":"handle failed","fields":{"err":{}}}
{"time":"...","level":"ERROR","message":"handle failed","fields":{"err":"stage re…"}}

Same message, same field, two different encodings -- one useful, one useless. The empty-object form is what an operator hits when diagnosing a stuck task, which is exactly when the log is the only evidence available.

Likely mechanism (to be confirmed, not assumed)

{} is what encoding/json produces for a struct with no exported fields. A custom error type (a struct implementing error via a value or pointer receiver, with all fields unexported) marshals to {} rather than to its Error() string, because encoding/json does not consult the error interface. Errors that happen to be *errors.errorString or fmt.Errorf results go through a different path and survive as text.

Start at internal/logging (attrs.go and its tests already reference a "handle failed" record, so the attribute handling is there) and establish where an error attribute is converted for the JSONL sink. The fix is to render errors through their Error() string -- and, where the error carries structured context worth keeping, to do so ADDITIONALLY rather than instead.

Why P1

Sam's words: "LOGGING! ... this is another critical requirement." Diagnosis of every other defect depends on it. Two separate investigations this week were slowed by log output that recorded that something failed without recording what.

Note this compounds archie-core-1ysw-era debugging and the parked-task investigation: an operator seeing {"err":{}} has strictly less information than one seeing no log line at all, because the empty object implies the error was captured.

Steps to Reproduce

  1. Arrange for a code path that logs a custom error type (unexported fields) as an err attribute.
  2. Read the task's JSONL log via the dashboard, /api logs, or the task_logs tool.
  3. Observe "err":{} where the message should be.
  4. Compare with a path that logs a fmt.Errorf value and observe "err":"..." in the same file.

Acceptance Criteria

Every error logged as an attribute renders its Error() text in the JSONL sink regardless of the concrete error type; a custom error type with only unexported fields is covered by a test asserting the message survives; structured context on an error is preserved in addition to, never instead of, the message; a regression test fails against the current encoder; no log line can report an error as an empty object.

Close reason

Shipped in 6a23f8d: logging resolves every non-nil error attribute through Error(), with custom unexported-field and typed-nil regression coverage; included in archied v1.18.0.


Imported from beads archie-core-p1bl · GitHub #626 · type bug · priority P1 · created 2026-08-24 · closed 2026-08-25

Error values in task logs sometimes render as an empty JSON object, so the one field that says WHY something failed carries no information. Observed in production task logs 2026-08-24, in the same stream: {"time":"...","level":"ERROR","message":"handle failed","fields":{"err":{}}} {"time":"...","level":"ERROR","message":"handle failed","fields":{"err":"stage re…"}} Same message, same field, two different encodings -- one useful, one useless. The empty-object form is what an operator hits when diagnosing a stuck task, which is exactly when the log is the only evidence available. ## Likely mechanism (to be confirmed, not assumed) `{}` is what encoding/json produces for a struct with no exported fields. A custom error type (a struct implementing `error` via a value or pointer receiver, with all fields unexported) marshals to `{}` rather than to its Error() string, because encoding/json does not consult the error interface. Errors that happen to be `*errors.errorString` or `fmt.Errorf` results go through a different path and survive as text. Start at internal/logging (attrs.go and its tests already reference a "handle failed" record, so the attribute handling is there) and establish where an `error` attribute is converted for the JSONL sink. The fix is to render errors through their Error() string -- and, where the error carries structured context worth keeping, to do so ADDITIONALLY rather than instead. ## Why P1 Sam's words: "LOGGING! ... this is another critical requirement." Diagnosis of every other defect depends on it. Two separate investigations this week were slowed by log output that recorded that something failed without recording what. Note this compounds archie-core-1ysw-era debugging and the parked-task investigation: an operator seeing `{"err":{}}` has strictly less information than one seeing no log line at all, because the empty object implies the error was captured. ## Steps to Reproduce 1. Arrange for a code path that logs a custom error type (unexported fields) as an `err` attribute. 2. Read the task's JSONL log via the dashboard, /api logs, or the task_logs tool. 3. Observe `"err":{}` where the message should be. 4. Compare with a path that logs a fmt.Errorf value and observe `"err":"..."` in the same file. ## Acceptance Criteria Every error logged as an attribute renders its Error() text in the JSONL sink regardless of the concrete error type; a custom error type with only unexported fields is covered by a test asserting the message survives; structured context on an error is preserved in addition to, never instead of, the message; a regression test fails against the current encoder; no log line can report an error as an empty object. ### Close reason Shipped in 6a23f8d: logging resolves every non-nil error attribute through Error(), with custom unexported-field and typed-nil regression coverage; included in archied v1.18.0. --- _Imported from beads `archie-core-p1bl` · GitHub #626 · type bug · priority P1 · created 2026-08-24 · closed 2026-08-25_
sam added the highbug labels 2026-10-27 13:40:39 +00:00
sam self-assigned this 2026-10-27 13:40:39 +00:00
sam closed this issue 2026-10-27 13:40:39 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1500