Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Tail the running step instead of a duplicate job output

86ced8c53ed2f2aa41fbf20b84321ad20195e620 · Keenan Nemetz · 17d ago · parent 9b76484a

Tail the running step instead of a duplicate job output

The live page opened a "Job output" pane holding the whole attempt log above the
step accordion, so every step's bytes appeared twice: once in that pane and once
when the step was expanded. The pane existed because the accordion was a
snapshot and only the pane followed the attempt.

Now the running step's own accordion entry is the live view: it opens by default
and app.js tails that step's byte range, so the page never repeats a step. When
the step ends the page reloads to pick up the next one, or to become the
finished run; a reload that lands between steps waits and tries again. A reader
who expands another step is left where they are rather than being reloaded out
of it.

server/web/static/app.js +75−65

@@ -575,76 +575,86 @@ const fitTextarea = (area) => {
575 575 });
576 576 })();
577 577
578 // Live CI job output. The server serves the attempt's file from a byte offset and
579 // says when the log is final; the page asks again only while the job is running.
580 // Chunks are decoded with a streaming TextDecoder because a multi-byte character
581 // can straddle two byte offsets.
578 // Live step output. A running attempt reports each step's byte range, so the
579 // step that is running can be tailed in its own accordion entry instead of
580 // repeating every step in a separate job-output pane. When that step ends the
581 // page reloads, which opens the next running step or shows the finished run. A
582 // reader who opens another step has taken over, so the page stays put.
582 583 (() => {
583 const follow = (pre) => {
584 if (pre.dataset.logStreaming) return;
585 pre.dataset.logStreaming = '1';
586 const url = pre.dataset.logUrl;
587 if (!url) return;
588 const decoder = new TextDecoder();
589 let offset = 0;
590 let stopped = false;
591 const finalOn404 = pre.dataset.logFinal === '1';
592 const schedule = () => {
593 if (!stopped) setTimeout(tick, 1000);
594 };
595 const tick = async () => {
596 let res;
597 try {
598 res = await fetch(url + (url.includes('?') ? '&' : '?') + 'after=' + offset, {
599 cache: 'no-store',
600 credentials: 'same-origin',
601 });
602 } catch (_) {
603 schedule();
604 return;
605 }
606 if (res.status === 404) {
607 if (finalOn404 || res.headers.get('X-Log-Final') === '1') return;
608 schedule();
609 return;
610 }
611 if (!res.ok) {
612 schedule();
613 return;
614 }
615 let buf;
616 try {
617 buf = await res.arrayBuffer();
618 } catch (_) {
619 schedule();
620 return;
621 }
622 if (buf.byteLength) {
623 const stick = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 12;
624 pre.appendChild(document.createTextNode(decoder.decode(buf, { stream: true })));
625 offset += buf.byteLength;
626 if (stick) pre.scrollTop = pre.scrollHeight;
627 }
628 if (res.headers.get('X-Log-Final') === '1') {
629 pre.appendChild(document.createTextNode(decoder.decode()));
630 pre.dataset.logStreaming = 'done';
631 const state = pre.closest('details')?.querySelector('.run-log-state');
632 if (state) state.textContent = 'complete';
633 return;
634 }
635 schedule();
636 };
637 tick();
638 };
584 const card = document.querySelector('[data-live-run]');
585 if (!card) return;
639 586
640 document.querySelectorAll('details').forEach((details) => {
641 const pre = details.querySelector('pre[data-log-stream]');
642 if (!pre) return;
643 if (details.open) follow(pre);
587 let detached = false;
588 document.querySelectorAll('.run-log-card details.run-log').forEach((details) => {
644 589 details.addEventListener('toggle', () => {
645 if (details.open) follow(pre);
590 detached = true;
646 591 });
647 592 });
593
594 const pane = document.querySelector('pre[data-live-step-log]');
595 if (!pane) {
596 // Between steps there is no range to follow yet. Reload until the next step
597 // starts or the run finishes, unless the reader is reading another step.
598 setTimeout(() => {
599 if (!detached) location.reload();
600 }, 2000);
601 return;
602 }
603
604 const url = pane.dataset.logUrl;
605 if (!url) return;
606
607 const decoder = new TextDecoder();
608 let offset = 0;
609 let stopped = false;
610
611 const schedule = () => {
612 if (!stopped) setTimeout(tick, 1000);
613 };
614
615 const tick = async () => {
616 if (stopped) return;
617 let res;
618 try {
619 res = await fetch(url + '&after=' + offset, {
620 cache: 'no-store',
621 credentials: 'same-origin',
622 });
623 } catch (_) {
624 schedule();
625 return;
626 }
627 if (res.status === 404) {
628 schedule();
629 return;
630 }
631 if (!res.ok) {
632 schedule();
633 return;
634 }
635 let buf;
636 try {
637 buf = await res.arrayBuffer();
638 } catch (_) {
639 schedule();
640 return;
641 }
642 if (buf.byteLength) {
643 const stick = pane.scrollTop + pane.clientHeight >= pane.scrollHeight - 12;
644 pane.appendChild(document.createTextNode(decoder.decode(buf, { stream: true })));
645 offset += buf.byteLength;
646 if (stick) pane.scrollTop = pane.scrollHeight;
647 }
648 if (res.headers.get('X-Step-Final') === '1') {
649 pane.appendChild(document.createTextNode(decoder.decode()));
650 stopped = true;
651 if (!detached) setTimeout(() => location.reload(), 800);
652 return;
653 }
654 schedule();
655 };
656
657 tick();
648 658 })();
649 659
650 660 // Relative times and live durations. The server renders the same words, so a page