Skip to content

fix(harness): formatValue's truncation marker could push output past VALUE_CAP - #675

Open
teyrebaz33 wants to merge 1 commit into
sapiom:mainfrom
teyrebaz33:fix/harness-web-formatvalue-budget-overrun
Open

fix(harness): formatValue's truncation marker could push output past VALUE_CAP#675
teyrebaz33 wants to merge 1 commit into
sapiom:mainfrom
teyrebaz33:fix/harness-web-formatvalue-budget-overrun

Conversation

@teyrebaz33

Copy link
Copy Markdown

Primary change type

  • Bug fix
  • Documentation
  • Feature
  • Tests
  • Dependency update
  • Maintenance or refactor

Problem and motivation

formatValue (packages/harness/web/src/lib/extract-step-context.ts) is documented as producing output "capped at VALUE_CAP characters," but it sliced content to exactly VALUE_CAP and then appended a truncation marker AFTER the slice — so the total could exceed VALUE_CAP by the marker's length. This is the fourth instance of the same bug class found in a repo-wide sweep; the other three (truncateForPayload/clip/clamp in packages/harness/src/core/) are fixed in #656 — this one lives in a different subsystem (the web frontend's run-inspector Debug/Explain macro context builder), so it's a separate PR.

Summary and scope

Unlike the three fixed in #656, this marker (\n… (truncated, N chars total)) reports the value's original total length, which doesn't change with where the slice lands — so the fix here is a single subtraction, not a converging loop: the marker's length is fixed once text.length is known, so there's nothing to iterate on. Reserve the marker's length within VALUE_CAP before slicing.

Out of scope: the three packages/harness/src/core/ instances (separate PR, #656); no dependency changes.

Related work

Related issue or discussion: #674

Validation

# packages/harness: vitest run web/src/lib/extract-step-context.test.ts
51/51 passing
tsc --noEmit (server tsconfig): clean
tsc --noEmit -p web/tsconfig.json: clean
# web/ is excluded from this package's eslint config (.eslintrc.cjs ignorePatterns),
# pre-existing and unrelated to this change

Tests and documentation

Updated the one existing test whose exact-match assertion had encoded the old (over-budget) output as the expected value, with the new expected value computed independently. No user-facing documentation changes needed.

Compatibility and release impact

  • Breaking or externally visible changes: None. formatValue is not exported; extractStepContext's signature and return type are unchanged. Truncated output near the cap gets slightly shorter (by the marker's length) to actually respect the documented bound.
  • Changeset: Added (.changeset/fix-formatvalue-budget-overrun.md), patch bump for @sapiom/harness.

Security

  • I have not included secrets, credentials, private data, or unsanitized logs.
  • This pull request does not publicly disclose a suspected vulnerability. I
    will follow the
    Security Policy for
    private reporting.

AI assistance

  • I did not use AI assistance for this change.
  • I used AI assistance and have described it below.

I used Claude (Anthropic) as a coding assistant throughout: it helped find the bug (via a repo-wide grep sweep for the same marker pattern), draft the fix and the updated test, and run the verification commands quoted above. I reviewed and ran every command myself, read and understood the resulting diff line by line, and can explain and maintain every change in this PR.

Checklist

  • I read CONTRIBUTING.md, and this contribution follows the direct-PR or issue-first policy.
  • This pull request addresses one focused problem and contains no unrelated cleanup.
  • I added or updated tests, or explained above why tests are not applicable.
  • I ran the relevant build, typecheck, lint, and test commands, or explained
    any N/A checks above.
  • I updated documentation for user-facing changes, or marked it N/A above.
  • I added a Changeset for a published-package change, or explained why it is not applicable.
  • I can explain and maintain every submitted change, including any AI-assisted work.

…VALUE_CAP

Fourth instance of the same bug class found in the repo-wide sweep that
also turned up the three fixed in sapiom#656 (normalizer.ts, record-archive.ts,
resume-brief.ts) -- this one lives in the web frontend
(web/src/lib/extract-step-context.ts), a different subsystem entirely
(the run-inspector's Debug/Explain macro context builder), so it gets its
own PR rather than joining that one.

formatValue's doc comment says values are "capped at VALUE_CAP
characters," but it sliced to exactly VALUE_CAP then appended a marker
after the slice, so the total could exceed VALUE_CAP by the marker's
length.

Unlike the three fixed in sapiom#656, this marker (`\n… (truncated, N chars
total)`) reports the value's original total length, which doesn't
change with where the slice lands -- so unlike those three, the fix
here is a single subtraction, not a converging loop: the marker's
length is fixed once `text.length` is known, so there's nothing to
iterate on.

Updated the one existing test whose exact-match assertion had encoded
the old (over-budget) output as the expected value, with the new
expected value computed independently. vitest run
web/src/lib/extract-step-context.test.ts: 51/51 passing. tsc --noEmit
clean on both the server and web tsconfigs. `web/` is excluded from
this package's eslint config (see .eslintrc.cjs's ignorePatterns) --
pre-existing, unrelated to this change.

No dependency or lockfile changes.
@github-actions github-actions Bot added bug Something isn't working contributor: external Pull request author does not have write, maintain, or admin access to sapiom-js needs-triage Awaiting maintainer review and classification size: small Review size is at most 100 changed lines area: studio Changes to Agent Studio or harness applications labels Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: studio Changes to Agent Studio or harness applications bug Something isn't working contributor: external Pull request author does not have write, maintain, or admin access to sapiom-js needs-triage Awaiting maintainer review and classification size: small Review size is at most 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant