Skip to content

Commit c33e8ce

Browse files
committed
[fix.research.σ.D8+] Close Qwen semantics after exact intent selection
Constrain the second structured generation to action-specific constants after Qwen has selected the intent and subject. This removes an observed failure mode where a valid JSON grammar still let free text consume the completion budget, while preserving the model-owned multilingual decision and keeping IDs, governance, hypotheses, and execution consequences server bounded. Regenerate the architecture twin and make the 16 GiB benchmark default conservative. The previously truncating 6.5k-character mixed-language case now compiles to the exact expected preparation Command in one attempt.
1 parent a1f8ee5 commit c33e8ce

6 files changed

Lines changed: 2054 additions & 1083 deletions

File tree

‎backend/research/reasoner.py‎

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,54 @@ def build_generation_schema(
470470
return schema
471471

472472

473-
def build_action_semantics_schema() -> dict[str, Any]:
474-
"""Small model-owned WHY surface; IDs and governance stay server-owned."""
475-
fields = ("summary", "scientific_question", "rationale",
476-
"expected_observation", "falsifier")
473+
def build_action_semantics_schema(selected_template_id: str) -> dict[str, Any]:
474+
"""Closed action semantics; the model chooses, while prose cannot run away."""
475+
by_template = {
476+
"fep.run_selected_edge.v1": {
477+
"summary": "Run the selected prepared FEP edge.",
478+
"scientific_question": "What FEP result does the selected prepared edge produce?",
479+
"rationale": "The selected edge is prepared and matches the current human goal.",
480+
"expected_observation": "A governed FEP method result is recorded for the selected edge.",
481+
"falsifier": "Stale context, failed admission, or an invalid result blocks this proposal.",
482+
},
483+
"fep.prepare_selected_edge.v1": {
484+
"summary": "Prepare the selected edge for FEP.",
485+
"scientific_question": "Can the selected edge be prepared under the governed protocol?",
486+
"rationale": "The requested FEP edge exists but is not yet prepared.",
487+
"expected_observation": "A governed prepared-system result is recorded for the selected edge.",
488+
"falsifier": "Preparation failure or stale Campaign state blocks this proposal.",
489+
},
490+
"fep.replan_network.v1": {
491+
"summary": "Build a governed RBFE network.",
492+
"scientific_question": "Which governed RBFE network represents the current ligand series?",
493+
"rationale": "The current human goal requests network construction before edge execution.",
494+
"expected_observation": "A governed RBFE network artifact is recorded for the Campaign.",
495+
"falsifier": "Invalid Campaign inputs or stale context blocks network construction.",
496+
},
497+
"fep.defer_for_experiment.v1": {
498+
"summary": "Defer the next decision to the requested experiment.",
499+
"scientific_question": "Which requested external observation is needed before more FEP work?",
500+
"rationale": "The current human goal requests an experiment rather than computational FEP.",
501+
"expected_observation": "The loop records the requested experiment as the next action boundary.",
502+
"falsifier": "A revised human goal that requests a governed computational action supersedes it.",
503+
},
504+
"fep.stop.v1": {
505+
"summary": "Stop the research loop without starting new work.",
506+
"scientific_question": "Has the human goal explicitly ended this research loop?",
507+
"rationale": "The current human goal explicitly requests no new governed action.",
508+
"expected_observation": "The loop reaches a terminal stopped state without dispatching work.",
509+
"falsifier": "A later explicit human request must create or resume an authorized workflow.",
510+
},
511+
}
512+
values = by_template.get(selected_template_id)
513+
if values is None:
514+
raise failures.DiracInternal(
515+
f"unknown action template for semantics schema: {selected_template_id}")
477516
return {
478517
"type": "object", "additionalProperties": False,
479-
"required": list(fields),
518+
"required": list(values),
480519
"properties": {
481-
field: {"type": "string", "minLength": 1, "maxLength": 96}
482-
for field in fields
520+
field: {"const": value} for field, value in values.items()
483521
},
484522
}
485523

@@ -799,7 +837,8 @@ def propose_handler(payload: dict, ctx: InvocationContext) -> HandlerResult:
799837
interpreter_result)
800838
provider_http_attempts += interpreter_result.attempts
801839
_sum_usage(usage, interpreter_result.usage)
802-
output_schema = build_action_semantics_schema()
840+
output_schema = build_action_semantics_schema(
841+
str(goal_interpretation["selected_template_id"]))
803842
maximum_regenerations = int(profile.document["bounds"]["max_schema_regenerations"])
804843
validation_error: dict[str, Any] | None = None
805844
latest_metadata: dict[str, Any] = {}

‎backend/tests/test_research_reasoner_method.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ def tearDown(self):
9090
self.server.server_close()
9191
self.thread.join(timeout=2)
9292

93-
def test_local_qwen_semantics_are_bounded_below_completion_budget(self):
94-
schema = build_action_semantics_schema()
95-
self.assertEqual(
96-
{field["maxLength"] for field in schema["properties"].values()},
97-
{96},
98-
)
93+
def test_local_qwen_semantics_are_closed_by_selected_action(self):
94+
schema = build_action_semantics_schema("fep.run_selected_edge.v1")
95+
self.assertTrue(all(
96+
set(field) == {"const"}
97+
for field in schema["properties"].values()
98+
))
9999
profile = EXAMPLE["profiles"][1]
100100
for request_fields in (
101101
"static_request_fields", "classifier_request_fields"):

‎docs/architecture/dirac-digital-twin.html‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)