Skip to content

fix: avoid hardcoded sandbox skill root in prompt fallback#6983

Closed
1zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
1zzxy1:fix/sandbox-skill-path-fallback
Closed

fix: avoid hardcoded sandbox skill root in prompt fallback#6983
1zzxy1 wants to merge 1 commit intoAstrBotDevs:masterfrom
1zzxy1:fix/sandbox-skill-path-fallback

Conversation

@1zzxy1
Copy link
Copy Markdown
Contributor

@1zzxy1 1zzxy1 commented Mar 26, 2026

Summary

  • stop falling back to a hardcoded /workspace/skills/... path for sandbox skills when cache metadata is missing or invalid
  • use the sandbox-relative skills//SKILL.md fallback so shipyard sandboxes still get a readable prompt path
  • relax the prompt wording from �bsolute path to path shown above and add regression coverage for the fallback path behavior

Fixes #5922

Testing

  • uv run --group dev pytest tests/test_skill_manager_sandbox_cache.py::test_sandbox_path_fallback_uses_relative_skills_root tests/test_skill_metadata_enrichment.py::test_build_skills_prompt_allows_relative_sandbox_path_examples -q`n- full ests/test_skill_metadata_enrichment.py was not run in this Windows environment because several existing Windows-path assertions in that file assume Linux-style os.path behavior

Summary by Sourcery

Adjust sandbox skill path handling and prompt instructions to avoid hardcoded workspace paths and support relative sandbox paths.

Bug Fixes:

  • Stop using a hardcoded /workspace-based fallback path for sandbox skills when cache metadata is missing or invalid.

Enhancements:

  • Fallback sandbox skill paths now use a sandbox-relative skills//SKILL.md location.
  • Relax the skills prompt wording to reference the shown path instead of requiring an absolute path.
  • Add regression tests for sandbox path fallback behavior and relative sandbox path examples in the skills prompt.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 26, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where sandbox skill paths would incorrectly fall back to a hardcoded absolute path. It refactors the skill manager to use a relative path for sandbox skills, improving flexibility and correctness. Additionally, the user prompt for skill grounding has been updated to reflect this change, and comprehensive regression tests have been added to ensure the new behavior is robust.

Highlights

  • Eliminated hardcoded sandbox skill root: The /workspace/skills/... path is no longer used as a fallback for sandbox skills when cache metadata is missing or invalid.
  • Implemented relative path fallback: Sandbox skills now correctly use skills/<name>/SKILL.md as a fallback, ensuring shipyard sandboxes receive a readable prompt path.
  • Updated prompt wording: The prompt now refers to 'path shown above' instead of 'absolute path' for skill grounding instructions.
  • Added regression tests: New test cases cover the updated sandbox path fallback behavior and verify the relaxed prompt wording.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot Bot added the area:core The bug / feature is about astrbot's core, backend label Mar 26, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider updating the docstring or adding a short comment for _default_sandbox_skill_path to make it explicit that it now returns a sandbox-relative path instead of an absolute path, so future callers don’t assume absolute semantics.
  • It may be worth scanning for any remaining references or assumptions about /workspace/skills/... elsewhere in the codebase and consolidating them to use the new sandbox-relative skills/<name>/SKILL.md convention to avoid mixed path styles.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider updating the docstring or adding a short comment for `_default_sandbox_skill_path` to make it explicit that it now returns a sandbox-relative path instead of an absolute path, so future callers don’t assume absolute semantics.
- It may be worth scanning for any remaining references or assumptions about `/workspace/skills/...` elsewhere in the codebase and consolidating them to use the new sandbox-relative `skills/<name>/SKILL.md` convention to avoid mixed path styles.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors how sandbox skill paths are handled, transitioning from absolute paths (prefixed with /workspace) to relative paths. This change involves removing the SANDBOX_WORKSPACE_ROOT constant, updating the _default_sandbox_skill_path function, and modifying the build_skills_prompt to remove the 'absolute path' requirement. New tests have been added to validate these changes. A suggestion was made to refactor repeated test setup logic into a pytest fixture to improve maintainability and reduce code duplication.

Comment on lines +163 to +179
data_dir = tmp_path / "data"
temp_dir = tmp_path / "temp"
skills_root = tmp_path / "skills"
data_dir.mkdir(parents=True, exist_ok=True)
temp_dir.mkdir(parents=True, exist_ok=True)
skills_root.mkdir(parents=True, exist_ok=True)

monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_data_path",
lambda: str(data_dir),
)
monkeypatch.setattr(
"astrbot.core.skills.skill_manager.get_astrbot_temp_path",
lambda: str(temp_dir),
)

mgr = SkillManager(skills_root=str(skills_root))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The setup logic for creating directories and monkeypatching path functions is repeated across multiple tests in this file. To improve maintainability and reduce code duplication, consider extracting this common setup into a pytest fixture.

This would make the tests cleaner and easier to manage. For example:

@pytest.fixture
def skill_manager(monkeypatch, tmp_path: Path) -> SkillManager:
    data_dir = tmp_path / "data"
    temp_dir = tmp_path / "temp"
    skills_root = tmp_path / "skills"
    data_dir.mkdir(parents=True, exist_ok=True)
    temp_dir.mkdir(parents=True, exist_ok=True)
    skills_root.mkdir(parents=True, exist_ok=True)

    monkeypatch.setattr(
        "astrbot.core.skills.skill_manager.get_astrbot_data_path",
        lambda: str(data_dir),
    )
    monkeypatch.setattr(
        "astrbot.core.skills.skill_manager.get_astrbot_temp_path",
        lambda: str(temp_dir),
    )

    return SkillManager(skills_root=str(skills_root))

Tests can then be simplified by using this fixture, for example:

def test_sandbox_path_fallback_uses_relative_skills_root(skill_manager: SkillManager):
    skill_manager.set_sandbox_skills_cache(...)
    skills = skill_manager.list_skills(runtime="sandbox")
    # ... assertions

@1zzxy1
Copy link
Copy Markdown
Contributor Author

1zzxy1 commented Mar 26, 2026

Closing this PR until it has been properly tested.

@1zzxy1 1zzxy1 closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]Wrong skill path of system prompt in shipyard sandbox

1 participant