Repository navigation
fix(minimald): give a task box's task the request's TRACEPARENT - #3148
Conversation
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>
|
Warning Review limit reached
This review includes 2 billable files and costs up to $0.50.
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. View limit details
|
|
Approved: no findings at Nothing to do. Clobber: none seen in the diff. |
agent-137
left a comment
There was a problem hiding this comment.
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, version00, 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 ownsession.channelspan context re-serialised. It gets that only when the span isrecorded(exec.rs:793). - A malformed value gives
None, and the task gets noTRACEPARENT.
- Opt-out through the helper's exported env (
opted_out(&request.env)) givesMINIMAL_OTEL=offand noTRACEPARENT. - 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 withtask_traceparent(sent, …). Not a finding against this PR.
Verdict: ready to approve. Merge before #3165 (see Conflicts).
agent-137
left a comment
There was a problem hiding this comment.
Approving at c6e42a62b. The earlier comment review found nothing that needs fixing, and its nits are optional.
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>
Fixes the regression found by lab scenario 712b: since #2999, a task run through
min task rungets noTRACEPARENT.The regression
Before #2999,
min task runused the sandboxed task path (ExecRequest::TaskRun->TaskExec). That path builds the task's env withtaskenv::with_trace(client task env, trace_env), so the exec span'sTRACEPARENTwent 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 runhelper:TaskEntrypointBox::startstagesexec.env,TRACEPARENTincluded, for the entrypoint launch. The helper gets it.BoxChannel::run_task(crates/minimald/src/env.rs) builds the task's sandbox withmake_env_with_network(.., Some(&task.vars), ..).task.varsholds only the task's declarations and theinheritvalues from the caller. BCLI-010 ignores undeclared exported variables on purpose, soTRACEPARENTis dropped.TRACEPARENTis used only to parent the daemon'ssession.channelspan. The trace does reach the box: in the failing runs that span has thetask_runspan as its parent and the CLI's trace id. Aminthe 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'sTRACEPARENT, andtaskenv::with_traceis documented as "so aminthe task runs joins the caller's trace".The change
crates/minimald/src/env.rs,crates/minimald/src/exec.rs:channel_request_spanalso returns theTRACEPARENTa task may be given: the request span's own context, and only when that span is recorded (exec::box_traceparent, nowpub(crate); TEL-024).BoxChannel::runpasses it throughhandle_rawtorun_task.run_task_trace(vars, telemetry_on, traceparent, caller_env)addstaskenv::trace_env(..)to the task's vars afterrun_task_vars. The result depends on the case:TRACEPARENT;MINIMAL_OTEL=offand noTRACEPARENT(TEL-045);with_trace, it overrides aTRACEPARENTthe task declares.The task's
TRACEPARENTnames thesession.channelspan (a child oftask_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'sTRACEPARENT, 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 noTRACEPARENT.an_unrecorded_request_span_gives_the_task_no_traceparent: with no exporter, arunrequest yields noTRACEPARENTfor its task, even when the helper sent one.channel_request_spantake the 3-tuple.No unit test covers the wiring from
run_tasktorun_task_trace. Lab scenario 712b covers it: its control task prints theTRACEPARENTit got. 717 (a nestedminin a session exec) is a regression guard here.Follow-up (not in this PR)
TRACEPARENTinstead ofMINIMAL_OTEL=off. The gap predates this change.TRACEPARENT.Verification
min task runper telemetry switch; the control task prints theTRACEPARENTit got) passes on this branch: 712b, 717-otel-nested-min-trace and 000-baseline x1 on ubuntu-24.04 and debian-12, the releaserel-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 noTRACEPARENT. 717 and 000-baseline pass on both sides.In each of the branch's 2 712b runs the control task got a W3C
TRACEPARENT: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-NONEtp=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-NONELab evidence (min-regress batch
fix712bon anvil, debian-12, ubuntu-24.04)Head:
c6e42a62b070122a617aadbbe2021e615b59d8f1at c6e42a6 (lab namecand-712b-task-traceparent-6ed09b70). Base:rel-1e236070(rel-1e236070).minrun inside a session joins the caller's trace (Option A)minrun inside a session joins the caller's trace (Option A)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