Skip to content

Model-check Pickup reservation and Claim across competing hosts #881

Closed

Description

@JacobStephens2

This was generated by AI during triage.

Idea

Adapt Cursor's create-formal-verification-skill to thirdshift. It would produce a project-local skill that model-checks one promise thirdshift makes, and that an agent reruns whenever a change touches the code behind it.

Why this skill and not create-verification-skill

create-verification-skill generates a verify-<app> skill that launches the app and drives its user surface the way a user would, then captures evidence of that. thirdshift's surface is a CLI that drives GitHub, git and an agent Harness. The integration tests already drive it through fakes (tests/fakes/, tests/pickup_run.rs), and driving the real binary would need a sandbox GitHub repository and paid Harness sessions on every check. It would add little evidence for a high cost.

The formal skill targets "concurrency, retries, state machines": a promise that tests rarely reach and that harms users when it breaks. That describes thirdshift's riskiest code:

  • Pickup reservation (ADR-0017). Two hosts can read the same Ready issue. A --force-with-lease create of refs/heads/thirdshift/pickup/<n> elects a winner, and a Claim-count comparison against the full label history rejects stale selections. Two machines' Pickup runs can take the same Ready issue at once #712 was a real two-clone double dispatch. The current tests are examples of orders someone thought of.
  • Claim lifecycle. Make, keep, release and requeue Claims through failed runs, a Stop, Self-merge, the Sweep and Day shift hand-back. Releasing a reservation does not release a Claim.
  • Worktree acquisition and disposal. The GLOSSARY entry for Worktree is a list of before-and-after authority checks around every destructive attempt, including retries.

Proposed first target

The property is: for any number of Pickup hosts on one repository, at most one Run or Spec run is dispatched per Ready generation of an issue. The model includes crashes, a failed winner that restores ready-for-agent, and Day shift hand-back. If it breaks, two implement sessions push competing work to one Issue branch.

  • Tool: TLA+ with TLC. It answers the question "can steps happen in a bad order?" across processes and is independent of the implementation language. The Rust code itself is not what's in question here.
  • Each action in the model maps to a function in src/pickup* / src/claim.rs, and each atomic step matches one request to GitHub or origin.
  • The check must be shown failing on a broken variant, for example with the Claim-count recheck or the empty lease expectation removed.
  • The generated skill records which files and functions it covers and the commit it was last synced at. It runs as one command with a pinned TLC version.

Out of scope for the first pass

Worktree disposal and Self-merge's missing base guard (GLOSSARY: "offers no atomic expected-base guard") are good second targets but stay out of the first pass.

Open questions for the Day shift

  • Should the generated skill be a repository skill under .agents/skills/, or a Factory skill under skills/ that Runs load when their diff touches src/pickup* / src/claim.rs?
  • Should CI run TLC (it needs a JVM on the runner), or should it stay an agent-run check?

Activity

  1. added
    enhancement
    needs-triage
    on Oct 20, 2026
  2. JacobStephens2 commented on Oct 20, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Triage Notes

    Decided:

    • The generated verify skill is a repository skill under .agents/skills/, not a Factory skill under skills/. Bringing it into the Factory waits on a Verification run (Verification run: thirdshift creates and maintains a repository's verification skills unattended #883).
    • Import the matching upkeep skill, maintain-formal-verification-skill, into .agents/skills/ alongside create-formal-verification-skill. A Day shift session runs it after merges that touched covered code (src/pickup*, src/claim.rs) without rechecking. It walks the commits since the recorded sync commit and labels each check in sync, updated, bug or blocked. Its job is to catch the dangerous case: a check that still passes while describing code that no longer exists.

    Still open:

    • The model-checker choice and whether CI runs it. TLC needs a Java 11+ runtime (this dev box has Java 8). Stateright would keep the model in Rust under cargo test, at the cost of a less expressive model.
  3. JacobStephens2 commented on Oct 20, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Brief (ready-for-human)

    Category: enhancement
    Summary: Model-check with Stateright that competing Pickup runs dispatch at most one Run per Ready generation of an issue, and leave a repository skill that reruns and maintains the check.

    Why not ready-for-agent: The maintainer wants to review before an agent takes this. The modeling also needs judgment: deciding which requests are one indivisible step, and deciding whether a counterexample is a real bug or a modeling error.

    Decided:

    • Tool: Stateright. The model is Rust and runs under cargo test, so it runs in CI with the existing tests and needs no JVM. The first property only requires that nothing bad ever happens, which Stateright handles well, and ADR-0017 makes no "eventually" promise. TLA+ and TLC remain the fallback for a later target that needs an "eventually" property.
    • Skills: the generated verify skill goes under .agents/skills/, a repository skill and not a Factory skill. create-formal-verification-skill and maintain-formal-verification-skill are imported alongside it.

    Current behavior:
    ADR-0017 arbitrates competing Pickup runs. A reservation ref on origin is created with an empty --force-with-lease expectation and holds a unique parentless commit. After acquiring it, the winner rechecks that the issue is still Ready and that its Claim-application count in the label history is unchanged since selection. The reservation is released with a lease that expects exactly the owner's commit. A crashed owner's reservation waits for the Day shift. Tests in the pickup and reservation suites cover chosen interleavings only. #712 was a real double dispatch from two clones.

    Desired behavior:
    A Stateright model of Pickup selection, reservation, the Claim recheck, dispatch, the Claim ending and reservation release, covering:

    • N hosts, at least 3, competing for one issue;
    • host crashes at any step;
    • a failed winner that restores ready-for-agent;
    • the Day shift handing the issue back or deleting a stale reservation.

    Each model action names the function or request in the Pickup reservation code and the Claim module that it stands for, and each indivisible action is exactly one request to GitHub or origin. The checked property is: never two dispatched Runs or Spec runs for the same Ready generation of an issue.

    Key interfaces:

    • The Pickup reservation (create, recheck, release) and the Claim (claim::make, the Claim ending) are the code the model must describe.
    • A Stateright Model implementation, with a state that holds per-host phase, the reservation ref, the issue's labels and the Claim count.
    • A repository verify skill that records:
      • the covered files and functions;
      • the bounds and assumptions;
      • the single command that runs the check;
      • a sync commit.

    Acceptance criteria:

    • The model check runs as one cargo test invocation and passes in CI within the existing test job's time budget.
    • The check fails on at least two broken variants of the real protocol, shown in the PR: without the Claim-count recheck, and with a non-empty lease (or no lease) on reservation create. Each failure gives a counterexample narrated in GLOSSARY terms.
    • If the current code breaks the property, that is reported as a finding with its counterexample. The model and the property are not weakened to make the check pass, and no product code is changed.
    • The verify skill under .agents/skills/ lets a cold agent tell whether a change touches covered code, run the check, tell a real bug from a modeling error, and update the model and sync commit.
    • create-formal-verification-skill and maintain-formal-verification-skill are under .agents/skills/.
    • The PR states what is verified, under which bounds and assumptions, and what is left out.

    Out of scope:

  4. added
    ready-for-human
    and removed
    needs-triage
    on Oct 20, 2026
  5. JacobStephens2 commented on Oct 21, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    The maintainer has finished reviewing the brief above and moved this issue to ready-for-agent. That brief is the Agent Brief. Its "Why not ready-for-agent" note no longer applies; everything else in it stands.

  6. added
    ready-for-agent
    in-progress
    and removed
    ready-for-human
    ready-for-agent
    on Oct 21, 2026
  7. removed
    in-progress
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions