Skip to content

fix(cli): keep AGENTS.md enabled by default context reset#2082

Merged
LaZzyMan merged 2 commits into
QwenLM:mainfrom
zy6p:fix/2062-preserve-default-agents-context-loading
Mar 6, 2026
Merged

fix(cli): keep AGENTS.md enabled by default context reset#2082
LaZzyMan merged 2 commits into
QwenLM:mainfrom
zy6p:fix/2062-preserve-default-agents-context-loading

Conversation

@zy6p

@zy6p zy6p commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

TLDR

Fix default context filename reset so AGENTS.md remains effective when settings.context.fileName is not configured.

Dive Deeper

Root cause:

  • In loadCliConfig, when settings.context.fileName is absent, we called:
    • setGeminiMdFilename(getCurrentGeminiMdFilename())
  • getCurrentGeminiMdFilename() returns only the first configured file name.
  • Default state is [QWEN.md, AGENTS.md], but this code collapsed it into only QWEN.md, unintentionally disabling default AGENTS.md loading.

What changed:

  • packages/cli/src/config/config.ts
    • reset defaults using both filenames explicitly:
      • setGeminiMdFilename([DEFAULT_CONTEXT_FILENAME, AGENT_CONTEXT_FILENAME])
  • packages/cli/src/config/config.test.ts
    • added regression test: default path resets to both QWEN.md and AGENTS.md
    • added test: custom settings.context.fileName still overrides as expected

Reviewer Test Plan

  1. Run without context.fileName in settings.
  2. Verify setGeminiMdFilename receives both default names (QWEN.md, AGENTS.md).
  3. Set context.fileName = "CUSTOM_AGENTS.md" and verify custom filename is used.
  4. (Optional behavior check) Create AGENTS.md in project and ensure it is discovered in default configuration.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #2062

@LaZzyMan LaZzyMan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great catch on the root cause! The analysis is spot-on — getCurrentGeminiMdFilename() collapses the array into a single string.

A couple of suggestions:

1. Use getAllGeminiMdFilenames() instead of hardcoding the default array

The current fix hardcodes [DEFAULT_CONTEXT_FILENAME, AGENT_CONTEXT_FILENAME], which duplicates the default value defined in memoryTool.ts. If additional context filenames are added in the future, this code won't automatically pick them up. A more robust approach:

import {
  getAllGeminiMdFilenames,
  // remove getCurrentGeminiMdFilename if no longer needed
} from '@qwen-code/qwen-code-core';

// in loadCliConfig:
} else {
  setServerGeminiMdFilename(getAllGeminiMdFilenames());
}

This keeps the single source of truth in memoryTool.ts.

2. There's a similar issue in packages/core/src/utils/ignorePatterns.ts

ignorePatterns.ts also uses getCurrentGeminiMdFilename() to build file exclusion patterns (line 163):

patterns.push(`**/${getCurrentGeminiMdFilename()}`);

This means AGENTS.md is not excluded from tool scan results (e.g., read_many_files, glob search), causing its content to potentially appear twice in the model's context — once from system memory loading and once from tool output. It should iterate over getAllGeminiMdFilenames() to exclude all configured context files:

for (const filename of getAllGeminiMdFilenames()) {
  patterns.push(`**/${filename}`);
}

@zy6p

zy6p commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @LaZzyMan for the detailed review and the two concrete suggestions.

Both points make sense and I will update this PR accordingly:

  1. Replace the fallback in CLI config reset with getAllGeminiMdFilenames() instead of hardcoded defaults.
  2. Update packages/core/src/utils/ignorePatterns.ts to iterate over getAllGeminiMdFilenames() so all context files are excluded.

I’ll include test updates as well in the follow-up commit.

@zy6p

zy6p commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Implemented in commit d7d2ffb.

Addressed both suggestions:

  1. loadCliConfig fallback now uses getAllGeminiMdFilenames() (instead of hardcoded defaults).
  2. ignorePatterns.ts now excludes all configured context filenames by iterating getAllGeminiMdFilenames().

Also updated tests/mocks accordingly (config.test.ts, ignorePatterns.test.ts).

Thanks again for the review. Please take another look when convenient.

@LaZzyMan LaZzyMan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@LaZzyMan LaZzyMan merged commit 881bef1 into QwenLM:main Mar 6, 2026
14 checks passed
yeelam-gordon added a commit to yeelam-gordon/qwen-code that referenced this pull request Apr 28, 2026
Config.startNewSession() reassigns this.sessionId in the same process,
which is reached by /clear, /reset, /new and /resume. Previously the
old <oldId>.runtime.json was left behind, falsely claiming the still-
live PID for a session no longer being served, and no new sidecar was
written for the incoming session.

Centralize the swap by clearing the old sidecar and writing a fresh
one for the new session id from inside startNewSession itself, so all
same-PID transitions are covered. The refresh runs as a fire-and-
forget best-effort; failures must not block the session switch.

Mirrors the post-merge Codex P1 fix on kimi-cli PR QwenLM#2082 (the source
of the runtime.json sidecar pattern this PR ports).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
yeelam-gordon added a commit to yeelam-gordon/qwen-code that referenced this pull request Apr 29, 2026
Mirrors kimi-cli PR QwenLM#2082 commit e237951f (Codex P1 r3158754463): a
short-lived non-interactive invocation (qwen --prompt, ACP, etc.) that
runs `/clear` would otherwise call `Config.startNewSession()`, delete
a concurrent shell's runtime.json sidecar (same outgoing session id),
and never write a replacement — leaving the shell discoverable to
nobody.

Add a `runtimeStatusEnabled` flag on Config, flipped on by the
interactive UI bootstrap immediately after the first successful
sidecar write, and gate the swap-time refresh in
`startNewSession()` on it. Non-interactive entry points never reach
the bootstrap, so they won't touch sibling sidecars.

Kimi later reverted the equivalent `write only from shell mode`
guard (commit 7083975a) in favor of writing from every long-lived
mode, but qwen's wire point is already interactive-only, so the
narrower guard is the right shape here.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
wenshao pushed a commit that referenced this pull request May 10, 2026
* feat(core): write runtime.json sidecar for active sessions

Port kimi-cli PR #2082 part 1 to qwen-code.

On interactive session start, atomically write a small JSON sidecar at <projectDir>/chats/<sessionId>.runtime.json recording the (pid, session_id, work_dir, hostname, started_at, qwen_version) tuple.

External tools (terminal multiplexers, IDE integrations, status daemons) can map a running PID to its session id and work dir without parsing argv. Write is best-effort: a read-only filesystem must not block UI startup.

OS process title (was #3713) and dynamic OSC tab title (kimi #2083) remain out of scope.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(core): refresh runtime.json on same-PID session swap

Config.startNewSession() reassigns this.sessionId in the same process,
which is reached by /clear, /reset, /new and /resume. Previously the
old <oldId>.runtime.json was left behind, falsely claiming the still-
live PID for a session no longer being served, and no new sidecar was
written for the incoming session.

Centralize the swap by clearing the old sidecar and writing a fresh
one for the new session id from inside startNewSession itself, so all
same-PID transitions are covered. The refresh runs as a fire-and-
forget best-effort; failures must not block the session switch.

Mirrors the post-merge Codex P1 fix on kimi-cli PR #2082 (the source
of the runtime.json sidecar pattern this PR ports).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(core): only refresh runtime.json when this process owns it

Mirrors kimi-cli PR #2082 commit e237951f (Codex P1 r3158754463): a
short-lived non-interactive invocation (qwen --prompt, ACP, etc.) that
runs `/clear` would otherwise call `Config.startNewSession()`, delete
a concurrent shell's runtime.json sidecar (same outgoing session id),
and never write a replacement — leaving the shell discoverable to
nobody.

Add a `runtimeStatusEnabled` flag on Config, flipped on by the
interactive UI bootstrap immediately after the first successful
sidecar write, and gate the swap-time refresh in
`startNewSession()` on it. Non-interactive entry points never reach
the bootstrap, so they won't touch sibling sidecars.

Kimi later reverted the equivalent `write only from shell mode`
guard (commit 7083975a) in favor of writing from every long-lived
mode, but qwen's wire point is already interactive-only, so the
narrower guard is the right shape here.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
xaelistic pushed a commit to xaelistic/qwen-code that referenced this pull request Jun 7, 2026
…ents-context-loading

fix(cli): keep AGENTS.md enabled by default context reset
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.

AGENTS.md does not take effect

2 participants