Skip to content

fix(ai): shared agents leak memory across reviewed files, openai caps use the wrong token field, and delta metrics arrive out of order #664

Closed

Description

@dan-petty

Summary

Found in the release/v0.2.23 review (line numbers at 7fdaa9d).

  1. Agents keep memory across calls that should be independent. message_history=[] is documented as "sends only the current prompt" (src/devops_cli/ai/agents/pipeline.py:136-137). In practice the agent still:

    • writes every prompt into memory;
    • runs an LLM summarization once memory passes 96k characters;
    • injects a "Prior Interaction & Memory Summary" into the system prompt.

    The references are src/devops_cli/ai/agents/agent.py:629-636, :816-818 and :991-992. The review pipeline reuses cached persona agents across files it reviews concurrently (src/devops_cli/ai/review/pipeline.py:905). After about five pages:

    • every page pays for an extra summarization call over earlier files' code;
    • each file is reviewed with a summary of other files in its prompt;
    • the shared memory list is mutated without a lock.
  2. Reasoning models get the wrong token cap field. The review completion cap always sends max_tokens (8192) to models missing from the reasoning list, such as gpt-5 and gpt-5-mini, and drops a configured reasoning_effort (src/devops_cli/ai/client/openai.py:78-83, :112-116). With provider=openai and model=gpt-5, the API is expected to reject max_tokens and ask for max_completion_tokens (API behaviour unconfirmed). Matching for deepseek-r1 and qwq also changed from substring to prefix, so names like vendor/deepseek-r1 are no longer recognised.

  3. Delta metrics can arrive out of order (unconfirmed). Counters and histograms are exported as 1 ns deltas, one HTTP POST each through a 2-worker pool, under a host-wide service.instance.id (src/devops_cli/telemetry/tracer.py:564-566, :689-692, :982). Parallel LLM calls, or two processes on one host, can deliver points for the same stream out of order. The collector's deltatocumulative processor (k8s/otel/values.yaml:61) drops those points, so request, token and spend totals undercount.

Remediation Plan

  1. When the caller passes message_history=[], skip memory writes, summarization and summary injection. Keep per-run state out of shared cached agents, or give each file its own agent.
  2. Send max_completion_tokens and reasoning_effort for OpenAI reasoning families, matched by family prefix or substring including gpt-5*, and restore substring matching for deepseek-r1 and qwq.
  3. Confirm the metric ordering against a local collector. If it reproduces, give each process a unique service.instance.id and export cumulative temporality, or serialize exports per stream.
  4. Add tests for each change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/aitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions