Skip to content

fix(review): a group-analysis reply cut at its token cap is rejected, not shown as a checked explanation #876

Closed

Description

@dan-petty

Refreshed plan (2026-10-17, unblocking review)

This section supersedes any text below that conflicts with it.

Decisions

Current references (verified at 3dd7fa6; the refined plan's references below still hold)

Dependencies and order


Ready: implementation plan (refined 2026-10-17 at 3dd7fa6)

This section supersedes any text below that conflicts with it.

Decisions

Delivery

  1. PR 1 (S): check the finish reason before parsing in _execute_single_group_job, and reject a cut reply with reply-truncated. Tests first:

    • with a fake client whose reply is an LLMResponse holding valid but cut JSON and finish_reason="length", the group record is rejected with ["reply-truncated"] and has no output, report.rejections["reply-truncated"] == 1, and the fake client was called exactly once for that group;
    • the same JSON with finish_reason="stop" is verified (control);
    • render_model_analysis_markdown shows the rejection line for the cut group and none of its text.

    Files: src/devops_cli/review/analysis.py, tests/test_review_group_analysis.py. Closes fix(review): a group-analysis reply cut at its token cap is rejected, not shown as a checked explanation #876.

Acceptance criteria

  • A group-analysis reply whose provider reports length is never parsed or shown. Its record is rejected with reply-truncated, and analysis.json's rejections counts it.
  • A cut reply is not retried, so the fake client receives one call per group.
  • A reply with any other finish reason is handled exactly as today.
  • (person-run) The first branch review after the change records on the issue how many groups were rejected as reply-truncated, with the report stage's finish_reasons from profile.json.
  • Tests run offline with a fake client: no network, no model; each test under 1 s.
  • changelog.d/876.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
  • uv run devops ci passes.

Current references

Dependencies and order


Context & Rationale

Once #599 ships, each reply carries its finish reason, and profile.json counts length replies per stage and per backend. The review code does not act on them yet.

  • A persona reply is capped at 8,192 tokens (src/devops_cli/config/defaults.py:386, used at src/devops_cli/ai/review/runner.py:866 and src/devops_cli/ai/review/pipeline.py:928). Verification replies have their own cap (src/devops_cli/ai/review/verification.py:2063).
  • A reply cut inside its last finding still parses, with that finding cut short. At ef21785, a 5-finding reply cut two characters into the last description parsed to 5 findings; the last had the description "de". ReviewResult has no field that marks this.
  • runner.py:872 turns the reply into a plain string, which drops its metadata.
  • Two retries resend the same prompt: a failed segment (runner.py:858-900), and a reply that fails validation (src/devops_cli/ai/client/unified.py:599-612). vibes observations/devops-cli/15-llm-structured-output-repair-and-schema-reconciliation.md:32 records retries hitting the same token ceiling.

Whether any of this matters depends on how often replies are cut, and nobody has measured that yet.

Scope & Deliverables

  • Deliverable:
    • First, measure. If no stage has a length reply in 3 benchmark runs, record the figures on the issue and close it as Not planned.
    • Otherwise:
      • The runner reads finish_reason from the reply before str(res_obj) (runner.py:872).
      • The pipeline sets a new ReviewResult.truncated flag. A model cannot set it: parsing clears it, as _strip_model_set_verification_state does for verification state (src/devops_cli/ai/review_schema.py:1358).
      • On length, the last finding is dropped and the rest are kept.
      • The persona reply's outcome in profile.json is truncated.
      • A length reply is not retried with the same prompt. Its page is split in two with split_review_pages(page, max_chars=len(page) // 2) (src/devops_cli/ai/review/chunker.py:462), and each half is reviewed once.
  • Acceptance criteria:
    • Measurement, run by a person on the homelab gateway. Run uv run devops ai review benchmark src/devops_cli/ai --runs 3 --all. Then run jq '[.stages[] | {name, finish_reasons, truncated}]' on each profile.json it prints. Post the figures on the issue.
    • Unit tests, with a fake client that returns length:
      • truncated is True;
      • the last finding is dropped;
      • an earlier finding that has an empty field is kept;
      • the profile outcome is truncated;
      • the fake client receives two half-page prompts and never the original prompt again.
    • uv run devops ci passes, and the new tests take under 1 s.
  • Key questions:
    • What rate justifies the work? Any non-zero rate across 3 runs (proposed). Even one cut reply leaves one damaged finding.
    • Drop only the last finding? Yes (proposed). Only the last record can be cut. json-repair's log cannot tell whether it was, so the rule goes by position.
    • How many times can a page be re-split? Once (proposed). A half page that is cut again is kept and marked truncated, so the extra cost has a limit.
    • Why not raise the cap instead? Sizing reply budgets stays with feat(ai): gpt-oss reasoning effort for group analysis is measured and set on its gateway deployments #479.
  • Constraint:
    • Truncation comes only from the provider's reason.
    • No finding is dropped because a field is empty.
    • Tests touch no network, cluster or real model.

Strategic Alignment

Split off #599 during the v0.2.25/v0.2.26 readiness review (2026-10-01): This was deliverable (5) of #599's original text, which made it conditional on #599 measuring a non-zero truncation rate. That measurement can only happen after #599 ships, and a person has to run it on the homelab. So it cannot be in the same PR.

Scope added 2026-10-02: the measurement is done, on three branch reviews of release/v0.2.25 rather than the benchmark command. profile.json stages[].finish_reasons for persona review shows length on 2 of 76 dispatched calls in session 20261002-163203, 2 of 81 in 20261002-180320 and 1 of 40 in 20261002-200610. Replayed replies are not counted. The rate is not zero, so under the first key question the work goes ahead. Every cut came from ollama-16gib, which serves gpt-oss:20b (k8s/llm/gateway/configmap.yaml:99-103). The figures show two more things. First, a cut reply can read as a clean file. The release review evaluation ties the two cuts in 20261002-163203 to changelog.d/599.md and src/devops_cli/security/base.py. changelog.d/599.md came back empty, and the next run, which sampled it fresh, raised 4 findings on it. Second, the cut pages were small. The cut calls' prompts were 8,908 to 15,960 tokens, against a minimum of 7,971 across the three sessions. gpt-oss's complete persona replies averaged about 3,100 completion tokens (34 replies), against about 730 for qwen3-coder (158), in the spend ledger. Reasoning fills the cap, not the page, so a half page may be cut again. The once-only re-split bounds that cost, and the budget stays with #479. The cap is now DEFAULT_REVIEW_PERSONA_REPLY_MAX_TOKENS (config/defaults.py:398).

  • A unit test covers a length reply that parses to no findings: its outcome is truncated, not empty, and its page is re-split like any other cut reply.
  • (person-run) The first branch review after the change records on the issue how many re-split halves were cut again.

Activity

  1. added
    type/feature
    scope/review
    priority/p2-medium
    on Oct 1, 2026
  2. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Frozen by the evidence-first review redesign (#1137, owner direction of 2026-10-03): patches to the model generator and verifier stop, and tool-layer fixes continue. This item sits in the persona review stage (cut persona replies and re-chunking), which #1151 deletes together with the legacy engine (#995 lands first as its child).

    It stays open, labelled status/blocked, and closes as not planned with "Superseded by #1151" when that item lands. Do not start work on it.

  3. added
    status/blocked
    on Oct 3, 2026
  4. added this to the v0.2.37 milestone on Oct 17, 2026
  5. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.37: v0.2.37 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  6. removed
    status/blocked
    on Oct 17, 2026
  7. changed the title [-]feat(review): cut persona replies are marked, lose their cut finding and are re-chunked[/-] [+]fix(review): a group-analysis reply cut at its token cap is rejected, not shown as a checked explanation[/+] on Oct 18, 2026
  8. added
    status/in-progress
    on Oct 18, 2026
  9. added and removed
    status/in-progress
    on Oct 18, 2026
  10. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1665, merged into release/v0.2.37 as 66ff3d6.

    When an LLM response is truncated at its token ceiling (finish_reason == CONST_FINISH_REASON_LENGTH), json-repair fallback previously could parse the partial response into an incomplete GroupAnalysisOutput, passing G10 checks and surfacing a truncated explanation in review reports. Group analysis explanation is all-or-nothing and should not be retried with the same prompt.

    • Check finish_reason on the returned LLMResponse prior to parsing in _execute_single_group_job.
    • A cut reply (finish_reason="length") is rejected immediately with reason reply-truncated and output None.
    • Rejection is recorded in AnalysisReport.rejections without retry.
    • Rendered markdown displays the group rejection notice and none of the cut text.
    • Added CONST_ANALYSIS_REJECTION_REPLY_TRUNCATED, CONST_ANALYSIS_REJECTION_SCHEMA_VALIDATION_FAILED, and CONST_ANALYSIS_REJECTION_MODEL_CALL_ERROR in src/devops_cli/config/constants.py.
    • Decomposed rejected record creation into _rejected_group_record helper keeping cyclomatic complexity M <= 4.
    • Added comprehensive offline unit tests with fake client returning LLMResponse in tests/test_review_group_analysis.py.
    • Stripped stale metadata lines from task-983 to satisfy tests/test_agent_task_files.py.
    • Added changelog fragment changelog.d/876.md and task file docs/agent/tasks/task-876-group-analysis-cut-reply-rejected.md.

    Closes #876

    6 file(s) changed.

    How it was verified

    Check runs at bcf5804:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • DevContainer Image: skipping
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Static Analysis: pass
    • Changed-Test Independence: pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-876-group-analysis-cut-reply-rejected.md:

    • A group-analysis reply whose provider reports length is never parsed or shown. Its record is rejected with reply-truncated, and analysis.json's rejections counts it.
    • A cut reply is not retried, so the client receives one call per group.
    • A reply with any other finish reason (e.g. stop) is handled and verified as normal.
    • Pending a person: The first branch review after the change records on the issue how many groups were rejected as reply-truncated, with the report stage's finish_reasons from profile.json.
    • Tests run offline with a fake client returning LLMResponse: no network, no model; each test runs under 1 s.
    • changelog.d/876.md records the change; CHANGELOG.md and docs/ROADMAP.md are not edited.
    • uv run devops ci passes.
  11. added a commit that references this issue on Oct 20, 2026
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/reviewtype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions