Skip to content

feat(diagnostics): chain gateway traces into runs - #92161

Closed
lanzhi-lee wants to merge 1 commit into
openclaw:mainfrom
lanzhi-lee:codex/diagnostic-trace-chain
Closed

lanzhi-lee wants to merge 1 commit into
openclaw:mainfrom
lanzhi-lee:codex/diagnostic-trace-chain

Conversation

@lanzhi-lee

Copy link
Copy Markdown
Contributor

Summary

  • Chain gateway diagnostic traces into embedded agent runs using the existing DiagnosticTraceContext instead of adding a second run/request scope.
  • Add trusted-boundary-aware gateway request/message trace helpers, plus run.invocation / run.invocation.completed diagnostic events.
  • Record invocation lifecycle spans in diagnostics-otel so request -> invocation -> harness -> run/model/tool spans stay connected and close on success or pre-lifecycle failures.
  • Add focused tests for trusted/untrusted gateway traceparent handling and gateway-to-run trace propagation.

Verification

  • node scripts/run-vitest.mjs src/gateway/request-diagnostic-trace.test.ts src/gateway/server-http.request-trace.test.ts src/agents/embedded-agent-runner/run.diagnostic-trace-chain.test.ts
  • git diff --check
  • node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo (blocked after rebase by existing upstream src/agents/sessions/sdk.ts:279 TS2322, not touched by this branch)
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo (blocked after rebase by existing upstream src/agents/sessions/sdk.ts:279 TS2322, not touched by this branch)
  • .agents/skills/autoreview/scripts/autoreview --mode local (clean before final rebase; reruns after rebase drove the fixes in this branch, latest focused tests remain green; current core/extension tsgo is blocked by the upstream type drift above)

Notes

The gateway helper intentionally ignores inbound traceparent by default and only honors it for local-direct gateway boundaries, so public unauthenticated requests cannot spoof trusted telemetry trace IDs.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: diagnostics-otel Extension: diagnostics-otel agents Agent runtime and tooling size: L triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 11, 2026
@clawsweeper

clawsweeper Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 11:17 AM ET / 15:17 UTC.

ClawSweeper review

What this changes

This PR carries trusted Gateway request trace context into embedded agent runs and adds OpenTelemetry invocation spans so Gateway, harness, run, model, and tool work can share one trace.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 6 items remain

Keep open: the requested Gateway-to-run trace chain is not on current main, but this draft branch is conflicted, lacks real runtime trace proof, and still misclassifies an abort-rewritten failure as an invocation error. The prior P2 finding remains unresolved.

Priority: P2
Reviewed head: a9ec4a24e9a5f83341fc8b81c94f37bbc7c7cc5b

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The tracing concept and focused tests are useful, but an unresolved lifecycle defect, conflict with current main, and mock-only proof keep the PR below merge-ready quality.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR lists focused tests and static checks, but it contains no redacted after-fix Gateway-to-OTLP export, runtime log, terminal output, or artifact proving the linked trace path; add that evidence after rebasing and redact private endpoints, IDs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR lists focused tests and static checks, but it contains no redacted after-fix Gateway-to-OTLP export, runtime log, terminal output, or artifact proving the linked trace path; add that evidence after rebasing and redact private endpoints, IDs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Current main does not yet implement the requested chain: Current WebSocket message handling creates a fresh diagnostic trace for every frame, rather than deriving a frame trace from a persistent request trace and passing it into the embedded run.
Invocation completion is emitted before final abort translation: The branch emits run.invocation.completed with outcome: "error" in the rejection handler, then the subsequent catch can replace that error with postCompactionAbortError; diagnostics can therefore disagree with the run's final aborted outcome.
Current run diagnostics already centralize terminal outcome classification: Current main's attempt startup helper records one terminal run event with explicit completed, aborted, blocked, or error outcomes, which is the owner boundary the new invocation span should follow.
Findings 1 actionable finding [P2] Classify invocation completion after abort translation
Security None None.

How this fits together

Gateway HTTP and WebSocket requests establish diagnostic trace context for inbound work. Embedded agent runs and the diagnostics OpenTelemetry plugin consume that context to emit and export a connected lifecycle trace.

flowchart LR
  A[Inbound Gateway request] --> B[Gateway trace context]
  B --> C[WebSocket or HTTP dispatch]
  C --> D[Embedded agent run]
  D --> E[Invocation lifecycle events]
  E --> F[OpenTelemetry diagnostics plugin]
  F --> G[Linked exported trace]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR lists focused tests and static checks, but it contains no redacted after-fix Gateway-to-OTLP export, runtime log, terminal output, or artifact proving the linked trace path; add that evidence after rebasing and redact private endpoints, IDs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Classify invocation completion after abort translation (P2) - run.invocation.completed is emitted as error in the rejection handler, but the following catch can replace that error with postCompactionAbortError. The exported invocation span can therefore contradict the final embedded-run outcome; emit completion after the canonical abort/error classification instead. This is the unresolved prior finding.
  • Resolve merge risk (P1) - Merging after a mechanical conflict resolution could retain the branch's pre-final-classification completion event, producing misleading invocation-error spans for runs whose final outcome is aborted.
  • Resolve merge risk (P1) - The branch is draft and GitHub reports it as dirty against current main; its June implementation has not been reconciled with the current split embedded-run diagnostics architecture.
  • Resolve merge risk (P1) - Focused tests are listed, but there is no redacted after-fix Gateway-to-OTLP runtime trace proving that request, invocation, harness, run, model, and tool spans are linked and closed correctly.
  • Complete next step (P2) - A contributor or sponsor must rebase the dirty draft, address the remaining lifecycle defect, and provide real behavior proof; the proof gate cannot be completed by a read-only repair review.

Findings

  • [P2] Classify invocation completion after abort translation — src/agents/embedded-agent-runner/run.ts:1817-1824
Agent review details

Security

None.

PR surface

Source +197, Tests +211. Total +408 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 460 263 +197
Tests 3 211 0 +211
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 671 263 +408

Review metrics

Metric Value Why it matters
Invocation lifecycle events 2 added The new start/completion pair must agree on one terminal outcome or exported diagnostics become misleading.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/diagnostics-otel/src/service.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebase and align terminal classification (recommended)
    Update the invocation lifecycle to emit only after the final abort/error outcome is known, resolve the current-main conflict, and provide redacted runtime trace proof before merging.
  2. Pause the stale draft
    Keep the feature out of the merge queue until its author or a sponsor can rebase it and demonstrate the complete diagnostic trace in a real Gateway run.

Technical review

Best possible solution:

Rebase onto current main, make invocation completion use the same final terminal-outcome classification as the embedded-run lifecycle owner, add a regression for the post-compaction abort path, and attach redacted runtime trace-export evidence.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: make runEmbeddedAttemptWithBackend reject while postCompactionAbortError is set; the branch emits run.invocation.completed as error before translating the final result to an abort.

Is this the best way to solve the issue?

No. The trace-chain design remains useful, but its completion event must be emitted after the embedded-run lifecycle has determined the canonical terminal outcome, not from the earlier promise rejection handler.

Full review comments:

  • [P2] Classify invocation completion after abort translation — src/agents/embedded-agent-runner/run.ts:1817-1824
    run.invocation.completed is emitted as error in the rejection handler, but the following catch can replace that error with postCompactionAbortError. The exported invocation span can therefore contradict the final embedded-run outcome; emit completion after the canonical abort/error classification instead. This is the unresolved prior finding.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 71a59512ba47.

Labels

Label justifications:

  • P2: The proposed diagnostics feature has a concrete lifecycle correctness defect and a bounded but nontrivial stale-branch recovery path.
  • merge-risk: 🚨 other: The patch can export an invocation terminal state that disagrees with the run's final aborted outcome, misleading operators without necessarily failing ordinary tests.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR lists focused tests and static checks, but it contains no redacted after-fix Gateway-to-OTLP export, runtime log, terminal output, or artifact proving the linked trace path; add that evidence after rebasing and redact private endpoints, IDs, and credentials. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main does not yet implement the requested chain: Current WebSocket message handling creates a fresh diagnostic trace for every frame, rather than deriving a frame trace from a persistent request trace and passing it into the embedded run. (src/gateway/server/ws-connection/message-handler.ts:475, 71a59512ba47)
  • Invocation completion is emitted before final abort translation: The branch emits run.invocation.completed with outcome: "error" in the rejection handler, then the subsequent catch can replace that error with postCompactionAbortError; diagnostics can therefore disagree with the run's final aborted outcome. (src/agents/embedded-agent-runner/run.ts:1817, a9ec4a24e9a5)
  • Current run diagnostics already centralize terminal outcome classification: Current main's attempt startup helper records one terminal run event with explicit completed, aborted, blocked, or error outcomes, which is the owner boundary the new invocation span should follow. (src/agents/embedded-agent-runner/run/attempt-startup.ts:128, 71a59512ba47)
  • Current-area provenance: Current-line blame attributes the embedded-run diagnostic lifecycle helper to the recent main commit, providing a routing signal for the modern owner surface; available local history is shallow and could not provide older feature provenance without network access. (src/agents/embedded-agent-runner/run/attempt-startup.ts:134, b5f1bdb88600)
  • Branch provenance: The proposed implementation is a single June 11, 2026 commit based on an older main revision; GitHub reports the branch as dirty against current main, so it needs a rebase and fresh review before merge. (src/gateway/request-diagnostic-trace.ts:1, a9ec4a24e9a5)

Likely related people:

  • Peter Steinberger: Current-line blame for the embedded-run diagnostic lifecycle helper points to a recent main commit, making this the best available routing signal for the current owner boundary. (role: recent main contributor; confidence: medium; commits: b5f1bdb88600; files: src/agents/embedded-agent-runner/run/attempt-startup.ts, src/infra/diagnostic-trace-context.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase the draft and resolve the current-main conflict against the split embedded-run diagnostics owner.
  • Move invocation completion after final abort/error classification and add the matching regression test.
  • Post redacted runtime output or a trace artifact showing Gateway request through invocation, run, model, and tool spans; update the PR body to trigger re-review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-06-22T00:23:00.389Z sha a9ec4a2 :: needs real behavior proof before merge. :: [P2] Emit invocation completion after abort classification
  • reviewed 2026-06-30T23:07:05.480Z sha a9ec4a2 :: needs real behavior proof before merge. :: [P2] Emit invocation completion after abort classification
  • reviewed 2026-07-30T03:05:45.870Z sha a9ec4a2 :: needs real behavior proof before merge. :: [P2] Emit completion after final abort classification

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jun 11, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed stale Marked as stale due to inactivity labels Jul 21, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 1, 2026
@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Closing this draft because its useful trace-chain work has been superseded by the current owner architecture, while its remaining run.invocation lifecycle is duplicate and still misclassifies abort-translated failures.

The modern path is now split cleanly:

The one distinct remaining capability, trusted inbound HTTP continuation, is already isolated in #112991. Porting this older draft would reintroduce a second invocation lifecycle around the canonical run owner and preserve the known abort/error contradiction.

Thanks for establishing the original direction and tests; that work materially informed the landed implementation.

@vincentkoc vincentkoc closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: diagnostics-otel Extension: diagnostics-otel gateway Gateway runtime merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants