Skip to content

Commit 10a1035

Browse files
hyperpolymathclaude
andcommitted
feat(session-management): add Concurrent-Write Collision Protocol (companion-file pattern)
Codifies the companion-file pattern for handover documents that are under concurrent write by parallel sessions — the canonical case being ~/Desktop/AI-WORK.md and its project-scoped siblings, which routinely collide when multiple Claude sessions wrap up at the same time. First codified on 2026-04-13 by the F7 Diagnostics / Hexadeca-Connector session after five consecutive Edit-tool attempts on ~/Desktop/AI-WORK-007.md failed with "File has been modified since read". The parent doc grew 635 -> 840 -> 981 -> 1801 -> 1834 lines during the wrap-up window as three other sessions (T6 step-semantics, Metadatastician cross-estate, TRG sweep) landed their own addenda in parallel. Two duplicate `## 11.` section headers existed in the parent file before the F7 session began — a clear signal that the problem needed a formal protocol, not ad-hoc retry. New: - session-management-standards/CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc — cross-cutting protocol (applies to verify/, continuity/, and handover/ families). Defines: * When the pattern applies (5 triggers) * The three-step pattern: companion file + pointer section + footer collision note * Companion file naming convention (<PARENT-STEM>-<SESSION-TAG>-<YYYY-MM-DD>.md) * Section numbering rules under collision (skip a number after a collided cluster) * Consolidation protocol (optional, requires user authorisation) * Reading order when picking up a handover stack * Suggested detection-helper tooling Cross-references added to: - session-management-standards/README.adoc — new "cross-cutting" section in the protocol families listing + directory-map entry. - continuity/planned-session-close/CHECKLIST.adoc — new "Concurrent-write collisions" section linking to the protocol. - handover/full-transfer/CHECKLIST.adoc — same. - handover/collaborative-transfer/CHECKLIST.adoc — flagged as the most likely family to hit the problem (multi-party by design). - continuity/emergency-termination/CHECKLIST.adoc — "See Also" entry noting that Tier-2 emergency terminations may need the protocol; Tier-0 and Tier-1 never touch shared handover files. Continuity-core fields remain required regardless of capture location. Only *where* the content lands changes — inline for uncontended files, companion file for contended ones. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 76650fc commit 10a1035

File tree

6 files changed

+323
-0
lines changed

6 files changed

+323
-0
lines changed
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell (hyperpolymath)
3+
= Concurrent-Write Collision Protocol (Companion-File Pattern)
4+
Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
5+
v1.0, 2026-04-13
6+
:toc:
7+
:toclevels: 3
8+
9+
== Purpose
10+
11+
This document defines the canonical pattern for handling *concurrent-write
12+
collisions* on shared handover documents — files that multiple parallel Claude
13+
(or human) sessions write to simultaneously during session-close, handover, or
14+
checkpoint protocols.
15+
16+
The pattern applies whenever a session needs to write to a document that is
17+
being edited by other sessions faster than the writing session can finish its
18+
edits. The canonical example is `~/Desktop/AI-WORK.md` and its project-scoped
19+
siblings (e.g. `~/Desktop/AI-WORK-007.md`), which are written by every active
20+
Claude session working on the estate and routinely collide during wrap-up.
21+
22+
This protocol is *cross-cutting*: it applies to every family in this
23+
directory (`verify`, `continuity`, `handover`), not just `planned-session-close`.
24+
25+
== Origin incident
26+
27+
First codified on 2026-04-13 by the F7 Diagnostics / Hexadeca-Connector
28+
session (Opus 4.6, 1M context) after five consecutive
29+
`Edit`-tool attempts on `~/Desktop/AI-WORK-007.md` failed with
30+
`File has been modified since read`. The parent doc grew from
31+
635 → 840 → 981 → 1801 → 1834 lines during the wrap-up window as at least
32+
three other sessions (T6 step-semantics, Metadatastician cross-estate,
33+
TRG sweep) were landing their own addenda in parallel. Two duplicate
34+
`## 11.` section headers already existed in the parent file before the F7
35+
session began its wrap-up — the protocol documented here was born out of
36+
that failure mode.
37+
38+
== When this pattern applies
39+
40+
Use the companion-file pattern when **any** of these triggers is hit:
41+
42+
. Two or more `Edit`-tool calls on the same handover file in the same
43+
session have failed with `File has been modified since read`, even
44+
with freshly-read anchors.
45+
. The parent document has grown by more than 100 lines between the
46+
session's first read and its current edit attempt.
47+
. `grep -n '^## ' <file>` shows duplicate section-number headers
48+
(e.g. two `## 11.` entries) indicating that other sessions have
49+
already raced to claim the same slot.
50+
. The session is *aware* that one or more parallel sessions are also
51+
in wrap-up on the same file (e.g. via `git log --since=1h`, known
52+
lane ownership, or coordination chatter in §Coordination of the
53+
parent doc).
54+
. Network or filesystem latency is making the read→edit window wider
55+
than normal (sync delays on mounted drives, slow kernel writeback).
56+
57+
If **none** of those triggers are hit, inline addendum is still the
58+
preferred default — it keeps the handover file self-contained and
59+
avoids scattering context across multiple files.
60+
61+
== The pattern
62+
63+
=== Step 1 — land the full addendum as a companion file
64+
65+
Write the complete session-close addendum — scope delivered, test counts,
66+
commits pushed, continuity core, handover prompt for the next session,
67+
git state at close — to a *new* file adjacent to the parent document.
68+
69+
*Naming convention:*
70+
71+
[source,text]
72+
----
73+
~/Desktop/<PARENT-STEM>-<SESSION-TAG>-<YYYY-MM-DD>.md
74+
----
75+
76+
Examples:
77+
78+
* `~/Desktop/AI-WORK-007-F7-SESSION-2026-04-13.md`
79+
* `~/Desktop/AI-WORK-007-T6-STEP-SEMANTICS-2026-04-13.md`
80+
* `~/Desktop/AI-WORK-STANDARDS-PROTOCOL-LANDING-2026-04-13.md`
81+
82+
Where:
83+
84+
* `<PARENT-STEM>` matches the parent filename without extension
85+
(`AI-WORK-007` for `AI-WORK-007.md`).
86+
* `<SESSION-TAG>` is a short, human-readable identifier for *what* the
87+
session did. Prefer the slot designator (`F7`, `T6`, `M3`) when one
88+
exists; otherwise a short topic tag (`SECURITY-AUDIT`,
89+
`STANDARDS-LANDING`).
90+
* `<YYYY-MM-DD>` is the session-close date in ISO-8601 calendar form.
91+
92+
The companion file is a normal Markdown or AsciiDoc document with its
93+
own full continuity core. It MUST contain every field the parent's
94+
inline addendum would have contained — do not split content between
95+
the companion file and the parent.
96+
97+
=== Step 2 — write a *small* pointer section into the parent document
98+
99+
After the companion file lands, do ONE small `Edit` on the parent
100+
document that adds a pointer section. Keep it under ~40 lines so the
101+
edit window is narrow enough to slip between concurrent writes.
102+
103+
*Required content of the pointer section:*
104+
105+
. Section heading with a unique, non-colliding number. See §Section
106+
numbering under collision below.
107+
. A single paragraph stating *why* the addendum is a companion file
108+
(reference to this protocol, plus a one-line indication of the
109+
collision trigger that fired).
110+
. The exact path of the companion file in bold or code.
111+
. A one-line scope summary (what the session delivered) for readers
112+
who only skim the parent.
113+
. Git state at close (HEAD commits of affected repos).
114+
. Test counts at close.
115+
116+
*Suggested minimum template:*
117+
118+
[source,markdown]
119+
----
120+
---
121+
122+
## {{N}}. {{Session title}} — companion file
123+
124+
Full addendum landed as a separate file because this parent doc was under
125+
concurrent write during wrap-up (see
126+
`standards/session-management-standards/CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc`).
127+
Read:
128+
129+
**`~/Desktop/{{PARENT-STEM}}-{{SESSION-TAG}}-{{YYYY-MM-DD}}.md`**
130+
131+
### One-line scope
132+
133+
{{One sentence.}}
134+
135+
### Git state at close
136+
137+
- **{{repo-a}}** HEAD `{{sha-a}}`, pushed to origin/main.
138+
- **{{repo-b}}** HEAD `{{sha-b}}`, pushed to origin/main.
139+
140+
### Tests at close
141+
142+
- {{command}}: **{{n/n}}**
143+
----
144+
145+
=== Step 3 — write the collision trigger into the companion file's footer
146+
147+
At the bottom of the companion file, include a short "Note on why this
148+
is a separate file" section that explains the concrete collision trigger
149+
that fired. This exists so the *next* session picking up the work
150+
understands why the content is here and not in the parent — it is NOT
151+
an apology, it is a signal that this protocol fired as designed.
152+
153+
*Template:*
154+
155+
[source,markdown]
156+
----
157+
## Note on why this is a separate file
158+
159+
During this session's wrap-up, `{{parent path}}` was under heavy
160+
concurrent write by at least one other session. `Edit` tool calls
161+
repeatedly failed with "File has been modified since read" between
162+
read and write. Per
163+
`standards/session-management-standards/CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc`,
164+
this session landed the full addendum as a companion file and a
165+
small pointer edit to the parent doc instead.
166+
167+
If a future session consolidates the parent doc, the contents of this
168+
file can be pasted inline at the pointer section's location once
169+
concurrent writes have settled. The companion file should be retained
170+
either way as an immutable record of the session-close state.
171+
----
172+
173+
== Section numbering under collision
174+
175+
When the parent document has collided section numbers (e.g. two `## 11.`
176+
entries landed by different sessions), the companion-file pointer
177+
section MUST take a *new, unused* number rather than disputing an
178+
existing one. Run:
179+
180+
[source,bash]
181+
----
182+
grep -n '^## [0-9]' ~/Desktop/<parent>.md | tail -10
183+
----
184+
185+
Pick the next integer *above* the highest currently-in-use number. If
186+
two collided sections both claim `## 11`, skip to `## 13` (not `## 12`),
187+
because `## 12` may also be claimed by a parallel session that has not
188+
yet written its pointer. Leaving a one-number gap between the collided
189+
cluster and the new pointer reduces the chance of another collision at
190+
the new number.
191+
192+
**Do NOT renumber existing collided sections in-place** from a
193+
companion-file wrap-up — that is a separate consolidation task (see
194+
§Consolidation below) and should not be performed while other sessions
195+
are still actively writing.
196+
197+
== Consolidation (after concurrent writes settle)
198+
199+
Once the collision window has closed — typically when all parallel
200+
sessions have reported end-of-session — a later session may consolidate
201+
the parent document. Consolidation is OPTIONAL and should only be
202+
attempted when:
203+
204+
* All parallel sessions have committed their final state.
205+
* No duplicate section headers are being added by any active writer.
206+
* The consolidating session has *explicit user authorisation*.
207+
208+
When consolidating:
209+
210+
. Read the full current parent document.
211+
. Read every companion file referenced from it.
212+
. Renumber collided sections in-place to eliminate duplicates.
213+
. Optionally inline the companion-file contents at each pointer
214+
section (the user may prefer to keep the companion files as
215+
immutable session-close records — ask first).
216+
. Commit the consolidated parent in a single atomic edit.
217+
. **Do not delete the companion files** without explicit user
218+
authorisation. They are the immutable record of what each session
219+
actually produced; the parent document is a consolidated view.
220+
221+
== Reading the handover stack
222+
223+
When a future session picks up from a parent document that uses the
224+
companion-file pattern, the read order is:
225+
226+
. Parent document, full read.
227+
. Every companion file referenced from the pointer sections the
228+
session cares about, in order of relevance.
229+
. Any upstream design documents referenced from inside the companion
230+
files.
231+
232+
The companion files are *authoritative* for the continuity core of
233+
their own sessions. If the pointer section in the parent disagrees
234+
with the companion file, trust the companion file.
235+
236+
== Relationship to other protocols
237+
238+
This protocol is orthogonal to the canonical-command protocols in
239+
`verify/`, `continuity/`, and `handover/`. It describes *how* to
240+
write the output of those protocols when the target file is under
241+
concurrent write; it does not replace any of them.
242+
243+
Specifically:
244+
245+
* `continuity/planned-session-close/CHECKLIST.adoc` — the continuity
246+
core captured in the companion file must still follow this
247+
checklist. Only the *location* of that content changes.
248+
* `handover/full-transfer/CHECKLIST.adoc` — same.
249+
* `verify/substantial-completion/CHECKLIST.adoc` — same.
250+
251+
See link:adoption-and-integration-guide/GUIDE.adoc[adoption-and-integration-guide/GUIDE.adoc]
252+
for repository-local integration patterns once this protocol is
253+
wired into downstream repos.
254+
255+
== Detection helpers (suggested)
256+
257+
Future tooling may implement these as automated checks:
258+
259+
* `session-close-helper collision-check <parent-file>` — greps for
260+
duplicate section headers and reports the next safe number.
261+
* `session-close-helper companion-name <parent-file> <session-tag>`
262+
— generates the canonical companion filename from the parent stem
263+
and today's date.
264+
* `session-close-helper write-pointer <parent-file> <companion-file>`
265+
— attempts the pointer edit with exponential backoff across
266+
`File has been modified since read` failures, with a hard cap after
267+
which it falls through to a "manual consolidation needed" signal.
268+
269+
None of these are implemented yet. They are suggested follow-ups.
270+
271+
== Status
272+
273+
STANDING. Adopted 2026-04-13 after the F7 session collision incident.
274+
Downstream repositories using `AI-WORK*.md` patterns should reference
275+
this doc from their local CLAUDE.md and adoption guides.

session-management-standards/README.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ logic. Protocol definitions live here.
3737
* `model-transfer` (`handover model <path>`)
3838
* `human-transfer` (`handover human <path>`)
3939

40+
=== cross-cutting
41+
42+
Protocols that apply across every family above:
43+
44+
* `concurrent-write-collision` — companion-file pattern for handover
45+
documents under parallel-session write contention. See
46+
link:CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc[CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc].
47+
Adopted 2026-04-13.
48+
4049
== Shared Continuity Core
4150

4251
Every protocol and runtime artifact aligns to the same continuity core:
@@ -59,6 +68,7 @@ Every protocol and runtime artifact aligns to the same continuity core:
5968
----
6069
session-management-standards/
6170
README.adoc
71+
CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc # cross-cutting
6272
adoption-and-integration-guide/
6373
GUIDE.adoc
6474
verify/

session-management-standards/continuity/emergency-termination/CHECKLIST.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,4 @@ If emergency recovery fails:
520520
- link:../recovery-operation/CHECKLIST.adoc[Recovery Operation Protocol]
521521
- link:../../handover/full-transfer/CHECKLIST.adoc[Handover Protocol]
522522
- link:../repo-intake/CHECKLIST.adoc[Repo Intake Protocol]
523+
- link:../../CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc[Concurrent-Write Collision Protocol] — cross-cutting pattern for handover files under parallel-session write contention. Tier-2 Emergency Termination should switch to the companion-file pattern if the target handover file is hot; Tier-0 and Tier-1 never touch shared handover files, so the protocol does not apply to them.

session-management-standards/continuity/planned-session-close/CHECKLIST.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ Describe what successful execution of this protocol achieves.
3737
2. Required artifacts are present.
3838
3. Residual risks and blockers are explicit.
3939

40+
== Concurrent-write collisions
41+
42+
If the target handover document is under concurrent write by parallel
43+
sessions (symptom: repeated `File has been modified since read` errors,
44+
duplicate section-number headers in the parent doc, or known parallel
45+
sessions also in wrap-up), DO NOT retry inline edits indefinitely.
46+
Switch to the companion-file pattern defined in
47+
link:../../CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc[CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc]:
48+
49+
1. Land the full continuity core as a companion file adjacent to
50+
the parent document, named
51+
`<PARENT-STEM>-<SESSION-TAG>-<YYYY-MM-DD>.md`.
52+
2. Write a small pointer section into the parent doc at the next
53+
unused (non-collided) section number.
54+
3. Include a collision-trigger note in the companion file footer so
55+
future sessions understand why the content is separated.
56+
57+
The continuity core fields below are still required — only the
58+
location of their capture changes.
59+
4060
== Continuity Core Capture
4161

4262
* Goal

session-management-standards/handover/collaborative-transfer/CHECKLIST.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ Describe what successful execution of this protocol achieves.
3737
2. Required artifacts are present.
3838
3. Residual risks and blockers are explicit.
3939

40+
== Concurrent-write collisions
41+
42+
Collaborative transfers are the *most likely* family to hit
43+
concurrent-write collisions because the whole point of the protocol
44+
is that multiple parties are actively working in parallel. If the
45+
handover document is colliding, apply the companion-file pattern
46+
from
47+
link:../../CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc[CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc].
48+
4049
== Continuity Core Capture
4150

4251
* Goal

session-management-standards/handover/full-transfer/CHECKLIST.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ Describe what successful execution of this protocol achieves.
3737
2. Required artifacts are present.
3838
3. Residual risks and blockers are explicit.
3939

40+
== Concurrent-write collisions
41+
42+
If the target handover document is under concurrent write by parallel
43+
sessions, apply the companion-file pattern from
44+
link:../../CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc[CONCURRENT-WRITE-COLLISION-PROTOCOL.adoc].
45+
Continuity core fields remain required; only the location of their
46+
capture changes.
47+
4048
== Continuity Core Capture
4149

4250
* Goal

0 commit comments

Comments
 (0)