Skip to content

fix(#1691): honor decompress toFile destination (was ignored) - #1696

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-29_decompress-tofile-honored
Sep 29, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-29_decompress-tofile-honored

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Honors the toFile argument on the decompress tool — previously advertised in the schema/prompt but never read. Every restore went to os.tmpdir() when the body exceeded 10K chars and inlined otherwise, silently discarding any caller-supplied path.

Fixes #1691

Root cause

Not a regression — the feature was never implemented. In src/decompress-shared.ts, resolveDecompress (the single execution chokepoint for both the whole-block restore and the CCR range restore) derived its output path exclusively from tmpdir(), gated only by body.length > 10000. The args.toFile field was read nowhere. (Prior changelog mentions of a "#1334/#1294 toFile path" refer to the auto-tmpdir file branch, not this user-facing argument.)

The tool schema and prompt strings live in acp-kernel and already advertise toFile correctly — no kernel change is needed; this makes the shipped behavior match the documented contract.

What changed

src/decompress-shared.ts:

  • New shared toFilePointer(args, ctx, header, body) helper. When args.toFile is a non-empty string it wins regardless of body size: resolves relative paths against the proxy cwd (path.resolve), creates parent dirs, writes with mode 0600, and returns/queues a lean pointer (… written to: <path>). The restored content is never inlined into context.
  • Wired into BOTH restore paths: the whole-block path returns the pointer early; the CCR range path queues only the pointer into pendingRetrievals (the full body is still never injected).
  • Explicit toFile destinations are intentionally NOT added to trackedTempFiles, so the temp-file reaper / beforeExit cleanup never touches a file the caller asked for by name.

Behavior change (old → new)

Input before after
toFile given ignored; dest = os.tmpdir() if body >10K, else inline honored for any size; writes to the requested path; never inflates context
relative toFile n/a resolved against the proxy cwd
malformed toFile (non-string) silently ignored one-line [acp-decompress] toFile must be a string… warning, then default output
no toFile auto-tmpdir >10K / inline ≤10K unchanged, byte-for-byte

No config surface added (owner-gated area); no persistence or wire-format change.

Tests

New tests/fix-decompress-tofile.test.ts (6 cases): a small restore written to a nested caller path (would otherwise inline), a large restore targeting the caller path instead of an acp-decompress-* tmpdir name, default unchanged (no toFile stays inline, no file created), a malformed value warning + falling back, a relative path resolving against cwd, and a range toFile writing the span while queueing only a lean pointer.

Pre-flight on rebased head (v0.1.172 / c0e9e65f): typecheck clean · full suite 3234 pass / 0 fail / 12 skipped · build success.

…pdir())

The decompress tool advertised a toFile argument in its schema and prompt but never read it: every restore went to os.tmpdir() above 10K chars and inlined below, silently discarding any caller-supplied path. resolveDecompress (single chokepoint for the whole-block and CCR range paths) now routes through a shared toFilePointer helper: an explicit non-empty string destination wins regardless of body size, resolves relative paths against the proxy cwd, creates parent dirs, writes 0600, and returns/queues only a lean pointer (never inflating context). Explicit paths are intentionally left out of the temp-file reaper. Absent/empty toFile falls back to the prior behavior byte-for-byte; malformed (non-string) values log a one-line warning.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-29_decompress-tofile-honored (1925fe3)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1638-pr.1696.153888e

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1696.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Reviewing this PR now (it's prior agent work — verifying rather than redoing). Code read-through done: diff is single-commit, 2 files (src/decompress-shared.ts +36/-2, new tests/fix-decompress-tofile.test.ts +177), branch is up to date with master (no rebase needed). Re-running pre-flight locally (typecheck / full suite / build) and checking CI status; will post the full review verdict shortly.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review verdict: mergeable. This is prior agent work, so I verified rather than redid it — pulled the branch at detached HEAD (1925fe3c) and checked everything below against the live tree.

① Original issue (#1691) — direction confirmed. I re-read the pre-fix source: args.toFile was indeed read nowhere; both restore paths in src/decompress-shared.ts derived their destination solely from tmpdir() gated on body.length > 10000. Not a regression — feature never implemented, matching the triage conclusion. Fix sits at the decision point (destination choice), not a downstream mask. Schema/prompt strings live in acp-kernel and already describe this behavior correctly, so no cross-repo change needed — correct call.

② Regression review — existing behaviors on touched paths, each verdict:

  1. Whole-block restore without toFile → unchanged. Early return fires only when toFilePointer returns non-null, which requires a non-empty string; otherwise the original code runs untouched.
  2. Whole-block telemetry (wholeBlockRestores* counters) → preserved: incremented before the toFile early return, so toFile restores still count.
  3. restoredInline flag / refold hint → correctly skipped on the file path — identical to the existing auto-tmpdir branch, which also returns before flagging (keeps the release v0.1.152 #1334/[feature] compress 回执加摘要指纹 + inline decompress 回执给再折叠指引 #1294 "file path stays unmarked" contract).
  4. CCR range restore without toFile → unchanged (else if (body.length > 10000) chain intact).
  5. Range restore with toFile → queues only the lean pointer into pendingRetrievals; chars: body.length matches how the auto-tmpdir branch already records chars (restored size, not injected size) — no accounting drift. Retry dedup on deterministic injId untouched.
  6. Temp-file reaper → explicit destinations deliberately excluded from trackedTempFiles (documented in-code): a caller-named artifact must not be cleaned up behind their back. Correct.
  7. Write-failure fallback → log line + bounded safePrefix(body, 4000) partial, same shape as the tmpdir failure path. No unbounded context inflation.

No unintended regressions found. Behavior changes disclosed in the PR (toFile honored for any size / relative→cwd / malformed→warn+default / no-toFile byte-for-byte unchanged) are accurate — I confirmed each against the code.

③ Code. Small, single-purpose helper; edge cases handled (undefined/null → default, non-string → warn+default, blank → default, parent dirs created, 0600, all fs errors caught). No as any, no console.error (uses ctx.log), tag hex-escapes followed in the test file. One accepted-risk note (not a blocker): an explicit toFile lets the model direct session-block content to any path the proxy user can write. The body is always block content (the caller picks destination only, never payload), every lane's agent already has filesystem-write capability, and an allow-root config knob would be owner-gated config surface that isn't approved — the issue's own suggestion marked validation as optional. Worth remembering if a future threat-model pass wants hardening.

④ Tests. All 6 have teeth: exact-path existence (incl. nested dirs), negative assertions (body not inlined, no refold hint, no acp-decompress-* spill name, no restoredInline flag), default-unchanged (no file created), malformed-value warning text, chdir-based relative resolution, and range-span bounds + lean-pointer queueing (full body asserted absent from the queued injection). If toFile regressed to being ignored, cases 1–2 fail immediately.

⑤ Diff. Single commit, 2 files (+211/−2), every line on-purpose; no lockfile/version churn; branch is current with master (verified merge-base --is-ancestor).

Evidence: local on rebased head — typecheck clean · build success · targeted 6/6 · full suite 3234 pass / 0 fail / 12 skipped (matches PR claims); GitHub CI on head 1925fe3c: 12/12 check-runs success (multi-OS test matrix, hermetic registry e2e, real codex/dsh/pi/opencode lanes, version-guard, build-artifact).

Auto-merge gate §7.4: passes all 8 items (single-module fix, regression-covered, green on fresh head, no config/wire/persistence/cross-repo/load-bearing-infra touch, pure fix:, clean diff, Fixes #1691). Merge stays your call either way — I can't merge PRs.

中文摘要:修复了 decompress 的 toFile 参数“文档承诺但从未实现”的问题(显式路径现在按任意大小写入、相对路径按代理 cwd 解析、只回指针不撑大上下文,不传时行为逐字节不变);我逐项核对了受影响路径的既有行为(无回归)、验证了本地与 CI 全绿(typecheck/build/3234 项测试/CI 12/12),测试有牙、diff 干净,可以合并。

@ranxianglei
ranxianglei merged commit c761596 into master Sep 29, 2026
12 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-29_decompress-tofile-honored branch October 15, 2026 05:32
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.

decompress: toFile is documented but never read — every restore goes to os.tmpdir()

1 participant