Skip to content

Fix system instruction loading failing on repeated calls#358

Open
gziolo wants to merge 6 commits intodevelopfrom
fix/require-once-system-instruction
Open

Fix system instruction loading failing on repeated calls#358
gziolo wants to merge 6 commits intodevelopfrom
fix/require-once-system-instruction

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented Apr 1, 2026

What?

Fix load_system_instruction_from_file() silently returning an empty string when get_system_instruction() is called more than once with the same explicit filename in a single request.

Why?

The method used require_once to load instruction files. On the first call, PHP returns the file's return value (the instruction string). On subsequent calls, require_once returns true instead, causing is_string($content) to fail and the method to silently return ''.

How?

  • Changed require_once to require, consistent with the automatic detection path which already uses require
  • Added a regression test that calls get_system_instruction() twice with the same file and asserts both calls return the instruction
  • Reduced duplication in Abstract_AbilityTest by extracting shared setup into setUp() and a temp file helper

Testing Instructions

  1. Pull this branch down and run composer install
  2. Run npm run test:php -- --filter='Abstract_AbilityTest' — all 10 tests should pass
  3. Run the full test suite with npm run test:php — all tests should pass
Open WordPress Playground Preview
gziolo and others added 3 commits April 1, 2026 10:08
…_file

Calling get_system_instruction() twice with the same explicit filename
silently returns an empty string on the second call because require_once
returns true instead of the file's return value.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EOF
)
Change require_once to require so the file's return value is always
returned, not just on the first inclusion. This matches the behavior
already used on line 175 for the automatic detection path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move shared ability construction and feature dir resolution into setUp.
Add a helper for temp file lifecycle with automatic cleanup in tearDown.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @copilot.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: Copilot.

Co-authored-by: gziolo <gziolo@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.70%. Comparing base (cde564d) to head (e283cd6).

Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #358   +/-   ##
==========================================
  Coverage      57.70%   57.70%           
  Complexity       617      617           
==========================================
  Files             46       46           
  Lines           3173     3173           
==========================================
  Hits            1831     1831           
  Misses          1342     1342           
Flag Coverage Δ
unit 57.70% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
…tyTest

Expose experiment as instance property so delegate tests can assert
against it, and add native PHP types to all test class properties.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gziolo gziolo force-pushed the fix/require-once-system-instruction branch from a0cc159 to d2e658b Compare April 1, 2026 08:27
@gziolo gziolo requested review from Copilot and dkotter April 1, 2026 08:28
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes repeated system-instruction loads returning an empty string by ensuring the instruction file’s return value is retrieved on every call, and adds/updates integration tests to prevent regressions.

Changes:

  • Switch explicit system-instruction loading from require_once to require to preserve the file’s returned string across consecutive calls.
  • Refactor Abstract_AbilityTest setup/cleanup to reduce duplication and add a regression test for consecutive calls.
  • Add a temp file helper and centralized cleanup in tearDown().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
includes/Abstracts/Abstract_Ability.php Fixes repeated loads by using require so the returned instruction string is available on every call.
tests/Integration/Includes/Abstracts/Abstract_AbilityTest.php Refactors common setup and adds coverage for the consecutive-call regression scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

gziolo and others added 2 commits April 1, 2026 10:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ire_once references

Agent-Logs-Url: https://github.com/WordPress/ai/sessions/d1d20095-084d-4a31-9bb9-3a41869f6494

Co-authored-by: gziolo <699132+gziolo@users.noreply.github.com>
@gziolo gziolo self-assigned this Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants