Skip to content

Model plan write ownership and close-event evidence #270

Done

Description

@DocksDocks

Goal

Make claim preparation, confirmation, and closure observations explicit in the plan helper. Preserve all refusal messages, ordering and public records. Check the reusable fake GitHub server for related correlated state, keeping independent scheduled events independent.

Yolo: the user delegated every decision except the merge to the agent.

Mode: plan-and-implement

Research

At 2120ef6e, types.ts PlanIssue represents one write with three independently optional fields. commands.ts readPlanIssue prepares a claim. github.ts refuseChangedIssue checks the snapshot owners, the viewer and any confirmed claim. writeIssueIfUnchanged checks the stored ID; claimBeforeClose and retirePlan separately clear the pending ID. writeReopen derives its claim from the guarded pre-write assignees. The final GraphQL read must match them before mutation, even if an intervening change only adds the acting viewer. The command verifies the single owner again before posting its comment. Its final assignment to confirmedOwner has no later reader.

Decision: distinguish a read-only issue from a prepared write. Carry the identified viewer in the latter. Represent an existing owner, a pending claim and a confirmed claim explicitly. Move pending-to-confirmed to the successful stored-ID check. Preserve acceptance of the pending viewer by ID or login, and check the login after confirmation. Keep the checked snapshot owners and the reopen path's final owner read: neither is interchangeable with the pending claim. Reject a shared global phase and independent optional flags; neither represents which identity each write must prove. This is a local representation change that the child PR can revert.

Closure evidence: github.ts latestCloser has either no event or an event with both its timestamp and its nullable closer. Null means that an event existed without an identified closer. An unselected connection and a selected empty one have the same observable meaning. Compare timestamps and the existing displayed closer exactly as writeReopen and settleAndReopen do now. Do not substitute object identity or strengthen GitHub compatibility checks. A merged PR guarantees a validated merge timestamp; only then is its own-merge evidence relevant. Retain the same malformed-response checks and their order even for unmerged PRs.

Decision: use one optional close-event object and the existing merged flag as the PR discriminator. Keep issue state/reason separate from the last close: a reopened issue can retain its prior event. Do not add a phase store or change GraphQL selection, pagination, write order, refusal text or dates. Near commands.ts createPlan, an unsupported parent flag leaves one pending link. Keep the fallback parent with the creation result, instead of a Boolean outside the request. Native linking, no parent and all other request failures must keep their behavior.

Coverage: inspected all nine modules under cli/src/plan. records.ts already derives explicit statuses from the remote state, labels and history; step statuses and frozen work remain independent. reviews.ts separates review kinds, archive cycles, grants and fence scopes. checkout.ts and bytes.ts model path traversal and byte recovery, not issue states. repository.ts resolves paths; services.ts supplies per-command process, filesystem and wait services. Connection cursors and read counts in github.ts are progress data, not authority. types.ts, commands.ts and github.ts own the confirmed candidates.

Fixture coverage: cli/test/fixtures/gh-stub/gh launches the fixture. state.ts describes independent scheduled events, sparse and deliberately malformed remote replies. ghStub.ts applies changes at read, mutation-field, comment, and close boundaries; different boundaries can occur in the same scenario. cli/test/lib/plan/harness.ts starts the real public CLI against isolated fixture state. Keep these independent mechanisms and representations; do not tighten test input shapes so that malformed replies become untestable. Checked the plan CLI suites, particularly children, archive, reopen, writes and status.

Verification skill detection: docks-kit agent-docs verify-skill detect printed verify skill: present. The skill has no plan-claims flow. Reuse the checked-in executable CLI scenarios instead of duplicating fixtures in a new flow. They already isolate remote writes, check stdout/stderr and stored issue data, and cover conditions a live issue cannot safely reproduce. No real issue is a test target.

Tool versions: Bun 1.4.5, Vitest 5.1.2, Node 26.13.0, Git 2.53.0, gh 2.103.3 and docks-kit 0.31.0 (local version commands); Effect 4.1.7 and TypeScript 7.0.2 (installed manifests). TypeScript narrowing supports the phase-specific fields. Existing repository schemas, not a new API or dependency, define which input is valid.

Steps

# Id Task Files Depends Effect Status Done when
1 ownership Prepare writable issues with an identified viewer and confirm each pending claim from stored evidence cli/src/plan/types.ts, cli/src/plan/commands.ts, cli/src/plan/github.ts - local done Read-only snapshots cannot authorize a write. Later writes reject lost or foreign ownership. Reopen derives its claim from pre-write owners and requires the final read to agree.
2 evidence Couple close and merge evidence and carry the pending child link with its created issue cli/src/plan/types.ts, cli/src/plan/github.ts, cli/src/plan/commands.ts 1 local done No consumer can see a closer without its event or use an unmerged PR as merge proof. Only a successful fallback create needs a separate link.

Acceptance

ID Command Expected
A1 Inspect git diff origin/main...HEAD -- cli/src/plan and run bun run check:types No independent claimant, confirmed-owner or event-time fields remain. Write functions require a prepared issue. Existing, pending and confirmed ownership remain distinct. Only a successful fallback create result carries a pending parent link; no flag escapes the creation request. All callers narrow before reading variant-specific evidence. Types and Effect diagnostics pass.
A2 bun run test:unit cli/test/unit/plan/write-gates.test.ts cli/test/unit/plan/write-postconditions.test.ts cli/test/unit/plan/status.test.ts Public plan commands preserve acceptance, exact refusal output, no-write conditions and stored ownership through a racing change, missing claim or successful claim.
A3 bun run test:unit cli/test/unit/plan/children.test.ts cli/test/unit/plan/archive-closer.test.ts cli/test/unit/plan/archive-landing.test.ts cli/test/unit/plan/archive-retire-list.test.ts cli/test/unit/plan/reopen.test.ts Native and fallback creation link once; failure leaves the same evidence. Archive and reopen preserve read counts, read order, lost-claim handling, identity checks, direct/commit/unknown close, earlier close and pending-close behavior. Fixtures capture actual CLI output and remote writes locally.
A4 bun run lint cli/src/plan/commands.ts cli/src/plan/types.ts cli/src/plan/github.ts and bun fmt --no-script --check cli/src/plan/commands.ts cli/src/plan/types.ts cli/src/plan/github.ts Both pass. Run the skill source-range guard if a citation references a shortened module.
A5 Request Full CI on the reviewed PR, verify the authorized ready event and first-attempt run, then check the tested merge parents, the current PR head and base, and GitHub's accepted required check All jobs succeed. The tested merge has the expected base and reviewed head as parents. The Actions check that GitHub evaluates for merging is the same run's successful Full CI; the current PR reports CLEAN. Report the full local gate separately; do not count a remote result as local.

Do not touch

Keep external CLI behavior, public issue records, auth rules, refusal precedence, protocol fields, compatibility modes and independent fixture schedules unchanged. Do not send test data to GitHub. No release, deployment, dependency upgrade or global transition framework.

Open questions

Verification Results

Candidate 3e1d72864b783016767782993854b826e2e0de70 on base 2120ef6ebaa82eff6b71e7ded58d6e9d01781a05. A1: writable issue and required viewer replace three optional ownership fields. Pending, assigned and confirmed states distinguish admission from proof. A complete close event, merged-only evidence and a pending link replace independent fields and flags. bun run check:types passed.

A2/A3: all 174 tests passed in the eight acceptance suites. They start the public CLI against isolated GitHub fixtures. A4: targeted Oxlint and Bun formatting passed on all three paths. No project skill cites these module paths. The full local gate did not run. A5 requires the reviewed pull request.

After round 1, 4aaf78f74ea064e967c6e23758739d9622843ef0 passed bun run check:types, scoped lint and formatting, and all 181 tests across the same eight public CLI suites. The new tests cover same-viewer reassignment between reads, pending and confirmed ID-only reads, unmerged response validation order, and the parent side of child linking. They use only the isolated GitHub fixture. Write reads always select label IDs when requested; the comment writer receives the single owner verified by the final read.

After round 2, dc3104a6bb3122a6c0991af4d70cb58cd8fb3b88 passed types, scoped lint and formatting and all 182 tests across eight CLI suites. The additional reopen case uses an assigned viewer and confirms that the body-only read does not consume the later assignee response.

A5: PR #276, head dc3104a6bb3122a6c0991af4d70cb58cd8fb3b88, base main at 2120ef6ebaa82eff6b71e7ded58d6e9d01781a05. The authorized ready event started run 46557006144 on its first attempt. All 10 jobs passed. Tested merge 21c26cd52e0d2d1bea45142f5c1429bcd28d08a4 has that base and head as parents. GitHub accepts the matching Actions job 142336125073 as its required Full CI; the PR reports CLEAN. The full local gate did not run.

Activity

  1. self-assigned this
    on Nov 30, 2026
  2. DocksDocks commented on Nov 30, 2026

    @DocksDocks
    OwnerAuthor

    Delegation grant: yolo: next up is a yolo issue for "scan this codebase for any implicit state machines and make it explicit"
    Parent event: 7294751276

  3. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Delegation grant: yolo: do all issues remaining following yolo skill without asking please.

  4. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 1

    Plan-review: repair

    • research_gap - Research lines 13–15; Steps ownership - writeReopen decides whether to claim from the assignees returned by the guarded pre-write read, not from the final GraphQL read. It first requires those two reads to agree (cli/src/plan/commands.ts:1110–1134). If the acting viewer becomes the assignee between them, the current command refuses without writing. Basing the decision on the last read alone would reopen without claiming - State that the guarded pre-write owners determine the claim, and that the final GraphQL read must agree before any mutation - class: wrong source of ownership evidence
    • goal_fit - Steps evidence; Acceptance A1 - A1 does not check whether the successful fallback create result carries its parent. A partial implementation could leave linkByRest unchanged in cli/src/plan/commands.ts:319–350 and still satisfy A1. A3's existing child tests check calls and stored results, which the old Boolean already produces (cli/test/unit/plan/children.test.ts:167–261) - Make A1 inspect the candidate's create result and require that only a successful fallback result carries the parent for the separate link - class: structural outcome absent from acceptance
    • goal_fit - Acceptance A5 - A5 explicitly allows the full local gate to go unrun. AGENTS.md:69–73 requires the full unit and golden gate at the pre-commit or release boundary. A successful Full CI run starts after the commit, when the PR is marked ready (.github/workflows/parity.yml:1–5), so it cannot satisfy the pre-commit requirement for this no-release plan - Require a passing bun run check at the pre-commit boundary and keep the protected CI check separate - class: required pre-commit gate made optional
    • goal_fit - Acceptance A5 - A successful run with matching head, base, and job results does not prove GitHub accepts that run's required check. AGENTS.md:81 requires that confirmation before asking to merge. GitHub can evaluate the current test merge commit instead of the PR head, so the run can be green while the merge box still reports the check as expected (GitHub required-check documentation) - Require A5 to verify the ready event, first attempt, tested commits, and that GitHub accepts the matching Actions Full CI result on the commit it evaluates - class: workflow success substituted for required-check acceptance
  5. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Plan review round 2, delta

    Plan-review: pass

    None.

    Previous findings:

    • Round-1 finding on Research lines 13–15 and Steps ownership: resolved - Both now say the guarded pre-write assignees determine the claim and the final GraphQL read must agree before any mutation.
    • Round-1 finding on Steps evidence and Acceptance A1: resolved - A1 now checks that only a successful fallback creation returns a pending parent link and that no separate flag escapes the creation request.
    • Round-1 finding on Acceptance A5, full local gate: rejected - not repeated. The dispatch requires targeted local checks and excludes remote CI as evidence for the separate local checklist item.
    • Round-1 finding on Acceptance A5, required-check acceptance: resolved - A5 now verifies the authorized ready event, first attempt, tested merge parents, current head and base, and that GitHub accepts the same run's successful Actions Full CI check.

    Manager response to round 1

    Repaired:

    • R1 Research 13–15 and ownership step: the pre-write owners decide the reopen claim; the final read must agree. The research and step now state both requirements.
    • R1 evidence step/A1: A1 explicitly checks that only a successful fallback creation returns its parent as a pending link.
    • R1 A5: the ready event, first attempt, merge parents, current base and head, check provenance and GitHub's accepted required check are now explicit.

    Redesigned: none.

    Rejected:

    • R1 A5, full local gate: the run's verification policy requires targeted local checks when narrower tests cover the changed behavior. A1–A4 name those checks, and the full remote gate remains mandatory. The separate local checklist item stays unticked; remote CI is not presented as a local pre-commit run.
  6. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Self-review

    Correctness: The active public callers preserve contract, viewer, labels and mutation ordering. Close comparisons still use timestamp and displayed closer. No behavioral finding.

    Spec and tests: The eight isolated CLI suites passed 174 cases. They run the actual CLI and verify stored remote state. No separate fixture transition is needed.

    Text and safety: readWritablePlan types its connection parameter as SnapshotOptions, which also exposes the read-only acting and namesOnly controls. No current caller passes those controls. Narrow the parameter and reusable archive connections to the write read's SnapshotConnections; keep names-only lookup with new.

  7. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 1, lens correctness

    Code-review: pass

    Standards

    None.

    Spec

    None.

    Code review round 1, lens spec-and-tests

    Code-review: pass

    Standards

    • [MEDIUM] Maintainability - cli/src/plan/commands.ts:1133-1153, cli/test/unit/plan/reopen.test.ts:773-822 - If the acting viewer becomes the sole assignee between the guarded pre-write read and the last GraphQL read, reopen must refuse without writing. The existing foreign-owner test would still pass if the exact owner comparison were removed, because the earlier foreign-owner check rejects that fixture. - Add an afterIssueViewOnce case that assigns only the acting viewer and asserts the settle refusal, a still-closed issue, and no writes. - class: untested same-viewer ownership race
    • [LOW] Maintainability - cli/src/plan/github.ts:974-989, cli/test/unit/plan/archive-closer.test.ts:98-109, cli/test/unit/plan/reopen.test.ts:225-234 - If an unmerged PR response has malformed closing references or merge metadata, the CLI must report that error before not merged. Both unmerged tests supply well-formed responses and would pass if the new early return moved ahead of those checks. - Use the existing response override to assert the exact refusal and no writes for malformed unmerged responses, including which error wins when both fields are malformed. - class: untested malformed-response precedence
    • [LOW] Maintainability - cli/src/plan/github.ts:799-817, cli/test/fixtures/gh-stub/ghStub.ts:171-173, cli/test/unit/plan/write-postconditions.test.ts:20-51 - If the guarded read returns the viewer's ID without a login, a pending claim may proceed but a confirmed claim may not. The fixture always returns the ID and login together, so the tests cannot distinguish ID-based admission from login-based proof. - Add a scoped pre-write response override and test both outcomes through the CLI. - class: untested identity fallback
    • [LOW] Bug - cli/test/unit/plan/children.test.ts:188-202, cli/test/fixtures/gh-stub/ghStub.ts:126-132 - The no-parent assertion reads the new issue's subIssues. It still passes if the issue is wrongly attached to an existing parent, because the fixture stores the link on that parent. - Seed a possible parent and assert that creating a plan without --parent leaves it unlinked. - class: assertion checks wrong side of relationship

    Spec

    • [LOW] Spec - cli/src/plan/commands.ts:1217-1243, cli/src/plan/commands.ts:1284-1290, plan-270.md:15, plan-270.md:33 - When reopen successfully claims an unassigned plan, it verifies the stored viewer ID and the final sole owner, but passes the original pending issue to the comment writer. The runtime guards still work, but the representation does not follow the plan's decision to "Move pending-to-confirmed to the successful stored-ID check." - Represent the checked claim locally and pass verified reopen evidence to the comment writer after the final owner read, without restoring an unread assignment or changing the read order. - class: confirmed claim still represented as pending

    Code review round 1, lens text-and-safety

    Code-review: pass

    Standards

    • [LOW] Maintainability - cli/src/plan/commands.ts:198-203, cli/src/plan/commands.ts:807-812, cli/src/plan/github.ts:609-615 - Unreached: readWritablePlan accepts the read-only namesOnly option and passes it through to the write query and label decoder. If a caller reuses the options from new, the write read silently omits label IDs. Inference: status or reopen could then try to create a phase label that already exists and fail. The current edit, status, step, archive, retire, and reopen callers and their CLI fixtures do not pass this option; only new uses it. - Narrow the write call sites to SnapshotConnections and make the write adapter select and decode label IDs explicitly. - class: read-only option leaks into write path
    • [LOW] Bug - cli/src/plan/github.ts:957-958, cli/src/plan/github.ts:988-989 - For a valid unmerged pull request, readPullRequest returns only its number and merged: false, but the comment still describes the PR body and whether it closes the plan as part of the result. Archive and reopen already narrow correctly. - Document which fields are returned only for merged pull requests. - class: stale return contract comment

    Spec

    None.

  8. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 2, delta

    Code-review: pass

    Previous findings

    • Round-1 finding on cli/src/plan/commands.ts:1133-1153: fixed - cli/test/unit/plan/reopen.test.ts:907-927 assigns only the acting viewer after the pre-write response and checks the exact refusal, closed state, and absence of writes.
    • Round-1 finding on cli/src/plan/github.ts:974-989: fixed - cli/test/unit/plan/reopen.test.ts:274-315 checks malformed closing references and merge metadata through the public CLI, including which error wins when both are malformed.
    • Round-1 finding on cli/src/plan/github.ts:799-817: fixed - cli/test/unit/plan/write-postconditions.test.ts:161-197 exercises both outcomes through retire. The fixture uses the same node ID for the viewer and the loginless assignee.
    • Round-1 finding on cli/test/unit/plan/children.test.ts:188-202: fixed - cli/test/unit/plan/children.test.ts:190-218 seeds an eligible parent and checks that no issue stores the new plan as a sub-issue.
    • Round-1 finding on cli/src/plan/commands.ts:1217-1243: fixed - cli/src/plan/commands.ts:1217-1248 requires stored-ID evidence when claiming, then passes the verified sole owner and the original close event to the comment writer instead of the pending issue.
    • Round-1 finding on cli/src/plan/commands.ts:198-203: fixed - cli/src/plan/commands.ts:198-203,807-812 and cli/src/plan/github.ts:621-633 keep read-only options out of the write path and use the same label-ID selection for the query and decoder.
    • Round-1 finding on cli/src/plan/github.ts:957-958: open - repeated under Standards.

    Standards

    • [LOW] Bug - cli/src/plan/github.ts:969-970,1010-1021 - The rewritten comment correctly describes unmerged results but still says merged results include closing references. The function returns only the closesPlan Boolean, which reopen uses to decide whether there is anything to reopen. - Say the merged result reports whether GitHub lists the plan among the issues the pull request closes. - class: stale return contract comment
    • [LOW] Bug - cli/test/fixtures/gh-stub/ghStub.ts:1343-1357, cli/test/fixtures/gh-stub/state.ts:180-183, cli/src/plan/commands.ts:1368-1372 - Unreached: if the omission is armed for a viewer-owned plan, reopen's initial body-only view consumes it before JSON field selection. Inference: the later assignee read would then receive the normal login, so a test could miss the intended identity check. Only the two retire cases arm the option today, and their target views select assignees. The option documents a view that lists the viewer as an assignee. - Consume the override only when the response includes assignees. - class: one-shot response override consumed before field selection

    Spec

    None.

    Manager response to round 1

    Commit 4aaf78f74ea064e967c6e23758739d9622843ef0 contains the following repairs. All 181 tests in eight CLI suites passed at this head.

    Repaired:

    • Round 1, commands.ts:1133–1153: the reopen CLI scenario exercises an intervening change to the acting viewer alone. Neither the earlier foreign-owner guard nor a missing mutation can satisfy the assertion.
    • Round 1, github.ts:974–989: unmerged responses with malformed closing references and merge data exercise decoder ordering through the public CLI.
    • Round 1, github.ts:799–817: check pending versus confirmed ownership using the fixture's legitimate viewer ID without a login on the pre-write read.
    • Round 1, children.test.ts:188–202: inspect the possible parent's stored links, not the new issue's children.
    • Round 1, commands.ts:1217–1243: postReopenComment receives the verified owner from the final read, not a pending plan. The recovery timestamp still belongs to the observed close. No extra read or write.
    • Round 1 and self-review, commands.ts:198–203, github.ts:609–615: write reads select IDs explicitly. Query construction and decoding use the same selection; only read-only callers can ask for names.
    • Round 1, github.ts:957–958: document the distinct unmerged and merged results.

    Redesigned: none.

    Rejected: none.

  9. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Code review round 3, delta

    Code-review: pass

    Previous findings

    • Round-2 finding on cli/src/plan/github.ts:969-970,1010-1021: fixed - The comment at cli/src/plan/github.ts:969 describes the repository-scoped closesPlan Boolean returned at lines 1016-1019, not the closing references used to compute it.
    • Round-2 finding on cli/test/fixtures/gh-stub/ghStub.ts:1343-1357, cli/test/fixtures/gh-stub/state.ts:180-183, cli/src/plan/commands.ts:1368-1372: fixed - cli/test/fixtures/gh-stub/ghStub.ts:1341-1359 leaves the override armed until a response includes the viewer in assignees. The public CLI test at cli/test/unit/plan/reopen.test.ts:833-848 checks that the body-only read leaves the override for the pre-write read, which refuses without reopening or writing.

    Standards

    None.

    Spec

    None.

    Manager response to round 2

    Commit dc3104a6bb3122a6c0991af4d70cb58cd8fb3b88 addresses both findings. All 182 CLI tests passed at this head.

    Repaired:

    • Round 2, github.ts:969–970: document closesPlan as the Boolean decision it actually returns.
    • Round 2, ghStub.ts:1343–1357: select the response fields before applying the one-time omission. A public reopen test uses its real body-only view followed by an assignee view and checks the refusal, closed issue and empty write log.

    Redesigned:

    • Previously the entire pull-request return object was restated in prose, first as one shape, then as two. That duplicated the type and still misdescribed closed.some(...). Document only the Boolean's repository-scoped meaning; the discriminated return type already defines the shapes. No public behavior changes.

    Rejected: none.

  10. DocksDocks commented on Dec 1, 2026

    @DocksDocks
    OwnerAuthor

    Archived with landing pull request #276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions