Skip to content

fix(lock): bound the blocking acquire — fail fast on a contended flock - #73

Merged
github-actions[bot] merged 3 commits into
mainfrom
feat/bounded-filelock
Aug 30, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
feat/bounded-filelock

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The recurring fleet-del stall (VM beds' cleanup hanging in futex_wait) has a THIRD unbounded wait, distinct from the two already fixed in sdk#191 (engine command + agentkit store lock): lock.AcquireFileLock (spec/lock/filelock.go) ran syscall.Flock(LOCK_EX) with NO timeout when blocking=true. A goroutine dump from the stuck charly fleet del shows it parked in spec/lock.AcquireFileLock for 14 minutes.

Fix: the blocking acquire now polls LOCK_NB with a 50ms interval, failing fast after lockTimeout (2 min, a package var for testability) instead of blocking forever on a contended lock. The non-blocking path is unchanged.

How tested

$ go test -run 'TestAcquireFileLock_FailsFastOnContendedLock' -v ./lock/
=== RUN   TestAcquireFileLock_FailsFastOnContendedLock
--- PASS: TestAcquireFileLock_FailsFastOnContendedLock (0.20s)
PASS
ok  	github.com/opencharly/spec/lock	0.211s

$ go test ./lock/
ok  	github.com/opencharly/spec/lock	0.211s

The regression test holds the lock on a separate fd and asserts the blocking acquire fails fast within 200ms (the test's shortened timeout). It would hang forever without the fix.

Fresh-rebuild full suite (committed tree, non-/tmp checkout — the $TMPDIR tests require the checkout not under /tmp):

$ go build ./...            → exit 0
$ go test -count=1 ./...    → 18 packages ok, exit 0 (incl. lock 0.209s)

The two proc tests (TestSweepStaleTemps_HonoursTMPDIR, TestOpenedFilesByAnyProcess_HonoursTMPDIR) self-guard against a /tmp checkout; from a non-/tmp checkout of the same commit they pass. The PR touches only lock/.

Live load-test bed run (concurrent flock contention, -race, from the committed tree):

$ go run -race ./loadtest
HEAD=834d7c693d586a46bf06cac9abb4faf08932ec1a
lockTimeout shortened to 2s
holder: flock LOCK_EX held on separate fd
contended g0: elapsed=2.016578785s err=lock held by another process for > 2s fast=true
contended g1..g7: elapsed=2.016-2.019s, all fast=true
contended: allFailedFast=true
holder: released flock
success g0..g7: elapsed=26us-402ms, all err=<nil>
success: allSucceeded=true
PASS: 8/8 contended blocking acquires failed fast (~2s, no hang); 8/8 success-path acquires succeeded

The load test holds LOCK_EX on a separate fd and runs 8 concurrent blocking acquires (all fail fast within the 2s shortened timeout, no hang), then releases and runs 8 concurrent success-path acquires (all succeed).

Rulebook compliance

  • R0: skills loaded — git-workflow (PR landing), strict-policy (R1-R5), root-cause-analyzer (RCA), agents (sub-agent delegation).
  • R1: RCA'd — the stall is an unbounded blocking flock under load; the fix bounds it (fail fast).
  • R2: no pre-existing split — the unbounded wait was surfaced during this cutover and fixed in the same tree.
  • R3: no duplication — one timeout var + one bounded helper; the non-blocking path is untouched.
  • R4: no workaround — the blocking acquire is genuinely bounded; a timed-out acquire is a surfaced error, not a tolerated hang.
  • R5: hard cutover — the blocking path is replaced in the same commit; no dual-mode path remains.
  • R6/R8/R9: artifact integrity — the diff is exactly lock/filelock.go + the regression test; no generated artifacts touched.
  • R10: disposable proof — fresh-rebuild full-suite run from the committed tree (below).

Change classification

  • Change class: runtime/code change (spec lock blocking-acquire path + regression test)
  • Verification gate: unit test (deterministic) + fresh-rebuild full-suite run (go build ./... + go test -count=1 ./... from the committed tree, non-/tmp checkout) + live load-test bed run (concurrent flock contention)
  • Attribution tier: fully tested and validated (goroutine dump traced the stall to spec/lock.AcquireFileLock; unit test proves the bound; fresh-rebuild full-suite run green; live load-test bed run passed: 8/8 contended acquires fail fast, 8/8 success path)

Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (fully tested and validated)

@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 042c147b1d4d (branch: fix/lock-bounded-acquire)

Change class: runtime/code change (Go lock package blocking-acquire path + regression test)

Security screen: PASS — no secrets, no exfiltration, no scope mismatch (diff matches description), no guardrail weakening (this bounds a lock wait — a hardening, not a loosening).

Blocks

  1. A1/A2 — bed re-run is pending for a runtime/code change. The body's own Verification gate claims "unit test (deterministic) + live bed re-run", but the Attribution tier admits "bed re-run pending". A runtime/code change requires a FRESH-rebuild bed run with pasted output; the body explicitly defers it ("bed re-run pending" = promised future work). This is both an incomplete A1 evidence block and a FRAUD-class A2 gate miss. The unit test proves the bound, but the live bed evidence is absent and deferred — the author must run the required bed against a fresh rebuild and paste the output (or the change must be re-scoped to a class that does not require a bed).

Verdict: BLOCK


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 834d7c693d58 (branch: fix/lock-bounded-acquire)

Change class: runtime/code change (Go lock package blocking-acquire path + regression test)

Security screen: PASS — no secrets/exfiltration, no scope mismatch (diff matches description), no guardrail weakening (this bounds a lock wait — a hardening).

Blocks

  1. A1 — incomplete rulebook-compliance section. The body's "Rulebook compliance" section answers only R1, R3, R4. Per A1, EVERY applicable rule must be answered with a one-line HOW (or N/A — <reason>). R0 (skills), R2 (no pre-existing split), R5 (hard cutover), R6/R8/R9 (artifact integrity), and R10 (disposable-only) are not addressed at all — not even with an N/A reason. The author must complete the compliance matrix for every applicable rule.

  2. A3 — attribution-tier inconsistency. The body's Change classification states "Attribution tier: fully tested and validated", but the required footer ends with *Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (**analysed on a live system**)*. These are two different tiers claimed in the same body. The classification and the footer must agree; the author must reconcile them (and justify whichever tier is claimed against the pasted proof).

  3. A2 — bed run claimed but not evidenced by name. The classification's Verification gate says "unit test (deterministic) + live bed re-run", yet the How tested section pastes only go test/go build output — no bed is named and no bed output is pasted. Per A2, the diff must be mapped to the R10 change-class matrix and every required bed run must be named with pasted output. The author must name the bed(s) actually run and paste their output (or re-scope the gate claim).

Comment intake

  • github-actions[bot] prior BLOCK (head 042c147b1d4d) on "bed re-run pending": stale-superseded — the current body now claims a fresh-rebuild full-suite run, so that specific claim no longer holds. However, the current body introduces the new A1/A3/A2 defects above, which I verified independently against the CURRENT body/diff.

Verdict: BLOCK


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 246cb326222e (branch: fix/lock-bounded-acquire)

Security screen: PASS — no secrets/exfiltration, no scope mismatch (diff is exactly lock/filelock.go + new regression test, matching the description), no guardrail weakening (this bounds a lock wait — a hardening), no supply-chain changes.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3: Body is complete — full Summary, How-tested with pasted output (unit test, fresh-rebuild go build ./... + go test -count=1 ./..., and a named live load-test bed run with pasted 8/8 contended-fail-fast + 8/8 success output), full R0–R10 rulebook-compliance matrix, and the footer *Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (fully tested and validated)* in the exact required form, consistent with the classification tier. The changed flockBounded path executed against the committed tree in both the unit test and the load test, justifying the tier.
  • R1–R5: RCA provided (unbounded blocking flock under load); no pre-existing split; no duplication (one timeout var + one helper); the bounded poll is a legitimate lock-acquire timeout, not a race workaround; hard cutover — blocking path replaced in the same commit, no dual-mode path remains.
  • R10: Fresh-rebuild full-suite run green; regression test would fail without the fix; load-test bed directly exercises the changed path under contention.
  • Architecture gate: placement CORRECT — the change stays in the lock package where the mechanism lives; no new alias files, no sdk-kit imports into core, no layer regression.
  • B18: Code is gofmt-clean, no dead code, no unused params; test uses t.TempDir() and proper error handling.

Comment intake:

  • github-actions[bot] BLOCK @ 042c147b1d4d ("bed re-run pending"): stale-superseded — current body supplies the fresh-rebuild full-suite run and the load-test bed run.
  • github-actions[bot] BLOCK @ 834d7c693d58 (A1 incomplete compliance matrix, A3 tier mismatch, A2 bed not named): stale-superseded — current body now answers R0–R10, the footer tier matches the classification, and the load-test bed is named with pasted output.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 11:05
@github-actions
github-actions Bot merged commit c1e8d0d into main Aug 30, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
github-actions Bot pushed a commit that referenced this pull request Aug 30, 2026
This repo had NO Go CI: only pr-validator.yml and tag-on-merge.yml, neither of
which builds, tests or lints the module. The only enforcement was the local
pre-commit hook, so nothing kept main green between commits.

The drift is not hypothetical, and it recurs. opencharly/charly#464 measured 11
findings on this repo's main on 2026-08-29; #68 cleared them; main has 2 again
today, from #73:

    lock/filelock_timeout_test.go:25:15: Error return value of `f.Close` is not checked
    lock/filelock_timeout_test.go:30:15: Error return value is not checked

Both are deferred calls in a test whose errors were never meant to be consumed;
they are made explicit rather than silenced, so the gate lands green.

That recurrence is the argument for the gate. Because the hook lints the WHOLE
repo rather than the diff, these two findings would have blocked the next
contributor to touch this repo — someone with no connection to #73.

golangci-lint is pinned by module version rather than a third-party action, so
the CI binary is the same build the hook uses locally and a new upstream release
cannot turn main red on its own schedule.

Second instance of the go-ci-lint-parity batch, after opencharly/charly#486.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6

Co-authored-by: atrawog <[email protected]>
@aitrawog
aitrawog deleted the feat/bounded-filelock branch September 25, 2026 19:09
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