Skip to content

🌱 tokens: cap promptsrc at 64 KiB and reject oversize whole instead of truncating - #12151

Merged
hivecommons-hive[bot] merged 1 commit into
v5from
tokens/12130-promptsrc-cap
Oct 15, 2026
Merged

hivecommons-hive[bot] merged 1 commit into
v5from
tokens/12130-promptsrc-cap

Conversation

@clubanderson

Copy link
Copy Markdown
Member

Closes #12130
Refs #12134

What

  • pkg/promptsrc: maxPromptBytes = 512 KiB (memory bound) β†’ DefaultMaxPromptBytes = 64 KiB (token budget), a named exported constant. Measured against every shipped template in src/policies/ and src/pkg/policies/defaults/ (83 files): the largest is scanner-automerge.md at 27,890 bytes, so 64 KiB is 2.3Γ— headroom. TestShippedTemplatesFitUnderCap walks both trees and fails if any template drops under 2Γ— headroom, naming the file.
  • Override: HIVE_PROMPT_SOURCE_MAX_BYTES (bytes, or KiB/MiB suffix); unparseable/non-positive keeps the default. Resolver.SetMaxBytes for programmatic override.
  • Oversize β†’ reject whole, never truncate. Resolve logs prompt from GitHub exceeds size cap; REJECTED whole (not truncated), falling back with repo, path, ref, size_bytes, cap_bytes, override_env, then serves the last-known-good cached copy if any, else returns Ok=false, Source:"oversize" so the scheduler takes the next resolution step (kick_template β†’ pack β†’ convention β†’ embedded default). The rejected body is never cached. FetchOnce returns a wrapped ErrPromptTooLarge naming source, size and cap, so the dashboard's bake/save flow refuses rather than writing a cut-off policy to /data/policies.
  • Docs: operator-reference.md (Notable fields), env-vars.md, agent-configuration.md; changelog fragment.

Constraints from the issue

  • Cap above shipped and real templates: yes, with a test pinning the margin.
  • Silent partial policy is worse than no remote policy: no truncation path remains; the two old *_TruncatesOversizeBody tests are replaced by reject/fallback/log tests.

Validation

gofmt -l clean on touched files; go build ./..., go vet ./pkg/promptsrc/... ./pkg/dashboard/ ./pkg/scheduler/, go test ./pkg/promptsrc/... ./pkg/config/... green locally.

cc @mrbobbytables

…f truncating

DefaultMaxPromptBytes = 64 KiB (largest shipped template ~28 KiB, >2x
headroom, pinned by TestShippedTemplatesFitUnderCap), overridable via
HIVE_PROMPT_SOURCE_MAX_BYTES. A body over the cap is rejected whole:
Resolve falls back to the cached copy, then the caller's inline chain,
logging repo/path/size/cap; FetchOnce returns ErrPromptTooLarge so the
dashboard refuses to bake a half-policy. Documented in operator-reference,
env-vars and agent-configuration.

Closes #12130
Refs #12134

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 15, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#12157 🌱 tokens: measure kick size per kick; keep kick_limits defaults same files src/docs/operator-reference.md
#12156 🌱 tokens: cap AGENTS.md injection at section boundaries with a visible warning same files src/docs/operator-reference.md
#12150 🌱 tokens: byte caps for knowledge primer and Context7 content, with visible truncation same files src/docs/operator-reference.md
#12025 ✨ keep unstick steps running in conserve API budget mode same files src/docs/operator-reference.md

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at c9f1586.

@kubestellar-prow
kubestellar-prow Bot deleted the tokens/12130-promptsrc-cap branch October 15, 2026 18:48
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🌱 tokens: lower promptsrc maxPromptBytes and reject/drop-whole instead of truncating (review A7)

1 participant