-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(core): honor runtime output dir for auto memory #4715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import { Storage } from '../config/storage.js'; | ||
| import { QWEN_DIR, sanitizeCwd } from '../utils/paths.js'; | ||
| import { QWEN_DIR, resolvePath, sanitizeCwd } from '../utils/paths.js'; | ||
| import type { AutoMemoryType } from './types.js'; | ||
|
|
||
| export const AUTO_MEMORY_DIRNAME = 'memory'; | ||
|
|
@@ -81,38 +81,42 @@ function findCanonicalGitRoot(startPath: string): string | null { | |
|
|
||
| /** | ||
| * Returns the base directory for all auto-memory storage. | ||
| * Defaults to the global qwen dir (`~/.qwen` or `$QWEN_HOME`); | ||
| * Defaults to the runtime output dir (`runtimeOutputDir`, `QWEN_RUNTIME_DIR`, | ||
| * or the global qwen dir); | ||
| * overridable via QWEN_CODE_MEMORY_BASE_DIR for tests. | ||
| */ | ||
| export function getMemoryBaseDir(): string { | ||
| if (process.env['QWEN_CODE_MEMORY_BASE_DIR']) { | ||
| return process.env['QWEN_CODE_MEMORY_BASE_DIR']; | ||
| return resolvePath(undefined, process.env['QWEN_CODE_MEMORY_BASE_DIR']); | ||
| } | ||
| return Storage.getGlobalQwenDir(); | ||
| return Storage.getRuntimeBaseDir(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] Changing from Suggested fix: Add a one-time migration — when the new path doesn't exist but the old — qwen3.7-max via Qwen Code /review |
||
| } | ||
|
|
||
| // Memoize by projectRoot — findCanonicalGitRoot() walks the file system (existsSync | ||
| // per directory) and is called from hot-path code such as schedulers and scanners. | ||
| // Memoize by projectRoot plus the runtime-specific base dir. In daemon mode, | ||
| // different sessions can share a project root while writing to different output dirs. | ||
| const _autoMemoryRootCache = new Map<string, string>(); | ||
|
|
||
| export function getAutoMemoryRoot(projectRoot: string): string { | ||
| const cached = _autoMemoryRootCache.get(projectRoot); | ||
| const useLocalMemory = process.env['QWEN_CODE_MEMORY_LOCAL'] === '1'; | ||
| const memoryBaseDir = useLocalMemory ? '' : getMemoryBaseDir(); | ||
| const cacheKey = `${useLocalMemory ? 'local' : memoryBaseDir}\0${projectRoot}`; | ||
| const cached = _autoMemoryRootCache.get(cacheKey); | ||
| if (cached !== undefined) return cached; | ||
|
|
||
| let result: string; | ||
| if (process.env['QWEN_CODE_MEMORY_LOCAL'] === '1') { | ||
| if (useLocalMemory) { | ||
| result = path.join(projectRoot, QWEN_DIR, AUTO_MEMORY_DIRNAME); | ||
| } else { | ||
| const canonicalRoot = | ||
| findCanonicalGitRoot(projectRoot) ?? path.resolve(projectRoot); | ||
| result = path.join( | ||
| getMemoryBaseDir(), | ||
| memoryBaseDir, | ||
| 'projects', | ||
| sanitizeCwd(canonicalRoot), | ||
| AUTO_MEMORY_DIRNAME, | ||
| ); | ||
| } | ||
| _autoMemoryRootCache.set(projectRoot, result); | ||
| _autoMemoryRootCache.set(cacheKey, result); | ||
| return result; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test