Skip to content

feat(headless): validate active-prune 2048 - #340

Merged
Astro-Han merged 7 commits into
mainfrom
codex/issue293-active-prune-2048
Jun 28, 2026
Merged

feat(headless): validate active-prune 2048#340
Astro-Han merged 7 commits into
mainfrom
codex/issue293-active-prune-2048

Conversation

@Astro-Han

@Astro-HanAstro-Han commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Set Harbor active tool-result pruning to the measured 2048-token threshold and surface prune diagnostics in cell output and A/B reports.
  • Add deterministic Harbor continuation plumbing for tool-step-cap recovery, including continuation failure propagation and max total runtime step accounting.
  • Fix provider replay for interleaved parallel tool calls and run A/B arms for the same task pair concurrently.

Why

Closes#293

The active-prune policy needs both a validated 2048-token threshold and benchmark evidence that it saves cost without a large regression detected under the 10pp phase-1 framing. Issue #293 frames this as a first-phase non-inferiority experiment with a 10 percentage-point margin, not as a proof of mathematical losslessness or a 5pp claim.

Evidence

Bottom line: archive-backed active tool-result prune at the 2048-token threshold did not show a regression larger than the declared 10pp non-inferiority margin, while saving 31.6% cost and 41.7% tokens across the combined evidence set. The margin clearance is narrow: the stratified 95% lower bound is -9.78pp against a -10pp margin, clearing by 0.22pp. This supports “no large regression detected” under the phase-1 framing, not proof of equivalence or absolute losslessness.

Design: non-inferiority test where A is prune off and B is active prune on with archive retrieval enabled. The evidence is reported as two strata because the older full runs predate continuation rescue and A/B pair concurrency, while the new rescue run uses the fixed harness.

StratumPairsA passB passDelta (B-A)95% lower bound
Old full runs, 4 slices893842+4.49pp-9.94pp
Continuation rescue32109-3.13ppwide, inconclusive alone
Stratified rollup1214851+2.48pp-9.78pp

Combined cost was $2.1600 baseline vs $1.4781 candidate, saving $0.6819 / 31.6%. Combined tokens were 192.0M vs 111.9M, saving 80.1M / 41.7%.

The new 32-task continuation rescue run is inconclusive by itself. Its value is that it exercises the replay fix, benchmark-safe continuation, and A/B pair concurrency on the tasks that previously hit the tool-step cap. The rescue run logs had no APICallError, insufficient tool messages, invalid_request_error, or runtime_error.

Per-run breakdown and local artifacts
RunSliceA passedB passedDeltaCost A -> BTokens A -> BNotes
issue293-active-prune-default-le30-005old full, <=30m21/3420/34-2.94pp$0.2867 -> $0.191721.91M -> 12.49M2048 snapshot, no continuation
issue293-active-prune-default-30to45-001old full, 30-45m3/63/60pp$0.0938 -> $0.10676.22M -> 7.34M2048 snapshot, no continuation
issue293-active-prune-default-45to60-001old full, 45-60m5/135/130pp$0.2429 -> $0.216819.69M -> 16.96M2048 snapshot, no continuation
issue293-active-prune-default-gt60missing-001old full, >60m/missing9/3614/36+13.89pp$0.6531 -> $0.445760.79M -> 34.67M2048 snapshot, no continuation
issue293-continuation-canary-002canary1/11/10pp$0.0496 -> $0.03234.69M -> 2.23Mcontinuation + replay fix smoke
issue293-continuation-rescue-001rescue, prior tool-step-cap tasks10/329/32-3.125pp$0.8836 -> $0.517283.38M -> 40.46Mcontinuation on, A/B pair concurrency on

Local artifacts used for the evidence above:

  • maka-eval/runs/issue293-prune-ab/issue293-active-prune-default-le30-005/runtime-policy-ab-result.json
  • maka-eval/runs/issue293-prune-ab/issue293-active-prune-default-30to45-001/runtime-policy-ab-result.json
  • maka-eval/runs/issue293-prune-ab/issue293-active-prune-default-45to60-001/runtime-policy-ab-result.json
  • maka-eval/runs/issue293-prune-ab/issue293-active-prune-default-gt60missing-001/runtime-policy-ab-result.json
  • maka-eval/runs/issue293-prune-ab/issue293-continuation-canary-002/runtime-policy-ab-result.json
  • maka-eval/runs/issue293-prune-ab/issue293-continuation-rescue-001/runtime-policy-ab-result.json
  • Report markdown exists beside each result as runtime-policy-ab-report.md.

Scope

Changed:

  • Runtime context-budget defaults and diagnostics for active current-turn tool-result pruning.
  • AI SDK replay materialization for interleaved parallel tool_call / tool_result events.
  • Harbor continuation env passthrough, continuation summaries, max total runtime step enforcement, per-turn cap diagnostics, and controller/report propagation.
  • Continuation error handling so a later-turn sendMessage failure is reported as a failed invocation instead of being hidden behind an earlier step-cap result.
  • Continuation step accounting now uses token-usage runtimeSteps diagnostics instead of counting RuntimeEvent rows.
  • Runtime-policy A/B execution so both arms for the same task/rep start concurrently.
  • Regression tests for replay grouping, continuation behavior, continuation error propagation, max total runtime steps, A/B pair concurrency, reports, and output contracts.

Not included:

  • No UI changes.
  • No provider secret or benchmark result artifacts are committed.
  • No maka-eval/ tracked files; local run outputs stay git-excluded.
  • No repo-local one-off Issue 293 rescue runner; the rescue run remains documented by local artifacts and explicit run settings.
  • No test-file boundary cleanup for packages/headless/src/__tests__/prompt-ab-run.test.ts; that file should be split in a follow-up pure test-organization PR.

Verification

Local gates:

  • npm --workspace @maka/runtime run build
  • npm --workspace @maka/headless run build
  • node --test packages/runtime/dist/__tests__/ai-sdk-backend.test.js packages/runtime/dist/__tests__/active-tool-result-prune.test.js packages/runtime/dist/__tests__/runtime-runner.test.js packages/headless/dist/__tests__/harbor-cell.test.js packages/headless/dist/__tests__/prompt-ab-run.test.js packages/headless/dist/__tests__/runtime-policy-ab-run.test.js packages/headless/dist/__tests__/fixed-prompt-controller.test.js packages/headless/dist/__tests__/cell-output.test.js packages/headless/dist/__tests__/harbor-adapter.test.js
  • git diff --check

Result: 221 related tests passed.

User-facing impact

None for the desktop UI. This affects benchmark/headless Harbor execution and runtime replay robustness. No changelog, docs, breaking changes, or migrations are included.

Reviewer notes

This is intentionally one PR because the 2048 policy evidence depends on the runtime replay fix, Harbor continuation, and A/B pair-concurrency fix being exercised together. The commits are split by concern for review.

The active-prune default of 2048 is intentional. Issue #293 was updated so this is no longer scoped as a non-goal: 8192 was the archive retrieval budget, while active current-turn prune should match the measured 2048 threshold and the existing stale tool-result prune default.

packages/headless/src/__tests__/prompt-ab-run.test.ts is now over 1.4k lines and mixes manifest, generic A/B execution, fingerprinting, summary/rendering, and prompt-specific run tests. That boundary cleanup is worthwhile, but it should be a separate pure test-organization PR so this PR does not mix behavior changes with file-move noise.

@Astro-HanAstro-Han changed the title Validate active-prune 2048 for Harbor policy A/Bfeat(headless): validate active-prune 2048Jun 28, 2026
@Astro-Han
Astro-Hanforce-pushed the codex/issue293-active-prune-2048 branch from 6d815eb to 8e2dbadCompareJune 28, 2026 05:41
@Astro-Han
Astro-Han merged commit a76720d into mainJun 28, 2026
@Astro-Han
Astro-Han deleted the codex/issue293-active-prune-2048 branch June 28, 2026 08:37
Astro-Han added a commit that referenced this pull request Jul 4, 2026
Document the desktop+headless default-on behavior, the 2048-token
threshold, the metadata-only placeholder behavior for oversized tool
results, the opt-out env, and the #340 non-inferiority evidence basis.
Per review feedback on the headless default behavior change.
Astro-Han added a commit that referenced this pull request Jul 4, 2026
…#498)
* feat(desktop): enable activeToolResultPrune by default
Add buildActiveToolResultPrunePolicy to the desktop context-budget
builder, aligned with the headless env names
(MAKA_CONTEXT_ACTIVE_TOOL_RESULT_PRUNE and aliases). Defaults to
enabled with the 2048-token threshold; explicit off/false opts out.
Wires the current-turn prune step that runs before the already
default-on semanticCompact, using the existing desktop
archiveToolResult/readToolResultArchive wiring.
* feat(headless): default activeToolResultPrune on
Flip activePruneEnabled from `?? false` to `?? true` so harbor cells
no longer need to set MAKA_CONTEXT_ACTIVE_TOOL_RESULT_PRUNE to get
current-turn large tool-result pruning. Explicit off/false still opts
out. Adjusts the existing explicit-false-like-boolean test (stale/archive
off no longer implies an empty context budget) and adds default-on and
explicit-off coverage.
* refactor(desktop): drop activeToolResultPrune threshold env alias
Keep only the canonical MAKA_CONTEXT_ACTIVE_TOOL_RESULT_MAX_ESTIMATED_TOKENS
env. The MAKA_CONTEXT_ACTIVE_TOOL_RESULT_PRUNE_MAX_ESTIMATED_TOKENS alias
was a half-alignment with headless (only the threshold alias, not the
enable/disable aliases); drop it per review feedback to avoid carrying
headless historical compatibility baggage on desktop.
* docs: changelog activeToolResultPrune default-on
Document the desktop+headless default-on behavior, the 2048-token
threshold, the metadata-only placeholder behavior for oversized tool
results, the opt-out env, and the #340 non-inferiority evidence basis.
Per review feedback on the headless default behavior change.
Sign up for freeto 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.

feat(headless): validate tool result pruning with A/B benchmark

1 participant

@Astro-Han