fix(loop): use string_length instead of first_char to detect valid response#138
Open
hlgreenblatt wants to merge 1 commit into
Open
fix(loop): use string_length instead of first_char to detect valid response#138hlgreenblatt wants to merge 1 commit into
hlgreenblatt wants to merge 1 commit into
Conversation
…sponse
The safety-net check at src/loop.metta:65 was `(== "(" (first_char $resp))`,
which fails reliably for Python-string returns from py-call even when the
string obviously starts with `(`, due to a String-vs-atom type mismatch in
the SWI-Prolog↔MeTTa binding for first_char/2. When this triggers, the
agent's actual output is discarded and substituted for the reminder
string.
Replace with a length-based check that gates against the empty-string
failure mode (the original intent) without false negatives on valid
py-call returns. No new dependencies; single line; no behavior change
for any valid (...)-prefixed response.
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Loosen the safety-net check at
src/loop.metta:65from(== "(" (first_char $resp))to(> (string_length $resp) 1). The originalfirst_char == "("check fails reliably for valid Python-string returns frompy-calleven when the returned string obviously starts with(, because of a String-vs-atom type mismatch in the SWI-Prolog↔MeTTa binding forfirst_char/2.When this check fails, the loop substitutes
(REMEMBER:OUTPUT_NOTHING_ELSE_THAN: ((skill arg) ...))for$responseand the agent's actual output gets discarded — the agent sees only the reminder string in the next iteration. The bug surfaces any time a skill body calls a Python helper that returns a string, including any new skill that wrapspy-calland returns an s-expression.The length-based replacement is permissive enough to let well-formed Python-string returns through and still gates against the empty-string failure mode that the original check was guarding.
Provenance
This bug is documented in a downstream fork's implementation notes from 2026-04-25 (gotcha #3 in a dual-format-LLM-adapter work item). The same one-line fix is in production use in that fork. Submitting upstream as a standalone single-concern PR.
Test plan
py-call(any new Python-bridged skill) now have their output reach$responsecleanly instead of being dropped.(= (echo $s) (py-call (helper.normalize_string $s))), ask the agent to call(echo "(send hi)"), observe that the next iteration's RESULTS contains(send hi)instead ofREMEMBER:OUTPUT_NOTHING_ELSE_THAN:.Scope
One line, one file. No new dependencies. No behavioral change for valid
(...)-prefixed responses (the new check is strictly more permissive on those). The only behavioral difference is that single-character outputs are now treated as valid and routed tosread, where they will fail parsing cleanly via the existingHandleError MULTI_COMMAND_FAILURE_...path rather than being substituted for the reminder string.