Skip to content

fix(tokenless): attribute stash artifact kinds - #10941

Open
boluochoufeng wants to merge 1 commit into
agentic-os-org:mainfrom
boluochoufeng:fix/tokenless/artifact-kind-attribution
Open

boluochoufeng wants to merge 1 commit into
agentic-os-org:mainfrom
boluochoufeng:fix/tokenless/artifact-kind-attribution

Conversation

@boluochoufeng

Copy link
Copy Markdown
Contributor

Why

In src/tokenless/crates/tokenless-runtime/src/lib.rs, record_entry_stats only checked AppliedOperation::SchemaCompression and AppliedOperation::JsonRecordReduction when choosing compression_artifacts.compressor_id, defaulting every other applied run with emitted stash keys to "json_truncation". As a result, stash artifacts written by build-log reduction, diff reduction, standalone/embedded HTML extraction, and browser snapshot reduction were all misattributed as "json_truncation" in stats.db.

What changed

  • Replaced the ad-hoc if / else if / else branch in src/tokenless/crates/tokenless-runtime/src/lib.rs with an exhaustive is_stash_producing_operation match over AppliedOperation and an artifact_kind_for_operations helper that derives labels directly from AppliedOperation::wire_str.
  • Selected the first stash-producing operation in applied_operations so preceding lossless operations (such as terminal_cleanup before build_log_reduction, or tabular_compaction / json_cleanup in mixed output) do not mask the operation that created the emitted markers; kept a defensive "unknown" fallback for an empty operation list instead of mislabeling it as "json_truncation".
  • Added unit tests and end-to-end TokenlessRuntime SQLite tests in src/tokenless/crates/tokenless-runtime/src/tests.rs verifying compression_artifacts.compressor_id across schema_compression, build_log_reduction, diff_reduction, standalone and JSON-embedded html_extraction, browser_snapshot_reduction, json_record_reduction, json_truncation, and tabular_row_reduction.

Related issue

no-issue: focused correctness fix for compression_artifacts.compressor_id attribution introduced when protocol v2 replaced stash_owning_compressor in 80938fb46.

User / Agent impact

None for CLI syntax, compression output, or tokenless stats summary results. Newly recorded rows in stats.db's compression_artifacts table now store each domain's actual compressor_id; historical rows are not rewritten.

Risk and compatibility

  • Public CLI, API, configuration, or documented behavior changed
  • Privileged or security-sensitive behavior changed
  • Cross-component contract changed
  • Migration or rollback guidance is needed

Low risk. The change is isolated to internal compressor_id label selection in tokenless-runtime, keeps stats and compression_artifacts schemas unchanged, and does not alter tokenless stats summary --json output or providers/tokenless contracts.

Validation

Ran on macOS (arm64) against branch base 9a99f8782 (tokenless 0.9.8):

  • cargo fmt --manifest-path src/tokenless/Cargo.toml --all -- --check: passed.
  • cargo clippy --manifest-path src/tokenless/Cargo.toml --all-targets -- -D warnings: passed (0 warnings).
  • cargo test --manifest-path src/tokenless/Cargo.toml -p tokenless-runtime -- --test-threads=1: passed (307 passed, 0 failed, including 2 new artifact-attribution unit and SQLite end-to-end tests).
  • cargo doc --manifest-path src/tokenless/Cargo.toml -p tokenless-runtime --no-deps: passed (0 warnings).

Not run locally: PyO3 Python runtime suite (make test-python-runtime), adapter/hook suites (make test-integration / make test-adapters), and Linux-only providers/tokenless tests; these will be exercised by GitHub Actions CI.

Documentation and rollback

No user-facing CLI, SDK, or schema documentation changes are required. Reverting this single commit restores the prior fallback behavior without affecting stored stash payloads or existing database rows.

`tokenless-runtime` now records the actual `compressor_id` in the
`compression_artifacts` table of `stats.db` for every stash-producing
domain instead of falling back to `"json_truncation"` whenever an
applied run is neither `schema_compression` nor
`json_record_reduction`. Previously, emitted stash keys from build-log
reduction, diff reduction, HTML extraction (both standalone and
JSON-embedded), and browser snapshot reduction were misattributed as
`"json_truncation"`, distorting per-compressor artifact ownership.

In `crates/tokenless-runtime/src/lib.rs`, replace the ad-hoc branch in
`record_entry_stats` with an exhaustive `is_stash_producing_operation`
match over `AppliedOperation` and an `artifact_kind_for_operations`
helper that maps through `AppliedOperation::wire_str`. Selecting the
first stash-producing operation ensures preceding lossless steps (such
as `terminal_cleanup` or `tabular_compaction` in mixed output) do not
mask the operation that emitted the recovery markers, while keeping the
match exhaustive so future `AppliedOperation` variants require an
explicit compile-time classification.

Add unit coverage for all stash-producing variants, lossless prefixes,
and defensive fallback behavior plus end-to-end SQLite runtime tests
verifying `compression_artifacts.compressor_id` across schema,
build-log, diff, standalone HTML, embedded HTML, browser snapshot, JSON
record reduction, and JSON truncation paths.

User-visible changes:
- `tokenless compress`:
  Command syntax, compression output, and `tokenless stats summary`
  behavior are unchanged. New rows written to `compression_artifacts`
  in `stats.db` now store each domain's actual `compressor_id` (shared
  with `TokenlessRuntime`); historical rows are not rewritten.

Fixes: 80938fb ("feat(tokenless)!: add protocol v2 lifecycle")
Assisted-by: Antigravity
Signed-off-by: blycf <1355990831@qq.com>
@github-actions github-actions Bot added the component:tokenless src/tokenless/ label Nov 29, 2026
@boluochoufeng
boluochoufeng deployed to ci-sccache-reader November 29, 2026 06:31 — with GitHub Actions Active
@boluochoufeng
boluochoufeng deployed to ci-sccache-reader November 29, 2026 06:31 — with GitHub Actions Active
@boluochoufeng
boluochoufeng deployed to ci-sccache-reader November 29, 2026 06:31 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
ci-sccache-reader — ec651663 Deployed Nov 29, 2026 by boluochoufeng via Test tokenless (Rust & benchmarks) #22504
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:tokenless src/tokenless/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant