fix(issue-36): the legacy shell loop and lib.sh's submit helpers pass prompts by file

The two remaining exec points that carried a prompt as one argv string
(capped at 131,072 bytes):

- run_loop.sh (MAM_LOOP_PY=0): delegate_job_safe, which all eleven shell
  delegations go through, turns `--prompt <text>` into `--prompt-file` under
  the control root's .mam/ and removes the file once the wrapper returns. Its
  failure lines go to stderr: callers capture stdout, and under set -e a
  failed submit ends the loop at that line with the wrapper's code, so the
  cause was being swallowed.
- lib.sh delegate_submit_job and its legacy twin (create_session's onboarding
  and --submit-job): the prompt is written under .mam/ and handed on as
  --prompt-file; lib_py.delegation.cli submit accepts --prompt-file and
  forwards it to the registry. --prompt keeps working everywhere.

S6/S6b push a 140,000-byte prompt through the CLI and both helpers; S7 runs
the real run_loop.sh with a 140,000-byte plan and a 150,000-byte diff; S7b
fixes a nonzero exit when the implementation or compliance job cannot be
registered. All six fail on 14d11bf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GodopuandClaude Opus 5.5 committed 2026-09-24 06:08:25 +00:00
1 parent 14d11bf062
commit f26952ccc3
4 files changed
+189 -15

No files matched your search

+22 -4
View File
@@ -2032,22 +2032,36 @@ _delegate_script() {
printf '%s\n' "$(find "$skill_dir" -name "$name" 2>/dev/null | head -n 1 || true)"
}
# _delegate_prompt_file <prompt> — write the prompt to a new file under the
# control root's .mam/ and echo its path. Issue #36: a prompt handed to an exec
# as one argv string is capped at 131,072 bytes; the caller removes the file.
_delegate_prompt_file() {
local dir="${WORKSPACE_ROOT:-$PWD}/.mam" f
mkdir -p "$dir" || return 1
f="$(mktemp "$dir/prompt-submit-XXXXXX")" || return 1
printf '%s' "$1" > "$f" || { rm -f "$f"; return 1; }
printf '%s\n' "$f"
}
# delegate_submit_job <prompt> <agent> <agent_session>
#
# Register a job in the multi-agent-mux-delegate-job registry. Prints the new JID on stdout.
_delegate_submit_job_legacy() {
local prompt="$1" agent="$2" session="$3"
local py_bin registry_py
local py_bin registry_py prompt_file rc=0
py_bin="$(_delegate_py_bin)"
registry_py="$(_delegate_script registry.py)"
if [ -z "$registry_py" ] || [ ! -f "$registry_py" ]; then
echo "ERROR: multi-agent-mux-delegate-job registry.py not found under .agents/skills/" >&2
return 1
fi
prompt_file="$(_delegate_prompt_file "$prompt")" || { echo "ERROR: cannot write the prompt file" >&2; return 1; }
"$py_bin" "$registry_py" register \
--prompt "$prompt" \
--prompt-file "$prompt_file" \
--agent "$agent" \
--agent-session "$session"
--agent-session "$session" || rc=$?
rm -f "$prompt_file"
return $rc
}
# delegate_publish_event <job_id> <event> [detail]
@@ -2152,7 +2166,11 @@ delegate_submit_job() {
echo "ERROR: multi-agent-mux-delegate-job registry.py not found under .agents/skills/" >&2
return 1
fi
_delegation_py submit --prompt "$prompt" --agent "$agent" --agent-session "$session"
local prompt_file rc=0
prompt_file="$(_delegate_prompt_file "$prompt")" || { echo "ERROR: cannot write the prompt file" >&2; return 1; }
_delegation_py submit --prompt-file "$prompt_file" --agent "$agent" --agent-session "$session" || rc=$?
rm -f "$prompt_file"
return $rc
}
# delegate_publish_event <job_id> <event> [detail]
+8 -2
View File
@@ -26,7 +26,11 @@ def _build_parser() -> argparse.ArgumentParser:
sub = parser.add_subparsers(dest="command", required=True)
p_submit = sub.add_parser("submit", help="register a job; prints the job id")
p_submit.add_argument("--prompt", required=True)
# Issue #36: lib.sh passes the prompt by file (one argv string is capped
# at 131,072 bytes); --prompt keeps working.
submit_prompt = p_submit.add_mutually_exclusive_group(required=True)
submit_prompt.add_argument("--prompt")
submit_prompt.add_argument("--prompt-file")
p_submit.add_argument("--agent", default="claude-code")
p_submit.add_argument("--agent-session", default="herdr:claude")
p_submit.add_argument("--registry-dir", default=None)
@@ -57,7 +61,9 @@ def main(argv: Optional[List[str]] = None) -> int:
args = _build_parser().parse_args(argv)
if args.command == "submit":
forward = ["register", "--prompt", args.prompt,
prompt_arg = (["--prompt-file", args.prompt_file] if args.prompt_file is not None
else ["--prompt", args.prompt])
forward = ["register", *prompt_arg,
"--agent", args.agent, "--agent-session", args.agent_session]
if args.registry_dir:
forward = ["--registry-dir", args.registry_dir] + forward
@@ -187,14 +187,36 @@ _mam_release_guard() {
# Runs the delegate-job wrapper from the frozen skills tree (REPO_ROOT).
# Stage 2 creates a single snapshot at loop initialization outside the skill tree (B-13),
# keeping the running loop immune across turns without per-call copies or tree pollution (B-6).
#
# Issue #36: a `--prompt <text>` argument is handed to the wrapper as
# `--prompt-file <path>` instead - one argv string is capped at 131,072 bytes
# and a review prompt carries the whole diff. The file lives under the control
# root's .mam/ and is removed once the wrapper returns (it blocks until the
# job ends, so nothing reads the file afterwards).
delegate_job_safe() {
local wrapper_script="$REPO_ROOT/.agents/skills/multi-agent-mux-delegate-job/multi-agent-mux-delegate-job"
local rc=0
bash "$wrapper_script" "$@" || rc=$?
local rc=0 prompt_file="" args=()
while [ $# -gt 0 ]; do
if [ "$1" = "--prompt" ] && [ $# -ge 2 ]; then
mkdir -p "$MAM_REAL_ROOT/.mam" \
&& prompt_file="$(mktemp "$MAM_REAL_ROOT/.mam/prompt-shloop-XXXXXX")" \
&& printf '%s' "$2" > "$prompt_file" \
|| { log_error "delegate_job_safe: cannot write the prompt file under $MAM_REAL_ROOT/.mam"; return 1; }
args+=(--prompt-file "$prompt_file")
shift 2
else
args+=("$1")
shift
fi
done
bash "$wrapper_script" ${args[@]+"${args[@]}"} || rc=$?
[ -n "$prompt_file" ] && rm -f "$prompt_file"
if [ "$rc" -ne 0 ]; then
log_error "delegate_job_safe failed (exit $rc): $wrapper_script"
log_error " if this loop edits framework skills in place, check that file's syntax:"
log_error " bash -n \"$wrapper_script\""
# stderr: callers capture stdout with $(...), and under set -e a failed
# submit ends the loop right there - this line is the only cause shown.
log_error "delegate_job_safe failed (exit $rc): $wrapper_script" >&2
log_error " if this loop edits framework skills in place, check that file's syntax:" >&2
log_error " bash -n \"$wrapper_script\"" >&2
fi
return $rc
}