Skip to content

Commit de20243

Browse files
committed
fix: corrected read file worker guard
1 parent ca05378 commit de20243

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

api/.hermes/plugins/worker_guard/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ def _primary_read_max_lines() -> int:
9595
return _DEFAULT_PRIMARY_READ_MAX_LINES
9696

9797

98-
def _is_primary(task_id: str) -> bool:
99-
"""True only for the primary's own task_id (never a delegated sub-agent). Relies on the
100-
primary/sub-agent state already populated by on_pre_tool_call for this same call."""
98+
def _is_subagent(task_id: str) -> bool:
99+
"""True only for a task_id we've positively identified as a delegated sub-agent (registered by
100+
on_pre_tool_call before the tool ran). Everything else — including the top-level primary, whose
101+
task_id is empty (`""`) — is treated as NOT a sub-agent. Detection is by exclusion: we can't
102+
rely on a positive primary id, because the primary often has none."""
101103
with _LOCK:
102-
return bool(task_id) and task_id == _STATE["primary"] and task_id not in _STATE["subagents"]
104+
return bool(task_id) and task_id in _STATE["subagents"]
103105

104106

105107
def _has_write_redirect(cmd: str) -> bool:
@@ -205,11 +207,16 @@ def on_transform_tool_result(
205207
"""Cap an over-long read_file result for the PRIMARY only — truncating the JSON `content`
206208
to the line budget and appending a note to delegate the rest. Sub-agents are never capped, so
207209
they still read whole files to do the work. Returning a string replaces the result the model
208-
sees; None leaves it untouched. Fail-open — never raise."""
210+
sees; None leaves it untouched. Fail-open — never raise.
211+
212+
The primary is identified by EXCLUSION (not a known sub-agent), mirroring the write-block in
213+
on_pre_tool_call. A positive `_is_primary` id check used to gate this, but the top-level
214+
primary's task_id is empty (`""`), so that check was always false and the cap silently never
215+
fired — the bug this replaces."""
209216
if not _phase_ok() or tool_name not in _READ_TOOLS or not isinstance(result, str):
210217
return None
211218
try:
212-
if not _is_primary(task_id):
219+
if _is_subagent(task_id):
213220
return None
214221

215222
data = json.loads(result)

0 commit comments

Comments
 (0)