Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/core/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { SubagentManager } from '../subagents/subagent-manager.js';
import type { SubagentConfig } from '../subagents/types.js';
import { BackgroundTaskRegistry } from '../agents/background-tasks.js';
import { BackgroundShellRegistry } from '../services/backgroundShellRegistry.js';
import { FileReadCache } from '../services/fileReadCache.js';
import {
DEFAULT_OTLP_ENDPOINT,
DEFAULT_TELEMETRY_TARGET,
Expand Down Expand Up @@ -365,6 +366,14 @@ export interface ConfigParameters {
telemetry?: TelemetrySettings;
gitCoAuthor?: boolean;
usageStatisticsEnabled?: boolean;
/**
* If true, disables the per-session FileReadCache short-circuit
* (file_unchanged placeholder). Useful for sessions that may undergo
* context compaction or transcript transformation, where the model
* cannot reliably retrieve a previously-emitted full file content
* from prior tool results. Defaults to false (cache active).
*/
fileReadCacheDisabled?: boolean;
fileFiltering?: {
respectGitIgnore?: boolean;
respectQwenIgnore?: boolean;
Expand Down Expand Up @@ -547,6 +556,7 @@ export class Config {
private subagentManager!: SubagentManager;
private readonly backgroundTaskRegistry = new BackgroundTaskRegistry();
private readonly backgroundShellRegistry = new BackgroundShellRegistry();
private readonly fileReadCache = new FileReadCache();
Comment thread
wenshao marked this conversation as resolved.
Resolved
private extensionManager!: ExtensionManager;
private skillManager: SkillManager | null = null;
private permissionManager: PermissionManager | null = null;
Expand Down Expand Up @@ -601,6 +611,7 @@ export class Config {
private readonly telemetrySettings: TelemetrySettings;
private readonly gitCoAuthor: GitCoAuthorSettings;
private readonly usageStatisticsEnabled: boolean;
private readonly fileReadCacheDisabled: boolean;

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.

[Suggestion] fileReadCacheDisabled is readonly and only set from ConfigParameters in the constructor (L766). No CLI flag, settings.json key, or environment variable is bound to it (grep -r 'fileReadCacheDisabled' packages/cli returns zero hits). The placeholder text and the JSDoc on this field both advertise it as the escape hatch for compaction / transcript-transformation scenarios, but those are runtime events, not construction-time choices — by the time compaction fires, the Config is already built and frozen.

Result: the documented safety net is theoretical. An operator who needs to disable the cache during an incident has to ship a config change + restart, not flip a runtime knob.

Fix: drop readonly here, expose setFileReadCacheDisabled(boolean), and either bind it to a settings-reload path or to an env var (QWEN_DISABLE_FILE_READ_CACHE) so a hot-restart toggles it without code changes. This pairs with the compaction-clear fix in the related comment on startNewSession.

— claude-opus-4-7 via Qwen Code /review (test run)

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.

Acknowledged but not fixed in this PR.

The two failure modes the JSDoc and placeholder advertise are now handled differently:

  1. Compaction: tryCompressChat automatically calls cache.clear() after the prompt history is rewritten — operators no longer need to flip a runtime flag to recover from compaction.
  2. Subagent / transcript transformation: the cache is per-Config-instance (own-property in the getter), so subagents get fresh caches automatically.

What's left is the genuine "incident response" use case — an oncall wanting to disable the cache live without redeploying. That's real but lower-priority. Adding it cleanly requires dropping readonly, adding setFileReadCacheDisabled(boolean), and binding it to a CLI flag / settings entry / env var — which crosses into the @qwen-code/qwen-code (cli) package and reads more like a separately-reviewable scope.

I'd rather defer to a follow-up once we have hit-rate data telling us whether the live disable is actually needed. Happy to file a tracker issue. If you'd prefer to land this PR with the runtime knob already wired in, say the word and I'll add the cli binding before merge.

中文版本

承认问题,但本 PR 不修。

JSDoc 和 placeholder 列的两个失效场景现在分别有自动化处理:

  1. Compaction:tryCompressChat 在 prompt 重写后自动调 cache.clear()——运维方不用手动 flip flag。
  2. Subagent / transcript transformation:cache 现在是 per-Config 实例(getter 里 own-property),subagent 自动拿独立 cache。

剩下的是"事故响应"场景——oncall 想运行时关闭 cache 不重启。这是真需求但优先级较低。加进来要 drop readonly + 加 setFileReadCacheDisabled(boolean) + 绑 CLI flag / settings / env var——跨到 @qwen-code/qwen-code (cli) 包,更适合作为可独立 review 的 follow-up。

倾向先合本 PR,等真实 hit-rate 数据证明运行时开关有需求时再做 follow-up。可以开 tracker issue。如果你坚持本 PR 要带运行时开关,告诉我我就先加 cli 绑定再 merge。

private geminiClient!: GeminiClient;
private baseLlmClient!: BaseLlmClient;
private cronScheduler: CronScheduler | null = null;
Expand Down Expand Up @@ -752,6 +763,7 @@ export class Config {
email: 'qwen-coder@alibabacloud.com',
};
this.usageStatisticsEnabled = params.usageStatisticsEnabled ?? true;
this.fileReadCacheDisabled = params.fileReadCacheDisabled ?? false;
this.outputLanguageFilePath = params.outputLanguageFilePath;

this.fileFiltering = {
Expand Down Expand Up @@ -2496,6 +2508,28 @@ export class Config {
return this.backgroundShellRegistry;
}

/**
* Session-scoped cache that tracks Read / Edit / WriteFile operations
* on files. One instance per Config, which means each subagent that
* creates its own Config inherently starts with an empty cache.
*/
getFileReadCache(): FileReadCache {
return this.fileReadCache;
}

/**
* When true, ReadFile / Edit / WriteFile must bypass the session
* FileReadCache entirely and behave as if it did not exist (no
* `file_unchanged` placeholder, no future prior-read enforcement).
* Intended as an escape hatch for sessions where the cache's "model
* has already seen this content earlier in the conversation"
* assumption is unreliable — e.g. after context compaction or
* transcript transformation.
*/
getFileReadCacheDisabled(): boolean {
return this.fileReadCacheDisabled;
}

/**
* Whether interactive permission prompts should be auto-denied.
* True for background agents that have no UI to show prompts.
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export type { CronDeleteTool, CronDeleteParams } from './tools/cron-delete.js';
export * from './services/chatRecordingService.js';
export * from './services/cronScheduler.js';
export * from './services/fileDiscoveryService.js';
export * from './services/fileReadCache.js';
export * from './services/fileSystemService.js';
export * from './services/gitService.js';
export * from './services/gitWorktreeService.js';
Expand Down
Loading
Loading