Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion harness/lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function liveSessionIn(root, wt) {
let agents = null; try { agents = Ch.platformAgents(common); } catch { agents = null; }
const now = Date.now(), live = cand.filter(s => Ch.sessionLive(s, agents, now));
if (!live.length) return null;
return `live session ${live.map(s => Ch.sid8(s.session_id)).join(', ')} is working in ${wt} — let it finish (or end it), then batch again; --force bundles it anyway`;
// [자동 이슈 #88] 기록상 cwd · 기록 시각 · 플랫폼 cwd 를 실어 낡은 세션 기록인지 알아볼 수 있게(integrate.sessionWhere 와 같다)
const who = live.map(s => { const a = Ch.agentOf(s, agents); return `${Ch.sid8(s.session_id)}${I.sessionWhere({ cwd: s.cwd || s.root || null, last_seen: s.last_seen || null, platform_cwd: a && a.cwd || null })}`; });
return `live session ${who.join(', ')} is working in ${wt} — let it finish (or end it), then batch again; --force bundles it anyway`;
}

// 칸의 작업 폴더를 묶어도 되는가 → 안 되면 이유(문자열). accept(integrate.js)와 같은 보호 —
Expand Down
15 changes: 12 additions & 3 deletions harness/lib/integrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,22 @@ function liveLaneSessions(root, task) {
try { cand = Ch.listSessions(common).filter(s => String(s.session_id) !== self && (inside(s.root) || inside(s.cwd))); } catch { return []; }
if (!cand.length) return [];
let agents = null; try { agents = Ch.platformAgents(common); } catch { agents = null; }
return cand.filter(s => Ch.sessionLive(s, agents)).map(s => { const a = Ch.agentOf(s, agents); return { session_id: s.session_id, name: a && a.name || null, status: a && a.status || null }; });
return cand.filter(s => Ch.sessionLive(s, agents)).map(s => { const a = Ch.agentOf(s, agents); return { session_id: s.session_id, name: a && a.name || null, status: a && a.status || null, cwd: s.cwd || s.root || null, last_seen: s.last_seen || null, platform_cwd: a && a.cwd || null }; });
}
// [자동 이슈 #88] 세션 기록의 cwd 는 UserPromptSubmit 때만 갱신된다 — 그 세션이 레인에서 나간 뒤에도 낡은 기록으로 거부될 수 있다.
// 거부 이유에 기록상 cwd · 기록 시각 · (다르면) 플랫폼 목록의 cwd 를 실어 낡은 기록인지 알아볼 수 있게 한다.
function sessionWhere(s) {
const bits = [];
if (s.cwd) bits.push(`recorded cwd ${s.cwd}${s.last_seen ? ` at ${s.last_seen}` : ''}`);
const k = p => { const r = path.resolve(p); return S.IS_WIN ? r.toLowerCase() : r; };
if (s.platform_cwd && (!s.cwd || k(s.platform_cwd) !== k(s.cwd))) bits.push(`platform cwd ${s.platform_cwd}`);
return bits.length ? ` · ${bits.join(' · ')}` : '';
}
function liveSessionWhy(root, task, o, cmd) {
if (o.force) return null;
const live = liveLaneSessions(root, task);
if (!live.length) return null;
const who = live.slice(0, 3).map(s => `${s.name || String(s.session_id).slice(0, 8)}${s.status ? ` ${s.status}` : ''}`).join(', ');
const who = live.slice(0, 3).map(s => `${s.name || String(s.session_id).slice(0, 8)}${s.status ? ` ${s.status}` : ''}${sessionWhere(s)}`).join(', ');
return `a live session is working in this lane's worktree ${S.taskPathsFor(root, task).wt} (${who}) — finish and commit the work in that session (or end it), then run ${cmd} again; --force to ${cmd} anyway`;
}
// merge 잠금 → task 잠금 → 잠금 아래에서 task 를 **다시 읽고** 선행 조건을 다시 본다.
Expand Down Expand Up @@ -755,4 +764,4 @@ async function check(o) {
});
}

module.exports = { accept, cancel, restore, check, dirtyOverlap, archivePlan, acceptTarget, result, releaseResources, commitLeftovers, copyDir, isIndeterminate, serialRootOf, docsOnly, refuseKo, liveLaneSessions, MERGE_WAIT_MS };
module.exports = { accept, cancel, restore, check, dirtyOverlap, archivePlan, acceptTarget, result, releaseResources, commitLeftovers, copyDir, isIndeterminate, serialRootOf, docsOnly, refuseKo, liveLaneSessions, sessionWhere, MERGE_WAIT_MS };
9 changes: 9 additions & 0 deletions tests/unit/test_v5_accept2.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ console.log(out.join('\\n'));console.log('# pass '+p+'\\n# fail '+f);process.exi
a1.refused && /live session/.test(a1.reason) && /lane-1|lane-sess/.test(a1.reason) && /--force/.test(a1.reason) && k1.refused && c1.refused && /live session/.test(c1.reason)
&& git(r, ['rev-parse', 'main']) === main0 && fs.existsSync(path.join(wt, 'half.txt')) && S.readTask(r, t.id).status === 'open',
JSON.stringify({ a1: a1.reason, k1: k1.reason, c1: c1.reason }));
// [자동 이슈 #88] 세션 기록의 cwd 는 낡았고(레인) 플랫폼 목록의 cwd 는 이미 메인 체크아웃 — 거부 이유에 기록상 cwd · 기록 시각 · 플랫폼 cwd 를 싣는다
const rec = JSON.parse(fs.readFileSync(Ch.sessionPath(common, sid), 'utf8'));
write(agentsFile, JSON.stringify([{ sessionId: sid, pid: process.pid, cwd: r, kind: 'interactive', name: 'lane-1', status: 'idle' }]));
const k88 = await I.check({ ...quiet, root: r, id: t.id });
write(agentsFile, JSON.stringify([{ sessionId: sid, pid: process.pid, cwd: wt, kind: 'interactive', name: 'lane-1', status: 'busy' }]));
R.check('[AC2-14c] (#88) 낡은 세션 기록으로 거부할 때 이유에 기록상 cwd · 기록 시각 · 플랫폼 cwd 가 있다',
k88.refused && /live session/.test(k88.reason) && k88.reason.includes(`recorded cwd ${rec.cwd} at ${rec.last_seen}`) && k88.reason.includes(`platform cwd ${r}`) && /--force/.test(k88.reason)
&& I.refuseKo(k88.reason).includes(`platform cwd ${r}`) && !/live session/.test(I.refuseKo(k88.reason)),
JSON.stringify(k88.reason));
// [자동 이슈 #67] 부른 세션 자신 — 예전에 cwd 가 그 레인에 있었다가 메인으로 돌아와 accept 를 부른다(세션 파일의 cwd 는 아직 레인). 자기 자신은 산 작업자가 아니다
const hadSid = process.env.CLAUDE_CODE_SESSION_ID;
process.env.CLAUDE_CODE_SESSION_ID = sid;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_v5_batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ const parents = (cwd, ref) => git(cwd, ['rev-list', '--parents', '-n', '1', ref]
const bv = await B.create({ ...quiet, root: V.dir, all: true });
const mv = (B.readBatch(V.dir, bv.id).members || []).find(m => m.id === va.id) || {};
R.check('[BA-20] 산 세션이 일하는 칸은 batch(--all)가 건너뛴다(why: live session)', mv.status === 'skipped' && /live session live1111/.test(mv.why), JSON.stringify(mv));
R.check('[BA-20c] (#88) 산 세션으로 건너뛴 이유에 기록상 cwd · 기록 시각이 있다(낡은 기록인지 알아볼 수 있게)', /recorded cwd .+ at \d{4}-\d\d-\d\dT/.test(mv.why || '') && (mv.why || '').includes(va.wt), JSON.stringify(mv.why));
// [자동 이슈 #67] 부른 세션 자신이 그 칸을 가리키면(예전에 cd 했다) 건너뛰지 않는다
const hadSid = process.env.CLAUDE_CODE_SESSION_ID;
process.env.CLAUDE_CODE_SESSION_ID = 'live1111-aaaa';
Expand Down
Loading