Skip to content

Rectify: Token Summary Silent Session Exclusion — Structural Scoping Immunity#3900

Merged
Trecek merged 10 commits into
developfrom
token-summary-silently-excludes-worktree-scoped-sessions-imp/3886
Jun 8, 2026
Merged

Rectify: Token Summary Silent Session Exclusion — Structural Scoping Immunity#3900
Trecek merged 10 commits into
developfrom
token-summary-silently-excludes-worktree-scoped-sessions-imp/3886

Conversation

@Trecek

@Trecek Trecek commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

The token summary pipeline silently excludes worktree-scoped sessions because patch_pr_token_summary falls back to cwd_filter (exact path match) when order_id is absent, and worktree sessions have a different cwd than the clone root. The root architectural weakness is that the pipeline uses a positional attribute (filesystem path) as a logical grouping key, and every layer silently drops mismatches instead of surfacing them. The fix applied in PR #1686 added order_id_filter to the filtering layer but never wired it into any recipe YAML, leaving the infrastructure unused.

The immunity approach mirrors the pattern already used by token_summary_hook.py: use kitchen_id as the session-scoping fallback (via kitchen_id_filter, NOT order_id_filter), because kitchen_id is already written to every sessions.jsonl entry by flush_session_log and is shared by all sessions in a pipeline run regardless of their cwd. This is combined with a completeness assertion that cross-checks loaded token summary steps against the recipe's declared run_skill steps, turning silent data loss into a loud error.

Implementation Plan

Plan file: /home/talon/projects/autoskillit-runs/remediation-20260607-213554-028213/.autoskillit/temp/rectify/rectify_token_summary_session_scoping_2026-06-07_213554.md

Closes #3886

🤖 Generated with Claude Code via AutoSkillit

Token Usage Summary

Step Model count uncached output cache_read peak_ctx turns cache_write time
rectify* opus[1m] 1 102 35.3k 4.8M 151.3k 82 151.7k 29m 50s
review_approach* sonnet 1 52 7.5k 234.3k 54.4k 15 37.3k 6m 17s
dry_walkthrough* opus 1 62 15.4k 2.1M 105.5k 65 105.7k 7m 23s
audit_impl* sonnet 1 102 11.5k 485.1k 57.0k 34 36.1k 6m 1s
make_plan* sonnet 1 44 9.3k 167.2k 39.6k 10 23.1k 4m 31s
prepare_pr* MiniMax-M3 1 46.8k 4.1k 126.5k 52.4k 13 0 1m 19s
compose_pr* MiniMax-M3 1 35.1k 1.3k 188.1k 38.6k 12 0 54s
review_pr* sonnet 3 490 104.4k 3.9M 113.6k 162 258.0k 27m 47s
resolve_review* opus[1m] 2 123 39.7k 5.0M 109.6k 119 164.9k 22m 29s
diagnose_ci* MiniMax-M3 4 150.9k 8.6k 1.1M 43.7k 65 0 6m 6s
resolve_ci* opus[1m] 3 176 25.6k 5.6M 117.0k 145 157.5k 19m 35s
Total 233.9k 262.6k 23.7M 151.3k 934.2k 2h 12m

* Step used a non-Anthropic provider; caching behavior may differ.

Token Efficiency

Step LoC Changed cache_read/LoC cache_write/LoC output/LoC
rectify 0
review_approach 0
dry_walkthrough 0
audit_impl 0
make_plan 0
prepare_pr 0
compose_pr 0
review_pr 0
resolve_review 24 208781.6 6872.6 1652.4
diagnose_ci 0
resolve_ci 51 109290.2 3087.8 502.3
Total 75 316269.6 12456.1 3501.8

Model Usage Breakdown

Model steps uncached output cache_read cache_write time
opus[1m] 3 401 100.6k 15.4M 474.1k 1h 11m
sonnet 4 688 132.7k 4.8M 354.5k 44m 38s
opus 1 62 15.4k 2.1M 105.7k 7m 23s
MiniMax-M3 3 232.8k 13.9k 1.4M 0 8m 20s

Trecek and others added 6 commits June 7, 2026 23:30
Add a three-tier scoping fallback chain in patch_pr_token_summary so
worktree-scoped sessions are no longer silently excluded from PR token
summaries. order_id (fleet) → kitchen_id (standalone) → cwd (last
resort), mirroring the immunity pattern in token_summary_hook.py.

Add check_step_completeness to the TokenLog protocol and DefaultTokenLog
so silent data loss becomes a loud warning row in the PR body when
expected steps are missing. Add debug logging at the cwd_filter and
token-load skip points to eliminate "completely silent" anti-patterns.

Rename patch-token-summary-requires-order-id → requires-scoping-key and
add a new ERROR-severity mixed-cwd-without-scoping-key rule that fires
when run_skill steps mix cwd expressions but patch_pr_token_summary has
no scoping key. Add public read_kitchen_id_from_marker in core/runtime
for IL-0 callers to resolve kitchen_id from the on-disk hook config.

Fix session_log.py provenance anchoring to use project_dir (not cwd)
so worktree provenance survives worktree cleanup.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add tests covering: cwd_filter excludes worktree sessions, kitchen_id
filter includes them, patch_pr_token_summary kitchen_id fallback,
expected_steps missing-step warning, semantic rule severity and python:
shorthand detection, mixed-cwd ERROR rule, provenance anchored to
project_dir, and DefaultTokenLog satisfies updated TokenLog protocol
with check_step_completeness.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add autouse fixture to mock read_kitchen_id_from_marker in smoke_utils
  tests, preventing active kitchen sessions from interfering with
  cwd_filter-based test assertions
- Add mixed-cwd-without-scoping-key rule to _KNOWN_NON_CONFORMING_RULES
  allowlists across 5 recipe test files (the rule fires correctly but
  patch_pr_token_summary self-resolves kitchen_id from disk)
- Pass project_dir to _flush in provenance test to match the updated
  write_provenance_record signature (project_dir instead of cwd)
- Whitelist core/runtime/kitchen_state.py in hardcoded temp path test
  (stdlib-only IL-0 module that reads hook config from canonical path)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ss-order false negatives

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… to decouple from sort order

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rmalizer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Trecek Trecek force-pushed the token-summary-silently-excludes-worktree-scoped-sessions-imp/3886 branch from 2e92b9e to 114c36e Compare June 8, 2026 06:30
…docstring

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

@Trecek Trecek left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AutoSkillit review passed. No blocking issues found.

Trecek and others added 3 commits June 8, 2026 00:14
patch_pr_token_summary self-resolves kitchen_id from disk via
read_kitchen_id_from_marker, so the absence of the key in recipe
with_args is not a functional bug. ERROR severity caused
load_and_validate to return valid=False, breaking
test_content_integrity parametrized cases across 4 bundled recipes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Trecek Trecek added this pull request to the merge queue Jun 8, 2026
Merged via the queue into develop with commit df3a31b Jun 8, 2026
3 checks passed
@Trecek Trecek deleted the token-summary-silently-excludes-worktree-scoped-sessions-imp/3886 branch June 8, 2026 14:20
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