Skip to content

feat(autoresearch): reduce bash output token spend#3763

Closed
MattPua wants to merge 1 commit into
mainfrom
posthog-code/autoresearch-bash-token-spend
Closed

feat(autoresearch): reduce bash output token spend#3763
MattPua wants to merge 1 commit into
mainfrom
posthog-code/autoresearch-bash-token-spend

Conversation

@MattPua

@MattPua MattPua commented Jul 23, 2026

Copy link
Copy Markdown
Member

Results

Scope Before After Saved
Eligible noisy pnpm test 17766 96 17670 (99.46%)
Full seven-case corpus 214969 197299 17670 (8.22%)
Semantic fidelity 7/7 7/7 No detected loss
Before  ████████████████████████████████████████  214969
After   █████████████████████████████████████     197299
Saved   ███                                         17670

The measured saving comes from a representative noisy pnpm test fixture. Runtime validation also covered npm and Python test execution.

Created with Autoresearch.

Problem

Test output can spend substantial agent context on repetitive passing lines, hiding the failure or summary that matters.

The safety contract is strict:

flowchart LR
    A[Original command] --> B{Verified test form?}
    B -->|No| C[Run unchanged]
    B -->|Yes| D{Compatible RTK?}
    D -->|No| C
    D -->|Yes| E[Filter repetitive test output]
    E --> F[Preserve summary, failure, and exit code]
Loading

Methodology

Only test ecosystems exercised locally are eligible:

Ecosystem Eligible forms Runtime validation
JavaScript pnpm and npm test commands Real passing and failing processes
Python pytest, unittest, uv, and Poetry forms Real Python processes
Everything else Unchanged Explicit policy tests
flowchart TD
    C[Candidate command] --> S{Single bare command?}
    S -->|No| RAW[Run unchanged]
    S -->|Yes| T{Supported test form?}
    T -->|No| RAW
    T -->|Yes| M{Machine-readable flags?}
    M -->|Yes| RAW
    M -->|No| R{Executable RTK 0.43.0+?}
    R -->|No| RAW
    R -->|Yes| O[Use RTK test filtering]
Loading

Changes

Area Change Why it helps
Shared policy One provider-neutral eligibility policy Prevents Claude and Codex policy drift
Claude Deterministic hook uses the shared policy Compresses verified test forms automatically
Codex Guidance generated from the shared policy Applies the same narrow safety boundary
RTK detection Validate executable, identity, and minimum version Avoids breaking commands with unusable binaries
Exact output Reject shell operators and machine-readable modes Preserves command semantics and structured output

No PostHog-specific runtime commands or package names are included.

Verification

Check Result
Focused rewrite and guidance tests 92 passed
Provider/server RTK integration tests 7 passed
Agent typecheck Passed
Repository typecheck 24/24 tasks passed
Agent production build Passed
Real pnpm/npm/Python execution Exit codes and useful output preserved
Formatting and diff validation Passed

The research benchmark was run locally and is intentionally excluded from this PR.

Areas to watch

Risk Mitigation
RTK output behavior changes Require RTK 0.43.0+ and keep the allowlist narrow
Structured test output Commands with machine-readable flags remain raw
Unsupported ecosystems Remain raw until validated with real projects
Provider behavior differs Shared policy, plus provider-specific integration tests
Token estimate differs from a model tokenizer Use the estimate only for deterministic relative comparison

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

@trunk-io

trunk-io Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 6961434.

@MattPua
MattPua force-pushed the posthog-code/autoresearch-bash-token-spend branch 7 times, most recently from 0ca6637 to ebf991d Compare July 23, 2026 16:38
Generated-By: PostHog Code
Task-Id: 272f46f4-223e-41c5-8bd3-681e5d96028f
@MattPua
MattPua force-pushed the posthog-code/autoresearch-bash-token-spend branch from ebf991d to 6961434 Compare July 23, 2026 16:44
@MattPua MattPua closed this Jul 23, 2026
@MattPua
MattPua deleted the posthog-code/autoresearch-bash-token-spend branch July 23, 2026 19:22
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.

1 participant