Skip to content

Commit 8d1d061

Browse files
committed
fix carry-through of commands for different program
1 parent 130cd17 commit 8d1d061

2 files changed

Lines changed: 81 additions & 7 deletions

File tree

libtbx/langchain/agent/program_registry.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,23 @@ def build_command(self, program_name, files, strategy=None, log=None,
628628

629629
for key, value in strategy.items():
630630
if key not in strategy_defs:
631-
# Check if this looks like a PHENIX parameter (contains dots)
632-
# or is a known short PHIL name from directives/LLM
633-
if '.' in key or '=' in key or key in KNOWN_PHIL_SHORT_NAMES:
634-
# Pass through as key=value. If the value contains
635-
# spaces (e.g. selection expressions) wrap it in single
636-
# quotes so the shell sees it as one argument.
631+
# Allow known short PHIL names (nproc, twin_law, etc.) that
632+
# are not program-specific and don't need to be in strategy_flags.
633+
if key in KNOWN_PHIL_SHORT_NAMES or '=' in key:
637634
val_str = str(value)
638635
if ' ' in val_str and not (val_str.startswith("'") or val_str.startswith('"')):
639636
val_str = "'%s'" % val_str
640637
cmd_parts.append("%s=%s" % (key, val_str))
641-
log("PASSTHROUGH: Adding %s=%s (not in strategy_defs)" % (key, val_str))
638+
log("PASSTHROUGH: Adding %s=%s (known short PHIL name)" % (key, val_str))
639+
elif '.' in key:
640+
# Dotted-path PHIL keys (e.g. refinement.main.number_of_macro_cycles)
641+
# are always program-specific. If they are not in strategy_flags for
642+
# this program they almost certainly came from LLM history contamination
643+
# (copying parameters from a previous program into the current strategy).
644+
# Drop them here; user-supplied dotted overrides go through
645+
# _inject_user_params which appends them directly to the command string.
646+
log("DROPPED: '%s' is a dotted PHIL key not in strategy_flags for %s "
647+
"(likely history contamination from another program)" % (key, program_name))
642648
else:
643649
log("WARNING: Unknown strategy '%s' for %s" % (key, program_name))
644650
continue

libtbx/langchain/tests/tst_audit_fixes.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,74 @@ def test_s2i_build_short_circuits_on_program_stop():
38013801
print(" PASSED: BUILD short-circuits on program=='STOP'")
38023802

38033803

3804+
# =============================================================================
3805+
# CATEGORY S2j — dotted strategy keys from other programs are dropped
3806+
# =============================================================================
3807+
3808+
def test_s2j_refinement_key_dropped_from_ligandfit_strategy():
3809+
"""S2j: refinement.main.number_of_macro_cycles in ligandfit strategy is dropped,
3810+
not passed through to the ligandfit command."""
3811+
print("Test: s2j_refinement_key_dropped_from_ligandfit_strategy")
3812+
sys.path.insert(0, _PROJECT_ROOT)
3813+
try:
3814+
from agent.program_registry import ProgramRegistry
3815+
except ImportError:
3816+
print(" SKIP (ProgramRegistry unavailable)")
3817+
return
3818+
3819+
registry = ProgramRegistry(use_yaml=True)
3820+
dropped = []
3821+
passed = []
3822+
3823+
def log(msg):
3824+
if "DROPPED" in msg:
3825+
dropped.append(msg)
3826+
elif "PASSTHROUGH" in msg:
3827+
passed.append(msg)
3828+
3829+
strategy = {
3830+
"refinement.main.number_of_macro_cycles": 2, # belongs to phenix.refine — must be dropped
3831+
}
3832+
files = {"model": "/fake/placed.pdb", "data": "/fake/data.mtz"}
3833+
cmd = registry.build_command("phenix.ligandfit", files, strategy, log=log)
3834+
3835+
assert_true(len(dropped) > 0,
3836+
"refinement.main.number_of_macro_cycles must be DROPPED for ligandfit, "
3837+
"but got cmd: %r" % cmd)
3838+
assert_true("number_of_macro_cycles" not in (cmd or ""),
3839+
"refinement.main.number_of_macro_cycles must not appear in ligandfit command, "
3840+
"got: %r" % cmd)
3841+
assert_true(len(passed) == 0,
3842+
"No dotted key should be passed through, got: %r" % passed)
3843+
print(" PASSED: refinement.main.number_of_macro_cycles correctly dropped from ligandfit")
3844+
3845+
3846+
def test_s2j_known_short_names_still_pass_through():
3847+
"""S2j: KNOWN_PHIL_SHORT_NAMES (nproc, twin_law, etc.) still pass through normally."""
3848+
print("Test: s2j_known_short_names_still_pass_through")
3849+
sys.path.insert(0, _PROJECT_ROOT)
3850+
try:
3851+
from agent.program_registry import ProgramRegistry
3852+
except ImportError:
3853+
print(" SKIP (ProgramRegistry unavailable)")
3854+
return
3855+
3856+
registry = ProgramRegistry(use_yaml=True)
3857+
passed = []
3858+
3859+
def log(msg):
3860+
if "PASSTHROUGH" in msg and "nproc" in msg:
3861+
passed.append(msg)
3862+
3863+
strategy = {"nproc": 4}
3864+
files = {"model": "/fake/model.pdb", "data": "/fake/data.mtz"}
3865+
cmd = registry.build_command("phenix.ligandfit", files, strategy, log=log)
3866+
3867+
assert_true(len(passed) > 0 or (cmd and "nproc=4" in cmd),
3868+
"nproc should still pass through as a KNOWN_PHIL_SHORT_NAME")
3869+
print(" PASSED: nproc still passes through correctly")
3870+
3871+
38043872
# RUN ALL TESTS
38053873
# =============================================================================
38063874

0 commit comments

Comments
 (0)