Skip to content

feat(heartbeat): report update_in_progress so the manager can clear updating - #98

Merged
omarsy merged 3 commits into
mainfrom
fix/greffer-heartbeat-update-in-progress
Jun 18, 2026
Merged

omarsy merged 3 commits into
mainfrom
fix/greffer-heartbeat-update-in-progress

Conversation

@omarsy

@omarsy omarsy commented Jun 18, 2026

Copy link
Copy Markdown
Member

Why

The manager's updating UI flag stayed stuck for the full 600s grace after a manager-triggered remote update, because the manager had no signal for "the update is no longer in flight" — see the paired greffon/manager PR. The case that needs an explicit signal is an update that fails without restarting the node (the updater dies during verify/pull before any recreate): the greffer keeps heartbeating, so no re-register fires.

Change

Report update_in_progress in every heartbeat: the same non-blocking flock probe of $GREFFON_PATH/.update.lock the controller already uses to 409 start/stop/update (HLD §10), at the same path. The manager treats a settled false as "done/failed" and clears the flag. The probe fails safe to False (can't tell → don't claim updating).

Bump 0.3.9 → 0.3.10.

Pairing / rollout

Pairs with greffon/manager (clears last_update_started_at on re-register + on this heartbeat signal). The manager change is backward-compatible and deploys first; a greffer that omits this field falls back to the manager's re-register clear + grace. This field adds the no-restart-failure clear once a greffer runs 0.3.10+.

Tests

test_one_heartbeat_reports_update_in_progress (reports the probe + probes the controller's lock path) and an assertion in the existing payload test. Heartbeat + register suites green.

🤖 Generated with Claude Code

…updating`

The greffer now reports update_in_progress in every heartbeat: the same
non-blocking flock probe of $GREFFON_PATH/.update.lock the controller uses to
409 start/stop/update (HLD section 10). The manager uses a settled false to
clear its transient `updating` UI flag, which otherwise stuck for the full
600s grace after a manager-triggered update.

This is the signal that covers an update which FAILS WITHOUT restarting the
node (the updater dies during verify/pull before any recreate): the node keeps
beating, so no re-register fires, and the manager would otherwise show
"updating" until the grace lapsed. The probe fails safe to False.

Bump 0.3.9 -> 0.3.10. Pairs with the manager fix; the manager handles the
field's absence (older greffers) gracefully.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c18cf8e69a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/workers/heartbeat.py

from apps.utils.docker import updater

return updater.update_in_progress(Path(settings.greffon_path) / ".update.lock")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not let heartbeats contend with the update lock

When a heartbeat runs during the small window after /remote_update starts the detached updater but before the updater has acquired /data/.update.lock, this call can briefly take the same exclusive non-blocking flock used by apps.utils.docker.updater.update_in_progress. The updater entrypoint also uses LOCK_EX | LOCK_NB and treats any held lock as “another update” (cli/greffer_cli/updater/__main__.py:53-58), so a regular 5s heartbeat can make a valid manager-triggered update exit as refused before it starts.

Useful? React with 👍 / 👎.

…se an update

Codex review (greffer#98): the new heartbeat update_in_progress probe (and the
controller's start/stop/update guard) take LOCK_EX|LOCK_NB on /data/.update.lock
acquire-then-immediately-release. The detached updater's one-shot acquire could
land inside that microsecond hold and exit EXIT_REFUSED ("another update in
progress") before the update even starts.

acquire_lock now retries briefly (~1s) before giving up: a transient probe hold
is absorbed, while a genuine concurrent update (holds the lock for its whole run)
still refuses after the bounded retry. Also hardens the pre-existing
controller-probe vs updater-acquire contention.
@omarsy

omarsy commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

Good catch — fixed in 2dfc315. Confirmed the updater's acquire_lock was a one-shot LOCK_EX|LOCK_NB with no retry, so a microsecond probe hold (heartbeat or the controller's own _refuse_if_updating) could make a valid update exit EXIT_REFUSED. acquire_lock now retries briefly (~1s) before giving up: a transient probe hold is absorbed, while a genuine concurrent update (holds the lock for its whole run) still refuses after the bounded retry. This also hardens the pre-existing controller-probe vs updater-acquire contention. Added retry-through-transient-hold and gives-up-on-persistent-hold tests.

@omarsy

omarsy commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dfc315b7f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/workers/heartbeat.py
# Lets the manager clear its transient "updating" flag the moment a
# self-update finishes or fails (lock released), instead of waiting out
# its grace window (covers a failed update that never restarts the node).
"update_in_progress": _update_in_progress(settings),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retry the host CLI lock path as well

When an operator runs greffer update while the daemon is otherwise idle, this new per-heartbeat probe briefly takes the same $GREFFON_PATH/.update.lock exclusive flock; the host CLI still does a single non-blocking flock in cli/greffer_cli/update.py:406-409 and returns EXIT_PREFLIGHT_REFUSED at cli/greffer_cli/update.py:517-521, so a valid manual update can be rejected just because it landed during a heartbeat. The in-container updater was given a bounded retry for this same probe race, but the host update path needs the same treatment or the heartbeat should avoid taking an exclusive lock.

Useful? React with 👍 / 👎.

Codex review (greffer#98 round 2): the bounded-retry fix for the in-container
updater's acquire_lock left the HOST `greffer update` path (update.py
_acquire_update_lock) still doing a one-shot LOCK_EX|LOCK_NB. The greffer's new
per-heartbeat update_in_progress probe holds the same /data/.update.lock for
microseconds, so a manual `greffer update` landing in that window would be
spuriously refused (EXIT_PREFLIGHT_REFUSED).

Apply the same ~1s bounded retry to the host lock: a transient probe hold is
absorbed; a genuine concurrent run (host or in-container updater) still refuses
after the retry.
@omarsy

omarsy commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

Good catch — fixed in 719164c. You're right that the bounded retry only covered the in-container updater; the host greffer update path (_acquire_update_lock) was still a one-shot flock and contends with the same per-heartbeat probe. Applied the identical ~1s bounded retry there: a transient probe hold is absorbed, a genuine concurrent run (host or in-container updater) still refuses after the retry. Added retry-through-transient and gives-up-on-persistent tests for the host path too.

(Note: the host-CLI fix ships in a new cli-v* release; the practical risk against an older CLI is minuscule — the probe hold is microseconds — but this hardens it.)

@omarsy

omarsy commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 719164c24a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@omarsy
omarsy merged commit 08edca5 into main Jun 18, 2026
6 checks passed
@omarsy
omarsy deleted the fix/greffer-heartbeat-update-in-progress branch June 18, 2026 10:06
omarsy added a commit that referenced this pull request Jun 23, 2026
Resolve the heartbeat-payload conflict by keeping BOTH features: cert_serial
(R-DR10 DR reconciliation, this branch) and update_in_progress (self-update
clear, from main #98). Both keys ride the same beat; the two new tests become
two separate self-contained tests. 35 heartbeat tests pass.
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.

1 participant