Skip to content

Commit 1c3b280

Browse files
fix: 尝试修复多轮对话缓存失效 skill 提升的问题
1 parent 7a3cc24 commit 1c3b280

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/utils/attachments.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,10 @@ export async function getAttachments(
819819
!options?.skipSkillDiscovery
820820
? [
821821
maybe('skill_discovery', async () => {
822+
if (suppressNextDiscovery) {
823+
suppressNextDiscovery = false
824+
return []
825+
}
822826
const result = await skillSearchModules.prefetch.getTurnZeroSkillDiscovery(
823827
input,
824828
messages ?? [],
@@ -2638,6 +2642,7 @@ const sentSkillNames = new Map<string, Set<string>>()
26382642
export function resetSentSkillNames(): void {
26392643
sentSkillNames.clear()
26402644
suppressNext = false
2645+
suppressNextDiscovery = false
26412646
}
26422647

26432648
/**
@@ -2661,6 +2666,18 @@ export function suppressNextSkillListing(): void {
26612666
}
26622667
let suppressNext = false
26632668

2669+
/**
2670+
* Suppress the next skill-discovery injection on resume. Same rationale as
2671+
* suppressNextSkillListing: skill_discovery attachments are not persisted to
2672+
* transcript for non-ant users, so the prior process's discovery result is
2673+
* already in the conversation history the model sees. Re-generating it would
2674+
* inject duplicate content and bust the prompt cache prefix.
2675+
*/
2676+
export function suppressNextSkillDiscovery(): void {
2677+
suppressNextDiscovery = true
2678+
}
2679+
let suppressNextDiscovery = false
2680+
26642681
// When skill-search is enabled and the filtered (bundled + MCP) listing exceeds
26652682
// this count, fall back to bundled-only. Protects MCP-heavy users (100+ servers)
26662683
// from truncation while keeping the turn-0 guarantee for typical setups.

src/utils/conversationRecovery.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import type {
1818
NormalizedUserMessage,
1919
} from '../types/message.js'
2020
import { PERMISSION_MODES } from '../types/permissions.js'
21-
import { suppressNextSkillListing } from './attachments.js'
21+
import { suppressNextSkillDiscovery, suppressNextSkillListing } from './attachments.js'
2222
import {
2323
copyFileHistoryForResume,
2424
type FileHistorySnapshot,
@@ -403,6 +403,16 @@ export function restoreSkillStateFromMessages(messages: Message[]): void {
403403
suppressNextSkillListing()
404404
}
405405
}
406+
407+
// Unconditionally suppress skill_listing and skill_discovery on resume.
408+
// Attachments are not persisted to transcript for non-ant users
409+
// (isLoggableMessage filters them out), so the per-type checks above may
410+
// never find them even though the prior process already injected the content
411+
// into the conversation via <system-reminder> blocks. Without this, every
412+
// resume re-injects ~1K tokens of duplicate content and busts the Anthropic
413+
// prompt cache prefix (which requires 100% byte-identical segments).
414+
suppressNextSkillListing()
415+
suppressNextSkillDiscovery()
406416
}
407417

408418
/**

0 commit comments

Comments
 (0)