feat(dream): add --break-lock for gbrain-cycle (closes #1591)#2173
Open
lost9999 wants to merge 1 commit into
Open
feat(dream): add --break-lock for gbrain-cycle (closes #1591)#2173lost9999 wants to merge 1 commit into
lost9999 wants to merge 1 commit into
Conversation
The cycle lock (held by `gbrain dream`/autopilot) had no CLI escape
hatch, so a wedged cycle stranded it indefinitely and `gbrain doctor`'s
hint routed operators to `gbrain sync --break-lock` which couldn't
actually break it.
Adds `gbrain dream --break-lock` with the same safety semantics as the
existing `gbrain sync --break-lock` (src/commands/sync.ts:810-966):
- safe path: refuses if holder alive, refuses cross-host
- --max-age <seconds>: atomic TOCTOU-safe age-gated delete
- --force-break-lock: skip guards, atomic DELETE, loud warning
- --source <id>: per-source scoping (resolves to gbrain-cycle:<id>)
- --json: machine-readable output
Files:
- src/commands/dream.ts: +129 lines (runCycleLockBreak + formatAgeHuman
+ --break-lock short-circuit + 3 imports)
- CHANGELOG.md: +4 lines ([Unreleased] section)
Doctor hint follow-up (route cycle locks to this command instead of
`gbrain sync --break-lock`) is intentionally deferred to a separate
commit so this PR stays scoped to the dream-side escape hatch.
Closes garrytan#1591
49dcac3 to
2da3b82
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The cycle lock (held by
gbrain dream/ autopilot) had no CLI escape hatch, so a wedged cycle stranded it indefinitely andgbrain doctor's hint routed operators togbrain sync --break-lockwhich couldn't actually break it.This PR adds
gbrain dream --break-lockwith the same safety semantics as the existinggbrain sync --break-lock:--max-age <seconds>: atomic TOCTOU-safe age-gated DELETE keyed on(id, holder_pid, last_refreshed_at < NOW() - N * INTERVAL)--force-break-lock: skip guards, atomic DELETE, loud warning that the holder may still be writing--source <id>/--json: per-source scoping (resolves togbrain-cycle:<id>lock key) and machine-readable outputDoctor at
src/commands/doctor.ts:2417+already routes cycle locks togbrain dream --break-lock(the if-else chain is in place), so the moment this lands, the existing hint becomes actionable for the first time.Test plan
gbrain dream --break-lock(no cycle lock held) →Lock gbrain-cycle is not held (nothing to break).exit 0gbrain dream --break-lockwhile a healthy cycle holds it →holder is alive, use --max-age or --force-break-lockexit 1gbrain dream --break-lock --max-age 60while a long-dead cycle holds it →Broke cycle lock gbrain-cycle ...exit 0gbrain dream --break-lock --force-break-lock→ atomic DELETE, warning emittedgbrain doctorafter merge →stale_locksWARN should clearFiles
src/commands/dream.ts: +129 lines (runCycleLockBreak+formatAgeHuman+--break-lockshort-circuit + 3 imports)CHANGELOG.md: +4 lines ([Unreleased] section)Closes #1591