Skip to content

fix(workflows): enforce text projection line bounds - #331

Merged
tt-a1i merged 1 commit into
openpi-dev:mainfrom
JuiXiang:fix/issue-329-workflow-text-projection
Sep 1, 2026
Merged

tt-a1i merged 1 commit into
openpi-dev:mainfrom
JuiXiang:fix/issue-329-workflow-text-projection

Conversation

@JuiXiang

@JuiXiang JuiXiang commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #329.

projectText() detects overflow with both maxBytes and maxLines, but the existing head/tail projection only applies byte limits. Its final validation also checks only the byte count.

A 40-line, 149-byte input projected with maxLines: 3 and maxBytes: 2048 therefore produces 85 lines and duplicates the complete input around the omission marker. The footer reports showing 298 B of 149 B, confirming that the selected head and tail overlap.

This affects bounded Workflow result messages, completion batches, handoffs, and operator-facing completion reports.

Value

This change makes the { maxBytes, maxLines } contract dependable. A caller that allocates 400 lines can treat that value as a hard upper bound rather than a hint that is checked once and then lost during projection. The byte limit cannot replace the line limit: logs, file lists, and compact records can contain hundreds of short lines while remaining well below their byte budget.

For model-facing Workflow results, enforcing both limits keeps projected output within the context shape selected by the caller. The current bug can turn a small line-only overflow into a larger result by including the same source text as both the head and the tail. Removing that overlap avoids spending context on duplicate evidence and leaves the available projection budget for distinct information from the beginning and end of the result.

This also improves the quality of the evidence presented to the model. Repeating the same conclusion or error text can give it disproportionate weight during synthesis, even though the repetition was introduced by the projection layer rather than the Workflow itself. A non-overlapping head/tail projection preserves more of the source's actual coverage and does not manufacture repetition.

The same helper is used for parent-model result delivery, background completion batches, downstream handoffs, and expanded operator reports. Fixing the shared projection contract gives those paths consistent behavior without adding separate truncation rules to each Workflow surface.

Finally, projection diagnostics become internally consistent. A footer such as showing 298 B of 149 B is impossible when the selected source ranges do not overlap, and the reported bounds once again describe the text that was actually returned.

The change is limited to derived projections. Workflow execution, canonical results, persisted audit artifacts, and configured production limits are unchanged. Content that already fits both limits still passes through byte-for-byte, while the exact source remains recoverable from the existing artifacts when projection is required.

Approach

  • Apply both byte and line budgets when selecting the projected head and tail.
  • Preserve the existing 75/25 head-to-tail allocation.
  • Include omission markers, separator lines, the footer, and multi-line recovery text in the line budget.
  • Use a compact, visibly omitted representation when the line budget cannot fit the normal framed projection.
  • Validate the completed projection against both limits before returning it.
  • Preserve byte-for-byte passthrough for input that already fits both limits.
  • Add regression coverage for line-only overflow, small budgets, UTF-8 input, LF/CRLF input, and combined byte/line limits.

Validation

Passed:

  • git diff --check

  • Target-file Biome format check

  • Target-file Biome lint with --error-on-warnings

  • bun run lint — 280 files checked

  • tsc --noEmit

  • node scripts/check-config-contract.mjs — 14 persisted fields checked

  • node scripts/check-discipline-ledger.mjs — 12 append-only rows checked

  • Relevant Node tests:

    node --test --experimental-strip-types \
      tests/extensions/shared/text-projection.test.ts \
      tests/extensions/workflows/prompt.test.ts \
      tests/extensions/workflows/handoff.test.ts
    

    Result: 40 passed, 0 failed.

Not completed cleanly in the existing Windows checkout:

  • bun run check reaches format:check, which reports 262 formatting diagnostics caused by pre-existing CRLF working-tree files outside this PR. Both changed files pass the same formatter, and full lint plus type checking pass separately.
  • bun run test reaches the existing Windows background-terminals process-termination failures and then stops making progress. Four failures were observed in that area before the run was interrupted. This matches test: eliminate Windows background-terminal process-test flakes in the full suite #304; this PR does not modify background terminal code.

No benchmark was run because the change affects bounded text selection rather than a performance-sensitive execution path.

Impact

  • User-visible behavior: truncated Workflow reports stay within their configured line limit and no longer repeat overlapping source text.
  • Model-visible context: bounded Workflow results and handoffs may contain a more compact projection when line limits are reached.
  • Runtime and lifecycle: no change.
  • Persisted configuration and data: no change.
  • Compatibility: input that fits both limits remains unchanged. Exact truncated content remains recoverable from the existing Workflow audit artifacts.

@tt-a1i tt-a1i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at exact head ded53f0. The change enforces the existing maxBytes/maxLines projection contract without altering canonical Workflow results or persisted artifacts. CI and focused boundary coverage are green; no blocking findings.

@tt-a1i
tt-a1i merged commit 2614b9b into openpi-dev:main Sep 1, 2026
5 checks passed
@JuiXiang
JuiXiang deleted the fix/issue-329-workflow-text-projection branch September 1, 2026 07:19
agnitum2009 pushed a commit to agnitum2009/openpi that referenced this pull request Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug (Workflow): projectText ignores maxLines and duplicates input during line-triggered projection

2 participants