Skip to content
Back to skills

1495 2026 02 02 Sanitize Canonical Cache 7ac05060

ASecurity

The sanitize cleanup loop re-canonicalized messages multiple times per iteration. We now cache canonical messages per iteration, recomputing only after mutations, and remove the double conversion inside `find_dangling_tool_calls()`.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
testingperformance

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1495-2026-02-02-sanitize-canonical-cache_7ac05060 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1495 2026 02 02 Sanitize Canonical Cache 7ac05060?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1495 2026 02 02 Sanitize Canonical Cache 7ac05060
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1495-2026-02-02-sanitize-canonical-cache-7ac05060/badge)](https://www.skillsdirectory.com/skills/tools-only-1495-2026-02-02-sanitize-canonical-cache-7ac05060)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
---
title: Cache Canonical Messages in Cleanup Loop
link: sanitize-canonical-cache
type: delta
path: src/tunacode/core/agents/resume/sanitize.py
depth: 0
seams: [M, D]
ontological_relations:
  - relates_to: [[message-history]]
  - affects: [[sanitize-loop]]
  - fixes: [[canonicalization-bottleneck]]
tags:
  - performance
  - sanitize
  - canonicalization
  - cleanup-loop
created_at: 2026-02-03T03:20:03Z
updated_at: 2026-02-03T03:20:03Z
uuid: ac2bdaf8-9aae-4027-8841-170a46503d96
---

# Cache Canonical Messages in Cleanup Loop

## Summary

The sanitize cleanup loop re-canonicalized messages multiple times per iteration. We now cache canonical messages per iteration, recomputing only after mutations, and remove the double conversion inside `find_dangling_tool_calls()`.

## Context

- Files: `src/tunacode/core/agents/resume/sanitize.py`, `src/tunacode/utils/messaging/adapter.py`
- Symptom: redundant `to_canonical()` calls during cleanup iterations.

## Root Cause

Canonicalization was happening in each cleanup helper (and twice per message in `find_dangling_tool_calls()`), so a single iteration performed multiple full conversions of the same message list.

## Changes

- Converted each message once inside `find_dangling_tool_calls()` by reusing a single canonical instance.
- Cached canonical messages at the start of each cleanup iteration and recomputed only after mutations.
- Added canonical cache passthroughs to `remove_empty_responses()` and `remove_consecutive_requests()`.
- Added a unit test to verify 1N conversions in a no-mutation iteration.

## Behavioral Impact

- Cleanup iterations now run with fewer canonicalization passes (1N without mutations, 2N when deletions occur).
- Cleanup behavior and tool-call pruning logic remain unchanged.

## Related Cards

- [[message-history]]
- [[sanitize-loop]]

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.