Skip to content

Commit 8b7caf6

Browse files
fix resolver identifier detection and hook defaults
1 parent c197076 commit 8b7caf6

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

engraphis/core/resolve.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -600,15 +600,9 @@ def _has_subject_identifier_drift(candidate_text: str, record_text: str) -> bool
600600
continue
601601
if any(_value_kind(value) != "num" for value in [*old_values, *new_values]):
602602
continue
603-
old_prefix = {
604-
candidate[index][0]
605-
for index in range(max(0, old_span[0] - 2), old_span[0])
606-
}
607-
new_prefix = {
608-
record[index][0]
609-
for index in range(max(0, new_span[0] - 2), new_span[0])
610-
}
611-
if old_prefix & new_prefix & _SUBJECT_IDENTIFIER_LABELS:
603+
old_label = candidate[old_span[0] - 1][0] if old_span[0] else ""
604+
new_label = record[new_span[0] - 1][0] if new_span[0] else ""
605+
if old_label == new_label and old_label in _SUBJECT_IDENTIFIER_LABELS:
612606
return True
613607
return False
614608

integrations/commandcode/session_start_hook.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def post(url, payload, timeout, session_id=None):
106106
return (responses[-1] if responses else None), response_session_id
107107

108108

109-
def rpc(method, params, rpc_id, deadline, session_id=None,
110-
url=MCP_URL_DEFAULT):
109+
def rpc(method, params, rpc_id, deadline, session_id=None, url=None):
111110
"""Issue one JSON-RPC request within the shared time budget.
112111
113112
``session_id`` is threaded into the Mcp-Session-Id header on every
@@ -116,6 +115,8 @@ def rpc(method, params, rpc_id, deadline, session_id=None,
116115
is the canonical case), the returned id is propagated so the caller
117116
threads it into every subsequent request on the same session.
118117
"""
118+
if url is None:
119+
url = MCP_URL
119120
remaining = deadline - time.monotonic()
120121
if remaining <= 0.05:
121122
raise TimeoutError("time budget exhausted")
@@ -136,9 +137,10 @@ def rpc(method, params, rpc_id, deadline, session_id=None,
136137
return None, next_session_id
137138

138139

139-
def notify_initialized(deadline, session_id=None,
140-
url=MCP_URL_DEFAULT):
140+
def notify_initialized(deadline, session_id=None, url=None):
141141
"""Best-effort notifications/initialized; stateless servers reply 202/empty."""
142+
if url is None:
143+
url = MCP_URL
142144
remaining = deadline - time.monotonic()
143145
if remaining <= 0.05:
144146
return session_id
@@ -171,14 +173,16 @@ def extract_context(result):
171173
return ""
172174

173175

174-
def session_context(repo, workspace, deadline, mcp_url=MCP_URL_DEFAULT):
176+
def session_context(repo, workspace, deadline, mcp_url=None):
175177
"""initialize -> initialized -> tools/call engraphis_session(action=start).
176178
177179
The Mcp-Session-Id returned by initialize is threaded into every
178180
subsequent request so a stateful transport (e.g. the dashboard /mcp
179181
endpoint) keeps the connection open and recognises the tool call as
180182
part of the same session.
181183
"""
184+
if mcp_url is None:
185+
mcp_url = MCP_URL
182186
_, session_id = rpc(
183187
"initialize",
184188
{
@@ -243,9 +247,9 @@ def build_additional_context(context, workspace, max_context_chars=None):
243247

244248

245249
def main():
246-
mcp_url = os.environ.get("ENGRAPHIS_MCP_URL") or MCP_URL_DEFAULT
247-
budget_seconds = _env_float("ENGRAPHIS_HOOK_BUDGET_S", BUDGET_SECONDS_DEFAULT)
248-
max_context_chars = _env_int("ENGRAPHIS_HOOK_MAX_CHARS", MAX_CONTEXT_CHARS_DEFAULT)
250+
mcp_url = os.environ.get("ENGRAPHIS_MCP_URL") or MCP_URL
251+
budget_seconds = _env_float("ENGRAPHIS_HOOK_BUDGET_S", BUDGET_SECONDS)
252+
max_context_chars = _env_int("ENGRAPHIS_HOOK_MAX_CHARS", MAX_CONTEXT_CHARS)
249253
deadline = time.monotonic() + budget_seconds
250254
try:
251255
payload = json.loads(sys.stdin.read() or "{}")

tests/test_resolve.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,14 @@ def test_numeric_subject_identifier_drift_does_not_invalidate():
374374
assert res.target_id == "mem_account_100"
375375

376376

377+
def test_numeric_value_after_non_identifier_label_invalidates():
378+
"""A changed timeout value must not be mistaken for subject identity drift."""
379+
neighbor = _rec("Server timeout is 30 seconds.", id="mem_timeout_30")
380+
res = resolve("Server timeout is 60 seconds.", [(0.9, neighbor)])
381+
assert res.op == ResolutionOp.INVALIDATE
382+
assert res.target_id == "mem_timeout_30"
383+
384+
377385
def test_named_identifier_swap_is_not_proven_a_correction_without_marker():
378386
# ProviderA -> ProviderB beside 4 -> 8 workers could be parallel infrastructure;
379387
# the hashing embedder cannot prove the same predicate, so both stay live.

0 commit comments

Comments
 (0)