fix(sourcehunt): bound persisted trace-step payloads - #205
Open
tsunoda-kazuya wants to merge 3 commits into
Open
fix(sourcehunt): bound persisted trace-step payloads#205tsunoda-kazuya wants to merge 3 commits into
tsunoda-kazuya wants to merge 3 commits into
Conversation
record_trace_step accepted arbitrarily large code_snippet and note strings and appended them straight onto ctx.trace_steps. Those strings flow through finding evidence into artifacts, so on large repos with chatty hunters they bloated reports and slowed downstream processing. Cap code_snippet and note at HunterContext.trace_step_max_chars (default 4096). When truncation occurs, mark the TraceStep with truncated=True and record original_chars so downstream can tell that content was clipped. Setting trace_step_max_chars <= 0 disables the cap entirely. The knob currently lives on HunterContext only; wiring it through SourceHuntConfig and the CLI is left for a follow-up to keep the surface change minimal (HunterContext has 9 constructor sites).
The streaming record_trace_step path caps code_snippet and note via
_cap_trace_strings, but the inline compat path in record_finding
(trace={"steps": [...]}) built TraceStep directly from the dict and
bypassed the cap. Chatty local models prefer the inline path, so the
bounded-evidence promise was broken on exactly the callers that motivate
this change. Route inline steps through the same helper and mark
truncated/original_chars accordingly.
Also drop the getattr fallback for ctx.trace_step_max_chars now that
HunterContext declares the field.
… --full-trace Adds HuntTuning.trace_step_max_chars (default 4096) so the trace-step cap is configurable through SourceHuntConfig. SourceHuntRunner accepts a trace_step_max_chars kwarg that reaches the hunt pool and the verifier HunterContext; HuntPoolConfig propagates it to each per-file hunter via _configure_hunter_context. The CLI gains --full-trace, which sets the cap to 0 to retain the full snippet on record_finding trace steps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
code_snippetandnoterecorded byrecord_trace_stepattrace_step_max_chars(default 4096) and mark truncated steps withtruncated: boolandoriginal_chars: int.record_finding(trace={"steps": [...]}), which chatty local models use in place of streamingrecord_trace_step.HuntTuning.trace_step_max_chars;--full-tracesets it to0(disabled).ctx.trace_stepsand flows intoFinding.vulnerability_traceand the written artifacts.Problem
record_trace_stepappends model-supplied text toctx.trace_stepswithout a size limit. Those steps travel into finding evidence and the written artifacts, so a long hunt on a large repository can produce artifacts far larger than the findings they describe. The machine-mode projection bounds what is returned to a caller, not what is stored.Fix
_cap_trace_stringshelper truncatescode_snippetandnoteatctx.trace_step_max_chars; attachestruncated=Trueandoriginal_chars=<combined pre-truncation char count>when it clips.record_trace_step(streaming path) applies the cap before constructingTraceStep.record_finding's compatibility path for inlinetrace={"steps": [...]}routes each step through_build_capped_trace_stepso the two entry points behave identically.HuntTuning.trace_step_max_chars(default 4096);HuntPoolConfigandSourceHuntRunnerthread it toHunterContext.--full-tracesets the value to0, which the helper treats as unlimited.Validation
uv run --frozen --extra dev pytest -q tests/test_hunt_reporting_tools.py tests/test_sourcehunt_hunter.py tests/test_sourcehunt_trace_cap_config.py— 102 passed; new regressions: below-cap preserved byte-identically; above-cap truncated withoriginal_charsset; inlinerecord_findingpath capped identically;--full-trace(cap=0) leaves 1 MB inputs untouched; config default 4096; pool setsctx.trace_step_max_charsfrom config.uv run --frozen --extra dev ruff check clearwing/agent/tools/hunt/reporting.py clearwing/agent/tools/hunt/sandbox.py clearwing/findings/types.py clearwing/sourcehunt/config.py clearwing/sourcehunt/pool.py clearwing/sourcehunt/runner.py clearwing/ui/commands/sourcehunt.pygit diff --checkBackward compatibility
Steps under 4096 characters are unchanged. Consumers see two new optional keys only on truncated steps (both default to
False/0).--full-tracerestores the previous unlimited behaviour.Independent of the other 4 PRs in this batch; trivial rebase if any lands first.