Skip to content

fix(minimald): give a task box's task the request's TRACEPARENT - #3148

Merged
bryan-minimal merged 1 commit into
mainfrom
fix/712b-task-traceparent
Nov 10, 2026
Merged

bryan-minimal merged 1 commit into
mainfrom
fix/712b-task-traceparent

Conversation

@bryan-minimal

Copy link
Copy Markdown
Member

Fixes the regression found by lab scenario 712b: since #2999, a task run through min task run gets no TRACEPARENT.

The regression

Before #2999, min task run used the sandboxed task path (ExecRequest::TaskRun -> TaskExec). That path builds the task's env with taskenv::with_trace(client task env, trace_env), so the exec span's TRACEPARENT went straight into the task's env (TEL-023).

Since #2999, a task with a spec runs as its task box's entrypoint, and that entrypoint is the in-box min task run helper:

  • TaskEntrypointBox::start stages exec.env, TRACEPARENT included, for the entrypoint launch. The helper gets it.
  • The helper asks the box channel to run the task. BoxChannel::run_task (crates/minimald/src/env.rs) builds the task's sandbox with make_env_with_network(.., Some(&task.vars), ..).
  • task.vars holds only the task's declarations and the inherit values from the caller. BCLI-010 ignores undeclared exported variables on purpose, so TRACEPARENT is dropped.
  • The helper's TRACEPARENT is used only to parent the daemon's session.channel span. The trace does reach the box: in the failing runs that span has the task_run span as its parent and the CLI's trace id. A min the task runs, though, starts a trace of its own.

The loss was not by design. #2999 says nothing about traces. TEL-023 (docs/specs/25-spec-telemetry) still says a run in a box gets the exec span's TRACEPARENT, and taskenv::with_trace is documented as "so a min the task runs joins the caller's trace".

The change

crates/minimald/src/env.rs, crates/minimald/src/exec.rs:

  • channel_request_span also returns the TRACEPARENT a task may be given: the request span's own context, and only when that span is recorded (exec::box_traceparent, now pub(crate); TEL-024).
  • BoxChannel::run passes it through handle_raw to run_task.
  • A new run_task_trace(vars, telemetry_on, traceparent, caller_env) adds taskenv::trace_env(..) to the task's vars after run_task_vars. The result depends on the case:
    • telemetry on: TRACEPARENT;
    • the helper's exported env carries the opt-out marker: MINIMAL_OTEL=off and no TRACEPARENT (TEL-045);
    • telemetry off: nothing.
  • Like with_trace, it overrides a TRACEPARENT the task declares.

The task's TRACEPARENT names the session.channel span (a child of task_run, which is a child of the CLI's span), not the exec span, so the task's work hangs under the span that served it.

Tests

  • an_in_box_task_run_gives_the_task_the_request_traceparent: the task gets the request span's TRACEPARENT, not the exec's, in place of the one it declares, and keeps its other variables. Telemetry off, or no recorded span, adds nothing. An opted-out helper's task gets the opt-out marker and no TRACEPARENT.
  • an_unrecorded_request_span_gives_the_task_no_traceparent: with no exporter, a run request yields no TRACEPARENT for its task, even when the helper sent one.
  • The existing callers of channel_request_span take the 3-tuple.

No unit test covers the wiring from run_task to run_task_trace. Lab scenario 712b covers it: its control task prints the TRACEPARENT it got. 717 (a nested min in a session exec) is a regression guard here.

Follow-up (not in this PR)

  • TEL-045: opt-out detection reads only the request's env. A helper that opted out sends no trace prefix, so the daemon mints a recorded root, and the task now gets that root's TRACEPARENT instead of MINIMAL_OTEL=off. The gap predates this change.
  • The fix applies where the daemon serving the box channel is the exporting one (local minimald). Under a VM provider whose guest daemon does not export, the task still gets no TRACEPARENT.

Verification

  • prepush (CI's exact commands): green at c6e42a6
  • Lab scenario 712b (a min task run per telemetry switch; the control task prints the TRACEPARENT it got) passes on this branch: 712b, 717-otel-nested-min-trace and 000-baseline x1 on ubuntu-24.04 and debian-12, the release rel-1e236070 (which has T43 — Run a task as a task box that returns its exit code #2999) vs a build of this branch (cand-712b-task-traceparent-6ed09b70). 712b on the release: {'env-fail': 1}; it reports ENV when the control task gets no TRACEPARENT. 717 and 000-baseline pass on both sides.
scenario release this branch
000-baseline {'pass': 1} {'pass': 1}
712b-otel-switch-precedence {'env-fail': 1} {'pass': 1}
717-otel-nested-min-trace {'pass': 1} {'pass': 1}
000-baseline {'pass': 1} {'pass': 1}
712b-otel-switch-precedence {'env-fail': 1} {'pass': 1}
717-otel-nested-min-trace {'pass': 1} {'pass': 1}

In each of the branch's 2 712b runs the control task got a W3C TRACEPARENT:

  • ubuntu-24.04: control task tp=00-26eac0f77775ea702360f877f14bc736-b1bdbff13af8208a-01; sdk_true_files=0 sdk_true_threads=0 sdk_true_conns=0 sdk_true_spans=0 sdk_true_logs=0 sdk_true_tp=TP-NONE sdk1_spans=55 logs_only_logs=74 logs_only_spans=0 logs_only_tp=TP-NONE
  • debian-12: control task tp=00-a3c71cd3883790ae3d8c72f123757625-99e022de9055aede-01; sdk_true_files=0 sdk_true_threads=0 sdk_true_conns=0 sdk_true_spans=0 sdk_true_logs=0 sdk_true_tp=TP-NONE sdk1_spans=55 logs_only_logs=74 logs_only_spans=0 logs_only_tp=TP-NONE

Lab evidence (min-regress batch fix712b on anvil, debian-12, ubuntu-24.04)

Head: c6e42a62b070122a617aadbbe2021e615b59d8f1 at c6e42a6 (lab name cand-712b-task-traceparent-6ed09b70). Base: rel-1e236070 (rel-1e236070).

scenario distro base head
000-baseline: baseline (CPU + install sanity; not a bug) debian-12 pass pass
000-baseline: baseline (CPU + install sanity; not a bug) ubuntu-24.04 pass pass
712b-otel-switch-precedence: gominimal/inbox#515 Story 3: the switch precedence (OTEL_SDK_DISABLED, per-signal exporters) the off-test never reached debian-12 env-fail pass
712b-otel-switch-precedence: gominimal/inbox#515 Story 3: the switch precedence (OTEL_SDK_DISABLED, per-signal exporters) the off-test never reached ubuntu-24.04 env-fail pass
717-otel-nested-min-trace: gominimal/inbox#515: a min run inside a session joins the caller's trace (Option A) debian-12 pass pass
717-otel-nested-min-trace: gominimal/inbox#515: a min run inside a session joins the caller's trace (Option A) ubuntu-24.04 pass pass

Fixed since base: 0. Still reproducing on both: 0. Regressed: 0. Passing on both: 4. Inconclusive cells (an environment or setup failure on a side, not counted): 2. A verdict links to the run's trace in Cloud Trace (project access needed); the scenario link is its source with the # issue: it reproduces.

🤖 Generated with Claude Code

Since T43 (#2999) min task run starts the task as its box's entrypoint,
the in-box min task run. The exec's TRACEPARENT reaches that helper and
rides its run request as the trace prefix, but the channel built the
task's sandbox from the task's own variables, so the task got no
TRACEPARENT and a min it ran started a trace of its own (TEL-023).

The channel now adds the trace variables to the task's, as the sandboxed
task path does: the request span's TRACEPARENT when that span is
recorded (TEL-024), the opt-out marker for a helper that opted out
(TEL-045), and nothing with telemetry off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bryan-minimal
bryan-minimal requested a review from a team as a code owner November 7, 2026 17:45
@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 2 billable files and costs up to $0.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 57 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 671278e0-2217-4076-abab-c1824773e63e
Commits

Reviewing files that changed from the base of the PR and between c54e368 and c6e42a6.

Files selected for processing: 2

  • crates/minimald/src/env.rs
  • crates/minimald/src/exec.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@minimal-foundry

minimal-foundry Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Approved: no findings at c6e42a62b070.

Nothing to do.

Clobber: none seen in the diff.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimal-review — advisory review

Verdict COMMENT — No findings.

Panel: 2 of 3 personas ran (correctness, security); did not complete: supply-chain.

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Nov 7, 2026

@agent-137 agent-137 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review on Karl's behalf, at c6e42a62b. This is a comment, not an approval. Nothing was built for it: every point comes from reading the code, and each finding says how it was checked.

  • CI at c6e42a62: all green.
  • Reviews: minimal-review COMMENT at head, with no findings and the supply-chain persona not completed. CodeRabbit is rate-limited, so there is no review on head.

Should-fix: none.

Nit: none.

No findings. What I checked (TRACEPARENT validation):

  • The client-supplied TRACEPARENT is validated, not passed through raw.
    • The helper gates it with a 55-character W3C regex.
    • The daemon parses it with TraceContext::parse_traceparent. That parser is strict: exact length, version 00, lowercase hex only, all-zero trace id and span id rejected, flags masked (crates/minimald-rpc/src/trace.rs:161-181).
    • The task never gets the client's string. It gets box_traceparent(&adopted) = adopted.ctx.traceparent(), which is the daemon's own session.channel span context re-serialised. It gets that only when the span is recorded (exec.rs:793).
    • A malformed value gives None, and the task gets no TRACEPARENT.
  • Opt-out through the helper's exported env (opted_out(&request.env)) gives MINIMAL_OTEL=off and no TRACEPARENT.
  • Known gap: the Line-form or bare-request case hands the task the daemon-minted root's TRACEPARENT. The PR states this as a follow-up, and #3165 fixes it with task_traceparent(sent, …). Not a finding against this PR.

Verdict: ready to approve. Merge before #3165 (see Conflicts).

@agent-137 agent-137 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at c6e42a62b. The earlier comment review found nothing that needs fixing, and its nits are optional.

@bryan-minimal
bryan-minimal added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 59c5552 Nov 10, 2026
36 checks passed
@bryan-minimal
bryan-minimal deleted the fix/712b-task-traceparent branch November 10, 2026 01:01
bryan-minimal added a commit that referenced this pull request Nov 10, 2026
Main took #3148's shape of the channel request's task trace (an
`Option<String>` for the request span's context); this branch's
`TaskTrace` carries that and the opt-out, so every conflicting site
keeps the branch's shape and main's call sites take it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants