Skip to content

feat(roadmap): output truncation and secret masking for planner run tool #4006

Closed

Description

@dan-petty

Problem or Motivation

A command executed in the sandbox can produce excessive output that exceeds the LLM context window or inadvertently output sensitive strings. As required by ADR 0018 (docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, #3242), output returned to the planner must be capped and sanitized.

Proposed Solution & Architectural Design

Implement output truncation and secret sanitization for the planner run tool:

  1. Truncate command output to a maximum of 8 KiB and 120 lines.
  2. When output is truncated, append an explanatory line that names the omitted byte and line count.
  3. Run mask_secrets from src/devops_cli/security/sanitizer.py over all stdout and stderr streams.
  4. Format the final sanitized and truncated output so the planner can quote it directly into the ## Feasibility section of the proposal.

Depends on: #3242 (ADR 0018).

Target Subsystem

AI & Agentic Review Pipeline

Existing Tool Considered

src/devops_cli/security/sanitizer.py:mask_secrets already provides audited secret scrubbing for CLI and agent output. Standard Python string slicing handles truncation. Building this formatter costs approximately 6,000 tokens and 0.25 elapsed days.

Proposed design

Problem statement

A command that the planner runs can print more text than the plan's token budget holds. It can also print a credential. ADR 0018 requires the run tool to cap the text at 8 KiB and 120 lines and to mask secrets. This item adds the cap, the trailer line that names the omitted counts, and the mask_secrets call.

Acceptance criteria

Requirement: Output cap

The run tool SHALL return at most 8192 bytes and at most 120 lines of text for one run, the trailer line included.

Scenario: Long output is cut

  • WHEN A command writes 20000 bytes over 400 lines.
  • THEN The returned text holds at most 8192 UTF-8 bytes and at most 120 lines.

Requirement: Trailer names the omitted counts

The returned text MUST end with one trailer line that states the omitted byte count and the omitted line count when the cut leaves text out.

Scenario: The cut leaves text out

  • WHEN A command writes 20000 bytes over 400 lines.
  • THEN The last line matches ^\[truncated: \d+ bytes and \d+ lines omitted\]$, and the kept body plus the omitted counts equal the input counts.

Requirement: No trailer for a short output

The run tool MUST return the text with no trailer line when the text fits within both caps.

Scenario: Short output is kept whole

  • WHEN A command writes 200 bytes over 3 lines.
  • THEN The returned text equals the masked input and holds no [truncated: line.

Requirement: Secret masking

The run tool MUST pass every returned text through mask_secrets of src/devops_cli/security/sanitizer.py before the planner reads it.

Scenario: A command prints a token on stderr

  • WHEN A command writes GITHUB_TOKEN=ghp_ and 36 further characters to stderr.
  • THEN The returned text holds <masked-github-token> and the 36 characters after the prefix are absent.

Requirement: Masking precedes the cut

The run tool SHALL mask the text before it cuts the text.

Scenario: The cap falls inside a private key block

  • WHEN A command writes a PEM private key whose end marker sits after byte 8192.
  • THEN The returned text holds <masked-private-key> and holds no line of the key body and no PRIVATE KEY marker.

Requirement: Feasibility quote block

The run tool SHALL format the masked text as a fenced code block that holds the command line, the exit code and the text.

Scenario: The planner quotes a failed run

  • WHEN The command devops k8s get pods exits 1 and writes 3 lines.
  • THEN The block opens with a fence longer than any backtick run in the text, holds the command line and exit 1, and closes with a fence of the same length.

Existing Tool Considered

No alternatives check has run. mask_secrets in src/devops_cli/security/sanitizer.py covers the masking need, and tests/security/test_secret_redaction.py tests it. It lacks a cap, because no function there truncates text. Python slicing covers the cap at no library cost. The body states a cost of about 6,000 tokens and 0.25 elapsed days to build the formatter.

Key questions

  • Which module holds the output cap, the trailer and the mask call?: Add src/devops_cli/roadmap/run_output.py. It holds the cap, the trailer and the mask_secrets call, and one test module covers it. The sanitizer stays unchanged, and the stage adapter calls the new function. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, src/devops_cli/security/sanitizer.py, src/devops_cli/roadmap/run.py]
    • Chosen: New module src/devops_cli/roadmap/run_output.py. The run tool is a roadmap feature, and one module with one test module keeps the concern in one place.
    • Rejected: Extend src/devops_cli/security/sanitizer.py. The sanitizer masks text for 84 caller paths and knows no cap.
    • Rejected: Extend src/devops_cli/roadmap/run.py. That module runs the stage row in the Service pod, and the cap needs no process.
  • In which order does the code mask and cut?: Mask first, then cut. The private-key pattern runs from the BEGIN line to the END line, so a cut before the END line leaves key material that no pattern masks. (best practice) [sources: src/devops_cli/security/sanitizer.py, docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: Mask, then cut. The mask sees the whole key block and replaces it before the cut.
    • Rejected: Cut, then mask. A cut inside a key block defeats the pattern that needs the END line.
  • Does the cap count the trailer line and its bytes?: The cap covers the trailer. The returned text holds at most 8192 bytes and 120 lines in all, the trailer line included, as ADR 0018 states. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: The cap covers the trailer line. ADR 0018 states that the text holds at most 8 KiB and 120 lines and ends with the trailer.
    • Rejected: The trailer line is outside the cap. The returned text would exceed the stated cap by one line.
  • How does the code measure bytes and place the cut?: Measure bytes with the UTF-8 encoding of the text and cut only at a line boundary. Keep the first lines. A cut at a line boundary never splits a character. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: Line boundary, UTF-8 bytes. A line boundary keeps every character whole and matches the first lines that ADR 0018 keeps.
    • Rejected: Byte offset. It can split a UTF-8 character and a line.
  • Which syntax does the masking call use?: Call mask_secrets(text) with the default syntax="data". Command output is terminal text and not code under review, so every credential-shaped value must be masked. (best practice) [sources: src/devops_cli/security/sanitizer.py]
    • Chosen: syntax="data". The code mode leaves an unquoted code expression as written, and a token can look like one.
    • Rejected: syntax="code". It leaves a value such as a token read from the environment unmasked.
  • What does the trailer line say?: Use [truncated: N bytes and M lines omitted] as the last line. N counts the input bytes that the body does not hold, and M counts the lines in the same way. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: [truncated: N bytes and M lines omitted]. One ASCII line names both counts, as ADR 0018 requires.
    • Rejected: A prose sentence. It costs more of the cap and names no count that a test reads.
  • How does the quote block look under ## Feasibility?: Open the block with a fence of backticks one longer than the longest backtick run in the text, and never fewer than three. Then write $ <command line>, then exit <code> or the signal name, then the text, then a closing fence of the same length. (best practice) [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md]
    • Chosen: Fence longer than the longest run in the text. CommonMark closes a block at a fence of the same length or longer, so a longer fence keeps the output inside.
    • Rejected: A fixed three-backtick fence. A line of three backticks in the output closes the block early.
  • Which outside work does this item wait on?: None beyond docs(security): design a sandboxed read-only run tool for the planner #3242, whose ADR is on the default branch at this commit. The cap and the mask are pure text functions, so they need no run Job. [sources: docs/adr/0018-a-sandboxed-read-only-run-tool-for-the-planner.md, src/devops_cli/security/sanitizer.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#3242

Alternatives check of 2026-11-09: none.
Tool: none found.

Activity

  1. added
    type/feature
    source/agent
    scope/roadmap
    on Nov 7, 2026
  2. added
    status/new
    value/high
    effort/low
    on Nov 7, 2026
  3. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

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

    • Priority: P2-Medium. ADR 0018 requires the change for safety, but it is a sub-task of an open design item and not a live defect.
    • Value: High. The change stops context overflow and stops secret leaks in planner output.
    • Effort: Low. The change reuses the audited mask_secrets function and simple string slicing, at about 0.25 days.
    • Related: docs(security): design a sandboxed read-only run tool for the planner #3242, which asks for a different change. The candidate implements the output limits that ADR 0018 requires, but the ADR only designs the run tool and adds no code.
  4. added
    priority/p2-medium
    status/ready
    and removed
    status/new
    on Nov 7, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

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

  6. devops-cli-service commented on Nov 9, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Two searches found no open library that caps text by bytes and lines, appends a trailer with the omitted counts, masks secrets before the cut, and builds a fenced Feasibility block. The results were unrelated MDN pages. The repository's own mask_secrets already covers the masking, and Python slicing covers the cap. The new run_output.py glue is small and specific to this project's format.

    Tool: none found

    Covers:

    • Masking is already covered in-repo by mask_secrets in src/devops_cli/security/sanitizer.py

    Lacks:

    • No external tool found for the 8 KiB and 120-line cap with the omitted-count trailer
    • No external tool found for the fenced Feasibility quote block with the command line and exit code

    Searches run:

    • python library truncate command output by bytes and lines with truncation trailer and mask secrets, results: 5
    • detect-secrets OR truncate-output library redact secrets from subprocess output for LLM agent, results: 5

    Checked on 2026-11-09. A person decides what this means for the item. The check changes no label and closes no issue.

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

    @devops-cli-service
    Contributor
  10. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-15 00:23 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/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions