Persist the delivery -> turn link for managed headless runtimes
From the maintainer reply on #197 (declined turn usage as scoped): "If the missing piece is a reliable link between a CCCC delivery and a provider turn, please open a new issue for that, with what reads it and what it does next. A link like that would need to work across runtimes, and it's a much smaller request."
Checked against ChesterRa/cccc main 8f5b6a791d6484c6ca3f02ee92597313eb2709f5 (v0.4.53); every
file:line below is that commit.
What exists today
runtime.deliveryrecords one delivery attempt per actor:actor_id,source_event_id,delivery_id,state,transport,reason. It has no turn id.crates/cccc-daemon/src/ops/runtime_delivery.rs:56-65(id),:80-87(event data).- Managed headless turn events carry only the provider's turn:
headless.turn.started/.completedgetturn_idandstream_id, nothing about the delivery.crates/cccc-daemon/src/ops/local_headless/output.rs:16-30. - DeepSeek already joins the two: its
headless.turn.startedcarriesevent_id(the delivery's source event), a syntheticturn_id(deepseek:{event_id}:{session_id}:{request_id}),session_idandrequest_id(deepseek_runtime/delivery.rs:168-187); the completed/failed events keepevent_id+turn_id+session_id(deepseek_runtime/delivery_projection.rs:143-163,:165-210). - Web-model / structured turns already carry the accepted batch:
runtime.turn.completedhasactor_id,turn_id,event_ids(the exact accepted delivery batch),statusanddelivery_id(runtime_completion.rs:53-63, kind at:185-188), and the writer checks everyevent_idsentry against aruntime.deliveryinaccepted/ambiguous(runtime_state.rs:776-804). - Managed sessions (Claude, Pi, Codex, OpenCode) build
actor-delivery:{source event ids}and pass it tostart_turn(local_headless/supervisor.rs:537-544,:554). Every adapter puts it on itsturn/startedasrequested_delegation_id: ACPacp/events.rs:346-360; Claudeclaude/transcript.rs:361-382; Pipi_rpc/events.rs:59-64; Codexprotocol.rs:425-437(turn id) and:453-467(delegation); OpenCodeopencode/v2/events.rs:73,195. The actor projection then drops it:local_headless/managed_reader.rs:38passes onlyevent.message, soAnalystEvent.requested_delegation_id(codex_voice_analyst.rs:136-141) never reaches the event data.
So the concept and most of the plumbing exist. What is missing is that the link is persisted
consistently: DeepSeek and runtime.turn.completed write it, the four managed adapters observe it
and throw it away.
Ask
Persist that link for managed headless runtimes (Claude, Pi, Codex, OpenCode), the way DeepSeek and
runtime.turn.completed already do. The smallest shape I can see is to have the shared managed
projection write the delivery ids it already holds onto headless.turn.started / .completed,
plus the runtime's own turn handle where one exists:
event_ids: the delivery events this turn was started for, same meaning asruntime.turn.completed.event_ids;delivery_idis already recomputable fromsource_event_id+ actor.runtime_turn_ref: the runtime's own id where it has one. Claude session id (+ prompt uuid), Pi turn id, and for Codex the app-server turn id CCCC already observes (protocol.rs:425-437) — not a rollout path. Null where the runtime has none; unknown stays null.- PTY: a delivery is a terminal write (
actor_delivery_worker.rs:827-840), its outcome becomesruntime.delivery(actor_delivery/drain.rs:30-46), and there is no turn boundary to name. The write time is the delivery event's timestamp and the turn handle stays null. Output and quiet time do not establish turn state: #178 (closed unmerged) and #146 draw that line explicitly, and I am not asking to cross it.
No counters, no pricing, no totals: the link only names the turn, so it means the same thing on
every runtime. Additive fields only; nothing in runtime.delivery needs to change.
What reads it
An operator report that already reads provider usage from the runtime's own logs, and now attributes each turn to the delivery, and through the sender's own task reference to the task. What it does next: a per-task cost line in that report; the report owns the arithmetic (per-message de-duplication, subagent transcripts), CCCC does not.
Test env
Source reading only, at the commit named above; no runtime change is proposed or tested yet.
Thanks for narrowing this the way the reply on #197 suggested, and for the source references.
We read it as two parts. The first is recording which CCCC messages a managed turn was started for, using CCCC's own event ids. The second is a runtime-native turn reference per provider. We are not planning to take the second: it differs per runtime, stays empty on some, and would have to be verified and maintained against each provider's releases.
The first part is closer to something CCCC could keep, but we are not committing to it yet. Today nothing in CCCC reads that link, and its meaning needs to be settled before it is persisted: several queued messages in one turn, input that arrives while a turn is running, turns that no delivery started. A link also cannot split one turn's cost between two tasks delivered together.
Two things would help us decide:
- Whether the existing information already helps your report. Each delivered message carries its source id in its header (
[event_id=...]). If the provider records that input, the header may offer a starting point; we haven't checked whether this gives your report a reliable join. - If it does not, one concrete case: the inputs, the link you expect, and how the report uses it.
This is not a request for a full PR at this stage.
Understood. I'll drop provider-native turn references from this proposal and check the existing source-event headers first. We have not yet established that they are insufficient in a concrete recorded-input case. I'll return with either a usable join and its limits, or one real failing case showing the inputs, expected association and report use. A message-to-turn link would not, by itself, allocate a coalesced turn's cost between tasks. I will not prepare a full persistence PR before that question is settled.