fix(config): catch schema validation errors in agent scanning loop#27998
Open
kagura-agent wants to merge 1 commit into
Open
fix(config): catch schema validation errors in agent scanning loop#27998kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
When ConfigParse.schema() throws for an agent .md file with invalid frontmatter, the unhandled exception crashes the entire for-loop in ConfigAgent.load(). Since glob returns files in alphabetical order, all agents sorted after the failing file are silently dropped. Wrap the schema validation in try/catch matching the existing error handling pattern for ConfigMarkdown.parse() above it: publish a Session.Event.Error, log the failure, and continue loading the remaining agents. Closes anomalyco#27988
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #27988
Type of change
What does this PR do?
ConfigAgent.load()iterates over all{agent,agents}/**/*.mdfiles using afor...ofloop. The markdown parsing step (ConfigMarkdown.parse) is wrapped in a.catch()that logs the error and continues, but the subsequentConfigParse.schema()call has no error handling. When any agent file fails schema validation (e.g. invalid frontmatter types), the thrownInvalidErrorpropagates up and aborts the entire loop.Since
globreturns files in alphabetical order, every agent file sorted after the failing one is silently dropped. This explains the symptom in #27988: 184 files exist but only ~119 register, with the missing ones clustering at the alphabetical tail.The fix wraps
ConfigParse.schema()in atry/catchthat mirrors the existing error handling pattern forConfigMarkdown.parse(): publish aSession.Event.Error, log the failure with the file path, and continue loading remaining agents.How did you verify your code works?
bun test test/config/— 163 pass, 0 failbun test test/agent/— 47 pass, 0 failloadMode()already handles this correctly viaSchema.decodeUnknownExit+Exit.isSuccesscheck, confirming this is specifically aload()gapScreenshots / recordings
N/A — no UI change.
Checklist