Skip to content

fix(heartbeat): persist dynamic local-container claims - #1385

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-1367-local-container-heartbeat
Aug 17, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-1367-local-container-heartbeat

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • add a provider-neutral optional exact-claim authorizer for runtime-derived ownership scopes while preserving core's generic static scope/resource validation
  • make local-container rehydrate and validate the recorded runtime context, endpoint, daemon identity, and exact container before heartbeat mutation
  • persist heartbeat timestamps, expiry, and explicit idle-timeout replacements through exact claim compare-and-swap; omitted timeouts preserve the stored value and fresh processes observe the committed state
  • document the capability and local-container behavior, with focused fail-closed regression coverage

Thanks @coygeek for the precise report and Docker reproduction.

Fixes #1367

Verification

  • gofmt on changed Go files
  • git diff --check
  • go test -race -count=1 -timeout=4m ./internal/cli -run 'Test(StatusWaitRequestsReadyProbe|StatusLeaseExactClaimAuthorizerOwnsDynamicScopeValidation|HeartbeatDirectProviderUsesTouchForExactClaim|HeartbeatDirectProviderOmitsIdleTimeoutOverrideIntent|HeartbeatDirectProviderRejectsClaimlessLease)$'
  • go test -race -count=1 -timeout=5m ./internal/providers/localcontainer -run 'Test(AuthorizeStatusTouchClaimHydratesDynamicRuntimeScope|LocalContainerTouchPersistsExactClaimLifecycle|LocalContainerTouchRejectsUnownedOrChangedClaimWithoutMutation)$'
  • go test -race -count=1 -p 1 -timeout=12m ./internal/providers/localcontainer
  • go test -race -count=1 -p 1 -timeout=6m ./internal/cli -run '^(TestHeartbeat|TestStatus)'
  • go vet -p 2 ./...
  • scripts/check-docs.sh
  • P1 autoreview: clean, no accepted or actionable findings

A repository-wide macOS internal/cli race run was also attempted; unrelated browser-opener and listener-helper tests failed before the package later timed out. The complete heartbeat/status race slice and full local-container race suite above pass, and required CI will provide the isolated full-suite result.

Live local-container proof

Provider: local-container on Docker-compatible OrbStack. Proof lease cbx_96f08273aaba was removed after verification.

  • created a retained lease with a 5-minute idle timeout
  • heartbeat succeeded with an explicit 11-minute replacement
  • a separate CLI process inspected lastTouchedAt=2026-08-17T08:59:32Z, idleTimeout=11m0s, and expiresAt=2026-08-17T09:10:32Z
  • a deliberately mismatched persisted runtime scope exited 4; the exact claim SHA-256 was identical before and after rejection, and heartbeat emitted no success output
  • restored the valid proof claim solely for cleanup, then stop removed the exact container, claim, per-lease SSH key directory, and bootstrap directory
  • final Docker lookup returned no proof-owned container and isolated claims list --json returned an empty claim set

Configuration and secrets

No new configuration, dependency, credential, or secret handling is introduced.

Delegate runtime-derived exact claim authorization to providers while preserving generic static-scope validation, and persist local-container heartbeat lifecycle changes through claim compare-and-swap.

Refs #1367

Co-authored-by: Coy Geek <[email protected]>
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 5:07 AM ET / 09:07 UTC.

ClawSweeper review

What this changes

The PR delegates runtime-derived lease-claim authorization to provider backends and makes local-container heartbeat updates durable across fresh CLI processes.

Regression provenance

Possible regression — probable (reproduction; reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open as the focused fix for the linked local-container heartbeat failure. The provider-neutral hook preserves core’s static validation while the local-container backend revalidates the exact runtime claim and persists lifecycle state with compare-and-swap semantics; no actionable patch defect was found.

Priority: P2
Reviewed head: a65f1cedbd2b346f626e09b0c622cd5817a41dae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation, fail-closed tests, and a detailed real local-container run support a solid merge-ready review pending ordinary required checks.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.
Evidence reviewed 7 items Core authorization boundary: After resolving an exact claim for the canonical provider, core delegates only runtime-derived authorization to the optional provider capability; static providers retain the existing scope/resource comparison.
Fail-closed local-container implementation: The provider checks lease ID, provider, exact container, captured runtime metadata, live runtime identity, and scope before touching a claim; Touch then writes through the exact carried snapshot.
Durability and rejection coverage: Focused tests cover runtime-scope hydration, retained timeout behavior across a fresh resolve, and missing, stale, changed, or mismatched claims without mutation.
Findings None None.
Security None None.

How this fits together

Crabbox heartbeat refreshes retained leases directly through an SSH-capable provider when no coordinator owns the lease. Before updating expiry state, the provider must verify the exact local ownership claim and then return the refreshed lease state to the CLI.

flowchart LR
  A[Heartbeat command] --> B[Resolve retained lease]
  B --> C[Read exact ownership claim]
  C --> D{Static or runtime scope}
  D -->|Static| E[Core validates scope and resource]
  D -->|Runtime| F[Provider validates recorded runtime and container]
  E --> G[Compare-and-swap lifecycle claim]
  F --> G
  G --> H[Refreshed lease state]
Loading

Before merge

  • Resolve merge risk (P1) - The new optional authorizer is an ownership-security boundary: any future provider implementation must preserve the documented exact-claim, runtime-identity, and fail-closed checks.
  • Resolve merge risk (P2) - Heartbeat now durably updates lease lifecycle state, so regression coverage must continue to protect compare-and-swap behavior and timeout preservation.
  • Complete next step (P2) - No actionable repair was found in this PR; normal required-check completion and merge review are the remaining steps.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Change mix production code +75/-17; tests +315/-26; docs +63/-11 The implementation is paired with substantially more targeted regression coverage and operator documentation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #1367
Summary: This PR is the focused candidate fix for the canonical dynamic local-container heartbeat claim-rejection report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land with exact-claim guardrails (recommended)
    Accept the residual lifecycle and ownership risk only with the new fail-closed claim tests retained and the required Go/local-container validation completing for this head.

Technical review

Best possible solution:

Merge the narrow provider-owned authorization path so valid retained local-container leases can heartbeat while changed, missing, or replaced claims remain unable to mutate lifecycle state.

Do we have a high-confidence way to reproduce the issue?

Yes — current-main source compares the stored claim to a static provider scope, while the linked report supplies a concrete Docker reproduction using a dynamic local-container runtime scope.

Is this the best way to solve the issue?

Yes — a narrow provider-owned authorizer keeps core provider-neutral while preserving static-provider validation and requiring local-container to validate its runtime identity before mutation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against bb8370aa3bdf.

Labels

Label changes:

  • add P2: This repairs a normal retained local-container lease workflow without evidence of a broader availability incident.
  • add merge-risk: 🚨 session-state: The patch changes durable timestamps, expiry, and idle-timeout state stored in exact lease claims.
  • add merge-risk: 🚨 security-boundary: The new provider capability decides whether a runtime-derived ownership claim may authorize a heartbeat mutation.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.

Label justifications:

  • P2: This repairs a normal retained local-container lease workflow without evidence of a broader availability incident.
  • merge-risk: 🚨 session-state: The patch changes durable timestamps, expiry, and idle-timeout state stored in exact lease claims.
  • merge-risk: 🚨 security-boundary: The new provider capability decides whether a runtime-derived ownership claim may authorize a heartbeat mutation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix OrbStack run with cross-process persisted state, a rejected changed-scope control that left the claim unchanged, and cleanup verification.

Evidence

What I checked:

  • Core authorization boundary: After resolving an exact claim for the canonical provider, core delegates only runtime-derived authorization to the optional provider capability; static providers retain the existing scope/resource comparison. (internal/cli/status.go:139, a65f1cedbd2b)
  • Fail-closed local-container implementation: The provider checks lease ID, provider, exact container, captured runtime metadata, live runtime identity, and scope before touching a claim; Touch then writes through the exact carried snapshot. (internal/providers/localcontainer/backend.go:931, a65f1cedbd2b)
  • Durability and rejection coverage: Focused tests cover runtime-scope hydration, retained timeout behavior across a fresh resolve, and missing, stale, changed, or mismatched claims without mutation. (internal/providers/localcontainer/backend_test.go:3661, a65f1cedbd2b)
  • Linked source reproduction: The linked report identifies the current static-scope equality check as rejecting a valid dynamic local-container runtime scope and supplies a Docker-based reproduction. (internal/cli/status.go:158, a65f1cedbd2b)
  • Branch and release provenance: This commit is directly based on current main and is not contained by a local release tag, so the fix is neither already on main nor released. (a65f1cedbd2b)
  • Feature history: The same contributor introduced heartbeat, then maintained static heartbeat persistence and local-container claim scope behavior immediately before this targeted fix. (internal/cli/heartbeat.go:1, ab0bca1c54e1)

Likely related people:

  • steipete: Current main history shows this contributor introduced heartbeat and recently maintained both static lifecycle persistence and local-container claim-scope handling. (role: feature owner and recent area contributor; confidence: high; commits: ab0bca1c54e1, f39dd170f403, 25df71fe5151; files: internal/cli/heartbeat.go, internal/cli/status.go, internal/providers/localcontainer/backend.go)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 055dde3 into main Aug 17, 2026
27 checks passed
@steipete
steipete deleted the steipete/fix-1367-local-container-heartbeat branch August 17, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(heartbeat): accept exact scoped local-container claims

1 participant