Skip to content

fix(observability): ConsoleLogger and JsonLogger record an error's cause chain - #37716

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-37658-observability-cause-chain
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-37658-observability-cause-chain

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #37658

Clause-②: yes (widening)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:运维用可观测性包的控制台或 JSON 日志器记录错误时,日志里多出被包装的原始错误(每层的消息与堆栈),之前只有最外层;其他用户无感。
  • 为什么做:服务器故障日志专题的后续,让这两个日志器与故障日志、内核日志器打出同一种原始错误链。
  • 出错会怎样:只影响日志内容,不影响任何请求与数据;可直接撤回。
  • 要你做的:无。

What changes

  • packages/observability/src/loggers.ts: ConsoleLogger and JsonLogger error() / fatal() now add causes beside error and stack when the error carries a cause chain: one entry per link, outermost first, each the link's message and stack; at most five links, a cycle stopped at its first repeat, and a marker entry whenever the chain was cut. An error with no cause logs byte-identically to before (causes omitted).
  • The helper is a private copy of faultCauseChain (@objectstack/types), because @objectstack/observability depends on @objectstack/spec alone. No runtime dependency added; no export added.
  • packages/observability/package.json: devDependency on @objectstack/types (workspace), for the parity test only; vitest.config.ts aliases it to source (check:test-source-alias), with the preset's console-intercept setting spelled in place (the plugin-email precedent).
  • packages/core/src/logger-error-cause.test.ts (N4 of the contract record on PR fix(types,core): the 5xx fault log and ObjectLogger print an error's cause chain #37652): the parity block gains one fixture that glues each of the 31 glued redact qualifiers to a default word, plus a control proving the fixture exercises each qualifier, so a list edit in either copy fails the parity test. ObjectLogger and logServerFault are unchanged.

Tests

observability: test + typecheck (head d2a09be)

pnpm --filter @objectstack/observability test then typecheck, under the verify lock: Test Files 7 passed (7) · Tests 120 passed (120) · both tsc programs clean · VERDICT command-exit 0. loggers.test.ts alone: Tests 44 passed (44) — per logger: each cause's message and stack, the no-cause control, a cycle, a deep chain cut at the limit; fatal for both; 12 parity fixtures per logger against faultCauseChain.

core: test + typecheck (head d2a09be)

pnpm --filter @objectstack/core test then typecheck: Test Files 158 passed (158) · Tests 3791 passed (3791) · VERDICT command-exit 0.

Ablation — the cause reading in errorFields (one, as ordered)

node scripts/ablation-replace.mjs --file packages/observability/src/loggers.ts --anchor " const causes = causeChain(error);" --replacement " const causes: CauseLine[] = []; // ABLATION" around the loggers test file. Landed: anchor 1 to 0, blob d037c912f881 to 3aed5820db82. Result: Tests 30 failed | 14 passed (44) — every cause, cycle, depth, fatal and non-empty parity case red; the 14 green are the pre-existing cases, the two no-cause controls, the fixture control and the throwing-getter parity case (an empty chain both ways). Restored: blob equals HEAD (d037c912f881), git diff HEAD empty. The test imports ../loggers.js from source, so no build or dist leg applies.

Acceptance notes

  • The two GLUED_QUALIFIERS fixture lists are hand copies of the list: a qualifier REMOVED from any copy fails a parity test; one ADDED to a single copy fails nothing until the fixture list grows too.
  • @objectstack/observability now carries the third copy of the cause-chain helper (types, core, observability), each pinned to faultCauseChain by a parity test.

Verification

Read first: packages/observability/src/loggers.ts (errorFields, causeChain — the only behaviour change), packages/observability/src/__tests__/loggers.test.ts (parity block), packages/observability/vitest.config.ts.

Two-minute check: pnpm --filter @objectstack/observability exec vitest run --maxWorkers=2 src/__tests__/loggers.test.ts prints Tests 44 passed (44).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc


Generated by Claude Code

…use chain

Both loggers now add `causes` (message and stack per link, at most five
links, cycle-safe) beside `error` and `stack`, in the shape faultCauseChain
and ObjectLogger record. The helper is a pinned copy, since the package
depends on @objectstack/spec alone; a parity test against faultCauseChain
(devDependency on @objectstack/types, aliased to source) holds the two to one
output. core's parity fixture now glues every redact qualifier to a default
word.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc
@github-actions github-actions Bot added size/m dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

16 anchor(s) derived from 1 changed package(s); no hand-written page names any of them. ⚠️ 1 changed file(s) yielded no anchor (packages/observability/vitest.config.ts), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

What this run could not see
  • 1 changed file(s) yielded no anchor (packages/observability/vitest.config.ts) — pages documenting those are invisible to this run
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 4 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json f722411eddac2c3e34235cd7a5ba1ccdda4d40d4 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from e41bcf21d8769eafb528451a68904ac1b309d150 — the merge of head 80855b22b02063419c2db2e6dab9bb9b2983eb0c into base f722411eddac2c3e34235cd7a5ba1ccdda4d40d4, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e41bcf21d8769eafb528451a68904ac1b309d150 && git checkout e41bcf21d8769eafb528451a68904ac1b309d150
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin f722411eddac2c3e34235cd7a5ba1ccdda4d40d4 80855b22b02063419c2db2e6dab9bb9b2983eb0c && git checkout -B drift-repro f722411eddac2c3e34235cd7a5ba1ccdda4d40d4 && git merge --no-ff 80855b22b02063419c2db2e6dab9bb9b2983eb0c

node scripts/docs-audit/affected-docs.mjs --json f722411eddac2c3e34235cd7a5ba1ccdda4d40d4

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc

Test UI (11/16) on head 80855b22b0 (run 45913543815, job 140228697600) has one failure out of 452 files, read from the full job log: ui/packages/auth/src/__tests__/AuthProvider.test.tsx › "a name save keeps the id and the email, takes the new name, and remounts nothing" fails with expected 2 to be 1, a render count.

This PR's tree does not reach that test. The diff is packages/observability/**, one packages/core test file, a changeset and the lockfile, and ui/packages/auth does not import @objectstack/observability. The same shard was green on the previous head d2a09be453 (Test UI 1–16/16 success). 80855b22b0 differs from that head by one changeset line. The area therefore judges the failure as not this PR's and re-runs the failed jobs once through rerun-failed.mjs when the run completes. If the same test fails again, the area reads it as a real red and files it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 80855b2 · 2026-11-27T00:51Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 80855b22b02063419c2db2e6dab9bb9b2983eb0c
Local-runs: none

Inputs read: card #37658 (body, triage, unblock, claim, os-dev report, claim amendment), PR #37716 (body, 7 files, net diff against main), N4 of the contract record on PR #37652, and the head's 73 check-runs (62 success, 11 skipped, none failed). The required set is green on this head: Lint & Repo Gates, TypeScript Type Check, Test Core 1-10/10, Build Core, Governed Surface Queue Guard, Validate Package Dependencies, Check Changeset, Lint UI, Type Check UI, Test UI 1-16/16, Build & E2E UI, Live E2E UI and Dogfood Regression Gate. Security-touching: yes because the diff adds a third copy of the field-name matcher that decides which object-cause fields an operator log withholds, and it adds content to what reaches operator log sinks.

① Derived judgments

  • Log record shape, ConsoleLogger / JsonLogger error() and fatal(): a new optional causes field beside error and stack. Right. errorFields builds { error, stack, ...(causes.length ? { causes } : {}) }. The key order and values are those of the old literal { error: error.message, stack: error.stack }, so an error with no cause (also cause: null, cause: undefined, or a throwing cause getter) serializes byte-identically on both loggers. The per-logger CONTROL test pins the omission. The other four levels are untouched.
  • The private causeChain copy against faultCauseChain (packages/types/src/server-fault-log.ts). Faithful, read line by line. It has the same loop: seen is seeded with the outer error, the cycle check runs before the depth check, the limit is 5 (CAUSE_DEPTH_LIMIT), and the three marker strings are identical (cycle, truncated after 5 links, unreadable link). causeOf is guarded, and causeLine renders name: message with stack omitted when it is empty. The string and JSON object-cause branches with their String() fallback match. The field-name matcher (DEFAULT_REDACTED_WORDS, tokenizeFieldName, singularizeWord, CONCATENATED_SECRET_QUALIFIERS, isQualifiedConcatenation, containsWordRun, fieldWordsMatchPattern) is a verbatim copy. The 31 qualifiers form the same set in all five places (core logger.ts, types, observability, and the two fixture lists). The one signature difference is causeChain(error: Error) with no isRedacted parameter, against faultCauseChain(thrown: unknown, isRedacted = default). It is behaviour-neutral, because the loggers have no redact config to pass.
  • Never-throw contract. Held. errorFields runs in error() / fatal(), outside emit's try. Every read it adds is guarded (causeOf try, per-link try), and the error.message / error.stack reads it keeps were already outside the try on main.
  • Parity binding, 12 fixtures × 2 loggers, toEqual(faultCauseChain(error)). Right, with one gap (N2). The fixtures pin the depth limit (a 9-cause chain, and the limit imported from @objectstack/types in the depth test), the cycle marker, the unreadable-link marker, the throwing getter, string, object and unserializable causes, and the whole-word field-name rule including all 31 glued qualifiers. A change to any branch the fixtures reach, in either copy, reds a case.
  • Public surface. Unchanged apart from the log field. src/index.ts is untouched: no export is added or removed. loggers.ts imports nothing new (only import type { Logger }). dependencies is still @objectstack/spec alone.
  • Accept-set. No accept-set change. The diff touches no schema, validator or parser.
  • Test-only edges. Right. @objectstack/types is a devDependency. @objectstack/types depends on @objectstack/spec only, so the workspace graph has no cycle (Validate Package Dependencies is green). vitest.config.ts is not in the package's files (dist, README.md, CHANGELOG.md). Its alias is anchored, ^@objectstack/types$ to ../types/src/index.ts, which re-exports server-fault-log.js. The preset's one setting, disableConsoleIntercept: true, is spelled in place, verbatim. The lockfile hunk is 3 lines, the new devDependency link in the observability importer and nothing else.
  • Core test (packages/core/src/logger-error-cause.test.ts). Test-only. It adds one fixture and a control. ObjectLogger and logServerFault are unchanged, as the claim requires.

② Semver level

Clause-②: yes (widening) — confirmed. The change is an additive, optional field on a log record that already merges arbitrary caller meta, so the record had no closed shape and no existing field changes. Metadata-protocol: none is right, because nothing a metadata author writes changes. Under AGENTS.md Post-Task Checklist §3, a non-protocol widening ships patch. The changeset is '@objectstack/observability': patch, it carries both bare lines, and so does the PR body (Check Changeset is green). The card's original Clause-②: no was corrected by the claim amendment, in line with the seat's reading on PR #37652. That correction is right.

Existing parsers of JsonLogger output: a line-per-record JSON reader sees one more key, and only on a caused error. Nothing breaks unless a consumer validates records against a closed schema, which a record merging free meta could never have satisfied. One precedence detail: a caller-supplied meta.causes is now overridden when the error has a chain. This is the same precedence meta.error and meta.stack already had, and git grep finds no caller that passes causes in logger meta. Lines grow by up to six stacks, as ObjectLogger lines already do.

③ Boundary flags

  • open_questions: none raised.
  • security_findings: the dev reported none. Nothing contrary was found in the diff.
  • deviations: none. The claim amendment widens the named file surface to package.json, vitest.config.ts and pnpm-lock.yaml, all inside the claim's "devDependency for the parity test" allowance. No runtime edge was added.
  • Out-of-scope finding (hand-copied fixture lists): answered as N1 below. It is real and does not block.
  • N4 of PR fix(types,core): the 5xx fault log and ObjectLogger print an error's cause chain #37652: closed as written. That record asked for "one fixture with each qualifier glued to a default word". GLUED_QUALIFIERS glues all 31 to key, and each ${q}key is a single token that matches only through its own qualifier: no compound path, no singular form, no other default word as a suffix. A qualifier removed from, or changed in, either copy therefore reds a parity case. The control proves the fixture currently exercises all 31 against faultCauseChain. The same fixture rides in observability's parity block.
  • Test UI (11/16): unreachable from this diff. It failed once, at ui/packages/auth/src/__tests__/AuthProvider.test.tsx on a render count, and is green on rerun on this head (job 140239738628, completed 2026-11-27T00:50Z). The diff has no ui/ path, no file under ui/ imports @objectstack/observability, ui/packages/auth depends on @objectstack/spec alone, and the only lockfile change is the observability importer.
  • SQL push-down (Prime Directive 5): not applicable. The diff touches no data path, no query, and no id materialisation or in-app join.

Findings:

  • N1 (nit): the drift guard is one-directional. A qualifier or default word that is removed or changed in any copy reds parity. One added to a single copy (to CONCATENATED_SECRET_QUALIFIERS or to DEFAULT_REDACTED_WORDS in types, core or observability) fails nothing until the hand-copied fixture lists grow too. The dev disclosed this, and core has the same shape. A follow-up could derive the fixture from one exported list.
  • N2 (nit): two branches that all three copies share have no fixture. One is an Error cause with an empty stack (the stack-omitted branch of causeLine). The other is a chain that continues through a non-Error object cause that itself carries cause. The copies agree there today on read. A drift in only one of them would pass the parity block.

Implemented-by: claude/issue-37658-observability-cause-chain
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: 80855b22b02063419c2db2e6dab9bb9b2983eb0c
ACCEPT — L1, seat repo:objectstack#5

  1. Shape: draft against main. 7 files, +401/−6. Not governed. Security-touching: the diff adds a third copy of the field-name matcher for object causes, and more content reaches operator log sinks. @objectstack/observability patch, Clause-②: yes (widening) for the additive causes field, Metadata-protocol: none: right. @objectstack/types is a devDependency only, with no runtime edge, and the lockfile change is 3 lines.
  2. Premise: the private cause-chain copy matches faultCauseChain line by line: the 5-link limit, the cycle check, the markers, the guarded reads, and the 31 qualifiers. An error with no cause logs byte-identically, and a CONTROL test pins that. Never-throw holds. N4 from fix(types,core): the 5xx fault log and ObjectLogger print an error's cause chain #37652 is closed as written: all 31 qualifiers are glued, with a control, in both parity blocks.
  3. Gates: contract record 7206884238 (TIER_DEFAULT, declaration face) reads PASS, with no must-fix or should-fix. CI on this head: 62 success, 11 skipped, 0 failed. Test UI (11/16) failed once on an AuthProvider render count that this diff cannot reach, since no ui/ path is touched. Its one rerun was green.
  4. Accepted deviations:
    • N1: the drift guard catches a removed or changed word but not one added to a single copy.
    • N2: two branches the copies share have no fixture: an empty stack, and a chain that continues through a non-Error cause.
    • Both go to a follow-up card for the seat that holds the topic.
  5. Out of scope and where it went: the seat holds a security note, handled privately.
  6. Landing terms: Tier S. The seat adds security, and the area lands it through the queue with --land.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Adding security: the observability loggers gain a field-name matcher that decides which object-cause fields an operator log withholds (contract record 7206884238; seat ACCEPT, item 1).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc

Landing: ACCEPT 7206892683 (contract record 7206884238, PASS) at head 80855b22b02063419c2db2e6dab9bb9b2983eb0c.

Probe Reading
Check-runs on head latest attempts 63 success, 15 skipped, 0 failed, 0 in progress; Test UI (11/16) re-run once (reason on this PR), attempt 2 green; security label on (seat)
Governed / size check-governed-merges --pr 37716: NOT governed, 407 changed lines ≤ 3000
landing-k OK — K = 8 < 15, no locale leg, no shared book moved under this PR

Status: ready + auto-merge (merge queue). On MERGED, #37658 closes by Fixes; N1 and N2 ride #37744 (filed under #37658, Blocked-by this PR), handed to repo:objectstack#1 with the rest of the topic.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 01:02
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 7e638ba Nov 27, 2026
122 of 124 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-37658-observability-cause-chain branch November 27, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation security size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

37598 跟进:可观测性包的控制台与 JSON 日志器也打印被包装的原始错误

2 participants