Phase 6.4: make the gates fail when they cannot verify something
A code review found seven ways these gates could pass green with something actually wrong. All are the same family: a missing value was treated as OK. The rule now written into all three files is that absent is not OK, absent is "could not verify", and that either fails or is reported as an explicit SKIP - it never slips through as green. 30_eval_suite.py: - A bucket with no baseline of its own fell back to the global 0.2750 and printed it in a column headed "baseline", as if it were that bucket's number. Measured against the real eval.jsonl buckets: negativos going from 0.12 to 0.33 is a real +0.21 regression, but the computed delta was +0.055 and it PASSED; manejo_errores sitting unchanged at 0.42 produced a fabricated +0.145 FAIL that would have discarded a healthy candidate mid-downtime. Now such buckets print SKIP and the verdict reports how many went unverified. - "VEREDICTO: FAIL" exited 0, so a runbook chaining the gate into quantization would have carried on to write 24 GB. Now exits 1. - A typo in BASELINE_BUCKET_LOSSES silently matched nothing; now aborts. - The penpot exemption is labelled honestly: those 11 rows are pre-existing LoRA #1 tool-calling, not new capability, so gate 1 has no regression coverage there and the log says so. 20_merge_lora.py dry-run (merge path untouched, verified by AST diff): - adapter_config.get("use_rslora", False) meant a missing key passed AND the log printed use_rslora=False, asserting it had checked something that was never there. A different PEFT version omitting a key was enough. - lora_bias was not checked at all, only bias. They are different fields: lora_bias puts a bias inside lora_B, which W + scaling * (B @ A) ignores. - The 620 keys were printed but never asserted, so an adapter with extra tensors printed "310 + 310 = 930" and passed. - rank_pattern/alpha_pattern were not checked. They set r per module, so scaling is not uniformly alpha/r while both the dry-run and the merge apply a single 2.0 to all 310 tensors. - A missing family was invisible: swap linear_attn for 150 mlp.gate targets and the total is still 310, no norm is zero because the family is simply gone, and it passed. Now presence and per-family counts are asserted, derived from the real adapter: linear_attn 150, shared_expert 120, attention_qkvo 40, otros 0. Verified against seven synthetic adapters plus the real phase 3 one; only the correct adapter passes. 21_quantize_nvfp4.py (recipe and oneshot untouched): the calibration cache now carries a provenance.json recording the training file's sha256, the recipe numbers and the bucket distribution, and loading aborts on mismatch. This is the phase's number one risk and it had no mechanical defence: the phase 5 cache on disk has exactly 512 rows, the same as the v2 recipe, so the only existing check could not tell them apart and reusing it would have calibrated with zero design data and washed out the new capability silently. Verified: that cache now aborts. gate 5: retry transport failures against the Penpot MCP, which drops connections mid-call intermittently (seen before in phase 4's gate 4). Without it a blip on prompt 6 of 8 kills a whole run and reads like a model failure. PluginNotConnected is deliberately not retried - that is a real state of the world. Also unwrap the {"result":..., "log":...} envelope the server wraps execute_code returns in; the gate was reading keys off the outer object and rejecting a valid page setup.
This commit is contained in:
@@ -75,6 +75,11 @@ DISJOINT_AGAINST = [
|
||||
]
|
||||
SHINGLE_N = 6
|
||||
|
||||
# Reintento de transporte contra el MCP de Penpot. El servidor corta la conexion a mitad de
|
||||
# llamada de forma intermitente; ya se habia visto en la puerta 4 de la Fase 4.
|
||||
MCP_MAX_RETRIES = int(os.environ.get("PENPOT_MCP_RETRIES", "4"))
|
||||
MCP_RETRY_BACKOFF = float(os.environ.get("PENPOT_MCP_RETRY_BACKOFF", "3"))
|
||||
|
||||
MAX_TURNS = int(os.environ.get("GATE5_MAX_TURNS", "14"))
|
||||
MAX_TOKENS = int(os.environ.get("GATE5_MAX_TOKENS", "4096"))
|
||||
HTTP_TIMEOUT = int(os.environ.get("GATE5_HTTP_TIMEOUT", "600"))
|
||||
@@ -276,11 +281,36 @@ class PenpotMCP:
|
||||
raise Gate5Error(f"el MCP de Penpot no devolvio respuesta para el metodo {payload.get('method')}")
|
||||
|
||||
def _request(self, method, params=None):
|
||||
self._next_id += 1
|
||||
payload = {"jsonrpc": "2.0", "id": self._next_id, "method": method}
|
||||
if params is not None:
|
||||
payload["params"] = params
|
||||
return self._post(payload)
|
||||
"""Envia un request JSON-RPC, reintentando los fallos de TRANSPORTE.
|
||||
|
||||
El MCP de Penpot corta la conexion a mitad de llamada de forma intermitente
|
||||
("transport dropped mid-call"); ya se habia visto en la puerta 4 de la Fase 4. Sin
|
||||
reintento, un corte transitorio en el prompt 6 de 8 tira abajo una corrida entera de la
|
||||
puerta, y peor: se diagnostica como un fallo del modelo cuando es de la red.
|
||||
|
||||
Se reintenta SOLO `Gate5Error` de transporte/protocolo. `PluginNotConnected` no se
|
||||
reintenta -- ese es un estado real del mundo (el usuario no tiene el plugin abierto) y
|
||||
reintentarlo solo demora el mensaje que hay que dar.
|
||||
"""
|
||||
ultimo = None
|
||||
for intento in range(1, MCP_MAX_RETRIES + 1):
|
||||
self._next_id += 1
|
||||
payload = {"jsonrpc": "2.0", "id": self._next_id, "method": method}
|
||||
if params is not None:
|
||||
payload["params"] = params
|
||||
try:
|
||||
return self._post(payload)
|
||||
except PluginNotConnected:
|
||||
raise
|
||||
except Gate5Error as e:
|
||||
ultimo = e
|
||||
if intento == MCP_MAX_RETRIES:
|
||||
break
|
||||
espera = MCP_RETRY_BACKOFF * intento
|
||||
print(f"[MCP] fallo transitorio en '{method}' (intento {intento}/"
|
||||
f"{MCP_MAX_RETRIES}): {e}. Reintento en {espera:.0f}s")
|
||||
time.sleep(espera)
|
||||
raise Gate5Error(f"el MCP de Penpot fallo {MCP_MAX_RETRIES} veces en '{method}': {ultimo}")
|
||||
|
||||
def _notify(self, method, params=None):
|
||||
payload = {"jsonrpc": "2.0", "method": method}
|
||||
@@ -334,12 +364,34 @@ class PenpotMCP:
|
||||
return texto, es_error
|
||||
|
||||
def execute_json(self, code, que):
|
||||
"""execute_code cuyo resultado la puerta necesita parsear como JSON."""
|
||||
"""execute_code cuyo resultado la puerta necesita parsear como JSON.
|
||||
|
||||
El servidor MCP no devuelve el `return` del payload pelado: lo envuelve en
|
||||
`{"result": <lo-que-retornaste>, "log": "<lo-que-escribiste-por-console>"}`. La puerta
|
||||
necesita el interior, asi que se desenvuelve ACA, en un solo lugar.
|
||||
|
||||
Ojo con no desenvolver de mas: si un payload de la puerta retornara a proposito un
|
||||
objeto con una clave `result` propia, desenvolver a ciegas lo destruiria. Por eso se
|
||||
exige la forma exacta del envoltorio (`result` presente y ninguna clave fuera de
|
||||
{result, log}).
|
||||
|
||||
`execute_code` (el metodo de abajo) NO desenvuelve: lo que ve el modelo como tool result
|
||||
tiene que ser byte a byte lo que le llegaria en produccion, envoltorio incluido.
|
||||
"""
|
||||
texto, es_error = self.execute_code(code)
|
||||
try:
|
||||
return json.loads(texto)
|
||||
parsed = json.loads(texto)
|
||||
except json.JSONDecodeError:
|
||||
raise Gate5Error(f"{que}: el MCP no devolvio JSON ({'error' if es_error else 'texto'}): {texto[:300]}")
|
||||
raise Gate5Error(
|
||||
f"{que}: el MCP no devolvio JSON ({'error' if es_error else 'texto'}): {texto[:300]}"
|
||||
)
|
||||
if (isinstance(parsed, dict) and "result" in parsed
|
||||
and set(parsed).issubset({"result", "log"})):
|
||||
log = (parsed.get("log") or "").strip()
|
||||
if log:
|
||||
print(f"[MCP] console del payload de la puerta ({que}): {log[:300]}")
|
||||
return parsed["result"]
|
||||
return parsed
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user