Cleanup pass on the events schema v2 work merged from origin/main.
Quality fixes:
- prompt.rs: drop dead `_visit` local; use stage_scope.visit at the
emit site (the value was being recomputed inline next to a scope
that already had it).
- llm/cli.rs: rename `_context` to `context` in CodergenBackend::run
(it's actually used now); delete the lingering `current_visit`
helper that was deleted from llm/api.rs in c6a78a428 but missed
here; use stage_scope.visit at the emit site.
- llm/api.rs: rename `event_scope` to `stage_scope` for consistency
with every other handler.
- agent.rs, fan_in.rs, parallel.rs: same `visit_from_context` →
`stage_scope.visit` substitution at every event-emit site.
- parallel.rs: switch ParallelStarted/ParallelCompleted from `emit`
to `emit_scoped` so they carry stage_id in the envelope.
- event.rs: fix the StageScope::for_handler docstring — the lifecycle
hook is `before_node`, not `before_attempt`.
Reuse fixes:
- run_event/mod.rs: add `ActorRef::agent(session_id, display)` symmetric
with the existing `ActorRef::user`; use it from agent_actor_for_event
in workflow event.rs.
Correctness fixes:
- event.rs: introduce `StageScope::for_parallel_branch` to name the
"branch starts at visit 1" invariant the parallel handler was
hardcoding via a struct literal at parallel.rs:307. This makes
the assumption auditable and gives a single place to fix when
parallel nodes ever loop.
Efficiency fixes:
- stage_id.rs: switch StageId/ParallelBranchId Serialize impls from
`serializer.serialize_str(&self.to_string())` to `collect_str(self)`,
removing one transient String allocation per ID per emitted event.
Hardening:
- event.rs: add `#[must_use]` on `to_run_event`, `to_run_event_at`,
and `event_name`.
- store/types.rs: add a second wire-envelope round-trip test that
populates stage_id, parallel_group_id, parallel_branch_id,
session_id, parent_session_id, tool_call_id, and actor — the
existing test only exercised stage_id, so a regression in any of
the other envelope fields' #[serde(flatten)] interaction would
have been silent.
All 3810 workspace tests pass; clippy and fmt clean.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>