fix(resume): no guess with two same-type rows in a cwd; refuse another row's id before spawning; the running branch uses the same decision (Issue #63)
This commit is contained in:
1 parent
3a2219454e
commit
fa93cc5622
4 files changed
+290
-27
No files matched your search
@@ -27,6 +27,8 @@ ROLE=""
|
||||
HERDR_SERVER_OPT=""
|
||||
HERDR_WORKSPACE_OPT=""
|
||||
CMD_FULL_OPT=""
|
||||
ALREADY_RUNNING=0
|
||||
DROP_STALE_ID=0
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
@@ -38,6 +40,8 @@ while [ $# -gt 0 ]; do
|
||||
--herdr-session|--herdr-server) HERDR_SERVER_OPT="$2"; shift 2 ;;
|
||||
--herdr-workspace) HERDR_WORKSPACE_OPT="$2"; shift 2 ;;
|
||||
--cmd-full) CMD_FULL_OPT="$2"; shift 2 ;;
|
||||
--already-running) ALREADY_RUNNING=1; shift ;;
|
||||
--drop-stale-id) DROP_STALE_ID=1; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "ERROR: unknown arg: $1" >&2; exit 2 ;;
|
||||
esac
|
||||
@@ -110,6 +114,7 @@ atomic_dump_yaml "$AGENT_SESSIONS_YAML" \
|
||||
NOW_EPOCH="$NOW_EPOCH" TARGET_WORKSPACE="${WORKSPACE:-$WORKSPACE_ROOT}" ROLE="$ROLE" \
|
||||
PANE_PID="$PANE_PID" CHILD_PID="$CHILD_PID" HERDR_SERVER_OPT_EXPLICIT="${HERDR_SERVER_OPT_EXPLICIT:-0}" \
|
||||
MAM_WS_LABEL="$MAM_WS_LABEL" MAM_WS_LABEL_EXPLICIT="${MAM_WS_LABEL_EXPLICIT:-0}" \
|
||||
ALREADY_RUNNING="$ALREADY_RUNNING" DROP_STALE_ID="$DROP_STALE_ID" \
|
||||
CMD_FULL_OPT="$CMD_FULL_OPT" <<'PYEOF'
|
||||
name = os.environ['SESSION_NAME']
|
||||
uuid = os.environ['UUID']
|
||||
@@ -173,7 +178,17 @@ if _cp_raw and not isinstance(target.get('control_plane'), dict):
|
||||
target['control_plane'] = {k: _cp[k] for k in ('workspace_root', 'agent_sessions_yaml', 'mam_jobs_dir', 'delegate_job_logs_dir')}
|
||||
except Exception:
|
||||
pass
|
||||
if not uuid:
|
||||
stale_dropped = ''
|
||||
if not uuid and os.environ.get('DROP_STALE_ID') == '1':
|
||||
from lib_py.agents.autopin import claimed_elsewhere
|
||||
from lib_py.agents.registry import get_adapter
|
||||
_adapter = get_adapter(agent)
|
||||
_own_key = _adapter.own_key if _adapter else ''
|
||||
_old = (target.get(_own_key) or '').strip() if _own_key else ''
|
||||
if _old and _old not in set(claimed_elsewhere(target, d)):
|
||||
target[_own_key] = None
|
||||
stale_dropped = _old
|
||||
if not uuid and os.environ.get('ALREADY_RUNNING') != '1':
|
||||
# ISSUE-3 (challenge c4b0a075): a Class A fresh-spawn resume re-arms
|
||||
# discovery from scratch - the resumed agent has not spoken yet, so any
|
||||
# on-disk conversation older than THIS resume must not be auto-pinned to
|
||||
@@ -196,6 +211,10 @@ target.pop('stop_reason', None)
|
||||
target.pop('resumable', None)
|
||||
if uuid:
|
||||
target['last_visible_status'] = f'resumed conversation {uuid} at {now}'
|
||||
elif os.environ.get('ALREADY_RUNNING') == '1':
|
||||
target['last_visible_status'] = f'already running; no id recorded at {now}'
|
||||
elif stale_dropped:
|
||||
target['last_visible_status'] = f'resumed (fresh spawn, recorded id {stale_dropped} no longer verified) at {now}'
|
||||
else:
|
||||
# ISSUE-3 Class A fresh-spawn resume: no conversation id existed yet.
|
||||
target['last_visible_status'] = f'resumed (fresh spawn, no prior turn) at {now}'
|
||||
|
||||
Reference in new issue
Block a user