Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

feat(reopen): a trunk conflict reopens for a main merge [B3,D1]

Corey Olsoneff739eb2634
diff --git a/docs/api.md b/docs/api.md
index 6d09e627..f923d480 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -283,7 +283,7 @@ The coordinator maintains the roadmap with `milestone add <name> [--note ...] [-
| `stream` | `version:number`, `event:object` |
<!-- api-http-shapes:end -->
-A move body is `{verb, item, args, agent}`. `item` is the positive integer id when the move needs one. `args` names its CLI positional arguments and flags; text values stay literal, including leading dashes. Omit `agent` to act as the coordinator, or name a registered agent to run in its worktree. Coordinator verification takes `args.as: "coordinator"`, matching the CLI's explicit identity check. The local session secret may act as any agent on that board. `result` is the CLI's JSON result. `next` claims work atomically; when a claim is already held it renews it and returns the renewal event. With no work available it returns the CLI's `NOTHING_FREE` refusal. Waiting remains a CLI option. `reopen` is coordinator-only: `args.note` is required, and it returns a submitted item to open without adding a verdict or replacing its last submitted commit.
+A move body is `{verb, item, args, agent}`. `item` is the positive integer id when the move needs one. `args` names its CLI positional arguments and flags; text values stay literal, including leading dashes. Omit `agent` to act as the coordinator, or name a registered agent to run in its worktree. Coordinator verification takes `args.as: "coordinator"`, matching the CLI's explicit identity check. The local session secret may act as any agent on that board. `result` is the CLI's JSON result. `next` claims work atomically; when a claim is already held it renews it and returns the renewal event. With no work available it returns the CLI's `NOTHING_FREE` refusal. Waiting remains a CLI option. `reopen` is coordinator-only: `args.note` is required, and it returns a submitted item to open without adding a verdict or replacing its last submitted commit. `args.conflict` names the files of an accepted item that conflicts with the trunk instead; it needs no note, records the trunk commit, and the item reads `needs main merge` until its next verdict.
Decision moves keep the CLI's routing: `shout` with `args.decision: true` may omit `args.to`; agents ask their coordinator, and the coordinator asks the person. `pass` takes the decision's id as `item` and `args.note`. Answering a decision addressed to the person requires `answer` with `args.as: "person"` from the coordinator's main checkout. Other callers receive the CLI's refusal.
diff --git a/docs/formats.md b/docs/formats.md
index dfc0bce0..ed647255 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -102,7 +102,7 @@ The board file is in the repository's Git common directory at `.git/pullboard/bo
| `row grammar` | `1` | `SPEC_GRAMMAR_VERSION` in `src/spec.js`; optional `<!-- pullboard-grammar N -->` line in either file (absence means the current grammar) | Both files share the version. A declared version must match; an incompatible grammar change requires a coordinated version bump and compatible files. No automatic conversion occurs. |
| `board schema` | `2` | `SCHEMA_VERSION` in `src/board.js`, persisted as `PRAGMA user_version` | Create missing tables and indexes, add missing columns in place with declared defaults, restore missing or changed triggers, and remove stale machine triggers without replacing rows. |
| `event log` | `1` | `EVENT_LOG_VERSION` in `src/board.js`, persisted in `board_meta` as `event_log_version` | Older event-log versions upgrade in place; newer versions are refused with `EVENT_LOG_VERSION`. Preserve event rows when the board schema changes. |
-| `move engine` | `20` | `ENGINE_VERSION` in `src/machine.js`, carried as `engine` in every sealed executable move | Bump when a move's meaning changes, independently of the event log and sealed envelope. A newer engine is refused with `ENGINE_VERSION`, naming both versions and asking you to upgrade Pullboard. |
+| `move engine` | `28` | `ENGINE_VERSION` in `src/machine.js`, carried as `engine` in every sealed executable move | Bump when a move's meaning changes, independently of the event log and sealed envelope. A newer engine is refused with `ENGINE_VERSION`, naming both versions and asking you to upgrade Pullboard. |
<!-- format-versions:end -->
Pullboard 0.6.1 released engine 1. Engine 2 records a fresh explicit-build claim's skipped-review snapshot. Pullboard 0.8.1 released engine 3, including lane-sensitive graft refusals and authenticated relay senders. Engine 4 adds captured background-baseline completions through `completeCheckBaseline`; released engine-3 clients stop with `ENGINE_VERSION` before interpreting this new operation or advancing their replay cursor. Engine 5 requires a one-line reason when releasing a review and gives that reviewer a one-hour cooldown for the current submission. Each sealed move replays under its recorded engine version: engines 1 through 4 retain the original release event and review-reservation behavior. Engine 5 retains support for older moves, including engine-4 baseline completions. Pullboard 0.8.3 released engine 6, adding board-scoped machine credentials and permitting machine execution only for one exact, earlier authenticated phone request, including its payload digest. Engine 7 adds ordered item holds through `holdItem` and `releaseItemHold`; engine-6 clients stop with `ENGINE_VERSION` before interpreting either operation or advancing their replay cursor. Engine 8, shared by the 0.8.5 move changes, retains merged-item exception notes, selects the next review in roadmap order, and adds coordinator-only `reopen` for a submission returned without a verdict; engine-7 clients stop with `ENGINE_VERSION` before interpreting this new operation or advancing their replay cursor. Recorded engines 1 through 7 retain their original tier-first review selection. Engine 8 also adds durable refusal recovery for blocked relay positions; each explicit skip publishes the readable prefix even when another unsupported record follows. Engine 8 also permits coordinator criterion/check edits on a live claim as pending corrections; the holder cannot renew or submit until a refreeze adopts the correction while preserving the claim. Older request receipts retain their recorded engine semantics. Upgrade every linked device before using the new moves. Each release shares one engine bump across its changed moves. Engine 8 also retains declared model labels on registration and records each registered agent move's model snapshot; engines 1 through 7 retain their original registration and event details without these model fields. Pullboard 0.8.8 released engine 9, which allows resubmitting the same rejected commit after a corrected criterion is refrozen, but only when the rejection names a different frozen digest. Engine 8 retains its HEAD_NOT_NEW refusal and prior submit-event detail. Engine-9 submit events add `criterionDigest`, and engine-8 boards replay with the original refusal and event history.
@@ -117,6 +117,8 @@ Engine 19 makes a corrected bar record why the old one was wrong. Once an item h
Engine 20 lets a decision name the items it changes. An `appendFact`, `answerDecision` or `verify` move may carry `implies`, a list of existing item ids, and an `answerDecision` move may carry `supersedes`, the shout id of an earlier answer. Either makes the move an engine-20 move: an older engine refuses it with `RELAY_MOVE` before changing its board or cursor, and a board replaying an older engine refuses `implies` with `ENGINE_VERSION`. Engine 20 also tells implied items when a decision is superseded: by a fact's `supersedes`, by an answer's `supersedes`, or by the next verdict on the same item. Moves recorded under engines 19 and earlier replay without these notices. Engine numbers 13 to 18 are allocated to other changes; whichever lands later renumbers, keeping every earlier engine's replay unchanged.
+Engine 28 reopens an accepted item that conflicts with the trunk for a main merge. A `reopen` move may carry `conflict: {files, trunk}`: the files that conflict, and the full trunk commit they conflict with. The CLI fills `trunk` from Git and refuses `NOT_CONFLICTING` when the accepted commit merges cleanly, or `CONFLICT_FILES` when a named file is not one Git reports as conflicting. The board refuses `NOT_ACCEPTED` unless the item is verified with an accept at its commit, and `BAD_CONFLICT` for a malformed conflict. A conflict needs no note and no landing failure; the event records `supersedes`, the accept it sets aside, and `conflict`, never `landingFailure`. The item reads `needs main merge` until its next verdict, and the re-review checks the frozen check at the new head. A `reopen` move carrying `conflict` requires engine 28, and older engines refuse it with `RELAY_MOVE` before changing their board or cursor; a board replaying an older engine refuses it with `ENGINE_VERSION`. Moves recorded under engines 27 and earlier replay unchanged. Engine numbers 21 to 27 are allocated to other changes; a gap is fine, a reused number is not.
+
The CLI declares its engine in every relay request's `X-Pullboard-Engine` header.
A linked board requires at least engine 3 after issuing any agent token, including
revoked or expired tokens. Issuing any machine credential raises that board’s minimum to engine 6, including after revocation or expiry. The minimum survives reopening the auth database;
@@ -317,7 +319,7 @@ The `event` table is a SQLite schema object governed by `SCHEMA_VERSION`; its ap
| `reserve` | reviewer | `until` |
| `accept` | reviewer | `reason`, `commit`, engine-20 `implies` |
| `reject` | reviewer | `reason`, `commit`, engine-20 `implies` |
-| `reopen` | coordinator | `commit`, `note`, `judgment`, engine-10 `supersedes`, `landingFailure` |
+| `reopen` | coordinator | `commit`, `note`, `judgment`, engine-10 `supersedes`, `landingFailure`, engine-28 `conflict` |
| `merged` | coordinator | `commit` |
| `landing_batch` | coordinator | `batch` |
| `landing_waiver` | person | `waiver` |
diff --git a/docs/formats.test.js b/docs/formats.test.js
index 2dec875f..b444acc0 100644
--- a/docs/formats.test.js
+++ b/docs/formats.test.js
@@ -331,6 +331,13 @@ function recordEventContract() {
tests: [{ file: 'test/format.test.js', name: 'keeps the example' }] }] } });
reopen(board, returned, { agentId: coordinator, note: `Landing batch ${failureBatch.id} failed test/format.test.js: keeps the example; merge commit ${'c'.repeat(40)}` });
+ const conflicting = addItem(board, { by: coordinator, lane: 'docs', title: 'Conflicting example' });
+ claim(board, conflicting, { agentId: returnedBuilder, lane: 'docs', leaseMs: 60_000, freeze: freeze('conflicting') });
+ const conflictingCommit = '1'.repeat(40);
+ submit(board, conflicting, { agentId: returnedBuilder, commit: conflictingCommit, tree: 'e'.repeat(40) });
+ verify(board, conflicting, { agentId: reviewer, decision: 'ACCEPT', reason: ACCEPT_REASON, note: 'checked the conflicting example', head: conflictingCommit, digest: 'conflicting', policy: 'agents' });
+ reopen(board, conflicting, { agentId: coordinator, conflict: { files: ['docs/formats.md'], trunk: '2'.repeat(40) } });
+
const withdrawn = addItem(board, { by: coordinator, lane: 'docs', title: 'Withdrawn example' });
withdraw(board, withdrawn, { agentId: coordinator, reason: 'duplicate fixture' });
holdLane(board, 'view', { agentId: coordinator, reason: 'fixture hold' });
diff --git a/docs/lifecycle.md b/docs/lifecycle.md
index d0672d72..05022a0a 100644
--- a/docs/lifecycle.md
+++ b/docs/lifecycle.md
@@ -58,7 +58,7 @@ Each move checks its guards in this order and refuses with the first one that do
| reserve | submitted | submitted | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), roadmapReadable (MILESTONES_CORRUPT), itemExists (NO_ITEM), inState (NOT_SUBMITTED), reviewCooldownElapsed (REVIEW_COOLDOWN), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD) |
| accept | submitted | verified | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonIsMet (BAD_REASON), trunkMergeClean (MERGE_CONFLICT or MERGE_CHECK_FAILED or NO_POLICY or NO_TRUNK), noUnverifiedStack (STACKED_ON_UNVERIFIED), itemCheckGreen (CHECK_RED or CHECK_UNVERIFIED), proofNoted (PROOF_REQUIRED), result (LAND_HEADER), result (ENGINE_VERSION) |
| reject | submitted | open | agent, coordinator | coordinatorSaysAs (MAIN_IS_COORDINATOR), joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), atSubmittedCommit (NOT_AT_COMMIT or OUTSIDE_LANE or NO_POLICY or BAD_CONFIG or GIT_GRAFTS), notBuilder (SELF_VERIFY), routeAllows (ROUTE), policyAllows (COORDINATOR_VERIFIES), familyAllows (O2_FAMILY_MATCH), reviewFree (REVIEW_HELD), criterionUnchanged (CRITERIA_CHANGED), reasonCoded (BAD_REASON), noteGiven (NOTE_REQUIRED), result (LAND_HEADER), result (ENGINE_VERSION) |
-| reopen | submitted, verified | open | coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), coordinatorOnly (COORDINATOR_ONLY), noteGiven (NOTE_REQUIRED), notMerged (ALREADY_MERGED), landingFailureRecorded (LANDING_FAILURE_REQUIRED) |
+| reopen | submitted, verified | open | coordinator | joined (NOT_JOINED), itemExists (NO_ITEM), inState (NOT_SUBMITTED), coordinatorOnly (COORDINATOR_ONLY), noteGiven (NOTE_REQUIRED), notMerged (ALREADY_MERGED), landingFailureRecorded (LANDING_FAILURE_REQUIRED), trunkConflicts (NOT_CONFLICTING or CONFLICT_FILES or NO_TRUNK or MERGE_CHECK_FAILED), conflictAccepted (NOT_ACCEPTED or BAD_CONFLICT or ENGINE_VERSION) |
| escalate | open, claimed | open | agent, coordinator | joined (NOT_JOINED), noteGiven (NOTE_REQUIRED), itemExists (NO_ITEM), holderOrCoordinator (NOT_YOURS), inState (CLOSED) |
| refreeze | open, claimed, submitted | open | coordinator, when there is no live claim awaiting a coordinator correction | joined (NOT_JOINED), coordinatorOnly (COORDINATOR_ONLY), itemExists (NO_ITEM), inState (CLOSED), rowsInForce (UNKNOWN_SPEC or A5_GRAMMAR_VERSION or NO_POLICY or BAD_CONFIG or SPEC_BEHIND_MAIN) |
| refreeze | claimed | claimed | agent, coordinator, when a live claim has a pending coordinator correction | joined (NOT_JOINED), itemExists (NO_ITEM), holderOrCoordinator (NOT_YOURS), inState (CLOSED), rowsInForce (UNKNOWN_SPEC or A5_GRAMMAR_VERSION or NO_POLICY or BAD_CONFIG or SPEC_BEHIND_MAIN) |
@@ -145,7 +145,14 @@ Each move checks its guards in this order and refuses with the first one that do
| REVIEW_COOLDOWN | the reviewer has not released this submission within the past hour, engine 5 or newer, only for the same reviewer and current submission | let another reviewer take it, or wait an hour or for a new submission |
| NOTE_REQUIRED | the move carries a note: what failed, what was tried, or why | --note "..." or --note-file <file> |
| ALREADY_MERGED | the item has no recorded merge receipt | a merged item cannot be reopened |
-| LANDING_FAILURE_REQUIRED | a verified item note names the failing test and landing merge commit | cite the recorded batch, or name the test and merge commit in a manual note |
+| LANDING_FAILURE_REQUIRED | a verified item note names the failing test and landing merge commit, unless the reopen names a trunk conflict | cite the recorded batch, or name the test and merge commit in a manual note; work that only conflicts with the trunk reopens with --conflict "<files>" |
+| NOT_CONFLICTING | the accepted commit no longer merges onto the trunk, and every named file is one that conflicts, only for reopen --conflict by the coordinator on accepted, unmerged work | merge it, or reopen after a red landing with --note "<test file>: <test name>; merge commit <sha>" |
+| CONFLICT_FILES | the accepted commit no longer merges onto the trunk, and every named file is one that conflicts, only for reopen --conflict by the coordinator on accepted, unmerged work | name only files Git reports as conflicting with the trunk |
+| NO_TRUNK | the accepted commit no longer merges onto the trunk, and every named file is one that conflicts, only for reopen --conflict by the coordinator on accepted, unmerged work | check out the trunk branch in the main checkout once and run pullboard inbox |
+| MERGE_CHECK_FAILED | the accepted commit no longer merges onto the trunk, and every named file is one that conflicts, only for reopen --conflict by the coordinator on accepted, unmerged work | use Git 2.38 or newer, restore its objects and retry |
+| NOT_ACCEPTED | a trunk conflict reopens an accepted item, names its files and the full trunk commit, and replays only under engine 28 or later, only for reopen --conflict | reopen a submission with --note "why" |
+| BAD_CONFLICT | a trunk conflict reopens an accepted item, names its files and the full trunk commit, and replays only under engine 28 or later, only for reopen --conflict | run pullboard reopen <id> --conflict "<files>" from the main checkout |
+| ENGINE_VERSION | a trunk conflict reopens an accepted item, names its files and the full trunk commit, and replays only under engine 28 or later, only for reopen --conflict | upgrade Pullboard on every linked device before using --conflict |
| LAND_HEADER | a displayed merge command fits the commit-header limit (accept result) | shorten the item title or cited rows so the merge header fits |
| ENGINE_VERSION | a verdict that implies items replays only under engine 20 or later (accept result) | upgrade Pullboard on every linked device before using --implies |
| LAND_HEADER | a displayed merge command fits the commit-header limit (reject result) | shorten the item title or cited rows so the merge header fits |
diff --git a/src/api-moves.js b/src/api-moves.js
index c107d3d2..c916f4e0 100644
--- a/src/api-moves.js
+++ b/src/api-moves.js
@@ -17,7 +17,7 @@ const MOVES = {
merged: { item: true, positions: ['commit'] },
withdraw: { item: true, positions: ['reason'] },
refreeze: { item: true },
- reopen: { item: true, flags: ['note'] },
+ reopen: { item: true, flags: ['note', 'conflict'] },
escalate: { item: true, flags: ['note'] },
hold: { positions: ['lane'], flags: ['reason'], booleans: ['off'] },
shout: { positions: ['to', 'text'], optional: ['to'], booleans: ['decision'], flags: ['evidence', 'outcome', 'item', 'commit'] },
diff --git a/src/board.js b/src/board.js
index 004f398a..884c3ba8 100644
--- a/src/board.js
+++ b/src/board.js
@@ -16,6 +16,7 @@ import { COORDINATOR } from './config.js';
import { ENGINE_VERSION, GUARDS, IN_STATE, MOVES, STATES, UNKNOWN_MOVE, effectiveGuards, storeTriggers } from './machine.js';
import { Refused } from './refused.js';
import { barCorrectionFields } from './bar-corrections.js';
+import { conflictNote, conflictProblem } from './trunk-conflict.js';
import { factFromEvent, requestAnswerRefusal, tellAnswerImplications, tellFactImplications, tellVerdictImplications } from './implies.js';
import { parseSpec } from './spec.js';
@@ -1542,9 +1543,10 @@ export function verify(board, id, { agentId, decision, reason, note = '', head,
* @param {{ agentId: string, note: string }} request
* @returns {{ id: number, commit: string, supersedes?: number, landingFailure?: object }}
*/
-export function reopen(board, id, { agentId, note }) {
+export function reopen(board, id, { agentId, note = '', conflict }) {
return atomic(board, () => {
let submittedCommit = null;
+ const forMerge = conflict !== undefined && conflict !== null;
let supersedes;
let landingFailure;
const currentEngine = board.executionEngineVersion ?? ENGINE_VERSION;
@@ -1556,12 +1558,12 @@ export function reopen(board, id, { agentId, note }) {
joined: null,
[IN_STATE]: (found) => new Refused('NOT_SUBMITTED', `item #${id} is ${current(board, found).item_status}, not submitted`),
coordinatorOnly: () => onlyCoordinator(agentId, 'reopens submissions'),
- noteGiven: () => (note.trim() ? null : new Refused('NOTE_REQUIRED', 'say why the criterion needs correction: --note "why"')),
+ noteGiven: () => (forMerge || note.trim() ? null : new Refused('NOTE_REQUIRED', 'say why the criterion needs correction: --note "why"')),
notMerged: (found) => found.item_status !== 'verified' || !found.item_merged_commit
? null
: new Refused('ALREADY_MERGED', `item #${id} was merged as ${found.item_merged_commit}; merged items cannot be reopened`),
landingFailureRecorded: (found) => {
- if (found.item_status !== 'verified') return null;
+ if (found.item_status !== 'verified' || forMerge) return null;
const accepted = events(board, { itemId: id }).findLast((event) => {
if (event.event_kind !== 'accept') return false;
return JSON.parse(event.event_detail).commit === found.item_commit;
@@ -1579,6 +1581,8 @@ export function reopen(board, id, { agentId, note }) {
: { batch: null, tests: manual.tests, mergeCommit: manual.mergeCommit };
return null;
},
+ trunkConflicts: null,
+ conflictAccepted: (found) => (forMerge ? conflictProblem(board, found, conflict, (accept) => { supersedes = accept; }) : null),
},
set: (found) => {
submittedCommit = found.item_commit;
@@ -1592,9 +1596,9 @@ export function reopen(board, id, { agentId, note }) {
};
},
});
- logEvent(board, agentId, 'reopen', id, { commit: submittedCommit, note: note.trim(), judgment: null,
- ...(supersedes ? { supersedes, landingFailure } : {}) });
- return { id: item.item_id, commit: submittedCommit, ...(supersedes ? { supersedes, landingFailure } : {}) };
+ const returned = forMerge ? { supersedes, conflict: { files: conflict.files, trunk: conflict.trunk } } : supersedes ? { supersedes, landingFailure } : {};
+ logEvent(board, agentId, 'reopen', id, { commit: submittedCommit, note: note.trim() || conflictNote(conflict), judgment: null, ...returned });
+ return { id: item.item_id, commit: submittedCommit, ...returned };
});
}
diff --git a/src/cli.js b/src/cli.js
index ccf54309..57f353e1 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -36,6 +36,7 @@ import { askedLaneNotes, detectGate, initRepo, proposeLanes, starterLane, starte
import { lifecycleMarkdown } from './machine.js';
import { HELP, VERSION } from './help.js';
import { barCorrectionLine, barCorrections, barStatsLines } from './bar-corrections.js';
+import { MAIN_MERGE_LABEL, mainMergeFor, mainMergeLines, reopenConflict } from './trunk-conflict.js';
import { checkImplies, decisionsImplying, parseImplies, takeDecisionNotices, whyLine } from './implies.js';
import { defaultViewPort } from './view-port.js';
export { HELP, VERSION };
@@ -82,7 +83,7 @@ import { serveApi } from './api.js';
import { serveMcp } from './mcp.js';
import { doctorProblems, doctrineProblems } from './doctor.js';
import { staleFrozenItems, staleItemFinding } from './approved-rows.js';
-import { mainPolicy, policyAt, itemPolicy, submissionPaths, frozenCheck, checkAtCommit, dependencySnapshots, requireTrunkMerge, trunkRef } from './trusted-policy.js';
+import { mainPolicy, policyAt, itemPolicy, submissionPaths, frozenCheck, checkAtCommit, dependencySnapshots, requireTrunkMerge, trunkMerge, trunkRef } from './trusted-policy.js';
import { proofStats } from './stats.js';
import { flowLines, flowAlertLine } from './stats-flow.js';
import { releaseHeadlinesBetween } from './changelog.js';
@@ -304,6 +305,7 @@ const OPTIONS = {
commit: { type: 'string' },
ref: { type: 'string' },
supersedes: { type: 'string' },
+ conflict: { type: 'string' },
implies: { type: 'string' },
owns: { type: 'string' },
help: { type: 'boolean', short: 'h' },
@@ -845,13 +847,13 @@ function firstLineOf(note) {
* @param {any} item
* @returns {string}
*/
-function itemLine(item, name = (id) => id) {
+function itemLine(item, name = (id) => id, mainMerge = false) {
const holder = item.item_status === 'claimed' ? ` ${name(item.item_owner)}` : '';
const verifier = item.item_status === 'verified' ? ` by ${name(item.item_verified_by)}` : '';
const specs = item.item_spec_ids ? ` [${item.item_spec_ids}]` : '';
const parent = item.item_parent_id ? ` under #${item.item_parent_id}` : '';
const after = item.item_after ? ` after ${item.item_after.split(',').map((id) => `#${id}`).join(',')}` : '';
- const rejected = item.item_status === 'open' && item.item_verdict === 'REJECT' ? ' (rejected)' : '';
+ const rejected = item.item_status === 'open' && item.item_verdict === 'REJECT' ? ' (rejected)' : mainMerge ? ` (${MAIN_MERGE_LABEL})` : '';
const light = item.item_route === 'strong' ? '' : ` ${item.item_route}`;
const hold = item.item_hold_reason ? ` held by ${name(item.item_hold_by)}: ${item.item_hold_reason}` : '';
return `#${item.item_id} ${item.item_status}${holder}${verifier}${rejected} ${item.item_lane} ${item.item_title}${specs}${parent}${after}${light}${hold}`;
@@ -1303,6 +1305,8 @@ function resumeHere(io) {
sentBack: all
.filter((item) => item.item_status === 'open' && item.item_verdict === 'REJECT' && item.item_built_by === me.id)
.map((item) => ({ item, verdict: store.verdictsFor(board, item.item_id).at(-1) })),
+ mainMerges: all.filter((item) => item.item_status === 'open' && item.item_built_by === me.id)
+ .map((item) => ({ item, merge: mainMergeFor(board, item.item_id) })).filter(({ merge }) => merge),
awaiting: all.filter((item) => item.item_status === 'submitted' && item.item_built_by === me.id),
toVerify: all.filter((item) => item.item_status === 'submitted' && item.item_built_by !== me.id),
toMerge,
@@ -1379,6 +1383,7 @@ function resumeHere(io) {
for (const { item, verdict } of card.sentBack) {
say(`sent back: #${item.item_id} ${verdict ? `${verdict.verdict_reason} by ${name(verdict.verdict_by)}: ${firstLine(verdict.verdict_note)}` : 'rejected'}`);
}
+ for (const { item, merge } of card.mainMerges) say(mainMergeLines(item, merge, name).join('; '));
if (isMain && card.staleFollowUps.count) say(`${plural(card.staleFollowUps.count, 'stale follow-up')}; list them with ${card.staleFollowUps.list}`);
else if (!isMain) for (const item of card.stale) say(`stale: ${item.message}; next: ${item.next}`);
if (card.awaiting.length) say(`awaiting a verdict: ${card.awaiting.map((item) => `#${item.item_id} (${span(ctx, item.item_updated_at)})`).join(', ')}`);
@@ -1420,6 +1425,7 @@ function resumeHere(io) {
if (isMain) next = coordinatorNext(card, loadSpec(root, ctx.config).rows);
else if (card.holding.length) next = buildNext(card);
else if (card.sentBack.length) next = reworkNext(card);
+ else if (card.mainMerges.length) next = `pullboard claim ${card.mainMerges[0].item.item_id}, merge main, resolve the conflicts, commit and submit again`;
else if (card.hold) next = 'wait for the hold to lift: pullboard next --wait 9 (minutes)';
else if (ready) next = `pullboard next (${ready} ready in your lane)`;
else if (inLane.length) next = `pullboard next --wait 9 (minutes); ${inLane.length} in your lane ${inLane.length === 1 ? 'waits' : 'wait'} on other work`;
@@ -2015,14 +2021,15 @@ function readCommands(io, { first, second, rest, values }) {
},
list: () => {
const ctx = context(io);
- const { items, agents } = withBoard(ctx, (board) => ({
+ const { items, agents, merging } = withBoard(ctx, (board) => ({
items: store.listItems(board, { lane: first, all: values.all }),
agents: store.listAgents(board),
+ merging: new Set(store.listItems(board, { lane: first }).filter((item) => mainMergeFor(board, item.item_id)).map((item) => item.item_id)),
}));
const filtered = items.filter((item) => !values.route || item.item_route === values.route);
if (values.json) io.result({ items: filtered });
else if (!filtered.length) io.say(values.all ? 'no items yet' : 'nothing open; --all shows closed items');
- else filtered.forEach((item) => io.say(itemLine(item, (id) => agentDisplayName(agents, ctx.config, id))));
+ else filtered.forEach((item) => io.say(itemLine(item, (id) => agentDisplayName(agents, ctx.config, id), merging.has(item.item_id))));
return 0;
},
roadmap: () => {
@@ -2054,7 +2061,7 @@ function readCommands(io, { first, second, rest, values }) {
show: () => {
const ctx = context(io);
const id = idArg(first);
- const { item, verdicts, moves, thread, related, reviewer, agents } = withBoard(ctx, (board) => ({
+ const { item, verdicts, moves, thread, related, reviewer, agents, mainMerge } = withBoard(ctx, (board) => ({
item: store.getItem(board, id),
verdicts: store.verdictsFor(board, id),
moves: store.events(board, { itemId: id }).filter((event) => ['attempt', 'escalate'].includes(event.event_kind)),
@@ -2062,13 +2069,14 @@ function readCommands(io, { first, second, rest, values }) {
related: store.relatedItems(board, store.getItem(board, id)),
reviewer: store.reviewHolder(board, store.getItem(board, id)),
agents: store.listAgents(board),
+ mainMerge: mainMergeFor(board, id),
}));
const agentName = (id) => displayAgentName(agents.find((agent) => agent.agent_id === id) ?? { agent_id: id }, ctx.config.agents.names);
if (values.json) {
io.result({ ...item, verdicts, thread });
return 0;
}
- io.say(itemLine(item, agentName));
+ io.say(itemLine(item, agentName, Boolean(mainMerge)));
if (item.item_criterion) io.say(`criterion: ${item.item_criterion}`);
if (item.item_check) io.say(`check: ${item.item_check}`);
sayCheckBaseline(io, item);
@@ -2099,6 +2107,7 @@ function readCommands(io, { first, second, rest, values }) {
});
if (notes.some((note, index) => note !== verdicts[index].verdict_note)) io.say(`(earlier verdicts shortened; every note in full: pullboard show ${id} --history)`);
for (const correction of barCorrections(thread)) io.say(barCorrectionLine(correction));
+ for (const line of mainMerge ? mainMergeLines(item, mainMerge, agentName) : []) io.say(line);
if (item.item_merged_commit) io.say(`merged as ${item.item_merged_commit}`);
if (item.item_withdrawn_reason) io.say(`withdrawn: ${item.item_withdrawn_reason}`);
io.say('thread:');
@@ -3173,11 +3182,14 @@ function workCommands(io, args) {
return 0;
}),
reopen: () => act(async (ctx, board, me) => {
- const result = await ordered(ctx, board, 'reopen', [idArg(first), { agentId: me.id, note: textArg(io, values, 'note') ?? '' }]);
+ const conflict = values.conflict === undefined ? undefined : reopenConflict({ item: store.getItem(board, idArg(first)), coordinator: me.id === COORDINATOR, text: values.conflict, trunkMerge: (commit) => trunkMerge(ctx.info.root, commit) });
+ const result = await ordered(ctx, board, 'reopen', [idArg(first), { agentId: me.id, note: textArg(io, values, 'note') ?? '', ...(conflict ? { conflict } : {}) }]);
io.result?.(result);
- io.say(result.landingFailure
- ? `reopened #${first} after landing failure; previous accept remains recorded at ${result.commit.slice(0, 12)}`
- : `reopened #${first} without a verdict; previous commit ${result.commit.slice(0, 12)} remains recorded`);
+ io.say(result.conflict
+ ? `reopened #${first} for a main merge: conflicts with the trunk at ${result.conflict.trunk.slice(0, 12)} in ${result.conflict.files.join(', ')}; the accept at ${result.commit.slice(0, 12)} stays recorded`
+ : result.landingFailure
+ ? `reopened #${first} after landing failure; previous accept remains recorded at ${result.commit.slice(0, 12)}`
+ : `reopened #${first} without a verdict; previous commit ${result.commit.slice(0, 12)} remains recorded`);
return 0;
}),
shout: () => act(async (ctx, board, me) => {
diff --git a/src/engine.js b/src/engine.js
index 8be6dc97..4b42551c 100644
--- a/src/engine.js
+++ b/src/engine.js
@@ -4,6 +4,7 @@ import * as store from './board.js';
import { recordedRefusal } from './recorded-refusal.js';
import { BAR_ENGINE, carriesBarReason } from './bar-corrections.js';
import { carriesImplies, IMPLIES_ENGINE } from './implies.js';
+import { carriesConflict, CONFLICT_ENGINE } from './trunk-conflict.js';
import { ENGINE_VERSION } from './machine.js';
import { Refused } from './refused.js';
import { requestMoveProblem, recordRequestMove } from './relay-requests.js';
@@ -24,9 +25,10 @@ export const ENGINE_OPERATIONS = Object.freeze([
/** Engine version at which each ordered operation first has stable replay semantics. */
const OPERATION_ENGINE = Object.freeze({ reopen: 8, recordLandingBatch: 8, recordLandingWaiver: 8, recordLandingFlake: 8, finishLandingBatch: 8 });
-/** Dependency edits add engine-10 meaning, edit reasons engine-19 and implied items engine-20, without changing ordinary historical envelopes. */
+/** Dependency edits add engine-10 meaning, edit reasons engine-19, implied items engine-20 and trunk conflicts engine-28, without changing ordinary historical envelopes. */
function minimumOperationEngine(operation, args) {
const options = args[1];
+ if (carriesConflict(operation, args)) return CONFLICT_ENGINE;
if (carriesImplies(operation, args)) return IMPLIES_ENGINE;
if (carriesBarReason(operation, args)) return BAR_ENGINE;
return operation === 'editItem' && options && Object.hasOwn(options, 'after') && options.after !== undefined
diff --git a/src/help.js b/src/help.js
index f04bad16..181ee598 100644
--- a/src/help.js
+++ b/src/help.js
@@ -122,6 +122,7 @@ Coordinator
pullboard withdraw <id> <reason> drop an item nobody should build
pullboard refreeze <id> adopt a corrected criterion or changed spec rows
pullboard reopen <id> --note "why" return a submission for criterion correction without a verdict
+ pullboard reopen <id> --conflict "<files>" return accepted work that conflicts with the trunk for a main merge
pullboard hold <lane> --reason "..." pause a lane: next there claims nothing and names the reason
pullboard hold <id> "reason" hold one item so next skips it
pullboard hold <lane|id> --off lift a lane or item hold
@@ -273,6 +274,7 @@ const HELP_FLAG_EXPLANATIONS = {
'--blueprint': 'start from a bundled blueprint or a JSON file',
'--brief': 'what a cold agent needs',
'--check': 'the command that proves it',
+ '--conflict': 'the files that conflict with the trunk; the accept stays recorded',
'--family': 'records the family name',
'--model': 'identifies the agent model; required unless PULLBOARD_MODEL is set',
'--implies': 'each named item gets a fact citing this decision',
diff --git a/src/machine.js b/src/machine.js
index 227bc125..beb187dd 100644
--- a/src/machine.js
+++ b/src/machine.js
@@ -10,7 +10,7 @@
*/
/** Executable move semantics, carried by every sealed move and retained during replay [H16]. */
-export const ENGINE_VERSION = 20;
+export const ENGINE_VERSION = 28;
/** @typedef {'agent' | 'coordinator' | 'clock'} Role */
@@ -140,7 +140,9 @@ export const GUARDS = [
{ id: 'reviewCooldownElapsed', refuse: 'REVIEW_COOLDOWN', rule: 'the reviewer has not released this submission within the past hour', next: 'let another reviewer take it, or wait an hour or for a new submission', source: 'board', when: 'engine 5 or newer, only for the same reviewer and current submission' },
{ id: 'noteGiven', refuse: 'NOTE_REQUIRED', rule: 'the move carries a note: what failed, what was tried, or why', next: '--note "..." or --note-file <file>', source: 'board' },
{ id: 'notMerged', refuse: 'ALREADY_MERGED', rule: 'the item has no recorded merge receipt', next: 'a merged item cannot be reopened', source: 'board' },
- { id: 'landingFailureRecorded', refuse: 'LANDING_FAILURE_REQUIRED', rule: 'a verified item note names the failing test and landing merge commit', next: 'cite the recorded batch, or name the test and merge commit in a manual note', source: 'board' },
+ { id: 'landingFailureRecorded', refuse: 'LANDING_FAILURE_REQUIRED', rule: 'a verified item note names the failing test and landing merge commit', next: 'cite the recorded batch, or name the test and merge commit in a manual note; work that only conflicts with the trunk reopens with --conflict "<files>"', source: 'board', when: 'unless the reopen names a trunk conflict' },
+ { id: 'trunkConflicts', refuse: 'NOT_CONFLICTING', alsoRefuses: [{ code: 'CONFLICT_FILES', next: 'name only files Git reports as conflicting with the trunk' }, { code: 'NO_TRUNK', next: 'check out the trunk branch in the main checkout once and run pullboard inbox' }, { code: 'MERGE_CHECK_FAILED', next: 'use Git 2.38 or newer, restore its objects and retry' }], rule: 'the accepted commit no longer merges onto the trunk, and every named file is one that conflicts', next: 'merge it, or reopen after a red landing with --note "<test file>: <test name>; merge commit <sha>"', source: 'cli', when: 'only for reopen --conflict by the coordinator on accepted, unmerged work' },
+ { id: 'conflictAccepted', refuse: 'NOT_ACCEPTED', alsoRefuses: [{ code: 'BAD_CONFLICT', next: 'run pullboard reopen <id> --conflict "<files>" from the main checkout' }, { code: 'ENGINE_VERSION', next: 'upgrade Pullboard on every linked device before using --conflict' }], rule: 'a trunk conflict reopens an accepted item, names its files and the full trunk commit, and replays only under engine 28 or later', next: 'reopen a submission with --note "why"', source: 'board', when: 'only for reopen --conflict' },
];
/** @type {Move[]} */
@@ -179,9 +181,9 @@ export const MOVES = [
},
{
verb: 'reopen', from: ['submitted', 'verified'], to: 'open', by: ['coordinator'], refuse: 'NOT_SUBMITTED',
- guards: ['joined', 'itemExists', IN_STATE, 'coordinatorOnly', 'noteGiven', 'notMerged', 'landingFailureRecorded'],
+ guards: ['joined', 'itemExists', IN_STATE, 'coordinatorOnly', 'noteGiven', 'notMerged', 'landingFailureRecorded', 'trunkConflicts', 'conflictAccepted'],
sets: ['item_verdict', 'item_verified_by', 'item_owner', 'item_lease_until', 'item_review_by', 'item_review_until'],
- command: 'pullboard reopen <id> --note "why"',
+ command: 'pullboard reopen <id> --note "why" | --conflict "<files>"',
},
{
verb: 'escalate', from: ['open', 'claimed'], to: 'open', by: ['agent', 'coordinator'], refuse: 'CLOSED',
diff --git a/src/next-steps.js b/src/next-steps.js
index 83fd45c4..cfc40587 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -141,7 +141,11 @@ export const NEXT_STEPS = Object.freeze({
ITEM_HELD: 'take another item with pullboard next while the coordinator holds this one',
ITEM_NOT_AVAILABLE: 'read the item from this API\'s board state',
ITEM_NOT_OPEN: 'hold only open or claimed items; see pullboard list',
- LANDING_FAILURE_REQUIRED: 'reopen with --note "<test file>: <test name>; merge commit <sha>"',
+ LANDING_FAILURE_REQUIRED: 'reopen with --note "<test file>: <test name>; merge commit <sha>", or with --conflict "<files>" when it only conflicts with the trunk',
+ NOT_CONFLICTING: 'merge it; reopen only after a red landing, with --note "<test file>: <test name>; merge commit <sha>"',
+ CONFLICT_FILES: 'name only the files Git reports as conflicting with the trunk: pullboard reopen <id> --conflict "<files>"',
+ NOT_ACCEPTED: 'reopen a submission with --note "why"; --conflict is for accepted work',
+ BAD_CONFLICT: 'run pullboard reopen <id> --conflict "<files>" from the main checkout',
LANE_TAKEN: 'choose a different lane name with pullboard lane add',
LAND_ADOPT: 'read pullboard resume, then run pullboard land --adopt, or pullboard land when nothing is unfinished',
LAND_BATCH: 'adopt the recorded batch: pullboard land --adopt',
diff --git a/src/trunk-conflict.js b/src/trunk-conflict.js
new file mode 100644
index 00000000..ad5b23cc
--- /dev/null
+++ b/src/trunk-conflict.js
@@ -0,0 +1,137 @@
+/**
+ * An accepted item that conflicts with the trunk reopens for a main merge [B3,D1].
+ *
+ * When two accepted items touch the same lines, the second no longer merges onto the trunk. That
+ * is not a failed test and not a reject: the work was accepted and only needs main merged into
+ * it. `pullboard reopen <id> --conflict "<files>"` records exactly that, naming the conflicting
+ * files and the trunk commit they conflict with, and keeps the original accept on record. The
+ * builder claims it with its bar unchanged, merges main and resubmits; the re-review checks the
+ * frozen check at the new head and nothing else.
+ */
+import { ENGINE_VERSION } from './machine.js';
+import { Refused } from './refused.js';
+
+/** The engine whose reopen may carry a trunk conflict; older engines refuse it before replay. */
+export const CONFLICT_ENGINE = 28;
+
+/** The label an item carries from a conflict reopen until its next verdict. */
+export const MAIN_MERGE_LABEL = 'needs main merge';
+
+/**
+ * True when a sealed move carries this engine's meaning, a trunk conflict on a reopen.
+ *
+ * @param {string} operation
+ * @param {any[]} args
+ * @returns {boolean}
+ */
+export function carriesConflict(operation, args) {
+ return operation === 'reopen' && args?.[1]?.conflict !== undefined && args?.[1]?.conflict !== null;
+}
+
+/**
+ * The file paths named by a `--conflict` value, split on commas and white space, without repeats.
+ *
+ * @param {string} text
+ * @returns {string[]}
+ */
+export function conflictFiles(text) {
+ return [...new Set(String(text ?? '').split(/[\s,]+/u).filter(Boolean))];
+}
+
+/**
+ * Check the trunk for the conflict the coordinator names, so --conflict cannot stand in for a
+ * landing failure note on work that merges cleanly. Every named file must be one Git reports as
+ * conflicting; the trunk commit comes from Git, never from the caller.
+ *
+ * @param {(commit: string) => { ref: string, commit: string, files: string[] | null }} trunkMerge - merges onto the trunk in memory
+ * @param {string} commit - the accepted commit
+ * @param {string[]} files - the files the coordinator names
+ * @returns {{ files: string[], trunk: string }}
+ */
+export function requireTrunkConflict(trunkMerge, commit, files) {
+ if (!files.length) throw new Refused('CONFLICT_FILES', 'name the files that conflict: pullboard reopen <id> --conflict "<file>, <file>"');
+ const merge = trunkMerge(commit);
+ const branch = merge.ref.replace(/^refs\/heads\//u, '');
+ if (!merge.files) throw new Refused('NOT_CONFLICTING', `${commit.slice(0, 12)} merges cleanly onto ${branch} at ${merge.commit.slice(0, 12)}; merge it, or reopen with --note "<test file>: <test name>; merge commit <sha>" after a red landing`);
+ const unknown = files.filter((file) => !merge.files.includes(file));
+ if (unknown.length) throw new Refused('CONFLICT_FILES', `${unknown.join(', ')} ${unknown.length === 1 ? 'does' : 'do'} not conflict with ${branch} at ${merge.commit.slice(0, 12)}; the conflicting files are ${merge.files.join(', ') || 'unnamed'}`);
+ return { files, trunk: merge.commit };
+}
+
+/**
+ * The conflict a coordinator's `--conflict` names, with the trunk commit Git reports. Anyone else,
+ * or an item that is not accepted and unmerged, gets the files alone, so the board's own guards
+ * refuse it in their declared order (COORDINATOR_ONLY, NOT_SUBMITTED, ALREADY_MERGED, NOT_ACCEPTED).
+ *
+ * @param {{ item: any, coordinator: boolean, text: string, trunkMerge: (commit: string) => { ref: string, commit: string, files: string[] | null } }} request
+ * @returns {{ files: string[], trunk: string | null }}
+ */
+export function reopenConflict({ item, coordinator, text, trunkMerge }) {
+ const files = conflictFiles(text);
+ if (!coordinator || item.item_status !== 'verified' || item.item_merged_commit || !item.item_commit) return { files, trunk: null };
+ return requireTrunkConflict(trunkMerge, item.item_commit, files);
+}
+
+/**
+ * The refusal for a conflict reopen the board cannot record, or null. A conflict reopens only an
+ * accepted item, and only under this engine; it names its files and a full trunk commit.
+ *
+ * @param {any} board
+ * @param {any} item
+ * @param {unknown} conflict
+ * @param {(accept: number) => void} found - receives the id of the accept the reopen sets aside
+ * @returns {Refused | null}
+ */
+export function conflictProblem(board, item, conflict, found) {
+ const engine = board.executionEngineVersion ?? ENGINE_VERSION;
+ if (engine < CONFLICT_ENGINE) return new Refused('ENGINE_VERSION', `a reopen for a main merge requires engine ${CONFLICT_ENGINE}; this board uses engine ${engine}; upgrade Pullboard before using --conflict`);
+ if (item.item_status !== 'verified') return new Refused('NOT_ACCEPTED', `item #${item.item_id} is ${item.item_status}; --conflict reopens accepted work for a main merge, and a submission reopens with --note "why"`);
+ const shape = /** @type {any} */ (conflict);
+ const files = Array.isArray(shape?.files) ? shape.files : [];
+ if (!files.length || files.some((file) => typeof file !== 'string' || !file.trim() || /[\r\n]/u.test(file)) || new Set(files).size !== files.length
+ || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(shape?.trunk ?? '')) {
+ return new Refused('BAD_CONFLICT', 'a trunk conflict names its files and the full trunk commit; run pullboard reopen <id> --conflict "<files>" from the main checkout');
+ }
+ const accept = board.db.prepare("SELECT event_id FROM event WHERE item_id = ? AND event_kind = 'accept' AND json_extract(event_detail, '$.commit') = ? ORDER BY event_id DESC LIMIT 1").get(item.item_id, item.item_commit);
+ if (!accept) return new Refused('NOT_ACCEPTED', `item #${item.item_id} has no accept at ${String(item.item_commit).slice(0, 12)}; --conflict reopens accepted work for a main merge`);
+ found(accept.event_id);
+ return null;
+}
+
+/** The note a conflict reopen records when the coordinator gives none. */
+export function conflictNote({ files, trunk }) {
+ return `conflicts with the trunk at ${trunk.slice(0, 12)} in ${files.join(', ')}; merge main and resubmit`;
+}
+
+/**
+ * The trunk conflict an item still carries, or null: the newest reopen, accept or reject on it is
+ * a conflict reopen. It names the accept it set aside, so the re-review knows what already passed.
+ *
+ * @param {any} board
+ * @param {number} id
+ * @returns {{ files: string[], trunk: string, commit: string, at: string, accept: { by: string, commit: string } | null } | null}
+ */
+export function mainMergeFor(board, id) {
+ const last = board.db.prepare("SELECT event_detail, event_at FROM event WHERE item_id = ? AND event_kind IN ('reopen', 'accept', 'reject') ORDER BY event_id DESC LIMIT 1").get(id);
+ const detail = last ? JSON.parse(last.event_detail) : null;
+ if (!detail?.conflict) return null;
+ const accept = board.db.prepare('SELECT event_by, event_detail FROM event WHERE event_id = ?').get(detail.supersedes);
+ return { ...detail.conflict, commit: detail.commit, at: last.event_at,
+ accept: accept ? { by: accept.event_by, commit: JSON.parse(accept.event_detail).commit } : null };
+}
+
+/**
+ * The lines `pullboard show` prints for an item that needs a main merge: what conflicts, then
+ * what to do now, for the builder before resubmitting and for the reviewer after.
+ *
+ * @param {any} item
+ * @param {NonNullable<ReturnType<typeof mainMergeFor>>} merge
+ * @param {(id: string) => string} [name]
+ * @returns {string[]}
+ */
+export function mainMergeLines(item, merge, name = (id) => id) {
+ const accepted = merge.accept ? `accepted by ${name(merge.accept.by)} at ${merge.accept.commit.slice(0, 12)}` : 'accepted';
+ const head = `${MAIN_MERGE_LABEL}: ${accepted}; conflicts with the trunk at ${merge.trunk.slice(0, 12)} in ${merge.files.join(', ')}`;
+ if (item.item_status === 'submitted') return [head, `re-review: main merge only; run the frozen check at ${item.item_commit.slice(0, 12)}; the accept above stands for the rest`];
+ return [head, `next: pullboard claim ${item.item_id} (the bar is unchanged), merge main, resolve ${merge.files.join(', ')}, commit, pullboard submit ${item.item_id}`];
+}
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index 26ac9d9b..79dae999 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -55,6 +55,20 @@ export function trunkRef(root, branch) {
* @returns {{ ref: string, commit: string }}
*/
export function requireTrunkMerge(root, commit, retainedRef = trunkRef(root)) {
+ const { files, ...trunk } = trunkMerge(root, commit, retainedRef);
+ if (!files) return trunk;
+ const branch = trunk.ref.replace(/^refs\/heads\//, '');
+ throw new Refused('MERGE_CONFLICT', `the candidate conflicts with the current trunk ${branch} in ${files.map(path => JSON.stringify(path)).join(', ') || 'unresolved files'}; merge the trunk into your branch, resolve these files, commit and resubmit`);
+}
+
+/** Merge a commit onto the trunk tip in memory: the ref, the tip, and the conflicting files or null [B34,V6].
+ *
+ * @param {string} root
+ * @param {string} commit
+ * @param {string} [retainedRef]
+ * @returns {{ ref: string, commit: string, files: string[] | null }}
+ */
+export function trunkMerge(root, commit, retainedRef = trunkRef(root)) {
const checkout = mainCheckout(root);
const branchRef = checkout?.branch ?? retainedRef;
if (!branchRef?.startsWith('refs/heads/')) throw new Refused('NO_TRUNK', 'no trunk branch was recorded; check out the trunk branch in the main checkout once and run pullboard inbox');
@@ -63,13 +77,11 @@ export function requireTrunkMerge(root, commit, retainedRef = trunkRef(root)) {
const result = spawnSync('git', ['--no-replace-objects', '-c', 'core.quotepath=false', 'merge-tree', '--write-tree', '--name-only', '-z', tip.stdout.trim(), commit], {
cwd: root, env: cleanGitEnvironment(), encoding: 'utf8', maxBuffer: 32 * 1024 * 1024,
});
- if (result.status === 0) return { ref: branchRef, commit: tip.stdout.trim() };
+ if (result.status === 0) return { ref: branchRef, commit: tip.stdout.trim(), files: null };
if (result.status !== 1) throw new Refused('MERGE_CHECK_FAILED', 'Git could not check the candidate against the trunk; use Git 2.38 or newer, restore its objects and retry');
const records = result.stdout.split('\0').slice(1);
const end = records.indexOf('');
- const files = records.slice(0, end < 0 ? records.length : end).map(path => JSON.stringify(path));
- const branch = branchRef.replace(/^refs\/heads\//, '');
- throw new Refused('MERGE_CONFLICT', `the candidate conflicts with the current trunk ${branch} in ${files.join(', ') || 'unresolved files'}; merge the trunk into your branch, resolve these files, commit and resubmit`);
+ return { ref: branchRef, commit: tip.stdout.trim(), files: records.slice(0, end < 0 ? records.length : end) };
}
/** Re-read coordinator settings from a pinned Git object; never from the candidate filesystem. */
diff --git a/test/reopen-conflict.test.js b/test/reopen-conflict.test.js
new file mode 100644
index 00000000..aca3d43f
--- /dev/null
+++ b/test/reopen-conflict.test.js
@@ -0,0 +1,159 @@
+/** Real Git and SQLite coverage for an accepted item that conflicts with the trunk [B3,D1]. */
+import assert from 'node:assert/strict';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { after, test } from 'node:test';
+import * as store from '../src/board.js';
+import { applyRelayMove, prepareEngineMove } from '../src/engine.js';
+import { exportBoard, importBoard } from '../src/exchange.js';
+import { ENGINE_VERSION } from '../src/machine.js';
+import { CONFLICT_ENGINE } from '../src/trunk-conflict.js';
+import { createE2eHelpers } from './e2e-helpers.js';
+
+const e2e = createE2eHelpers();
+after(e2e.cleanup);
+const { project, commitFile } = e2e;
+
+/** Read an item, its thread and its verdicts through a short-lived board connection. */
+function readItem(box, id) {
+ const board = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));
+ try { return { ...store.getItem(board, id), thread: store.itemThread(board, id), verdicts: store.verdictsFor(board, id) }; }
+ finally { store.closeBoard(board); }
+}
+
+/** Return the refusal code of a JSON run, failing with its output when it did not refuse. */
+function refusal(result) {
+ assert.equal(result.code, 1, [result.out, result.err].join('\n'));
+ return JSON.parse(result.out).error.code;
+}
+
+/** Add, claim, build and submit one web item from the joined builder worktree. */
+function submitItem(box, title, contents) {
+ const added = box.run(box.repo, 'add', 'web', title, '--specs', 'G1', '--criterion', `${title} stays valid`, '--check', 'node --check web/feature.js', '--json');
+ assert.equal(added.code, 0, added.err);
+ const id = JSON.parse(added.out).item.item_id;
+ assert.equal(box.run(box.web, 'claim', String(id)).code, 0);
+ const committed = commitFile(box, box.web, 'web/feature.js', contents, `feat(web): ${title.toLowerCase()} [G1]`);
+ assert.equal(committed.status, 0, committed.stderr);
+ const submitted = box.run(box.web, 'submit', String(id));
+ assert.equal(submitted.code, 0, submitted.err);
+ return { id, commit: box.git(box.web, 'rev-parse', 'HEAD') };
+}
+
+/** Accept an item as the coordinator at its submitted commit, then return the main checkout to main. */
+function accept(box, id, commit) {
+ box.git(box.repo, 'switch', '-q', '--detach', commit);
+ try {
+ const result = box.run(box.repo, 'verify', String(id), 'accept', '--as', 'coordinator', '--note', 'ran the frozen check at the submitted commit');
+ assert.equal(result.code, 0, result.err);
+ } finally { box.git(box.repo, 'switch', '-q', 'main'); }
+}
+
+/** Move the trunk under an accepted item: main changes the same line of web/feature.js. */
+function moveTrunk(box) {
+ const committed = commitFile(box, box.repo, 'web/feature.js', 'export const status = "TRUNK";\n', 'feat(web): trunk changes the status [G1]');
+ assert.equal(committed.status, 0, committed.stderr);
+ return box.git(box.repo, 'rev-parse', 'HEAD');
+}
+
+test('a conflicting accepted item reopens for a main merge [B3,D1]', () => {
+ const box = project();
+ const clean = submitItem(box, 'Clean item', 'export const status = "CLEAN";\n');
+ accept(box, clean.id, clean.commit);
+ const cleanReopen = box.run(box.repo, 'reopen', String(clean.id), '--conflict', 'web/feature.js', '--json');
+ assert.equal(refusal(cleanReopen), 'NOT_CONFLICTING', 'accepted work that merges cleanly cannot be reopened as a conflict');
+ assert.match(JSON.parse(cleanReopen.out).error.next, /merge it/u);
+ assert.equal(readItem(box, clean.id).item_status, 'verified');
+ assert.equal(box.tryGit(box.repo, 'merge', '-q', '--no-edit', clean.commit).status, 0);
+ assert.equal(box.run(box.repo, 'merged', String(clean.id), box.git(box.repo, 'rev-parse', 'HEAD')).code, 0);
+
+ const item = submitItem(box, 'Conflicting item', 'export const status = "ITEM";\n');
+ const submittedConflict = box.run(box.repo, 'reopen', String(item.id), '--conflict', 'web/feature.js', '--json');
+ assert.equal(refusal(submittedConflict), 'NOT_ACCEPTED', 'a submission is not accepted work; it reopens with --note');
+ accept(box, item.id, item.commit);
+ const frozen = readItem(box, item.id).item_frozen_digest;
+ const trunk = moveTrunk(box);
+
+ assert.equal(refusal(box.run(box.web, 'reopen', String(item.id), '--conflict', 'web/feature.js', '--json')), 'COORDINATOR_ONLY', 'an agent cannot reopen');
+ assert.equal(refusal(box.run(box.repo, 'reopen', String(item.id), '--json')), 'NOTE_REQUIRED');
+ assert.equal(refusal(box.run(box.repo, 'reopen', String(item.id), '--note', 'conflicts with main', '--json')), 'LANDING_FAILURE_REQUIRED',
+ 'a verified item without --conflict or a landing failure note is still refused');
+ const wrongFile = box.run(box.repo, 'reopen', String(item.id), '--conflict', 'web/feature.js, web/other.js', '--json');
+ assert.equal(refusal(wrongFile), 'CONFLICT_FILES', 'every named file must be one Git reports as conflicting');
+ assert.match(JSON.parse(wrongFile.out).error.message, /web\/other\.js does not conflict/u);
+ assert.equal(refusal(box.run(box.repo, 'reopen', String(item.id), '--conflict', ' , ', '--json')), 'CONFLICT_FILES');
+ assert.equal(readItem(box, item.id).item_status, 'verified', 'no refusal changed the item');
+
+ const reopened = box.run(box.repo, 'reopen', String(item.id), '--conflict', 'web/feature.js', '--json');
+ assert.equal(reopened.code, 0, [reopened.out, reopened.err].join('\n'));
+ const receipt = JSON.parse(reopened.out);
+ assert.deepEqual(receipt.conflict, { files: ['web/feature.js'], trunk }, 'the receipt names the conflicting files and the trunk commit');
+ assert.equal(receipt.landingFailure, undefined, 'a trunk conflict is never a landing test failure');
+ const returned = readItem(box, item.id);
+ assert.equal(returned.item_status, 'open');
+ assert.equal(returned.item_commit, item.commit, 'the accepted commit stays recorded');
+ const acceptEvent = returned.thread.findLast((entry) => entry.type === 'move' && entry.kind === 'accept');
+ const reopenEvent = returned.thread.findLast((entry) => entry.type === 'move' && entry.kind === 'reopen');
+ assert.equal(reopenEvent.detail.supersedes, acceptEvent.eventId, 'the reopen names the accept it sets aside');
+ assert.deepEqual(reopenEvent.detail.conflict, { files: ['web/feature.js'], trunk });
+ assert.equal(reopenEvent.detail.landingFailure, undefined);
+ assert.match(reopenEvent.detail.note, /conflicts with the trunk at [a-f0-9]{12} in web\/feature\.js/u);
+ assert.deepEqual(returned.verdicts.map((verdict) => verdict.verdict_decision), ['ACCEPT'], 'no reject is recorded; the accept stands');
+
+ const shown = box.run(box.repo, 'show', String(item.id));
+ assert.match(shown.out, new RegExp(`^#${item.id} open \\(needs main merge\\) web`, 'mu'), 'the item reads as needing a main merge, not rejected');
+ assert.doesNotMatch(shown.out, /\(rejected\)/u);
+ assert.match(shown.out, new RegExp(`needs main merge: accepted by coordinator \\(unknown\\) at ${item.commit.slice(0, 12)}; conflicts with the trunk at ${trunk.slice(0, 12)} in web/feature\\.js`, 'u'));
+ assert.match(shown.out, new RegExp(`next: pullboard claim ${item.id} \\(the bar is unchanged\\), merge main`, 'u'));
+ assert.match(box.run(box.repo, 'list', 'web').out, new RegExp(`#${item.id} open \\(needs main merge\\)`, 'u'));
+ const resume = box.run(box.web, 'resume', '--json');
+ assert.equal(resume.code, 0, resume.err);
+ assert.deepEqual(JSON.parse(resume.out).mainMerges.map((entry) => entry.item.item_id), [item.id], 'the builder sees its item needs a main merge');
+ assert.match(box.run(box.web, 'resume').out, new RegExp(`needs main merge: accepted by .*; next: pullboard claim ${item.id} \\(the bar is unchanged\\), merge main`, 'u'));
+
+ assert.equal(box.run(box.web, 'claim', String(item.id)).code, 0);
+ assert.equal(readItem(box, item.id).item_frozen_digest, frozen, 'the builder claims it with its bar unchanged');
+ const merged = box.tryGit(box.web, 'merge', '-q', '--no-edit', 'main');
+ assert.notEqual(merged.status, 0, 'merging main conflicts in the named file');
+ const resolved = commitFile(box, box.web, 'web/feature.js', 'export const status = "ITEM";\n', 'fix(web): merge main into the item [G1]');
+ assert.equal(resolved.status, 0, resolved.stderr);
+ const head = box.git(box.web, 'rev-parse', 'HEAD');
+ const resubmitted = box.run(box.web, 'submit', String(item.id));
+ assert.equal(resubmitted.code, 0, resubmitted.err);
+ const review = box.run(box.repo, 'show', String(item.id));
+ assert.match(review.out, new RegExp(`re-review: main merge only; run the frozen check at ${head.slice(0, 12)}`, 'u'), 'the re-review is the frozen check at the new head');
+ accept(box, item.id, head);
+ assert.doesNotMatch(box.run(box.repo, 'show', String(item.id)).out, /needs main merge/u, 'the new accept clears the label');
+});
+
+test('an older engine refuses a trunk conflict reopen before changing anything [B3,H16]', (t) => {
+ const box = project();
+ const item = submitItem(box, 'Engine item', 'export const status = "ITEM";\n');
+ accept(box, item.id, item.commit);
+ const trunk = moveTrunk(box);
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-conflict-engine-'));
+ const source = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));
+ const snapshot = exportBoard(source);
+ store.closeBoard(source);
+ const replica = store.openBoard(join(directory, 'replica.sqlite'));
+ t.after(() => { store.closeBoard(replica); rmSync(directory, { recursive: true, force: true }); });
+ importBoard(replica, snapshot);
+ assert.ok(ENGINE_VERSION >= CONFLICT_ENGINE);
+ const args = [item.id, { agentId: 'coordinator', note: '', conflict: { files: ['web/feature.js'], trunk } }];
+ const receipt = { sequence: 1, at: '2026-10-17T12:00:00.000Z', kind: 'move', sender: { kind: 'agent', userId: 'fixture-user', agent: 'coordinator' } };
+ const before = exportBoard(replica);
+ assert.throws(() => applyRelayMove(replica, { version: 1, engine: CONFLICT_ENGINE - 1, id: 'old-conflict', operation: 'reopen', args, actor: 'coordinator' }, receipt),
+ (error) => error.code === 'RELAY_MOVE' && error.message.includes(`introduced in engine ${CONFLICT_ENGINE}`));
+ assert.deepEqual(exportBoard(replica), before, 'an older engine move carrying a conflict changes nothing');
+ replica.executionEngineVersion = CONFLICT_ENGINE - 1;
+ assert.throws(() => store.reopen(replica, item.id, args[1]), (error) => error.code === 'ENGINE_VERSION', 'a board replaying an older engine refuses the conflict');
+ delete replica.executionEngineVersion;
+ assert.deepEqual(exportBoard(replica), before);
+ const move = prepareEngineMove(replica, 'reopen', args, { id: 'current-conflict', actor: 'coordinator' });
+ assert.equal(move.engine, ENGINE_VERSION);
+ const applied = applyRelayMove(replica, move, receipt);
+ assert.equal(applied.error, undefined, JSON.stringify(applied));
+ assert.deepEqual(applied.result.conflict, { files: ['web/feature.js'], trunk });
+ assert.equal(store.getItem(replica, item.id).item_status, 'open');
+});