Rectify: Token Summary Silent Session Exclusion — Structural Scoping Immunity#3900
Merged
Trecek merged 10 commits intoJun 8, 2026
Merged
Conversation
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>
2e92b9e to
114c36e
Compare
…docstring Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Trecek
commented
Jun 8, 2026
Trecek
left a comment
Collaborator
Author
There was a problem hiding this comment.
AutoSkillit review passed. No blocking issues found.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The token summary pipeline silently excludes worktree-scoped sessions because
patch_pr_token_summaryfalls back tocwd_filter(exact path match) whenorder_idis absent, and worktree sessions have a differentcwdthan 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 addedorder_id_filterto 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: usekitchen_idas the session-scoping fallback (viakitchen_id_filter, NOTorder_id_filter), becausekitchen_idis already written to everysessions.jsonlentry byflush_session_logand is shared by all sessions in a pipeline run regardless of theircwd. This is combined with a completeness assertion that cross-checks loaded token summary steps against the recipe's declaredrun_skillsteps, 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.mdCloses #3886
🤖 Generated with Claude Code via AutoSkillit
Token Usage Summary
* Step used a non-Anthropic provider; caching behavior may differ.
Token Efficiency
Model Usage Breakdown