Skip to content

Commit 3b3cfbf

Browse files
committed
Follow new agent answers in the conversation scroll pane
1 parent fabe0cd commit 3b3cfbf

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎docs/implementation/read-only-review.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ Codex options were checked against the installed CLI help and the official [non-
7676
Validation: 181 unit/integration tests, 19 browser tests, and typecheck pass. A delayed-initial-review regression reproduced an unresponsive Settings button; binding controls before awaiting the first load fixes it. The restarted PR #597 instance also passed an immediate Settings-open check with both provider options visible.
7777

7878
Single-click submission follow-up: a held `/api/action` browser request reproduced the lack of immediate feedback (the submit button stayed enabled with no saving state). Question/change submission now shows Saving immediately, disables submission while a review action or refresh is in progress, and scrolls the saved note into view. Failures explicitly retain the draft for refresh/retry. The delayed-request regression checks one click produces exactly one stored question and one agent invocation; a lost first click was not independently reproduced.
79+
80+
Answer scrolling: when an asynchronous answer or failure arrives, Conversation follows the bottom if the reader was already within 32 pixels of it. Scrolling up keeps the current position through polling updates. Only the conversation list scrolls; the code pane and composer stay in place. Browser regressions cover both arrival at the bottom and arrival while reading earlier messages; the bottom-follow test failed before the fix with a 1,302-pixel gap.

‎test/browser/review.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,17 @@ test('acknowledges the first Ask agent click immediately and prevents duplicate
151151
await expect(page.getByRole('button',{name:'Ask agent',exact:true})).toBeEnabled();
152152
expect(submissions).toBe(1);expect(calls).toBe(1);expect(app.service.store.getReviewNotes(config.identity)).toHaveLength(1);
153153
});
154+
for (const readingEarlier of [false,true]) test(`answer arrival ${readingEarlier ? 'preserves earlier reading position' : 'follows the conversation bottom'}`,async({page})=>{
155+
const config=app.service.config;await app.close();let answer!:(text:string)=>void;
156+
app=await startServer(config,0,()=>new Promise(resolve=>{answer=resolve;}));
157+
for(let i=0;i<3;i++) app.service.act({action:'note',item:'P1',kind:'change',text:`Earlier message ${i}\n`+'Earlier context.\n'.repeat(20),token:app.service.load().token});
158+
await page.goto(app.url);await page.getByLabel('Question about this item').fill('Explain the cap');await page.getByRole('button',{name:'Ask agent',exact:true}).click();
159+
await expect(page.getByText('Agent · Answering…',{exact:true})).toBeVisible();
160+
const notes=page.locator('#notes');
161+
await notes.evaluate((element,earlier)=>{element.scrollTop=earlier ? 80 : element.scrollHeight;},readingEarlier);
162+
const before=await notes.evaluate(element=>element.scrollTop);
163+
answer('Detailed answer.\n'.repeat(60)+'Answer end.');
164+
await expect(page.locator('.agent-answer')).toHaveCount(1,{timeout:10000});
165+
if(readingEarlier) expect(await notes.evaluate(element=>element.scrollTop)).toBeCloseTo(before,0);
166+
else await expect.poll(()=>notes.evaluate(element=>element.scrollHeight-element.clientHeight-element.scrollTop)).toBeLessThan(2);
167+
});

‎web/public/app.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,10 @@ function answerMarkup(note) {
530530
const error=answer?.status==="failed"?answer.error:answer?.status==="pending"?"Agent was interrupted or timed out.":"Answer not started. Choose an agent in Settings or retry when capacity is available.";
531531
return `<p class="warn">! ${esc(error)}</p><button data-retry-question="${esc(note.id)}">Retry answer</button>`;
532532
}
533-
function renderNotes() {
533+
function renderNotes({ follow = false } = {}) {
534+
const notes = $("notes");
535+
const scrollTop = notes.scrollTop;
536+
const atBottom = notes.scrollHeight - notes.clientHeight - scrollTop <= 32;
534537
const item=data.items.find(item=>item.id===selected);
535538
$("notes").innerHTML = item
536539
? data.notes
@@ -542,6 +545,7 @@ function renderNotes() {
542545
.join("") ||
543546
'<p class="muted">No conversation yet. Keep questions and requested changes beside the evidence.</p>'
544547
: '<p class="muted">Select a plan item to add a question or request a change.</p>';
548+
if (follow) notes.scrollTop = atBottom ? notes.scrollHeight : scrollTop;
545549
document.querySelectorAll("[data-note]").forEach(button => button.onclick = () => {
546550
const note = data.notes.find(note => note.id === button.dataset.note);
547551
const ref = note.reference;
@@ -561,10 +565,10 @@ setInterval(async()=>{
561565
if(pollingQuestions || busy || !data || !data.notes.some(n=>n.answer?.status==="pending")) return;
562566
if(data.notes.every(n=>n.answer?.status!=="pending" || n.answer.expiresAt<=Date.now())) {
563567
data.notes=data.notes.map(n=>n.answer?.status==="pending"?{...n,answer:{...n.answer,status:"failed",error:"Agent was interrupted or timed out. Retry the question."}}:n);
564-
renderNotes();return;
568+
renderNotes({ follow: true });return;
565569
}
566570
pollingQuestions=true;
567-
try {const response=await api("/api/questions");if(data){data.notes=response.notes;renderNotes();}}
571+
try {const response=await api("/api/questions");if(data){data.notes=response.notes;renderNotes({ follow: true });}}
568572
catch { $("saved").textContent="Could not refresh agent answers. Use Refresh to reconnect."; }
569573
finally {pollingQuestions=false;}
570574
},2000);

0 commit comments

Comments
 (0)