Skip to content

fix: use .get() for file_structure keys to prevent KeyError in workdir extras#1476

Open
wgnrai wants to merge 1 commit intoagent0ai:developmentfrom
wgnrai:fix/gitignore-keyerror-workdir-extras
Open

fix: use .get() for file_structure keys to prevent KeyError in workdir extras#1476
wgnrai wants to merge 1 commit intoagent0ai:developmentfrom
wgnrai:fix/gitignore-keyerror-workdir-extras

Conversation

@wgnrai
Copy link
Copy Markdown

@wgnrai wgnrai commented Apr 9, 2026

Problem

When a project's project.json has a file_structure section that is missing the gitignore key, the _75_include_workdir_extras extension crashes with a KeyError during prepare_prompt(). This kills the agent's monologue loop silently, causing the entire agent to halt with no error output.

KeyError: 'gitignore'

  File ".../_75_include_workdir_extras.py", line 33, in execute
    gitignore_raw = project["file_structure"]["gitignore"]

This is especially problematic because project.json files created without a gitignore field (or with partial file_structure configs) will crash every agent loop iteration.

Fix

Replace direct dict access with .get() and sensible defaults for all file_structure keys:

  • enabled -> .get("enabled", False)
  • max_depth -> .get("max_depth", 0)
  • gitignore -> .get("gitignore", "")

Files Changed

  • extensions/python/message_loop_prompts_after/_75_include_workdir_extras.py - 3 lines

Impact

This bug can cause agents to silently freeze/halt when a project is missing the gitignore key in its file_structure config. The fix ensures graceful degradation with defaults.

When a project.json file_structure section is missing the gitignore key,
the extension crashes with KeyError, which can halt the agent entirely.

Fix uses .get() with sensible defaults for all file_structure accesses:
- enabled -> .get("enabled", False)
- max_depth -> .get("max_depth", 0)
- gitignore -> .get("gitignore", "")
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.

1 participant