Skip to content

Feature/add skill recovery#985

Closed
sah1234567 wants to merge 2 commits intoHmbown:mainfrom
sah1234567:feature/add_skill_recovery
Closed

Feature/add skill recovery#985
sah1234567 wants to merge 2 commits intoHmbown:mainfrom
sah1234567:feature/add_skill_recovery

Conversation

@sah1234567
Copy link
Copy Markdown

@sah1234567 sah1234567 commented May 7, 2026

Summary

Add skill invocation tracking with deduplication and automatic post-compaction re-injection — the model no longer loses loaded skill content when context is compacted.

What changed

  • Session tracking (session.rs): new InvokedSkillRecord struct and invoked_skills: HashMap<String, InvokedSkillRecord> field on Session. Repeated load_skill calls for the same skill name overwrite the previous entry — the HashMap key is the dedup mechanism.

  • Turn loop recording (turn_loop.rs): when a load_skill tool call succeeds, the full raw body is recorded via Session::record_skill_invocation() so it survives compaction.

  • Compaction injection (compaction.rs): inject_invoked_skills() builds a single synthetic user message from every recorded skill, placed at the front of the post-compact message list. The format follows Claude Code's layout: a leading sentence (The following skills were invoked…), ### Skill: {name} markdown headers, --- separators, most-recent-first ordering, and no artificial token budget.

  • Cycle advance cleanup (engine.rs): invoked_skills is cleared alongside compaction_summary_prompt on cycle boundaries.

  • All 4 compact_messages_safe call sites (engine.rs, turn_loop.rs, capacity_flow.rs) pass invoked_skills through.

Files changed

File Change
crates/tui/src/core/session.rs +InvokedSkillRecord, +invoked_skills field, +record_skill_invocation() method
crates/tui/src/core/engine/turn_loop.rs Record on load_skill success
crates/tui/src/compaction.rs +inject_invoked_skills(), new param on compact_messages / compact_messages_safe
crates/tui/src/core/engine.rs Pass invoked_skills to compaction, clear on cycle advance
crates/tui/src/core/engine/capacity_flow.rs Pass invoked_skills to compaction
crates/tui/src/core/engine/tests.rs +7 engine-level tests
crates/tui/tests/skill_compaction_recovery.rs +7 integration tests
crates/tui/tests/test_skills/ 5 minimal skill fixtures for integration tests

Testing

  • cargo test -p deepseek-tui --bin deepseek-tui (2170 passed; 12 pre-existing repl::runtime failures unrelated to this PR)
  • cargo test -p deepseek-tui --test skill_compaction_recovery (7/7 passed)
  • Verified cargo build produces zero new warnings
  • Manual reasoning: traced end-to-end flow for dedup, compaction ordering, summary non-interference, and cycle clearing

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes (N/A — no UI surface, pure engine logic)

sah and others added 2 commits May 7, 2026 14:59
- Session: add `InvokedSkillRecord` and `invoked_skills` HashMap (dedup
  by skill_name key with overwrite-on-repeat semantics).
- Turn loop: record `load_skill` invocations with full raw body content.
- Compaction: inject all invoked skills as a single synthetic user
  message at the front of the post-compact message list (matching Claude
  Code's layout: leading sentence, `### Skill: {name}` headers, `---`
  separators, most-recent-first ordering, no artificial token budget).
- Cycle advance: clear `invoked_skills` alongside `compaction_summary_prompt`.
- All 4 `compact_messages_safe` call sites pass `invoked_skills`.

Tests: 17 new tests covering recording, dedup, injection format,
single-message bundling, ordering, and cycle-clear behavior.

Co-Authored-By: Opus 4.7 <noreply@anthropic.com>
Verifies on-demand loading (only invoked skills appear, not the full
catalogue), deduplication (repeat calls produce one entry with latest
content), and markdown structure alignment with Claude Code.

Includes 5 minimal skill fixtures under tests/test_skills/.

Co-Authored-By: Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a system to preserve invoked skill content during message compaction by re-injecting it as a synthetic user message. It introduces the InvokedSkillRecord struct and a HashMap in the Session to track and deduplicate skill invocations, ensuring the latest content is maintained. The engine's turn loop now records successful load_skill tool calls, and the compaction logic integrates these records into the post-compaction message stream. Comprehensive unit and integration tests have been added to verify the deduplication, ordering, and recovery of skill content. I have no feedback to provide.

@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 7, 2026

Thanks for working on this. This PR is too large or scope-mixed for review in this repo's current maintainer model. Please split it into one PR per accepted issue, each under 500 changed lines and with a concrete test plan. Changes to core compaction/session behavior need maintainer approval before implementation.

This PR also needs the admission details from the contributor guide before review: a linked accepted issue, AI-use disclosure, a human-owner statement that you have read and can explain every changed file, and a clean test plan with commands that pass. I am closing this PR, but a smaller PR against an accepted issue is welcome.

@Hmbown Hmbown closed this May 7, 2026
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.

2 participants