mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-30 19:59:40 +02:00
fix(plan-canvas): deliver browser chat to the agent every time (#2739)
Feedback sent from the canvas only reached an agent through a live /api/await long poll. When a turn ended with no await parked, queueFeedback wrote the message to sessions.json and nothing ever consumed it, so sending appeared to do nothing at all. The presence pill made it worse: workingKeys had no expiry and the feedback handler never broadcast presence, so it froze on "agent working" while nobody was listening. Delivery: - Add the stop:plan-canvas-pending hook. It drains undelivered feedback and blocks the Stop, handing the messages to the agent, so a canvas message lands even when no await is running. Scoped to sessions under cwd so parallel agents cannot swallow each other's feedback; set ECC_PLAN_CANVAS_STOP_SCOPE=all to widen. Honors stop_hook_active and fails open on every error path. - run-with-flags.js did not await a hook's run(), so any async hook silently degraded to pass-through. Fixed; plan-canvas-pending is the only async hook today. Presence and indicators: - Presence is now ended/typing/thinking/listening/queued/waiting. thinking and typing self-expire (90s/30s) and a 5s sweep pushes the decay to an idle browser, so the pill can no longer stick. - Broadcast presence when feedback is queued, and clear the activity state when an agent reply lands. - Add POST /api/session/:key/typing so agents can drive the indicator. - Chat shows an animated dots bubble for thinking and typing, plus an explicit note when a message is queued with nobody listening. Respects prefers-reduced-motion. - Send status reports what actually happened instead of always claiming the agent will pick it up. CLI and skill: - Add `ecc-plan-canvas pending` and `typing <file> --state ...`. - SKILL.md documents background await as the primary pattern and makes replying in the canvas mandatory. Tests: 6 new server cases covering queued presence, the typing endpoint, state expiry and the sweep, plus a new hook suite covering delivery, drain-once, stop_hook_active, cwd scoping and fail-open. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -253,11 +253,120 @@ async function main() {
|
||||
assert.strictEqual(result.items[0].anchor.selector, 'h2:nth-of-type(1)');
|
||||
assert.strictEqual(result.items[1].verdict, 'request-changes');
|
||||
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'working'));
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'thinking'));
|
||||
await waitFor(() => sse.received.some(e => e.event === 'chat-sync' && e.data.chat.length === 2));
|
||||
sse.close();
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Regression: feedback sent with nobody parked on `await` used to leave the
|
||||
// pill claiming "agent working" while the message sat undelivered forever.
|
||||
if (await test('feedback with no listener reports queued, not working', async () => {
|
||||
const queuedArtifact = path.join(tmp, 'queued.plan.md');
|
||||
fs.writeFileSync(queuedArtifact, '# Plan: Queued\n');
|
||||
const opened = jsonBody(await request(port, 'POST', '/api/sessions', { body: { file: queuedArtifact } }));
|
||||
const sse = openSse(port, opened.key);
|
||||
await sse.ready;
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'waiting'));
|
||||
|
||||
const post = await request(port, 'POST', `/api/session/${opened.key}/feedback`, {
|
||||
body: { items: [{ kind: 'chat', text: 'anyone there?' }] }
|
||||
});
|
||||
assert.strictEqual(jsonBody(post).presence, 'queued');
|
||||
assert.strictEqual(canvas.presenceFor(opened.key), 'queued');
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'queued'));
|
||||
|
||||
// Draining it hands the batch over and flips the indicator to thinking.
|
||||
const drained = jsonBody(await request(port, 'GET', `/api/await?key=${opened.key}&timeoutMs=0`));
|
||||
assert.strictEqual(drained.status, 'feedback');
|
||||
assert.strictEqual(canvas.presenceFor(opened.key), 'thinking');
|
||||
sse.close();
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (await test('typing endpoint drives the indicator and reply clears it', async () => {
|
||||
const typingArtifact = path.join(tmp, 'typing.plan.md');
|
||||
fs.writeFileSync(typingArtifact, '# Plan: Typing\n');
|
||||
const opened = jsonBody(await request(port, 'POST', '/api/sessions', { body: { file: typingArtifact } }));
|
||||
const sse = openSse(port, opened.key);
|
||||
await sse.ready;
|
||||
|
||||
const typing = await request(port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'typing' } });
|
||||
assert.strictEqual(jsonBody(typing).presence, 'typing');
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'typing'));
|
||||
|
||||
const thinking = await request(port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'thinking' } });
|
||||
assert.strictEqual(jsonBody(thinking).presence, 'thinking');
|
||||
|
||||
const bad = await request(port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'dancing' } });
|
||||
assert.strictEqual(bad.statusCode, 400);
|
||||
|
||||
// A landed reply must take the bubble down, not leave it spinning.
|
||||
await request(port, 'POST', `/api/session/${opened.key}/reply`, { body: { text: 'done' } });
|
||||
assert.strictEqual(canvas.presenceFor(opened.key), 'waiting');
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'waiting'));
|
||||
sse.close();
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (await test('thinking and typing states expire instead of sticking', async () => {
|
||||
const staleArtifact = path.join(tmp, 'stale.plan.md');
|
||||
fs.writeFileSync(staleArtifact, '# Plan: Stale\n');
|
||||
const staleStore = createSessionStore({ stateDir: path.join(tmp, 'stale-state') });
|
||||
const staleCanvas = createPlanCanvasServer({
|
||||
store: staleStore,
|
||||
version: '9.9.9-test',
|
||||
idleTimeoutMs: 0,
|
||||
thinkingStaleMs: 40,
|
||||
typingExpiryMs: 20,
|
||||
presenceSweepMs: 0
|
||||
});
|
||||
const bound = await staleCanvas.listen(0);
|
||||
const opened = jsonBody(await request(bound.port, 'POST', '/api/sessions', { body: { file: staleArtifact } }));
|
||||
|
||||
await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'typing' } });
|
||||
assert.strictEqual(staleCanvas.presenceFor(opened.key), 'typing');
|
||||
await new Promise(resolve => setTimeout(resolve, 60));
|
||||
assert.strictEqual(staleCanvas.presenceFor(opened.key), 'waiting');
|
||||
|
||||
// An abandoned agent decays to queued so the human is never told a
|
||||
// stalled session is still being worked on.
|
||||
await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'thinking' } });
|
||||
await request(bound.port, 'POST', `/api/session/${opened.key}/feedback`, {
|
||||
body: { items: [{ kind: 'chat', text: 'still there?' }] }
|
||||
});
|
||||
assert.strictEqual(staleCanvas.presenceFor(opened.key), 'thinking');
|
||||
await new Promise(resolve => setTimeout(resolve, 60));
|
||||
assert.strictEqual(staleCanvas.presenceFor(opened.key), 'queued');
|
||||
await staleCanvas.close();
|
||||
})) passed++; else failed++;
|
||||
|
||||
// The stuck pill only self-heals if the decay is pushed to an idle browser
|
||||
// that is not making any requests of its own.
|
||||
if (await test('presence sweep pushes the decayed state to an idle browser', async () => {
|
||||
const sweepArtifact = path.join(tmp, 'sweep.plan.md');
|
||||
fs.writeFileSync(sweepArtifact, '# Plan: Sweep\n');
|
||||
const sweepStore = createSessionStore({ stateDir: path.join(tmp, 'sweep-state') });
|
||||
const sweepCanvas = createPlanCanvasServer({
|
||||
store: sweepStore,
|
||||
version: '9.9.9-test',
|
||||
idleTimeoutMs: 0,
|
||||
thinkingStaleMs: 50,
|
||||
presenceSweepMs: 20
|
||||
});
|
||||
const bound = await sweepCanvas.listen(0);
|
||||
const opened = jsonBody(await request(bound.port, 'POST', '/api/sessions', { body: { file: sweepArtifact } }));
|
||||
const sse = openSse(bound.port, opened.key);
|
||||
await sse.ready;
|
||||
|
||||
await request(bound.port, 'POST', `/api/session/${opened.key}/typing`, { body: { state: 'thinking' } });
|
||||
await waitFor(() => sse.received.some(e => e.event === 'presence' && e.data.state === 'thinking'));
|
||||
|
||||
const before = sse.received.length;
|
||||
await waitFor(() =>
|
||||
sse.received.slice(before).some(e => e.event === 'presence' && e.data.state === 'waiting')
|
||||
);
|
||||
sse.close();
|
||||
await sweepCanvas.close();
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (await test('long-poll heartbeat whitespace arrives before the payload', async () => {
|
||||
const chunks = [];
|
||||
const done = new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user