forked from kunchenguid/firstmate
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(no-mistakes): Add run liveness detection tools #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9da566
Add fm-no-mistakes-liveness.sh: check no-mistakes run liveness and ta…
trillium 522a4bc
Add fm-nm-run-is-live.sh: lightweight run liveness check for supervision
trillium ef460f9
Add documentation for no-mistakes run liveness checks
trillium adfb815
Improve active_steps parsing for accurate liveness detection
trillium d805de6
no-mistakes(review): Fixed hardcoded path, unused functions, inconsis…
trillium a8b2794
no-mistakes(review): Fixed error handling, directory contexts, remove…
trillium 6835fd3
no-mistakes(document): Add liveness checking scripts to documentation…
trillium 5c8283b
no-mistakes: apply CI fixes
trillium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env bash | ||
| # fm-nm-run-is-live.sh - check if a specific no-mistakes run is genuinely live (not hung) | ||
| # | ||
| # Designed for use by fm-crew-state.sh: given a run ID, determine if it's genuinely | ||
| # progressing or has silently hung. This is a simpler facade over | ||
| # fm-no-mistakes-liveness.sh tuned for single-run checks during supervision. | ||
| # | ||
| # Usage: | ||
| # fm-nm-run-is-live.sh <run-id> | ||
| # | ||
| # Exit codes: | ||
| # 0 - run is live/progressing (or not a run-step that can hang) | ||
| # 1 - run is hung (step inactive for > FM_NM_LIVENESS_STALE seconds) | ||
| # 2 - usage error or precondition failed | ||
| # | ||
| set -u | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| # shellcheck source=bin/fm-no-mistakes-liveness.sh | ||
| . "$SCRIPT_DIR/fm-no-mistakes-liveness.sh" | ||
|
|
||
| # Check if a run is live (not hung) - simplified version for single-run checks | ||
| check_run_liveness() { # <run-id> | ||
| local run_id=$1 | ||
| local run_out outcome awaiting_msg elapsed | ||
|
|
||
| run_out=$(nm_run axi status --run "$run_id") || return 2 | ||
|
|
||
| [ -n "$run_out" ] || return 2 | ||
|
|
||
| outcome=$(strip_quotes "$(nm_field "$run_out" outcome)") | ||
|
|
||
| # Terminal outcomes are not hung | ||
| if [ -n "$outcome" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # Check if awaiting_agent (parked at gate) - not hung, deliberately waiting | ||
| awaiting_msg=$(printf '%s\n' "$run_out" | grep -E '^[[:space:]]*awaiting_agent:' | head -1) | ||
| if [ -n "$awaiting_msg" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| # Check active_steps table first (more accurate than steps table) | ||
| local active_steps_section active_step_line last_activity_field | ||
| active_steps_section=$(printf '%s\n' "$run_out" | sed -n '/^[[:space:]]*active_steps\[/,/^[^[:space:]]/p') | ||
|
|
||
| if [ -n "$active_steps_section" ]; then | ||
| active_step_line=$(printf '%s\n' "$active_steps_section" | grep -E '^[[:space:]]*[^,]+,(running|fixing),' | head -1 | sed 's/^[[:space:]]*//') | ||
|
|
||
| if [ -n "$active_step_line" ]; then | ||
| # Found an active running/fixing step. Extract last_activity. | ||
| # Format: step,status,active_for,"time ago: message","pid",round | ||
| if [[ "$active_step_line" =~ ^[^,]*,[^,]*,[^,]*,\"([^\"]*) ]]; then | ||
| last_activity_field="${BASH_REMATCH[1]}" | ||
| if [ -n "$last_activity_field" ]; then | ||
| elapsed=$(parse_active_steps_time "$last_activity_field") | ||
| if [ "$elapsed" -gt "$STALE_THRESHOLD" ]; then | ||
| return 1 # Hung | ||
| fi | ||
| return 0 # Live | ||
| fi | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| # Fallback: check steps table if no active_steps found | ||
| local step_line step_status duration | ||
| step_line=$(printf '%s\n' "$run_out" | grep -E '^[[:space:]]*[^,]+,[[:space:]]*"?(running|fixing)"?[[:space:]]*,' | head -1 | sed 's/^ *//') | ||
|
|
||
| if [ -z "$step_line" ]; then | ||
| # No running/fixing step - not hung | ||
| return 0 | ||
| fi | ||
|
|
||
| # Extract step status and duration | ||
| step_status="${step_line#*,}" | ||
| step_status="${step_status%,*}" | ||
| step_status=$(strip_quotes "$(trim "$step_status")") | ||
|
|
||
| # Skip findings count (third field) and get duration | ||
| local rest="${step_line#*,}" | ||
| rest="${rest#*,}" | ||
| rest="${rest#*,}" | ||
| duration=$(trim "$rest") | ||
|
|
||
| case "$step_status" in | ||
| running|fixing) | ||
| if [ -n "$duration" ] && [[ "$duration" =~ ^[0-9]+$ ]]; then | ||
| elapsed=$((duration / 1000)) | ||
| if [ "$elapsed" -gt "$STALE_THRESHOLD" ]; then | ||
| return 1 # Hung | ||
| fi | ||
| fi | ||
| ;; | ||
| esac | ||
|
|
||
| return 0 # Live | ||
| } | ||
|
|
||
| # --- main | ||
|
|
||
| run_id=${1:-} | ||
| [ -n "$run_id" ] || { echo "usage: fm-nm-run-is-live.sh <run-id>" >&2; exit 2; } | ||
|
|
||
| check_run_liveness "$run_id" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Duplicated
check_run_livenesswith diverging thresholds.bin/fm-nm-run-is-live.shsourcesbin/fm-no-mistakes-liveness.shand then redefinescheck_run_liveness. The two copies of the steps-table fallback disagree, so the same run can be reported live by one script and hung by the other.docs/configuration.mdline 406 documentsFM_NM_LIVENESS_STALEas the hung threshold, and the base copy ignores it.bin/fm-nm-run-is-live.sh#L23-L99: delete this redefinition and call the shared function frombin/fm-no-mistakes-liveness.sh. If the facade needs exit code 2 for a query failure, map the shared function's result instead of reimplementing the decision path.bin/fm-no-mistakes-liveness.sh#L271-L305: replace the hardcoded1800withSTALE_THRESHOLD, and treatrunningas hung-eligible in the fallback, so the single shared implementation honorsFM_NM_LIVENESS_STALEfor both step statuses.📍 Affects 2 files
bin/fm-nm-run-is-live.sh#L23-L99(this comment)bin/fm-no-mistakes-liveness.sh#L271-L305🤖 Prompt for AI Agents