Skip to content

fix(agent): skip unreadable rule files instead of failing all memory - #849

Merged
leookun merged 1 commit into
mainfrom
fix/rules-unreadable-file
Nov 9, 2026
Merged

leookun merged 1 commit into
mainfrom
fix/rules-unreadable-file

Conversation

@leookun

@leookun leookun commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

In the built-in kernel, MemoryLoader.addRules read every .md under .claude/rules with an unguarded readAsStringSync(). One file that isn't UTF-8 text — e.g. a macOS Finder alias named something.md — threw FileSystemException: Failed to decode data using encoding 'utf-8', which propagated out of MemoryLoader.load / reloadExtensions, so no instructions were loaded at all. nested() had the same unguarded read for CLAUDE.md.

Fix

  • Skip a rule file that can't be read; the rest still load.
  • Skip a rules folder whose listing fails (e.g. a subfolder without permission).
  • Same guard for nested CLAUDE.md / CLAUDE.local.md.

Notes

  • Symlinked rules, skills and commands (file links, folder links, a linked rules/skills folder) already worked in the built-in kernel; the new test covers linked rules (skipped on Windows).
  • For reference, the Claude Code CLI kernel (2.1.293) ignores rule symlinks that point outside the project, while following ones inside it; that's CLI behavior, not changed here.

Test

flutter test test/units/utils_test.dart --plain-name MemoryLoader in packages/bao_agent — the new test fails without the fix with the decode error above.

🤖 Generated with BaoCode

A file in .claude/rules that isn't UTF-8 text (e.g. a Finder alias named
`.md`) made MemoryLoader.load throw, so none of the project's
instructions were loaded. Skip such files, and a rules folder that can't
be listed; do the same for nested CLAUDE.md files.

Symlinked rules (files and folders) were already followed; the test now
covers them.

Co-Authored-By: BaoCode <noreply@baocode.dev>
@leookun
leookun merged commit 7231a41 into main Nov 9, 2026
3 checks passed
@leookun
leookun deleted the fix/rules-unreadable-file branch November 9, 2026 03:34
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