Skip to content

Rework ansi reporter#79

Merged
maksymiuks merged 8 commits intodevfrom
78-add-error-messaging-to-reporters-2
Feb 3, 2026
Merged

Rework ansi reporter#79
maksymiuks merged 8 commits intodevfrom
78-add-error-messaging-to-reporters-2

Conversation

@maksymiuks
Copy link
Collaborator

@maksymiuks maksymiuks commented Jan 30, 2026

When implementing error messaging, I encountered a serious issue with the current ansi tty design. Bacilly, whenever there were enough packages to make the buffer exceed the max tty height, the approach of returning n lines to redraw the line no longer works, because any value returned higher than the max height was trimmed to the max height. Therefore, I decided to rework it, introducing the concept of final lines. Those are lines that are no longer subject to change and thus can be removed from the interactive redrawing. Also, the buffer got changed into a moving window of active lines, which is the height of the tty-1. Meaning that at any point, the output includes all finalized lines, starting from the header, plus a window of 60 subsequent lines, which can be interactive. Whenever the number of consecutive finalized lines increases, the window moves. Of course, all processes, including those connected to not-yet-displayed lines, are still running in the background; they are simply temporarily not displayed because there is no room for them.

# to free memory from terminated processes
if (private$task_loop_counter %% 20 == 0) {
gc(verbose = FALSE, reset = FALSE, full = TRUE)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns up, forcing garbage collection in each step was responsible for the 70% increase in process runtime. Now it is executed every 20 passes which is still quit often, certainly frequent enough to not run out of the processes, but at the same time does not extend maintenance process too much.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just live in process$finish() and when self$is_done() so that it only runs when we're cleaning up terminated processes.

R/checker.R Outdated
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a typo in that condition (missing list extraction) makin it always return FALSE and, as a result, mark meta task as done too early (one of the nodes finish, not when both)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot to uncouple here. First of all, the original condition was not working as the second part !v$name %in% reporter$buffer$node was always returning true. That's because buffer data.frame is using node IDs, and not names, their look for names was always returning false (negated to TRUE). However, even after fixing it, it was still not behaving as expected, or more like not covering all the necessary nodes. Because it was leaving unaddressed all the nodes that were finished recently, but already were in the buffer for a few iterations, ergo they were not new for the buffer but still had updates to report. Therefore, I reworked it to cover either those not in buffer, or those that are in buffer but were not marked as final, meaning they are still subject to change.

reportable_lines[seq(which.max(reportable_lines) + reporter$buffer_height,
length(reportable_lines))] <- FALSE
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core of this change. Make sure that lines marked as final are not redrawn and are ignored when in the buffer. Thanks to that, we can have some kind of a moving window over the buffer that, at given times, redraws only the max height of the tty at once.

))))
}))

cat(failures_output, "\n")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failures should be displayed after the process ends (either finished or is interrupted) to not waste precious interactive buffer space.

#' @export
report_step.reporter_ansi_tty <- function(reporter, checker) {
checker$step()
checker$start_next_task() >= 0
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a step is a double-edged sword because it makes the reporting a bit faster (fewer cli calculations), but also really spaced out, especially at the beginning, which kinda negates the purpose of the reporter at all.

@maksymiuks
Copy link
Collaborator Author

@dgkf Hello! I'm not sure how much you want to be involved in this project at this stage, but as this feature is your "child", I found that you might be interested in these changes. That said, don't feel any pressure to contribute if you don't need/want/can. I'll leave this open for a while, then merge if you don't have anything to add.

Copy link

@dgkf dgkf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to still provide occasional feedback!

I focused on the parts with comments and skimmed the rest. Left some suggestions, but don't feel like you need to satisfy my requests to merge.

# to free memory from terminated processes
if (private$task_loop_counter %% 20 == 0) {
gc(verbose = FALSE, reset = FALSE, full = TRUE)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should just live in process$finish() and when self$is_done() so that it only runs when we're cleaning up terminated processes.

@maksymiuks
Copy link
Collaborator Author

Happy to still provide occasional feedback!

I focused on the parts with comments and skimmed the rest. Left some suggestions, but don't feel like you need to satisfy my requests to merge.

That's lovely! Thank you very much. And the comments sound really reasonable, so I will definitely look at them.

By the way, what do you generally think about that idea of that moving window to address ansi tty height limits?

maksymiuks and others added 4 commits February 2, 2026 13:01
Co-authored-by: Doug Kelkhoff <18220321+dgkf@users.noreply.github.com>
…nentech/checked into 78-add-error-messaging-to-reporters-2
@maksymiuks maksymiuks merged commit e7d7c2d into dev Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments