Skip to content

fix(roadmap): the log omits the text of schema violations #4269

Closed

Description

@dan-petty

Problem

On 2026-11-09 the log lines of the stage job of the roadmap Service show StructuredOutputValidationError: N schema violation(s), with N from 0 to 9. They give no text of the violations: no loc, no type, no message. The cause stays hidden.

This hid two real faults for one day. The null reference reason (#4214) and the cut at 4096 output tokens (#4220) both showed as 0 schema violation(s). The same line hid the joined tool call arguments of #4228.

Where the text is lost:

  • RunTrace._add_violations in src/devops_cli/roadmap/agent_run.py (about line 292) keeps only the count of the retry prompt. It counts only a retry prompt whose content is a list, and it drops the list.
  • _stopped in src/devops_cli/roadmap/stage/stage_toolbox.py raises StructuredOutputValidationError(message, violations=trace.violations). The error holds a number and no text.
  • _failure_of in src/devops_cli/roadmap/stage/stage.py (about line 1597) writes only MESSAGES.roadmap.stage_violations.format(count=...) into the StageFailure.

#4260 (merged) keeps a refused reply that failed the gates (<n>.refused.json). A reply that fails the schema never reaches the gates, so nothing is kept for it. #4204 names this in its scope: a schema violation is out of that delivery.

Expected

  1. The failure line and the log name, for a run that ended on a schema failure:
    • the first violations: at most 3, each with loc, type and a message cut at 200 characters;
    • the stop reason: length, no tool call, invalid arguments or validation;
    • the count.
  2. The text holds no reply text that could hold a secret. Each message passes through the masking helper of the project (mask_secrets in src/devops_cli/security/sanitizer.py).
  3. The file <n>.refused.json of fix(roadmap): keep refused stage replies, stop placeholder replies #4260 also records a schema failure, with the same fields.

Acceptance criteria

  1. A unit test runs a stage plan that fails validation with two violations, one with loc references.0.reason. It asserts that the text of the StageFailure contains references.0.reason and the error type. Today the text holds only the count, so the test fails.
  2. A unit test runs a plan that the provider stops by length. It asserts that the failure text names the length reason. (Run: uv run pytest tests/<stage test file> -k violation.)
  3. A unit test gives 5 violations and asserts that the text names 3 of them and the count 5, and that a message of 300 characters is cut at 200.
  4. A unit test gives a violation message that holds a token-shaped secret and asserts that the failure text and the kept file hold the masked value.
  5. A unit test asserts that a schema failure writes <n>.refused.json with the same fields, and that the staging of the item deletes the file as for a gate refusal.

Existing tool considered

The pydantic ValidationError.errors() and the retry prompt of pydantic-ai already carry loc, type and msg for each violation. The change only keeps these fields instead of their count, and it uses the existing masking helper. No new library and no hand-made parser are needed.

Cost

  • Build: small. About 3 files change (agent_run.py, stage_toolbox.py, stage.py) plus message text and tests. About 30,000 tokens and 1 to 2 hours.
  • Keep: low. The fields come from the library types, so a library change shows in the tests.
  • Fix: the cost of not building it is higher. Each hidden fault cost a day of failed stage rounds, and found only by reading gateway logs by hand.

Related

#4204, #4214, #4220, #4228, #4260.

Proposed design

Problem statement

A stage run that ends on a schema failure logs only StructuredOutputValidationError: N schema violation(s). The log has no loc, no type, no message and no stop reason. This hid the faults of #4214, #4220 and #4228 for one day. The run trace keeps only the count, the error carries only the count, and the failure text holds only the count. A reply that fails the schema leaves no kept file.

Acceptance criteria

Requirement: Failure text names the violations

The text of a StageFailure for a run that ends on a schema failure SHALL name the loc, the type and the message of each kept violation, and the error class.

Scenario: Plan fails validation with two violations

  • WHEN A stage plan run fails validation with two violations, and one has loc references.0.reason
  • THEN The reason of the StageFailure contains references.0.reason, the violation type and StructuredOutputValidationError

Requirement: Failure text names the stop reason

The failure text of a stage run that ends with no reply SHALL name the stop reason: length, no tool call, invalid arguments or validation.

Scenario: Provider stops the plan by length

  • WHEN The provider stops a plan run by length (uv run pytest tests/roadmap/stage -k violation)
  • THEN The failure text names the length reason

Requirement: Violations are bounded

The failure text SHALL name at most 3 violations, SHALL give the full count, and SHALL cut each message at 200 characters.

Scenario: Five violations and a long message

  • WHEN A run gives 5 violations, and one message has 300 characters
  • THEN The text names 3 violations and the count 5, and the long message ends at 200 characters

Requirement: Violation text is masked

Each loc and each message in the failure text and in the kept file MUST pass through mask_secrets before the job keeps or logs it.

Scenario: Message holds a token-shaped secret

  • WHEN A violation message holds a token-shaped secret
  • THEN The failure text and the kept file hold the masked value and not the secret

Requirement: The input of a violation is never kept

The job MUST NOT keep the input or the ctx of a violation in the trace, the error, the failure text or the file.

Scenario: Violation carries the reply value as input

  • WHEN A violation has an input value that holds the text of the reply
  • THEN No kept field and no failure text holds that value

Requirement: Schema failure writes the refused file

A schema failure of a stage plan SHALL write <n>.refused.json with the same fields as the failure text, and the staging of the item SHALL delete the file as it does for a gate refusal.

Scenario: Schema failure then staging

  • WHEN A plan run fails the schema, and later a rerun stages the item
  • THEN The failed run leaves <n>.refused.json with the stop reason, up to 3 violations and the count, and the staging deletes it

Existing Tool Considered

Pydantic ValidationError.errors() and the retry prompt of pydantic-ai (RetryPromptPart.content) already carry loc, type and msg for each violation. The project helper mask_secrets in src/devops_cli/security/sanitizer.py already masks text. No new library is needed. The change keeps these fields in place of their count and builds no parser. Cost to build: about 30,000 tokens and 1 to 2 hours. Cost to keep: low, as the fields come from library types. No alternatives check has run for this item.

Key questions

  • Where does the text of the violations exist today, and where is it lost?: The retry prompt of the output tool holds the violations in a list in RetryPromptPart.content. RunTrace._add_violations in src/devops_cli/roadmap/agent_run.py stores only the length of that list. _stopped in stage_toolbox.py passes only the count to the error, and _failure_of in stage.py formats only the count. [sources: src/devops_cli/roadmap/agent_run.py, src/devops_cli/roadmap/stage/stage_toolbox.py, src/devops_cli/roadmap/stage/stage.py]
  • An earlier change kept the field path out of the error, because a path can be a key that the model invented. Does the new text break that rule?: Keep loc, as the issue asks, but treat it as model text. Pass each loc and message through mask_secrets and cut each at 200 characters. Never keep the input or the ctx of a violation. The issue outranks the earlier rule because the hidden cause cost a day of failed rounds. (best practice) [sources: openspec/changes/archive/2026-10-30-2772-stage-group-files/proposal.md, src/devops_cli/security/sanitizer.py]
    • Rejected: Keep the count only. This hid three faults for one day.
    • Chosen: Keep loc, type and message, masked and cut. It gives the cause, and the masking helper covers the secret risk.
    • Rejected: Keep type and message, drop loc. The path is the most useful field to find a schema fault such as references.0.reason.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/low
    on Nov 9, 2026
  2. dan-petty commented on Nov 9, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It hid real faults for a full day but does not block delivery or expose a security risk.
    • Value: Medium. It cuts debug time from reading gateway logs by hand to reading one log line, but does not change user-facing behaviour.
    • Effort: Low. Three files change, the fields come from existing library types, and the candidate estimates 1 to 2 hours.
    • Related: feat(cli): lossless structured error reflection for schema retries #437, which asks for a different change. Both preserve schema violation details, but #437 targets the model retry prompt while the candidate targets the human-facing log line and StageFailure text.
  3. added
    priority/p2-medium
    owner/agent
    on Nov 9, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 9, 2026
  5. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at cefc184 (see proposed design in issue body).

  6. added
    status/in-review
    and removed
    status/ready
    on Nov 9, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 9, 2026
  8. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-09 21:51 UTC

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

    effort/lowpriority/p2-mediumscope/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions