Skip to content

[Correctness] Use context-local session attribution for process telemetry #22

@mark-e-deyoung

Description

@mark-e-deyoung

Problem

api/utils/process.py emits command-substrate telemetry by reading WINEBOT_SESSION_DIR from process environment. In concurrent request/task flows, env-based attribution can drift and write metrics to the wrong session artifact path.

Why this matters

  • Misattributed telemetry reduces trust in per-session diagnostics and performance analysis.
  • Race-prone attribution can hide regressions or create false positives in automation traces.

Proposed fix

  1. Introduce request/task-scoped session context using contextvars.ContextVar (for example, current_session_dir).
  2. Set and reset context explicitly at API and session lifecycle boundaries.
  3. Update process telemetry path resolution to prefer contextvar over env fallback.
  4. Add regression tests covering concurrent operations with different session IDs to verify no cross-session bleed.

Acceptance criteria

  • Command telemetry events are attributed to active request/session context under concurrency.
  • Existing behavior remains backward compatible when no context is set.
  • Tests fail without the fix and pass with it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions