Skip to content

fix(file): ensure JSON-serializable string paths in describe_available_files - #732

Open
pei711 wants to merge 1 commit into
OpenBMB:mainfrom
pei711:fix/describe-available-files-serialization
Open

pei711 wants to merge 1 commit into
OpenBMB:mainfrom
pei711:fix/describe-available-files-serialization

Conversation

@pei711

@pei711 pei711 commented Nov 18, 2026

Copy link
Copy Markdown

Description

This PR ensures that describe_available_files() in functions/function_calling/file.py returns string paths (as_posix() and str(abs_path)) so the resulting dictionary is JSON-serializable, and validates that limit is positive.

Problem

In functions/function_calling/file.py, describe_available_files() stored workspace_path and abs_path directly as pathlib.Path instances:

abs_path = (ctx.workspace_root / entry.path).resolve()
workspace_path = Path(entry.path)
entries.append({
    "id": entry.path,
    "name": Path(entry.path).name,
    "source": "workspace",
    "path": workspace_path,      # PosixPath object
    "absolute_path": abs_path,   # PosixPath object
    ...
})

Because Path instances are not JSON serializable, calling json.dumps() on the return dictionary raised TypeError: Object of type PosixPath is not JSON serializable. In the agent runtime (agent_executor.py), this failure caught in _stringify_tool_result forced a fallback to Python's str() representation ({'path': PosixPath('...')}), sending invalid non-JSON strings to the language model.

Additionally, describe_available_files() silently accepted non-positive limits (clamping them to 1) instead of raising ValueError("limit must be positive"), which is inconsistent with list_directory().

Solution

  1. Stored path as Path(entry.path).as_posix() and absolute_path as str(abs_path).
  2. Validated if limit <= 0: raise ValueError("limit must be positive"), matching list_directory().
  3. Added unit tests in tests/test_describe_available_files.py to verify JSON serializability, limit validation, truncation, and hidden file filtering.

Verification

  • pytest tests/test_describe_available_files.py: 4 passed in 0.06s.
  • pytest tests/test_websocket_send_message_sync.py tests/test_attachment_upload_filename.py: 20 passed.
  • ruff check tests/test_describe_available_files.py: All checks passed.
  • git diff origin/main --check: Clean.

AI Assistance Disclosure

This contribution was prepared with AI assistance; reproduction, patch implementation, and unit testing were developed and validated locally before submission.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T07:43:31.229453Z 8c0b4de PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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