counterparts 0.3.34 → 0.3.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.35 — 2026-10-24
4
+
5
+ The morning reflection reads a shorter list of the memories that may become core: at most 30 a night, the 20 strongest and 10 taking turns through the rest, with the others counted in one line (on a copy of the author's store, 132 candidates → 30 shown and "+102 more", the reflection's reading 85k characters in 4 parts → 74k in 3; a tail of about 100 comes round in about 10 nights). Day's end's known misread from 0.3.34 is fixed: a night that tells the day and then writes the page reads as a page revised. A memory written in one session now counts as used the first time another session draws on it, the same day. No store-format change (store v14, cache v7), no wiring change: `counterparts connect` is not needed after upgrading. Restart the dashboard and every Claude Code session afterwards so the long-running memory server and dashboard load the new version.
6
+
7
+ - **The morning reflection is shown at most 30 core candidates a night, not every one.** The 20 strongest felt and
8
+ newest come every night, and 10 more take turns through the rest, the ones it saw longest ago first, so each still
9
+ comes round. The rest are counted in one line. On a store with about 130 candidates the reflection's bundle is
10
+ about 11k characters shorter and one part fewer. Switch: `dream.REFLECT_CANDIDATES_CAP`.
11
+ - **Day's end that tells the day first and then writes the page anyway is read as a page
12
+ written.** The night's row, doctor and the dashboard said "nothing to say" for that night
13
+ although the page had changed; now they say it was revised, and the day summary stays
14
+ with it.
15
+ - **A memory can be credited on the day it was written, by any session but the one that wrote
16
+ it.** Until now no use counted on a memory's first day, so a note another session opened or
17
+ drew on within minutes stayed at zero uses. The rule's real cause was the writing session
18
+ seeing its own words in its reply, so that session is now the one refused that day. Switch:
19
+ `physics.OWN_WRITE_GATE`.
20
+
3
21
  ## 0.3.34 — 2026-10-23
4
22
 
5
23
  The night is lighter and better organised. Its helpers start slim, with only the memory tools they use and a short prompt of their own, and the dream's and the reflection's reading goes out as plain lines with short ids (on a copy of the author's store the dream's bundle fell by 43–45%, the reflection's by about 13%, with the same memories shown). The nightly page writer is now called **day's end**: it runs first, in its own child, reads the day by its chapters' summaries and its strongest memories, writes Lately and How I work, and leaves a short account of the day that the dream reads first; the reflection writes Core. The reflection sees the long view again: on busy nights it had been shown no core memories at all, and now it reads them first, with the last three weeks as a line a day. `counterparts night last` and doctor say what a night cost in tokens. No store-format change (store v14, cache v7), no wiring change: `counterparts connect` is not needed after upgrading. Restart the dashboard and every Claude Code session afterwards so the long-running memory server and dashboard load the new version.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.3.34",
3
+ "version": "0.3.35",
4
4
  "license": "MIT",
5
5
  "description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
6
6
  "repository": {
@@ -15,7 +15,7 @@ import {
15
15
  pageTooLargeDetail,
16
16
  } from "../../core/self/index.js";
17
17
  import type { TraceInput } from "../../core/self/page.js";
18
- import type { PageWriterMode } from "../../core/self/index.js";
18
+ import type { PageWriterMode, PageWriterRun } from "../../core/self/index.js";
19
19
  import type { ToolResult } from "./server-options.js";
20
20
  import { dreamHow, PAGE_REFUSAL_DETAIL, pageLaneAnswer, pageRoomAnswer } from "./server-words.js";
21
21
  import type { McpServer } from "./server.js";
@@ -704,7 +704,13 @@ export function selfPageTool(server: McpServer, args: Record<string, unknown>):
704
704
  // over the page-writer ask, and it is a DATE: a session asked to write
705
705
  // about 09-19 writes `writer` for that run and nothing else, and a stale
706
706
  // mark cannot relabel a write made two days later (`adapters/sessions.ts`).
707
- const writerFor = server["pageWriterMark"](claimedSession);
707
+ // DAY'S END TOLD THE DAY ALONE, THEN WROTE THE PAGE ANYWAY (the edge
708
+ // recorded at #606's merge): the alone call answered the night and closed
709
+ // the claim, so the mark is gone — but this is still day's end, and the
710
+ // night's row must say the page changed. Only a page, only the same
711
+ // session on the same day, only before the dream begins (`daysEndStood`).
712
+ const stood = typeof body === "string" ? daysEndStood(server, claimedSession) : null;
713
+ const writerFor = server["pageWriterMark"](claimedSession) ?? (stood === null ? null : { about: stood.about, mode: stood.mode });
708
714
  // THE PAGE WRITER'S OWN CHILD (2026-10-23, `self.PAGE_SPLIT`; review of
709
715
  // #603): every page write it makes is the writer's, held to the writer's
710
716
  // lane — its first write closes the night's claim, and a resend after it
@@ -786,11 +792,22 @@ export function selfPageTool(server: McpServer, args: Record<string, unknown>):
786
792
  ? `past-room: ${String(written.bytes)} bytes, ${String(written.bytes - written.overRoom)} over the ${String(written.overRoom)}-byte room`
787
793
  : written.reason,
788
794
  bytesAfter: written.written ? written.bytes : 0,
795
+ // After a summary sent alone, the page it stood on and what the claim was handed.
796
+ ...(stood === null ? {} : { bytesBefore: stood.bytesAfter, considered: stood.considered, omitted: stood.omitted }),
789
797
  // THE DAY SUMMARY rides on the night's own row (2026-10-23, lane D2),
790
798
  // with the session and run that told it, so the dream finds it.
791
799
  // Only on a page written (review of D2): a refused page's summary is
792
800
  // sent again with the page, and kept then.
793
- ...(keep === null || !written.written ? {} : summaryRow(server, claimedSession, keep)),
801
+ // Sent alone earlier (`stood`), it is carried onto this row, so the
802
+ // night's answer and its summary stay one row; a summary sent again
803
+ // with this page is the later telling and stands instead.
804
+ ...(!written.written
805
+ ? {}
806
+ : keep !== null
807
+ ? summaryRow(server, claimedSession, keep, stood?.run)
808
+ : stood !== null
809
+ ? { summary: stood.summary, summaryCites: stood.summaryCites, session: stood.session, run: stood.run }
810
+ : {}),
794
811
  });
795
812
  } catch {
796
813
  /* the page is written; the bookkeeping is not worth the answer */
@@ -800,9 +817,11 @@ export function selfPageTool(server: McpServer, args: Record<string, unknown>):
800
817
  // Day's end's page written with no summary, while day summaries are on:
801
818
  // said, since the night is answered now and its dream opens without one.
802
819
  const notSent =
803
- told === null && writerFor !== null && typeof body === "string" && written.written && SELF_TUNABLES.DAY_SUMMARY
804
- ? { summaryNotSent: "No day summary came with this write, so tonight's dream opens without one." }
805
- : {};
820
+ told === null && stood !== null && written.written
821
+ ? { summary: { kept: true, about: stood.about, chars: charCount(stood.summary), cites: stood.summaryCites.length, sentEarlier: true } }
822
+ : told === null && writerFor !== null && typeof body === "string" && written.written && SELF_TUNABLES.DAY_SUMMARY
823
+ ? { summaryNotSent: "No day summary came with this write, so tonight's dream opens without one." }
824
+ : {};
806
825
  const toldAnswer =
807
826
  told === null
808
827
  ? notSent
@@ -970,17 +989,49 @@ function daySummaryArgs(server: McpServer, sent: string, rawCites: unknown, from
970
989
  }
971
990
 
972
991
  /** The day summary's fields on the night's row: its words, cites, and the session and run that told it. */
973
- function summaryRow(server: McpServer, claimedSession: string | null, told: DaySummaryArgs): { summary: string; summaryCites: readonly string[]; session?: string; run?: string } {
992
+ function summaryRow(server: McpServer, claimedSession: string | null, told: DaySummaryArgs, knownRun?: string): { summary: string; summaryCites: readonly string[]; session?: string; run?: string } {
974
993
  const session = claimedSession ?? server.session ?? "";
975
- let run = "";
994
+ let run = knownRun ?? "";
976
995
  try {
977
- run = session === "" ? "" : (server.counterpart.nightClaimFor(session)?.run ?? "");
996
+ if (run === "") run = session === "" ? "" : (server.counterpart.nightClaimFor(session)?.run ?? "");
978
997
  } catch {
979
998
  run = "";
980
999
  }
981
1000
  return { summary: told.text, summaryCites: told.cites, ...(session === "" ? {} : { session }), ...(run === "" ? {} : { run }) };
982
1001
  }
983
1002
 
1003
+ /** What `daysEndAlone` writes as the row's detail, and how `daysEndStood` knows its row. */
1004
+ const DAYS_END_STOOD = "day's end left the page as it stands";
1005
+
1006
+ /**
1007
+ * DAY'S END'S SUMMARY SENT ALONE, STILL OPEN TO ITS PAGE (the edge recorded
1008
+ * at #606's merge): the night's newest settled row is the one `daysEndAlone`
1009
+ * wrote, today, for this call's session, on the nightly run's server, and
1010
+ * no dream has begun since — so a page written now is the same day's end
1011
+ * changing its mind, and the night's answer becomes the page written. The
1012
+ * run moving on (the dream's `begin`) ends it, as the open claim's
1013
+ * `closeNightWriter` does. Null otherwise. Never throws.
1014
+ */
1015
+ function daysEndStood(server: McpServer, claimedSession: string | null): PageWriterRun | null {
1016
+ try {
1017
+ if (claimedSession === null || !server["nightRun"]()) return null;
1018
+ const today = server.counterpart.self.calendarToday();
1019
+ const alone = server.counterpart
1020
+ .pageWriterRuns({})
1021
+ .find((r) => r.outcome === "nothing-to-say" && r.detail === DAYS_END_STOOD && r.session === claimedSession && r.on === today && r.summary.trim().length > 0);
1022
+ if (alone === undefined) return null;
1023
+ const settled = server.counterpart
1024
+ .pageWriterRuns({ about: alone.about })
1025
+ .find((r) => r.outcome === "revised" || r.outcome === "nothing-to-say" || r.outcome === "failed");
1026
+ if (settled === undefined || settled.at !== alone.at || settled.seq !== alone.seq) return null;
1027
+ const dream = server.counterpart.dreams.lastDream();
1028
+ if (dream !== null && dream.started_at >= alone.at) return null;
1029
+ return alone;
1030
+ } catch {
1031
+ return null;
1032
+ }
1033
+ }
1034
+
984
1035
  /**
985
1036
  * DAY'S END, THE PAGE STANDING (2026-10-23, lane D2): a summary sent alone
986
1037
  * answers the night as `nothing-to-say` — the page left as it stands, which
@@ -999,7 +1050,7 @@ function daysEndAlone(
999
1050
  about: input.writerFor.about,
1000
1051
  mode: input.writerFor.mode,
1001
1052
  outcome: "nothing-to-say",
1002
- detail: "day's end left the page as it stands",
1053
+ detail: DAYS_END_STOOD,
1003
1054
  bytesBefore: bytes,
1004
1055
  bytesAfter: bytes,
1005
1056
  ...(claim === null ? {} : { considered: claim.considered, omitted: claim.omitted }),
@@ -19,7 +19,7 @@ export const SERVER_NAME = "counterparts";
19
19
  * host decides whether to trust what follows. Read from a constant rather than
20
20
  * from disk so the server opens no file to answer its first message.
21
21
  */
22
- export const SERVER_VERSION = "0.3.34";
22
+ export const SERVER_VERSION = "0.3.35";
23
23
 
24
24
  /**
25
25
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -90,7 +90,7 @@ export interface DrewOnResult {
90
90
  /** Refused by name, in the order given: `not-shown`, `unknown-id`,
91
91
  * `archived`, `handoff`, `superseded`, `faded-under-newer`, or recall's or
92
92
  * physics' own reason (`already-credited-at-or-above`,
93
- * `already-credited-today`, `birth-day`, `observer`, …). */
93
+ * `already-credited-today`, `birth-day`, `own-write`, `observer`, …). */
94
94
  readonly refused: { id: string; reason: string }[];
95
95
  /** Past the boundary's cap (`DREW_ON_MAX_PER_BOUNDARY`), not attempted. */
96
96
  readonly capped: string[];
@@ -391,7 +391,7 @@ const EVENT_RING = REMEMBER.CONSUMED_LEDGER_MAX;
391
391
 
392
392
  /**
393
393
  * A use whose STRENGTH credit was refused only for its day cadence — recall's
394
- * once-per-lived-day gate, or physics' birth-day / stale-day / already-today —
394
+ * once-per-lived-day gate, or physics' birth-day / own-write / stale-day / already-today —
395
395
  * still counts as co-activation for links (2026-09-28, associate NOTES §8).
396
396
  */
397
397
  /** An unordered pair's key (`rateShown`'s once-per-stretch co-use links). */
@@ -403,7 +403,7 @@ function linksDespite(r: CreditResult): boolean {
403
403
  if (r.reason === "already-credited-at-or-above") return true;
404
404
  if (r.reason !== "physics-refused") return false;
405
405
  const why = r.outcome?.reason;
406
- return why === "birth-day" || why === "stale-day" || why === "already-credited-today";
406
+ return why === "birth-day" || why === "own-write" || why === "stale-day" || why === "already-credited-today";
407
407
  }
408
408
 
409
409
  export class Counterpart {
@@ -3061,8 +3061,10 @@ export class Counterpart {
3061
3061
  // record — it was drawn on, and nothing here revives it: the settle or
3062
3062
  // supersession that this session itself made still stands, and still
3063
3063
  // ranks the new one first. The OLD one is credited, not the head: the
3064
- // head was born today, and physics never credits a memory on its birth
3065
- // day (`creditUse`'s `birth-day`), so redirecting would credit nothing.
3064
+ // head was written by this session (`creditUse`'s `own-write`, since
3065
+ // 2026-10-24) or born today (`birth-day` when its writer is unknown),
3066
+ // so redirecting would credit nothing, or credit a memory the session
3067
+ // never saw.
3066
3068
  const replacedAs = row.superseded_by !== null ? "superseded" : fadeOf({ fade: row.fade }) < 1 ? "faded-under-newer" : null;
3067
3069
  if (replacedAs !== null) {
3068
3070
  const by = this.replacedHere(id, sessionId, day);
@@ -453,7 +453,8 @@ dream having run.
453
453
  everything but the long lists, which go on in order as far as the room allows — and
454
454
  the result says so; phase `part` hands the rest, `PART_CHARS` at a time, each memory
455
455
  as it reads now (one gone since is said to be gone). The parts' ids are kept on the
456
- row. **Fitted** (2026-09-28, build B; `fit/`): the WHOLE core, every core candidate and
456
+ row. **Fitted** (2026-09-28, build B; `fit/`): the WHOLE core, every core candidate (since
457
+ 2026-10-24 at most `CANDIDATES`, part of them rotated, the rest counted: R1) and
457
458
  every memory of the last few days are handed (they were the 20, 12 and 12 most felt),
458
459
  plus a page of the most strongly felt with its full count (`feltOf`); the fitter gives
459
460
  the most felt their whole text (up to `DETAIL_CHARS`), a line to the rest, an id alone
@@ -1159,3 +1159,26 @@ What it is for: a child's transcript or output is matched to its row by name, no
1159
1159
  Off: the same composition as master (the 10-23 corpus, to the noise of a run).
1160
1160
  - Not measured: whether the reflection writes better from the long view and summaries
1161
1161
  than from the chapters' words. A model night would tell; none was run (token budget).
1162
+
1163
+ ## 2026-10-24 — the core candidates, capped and rotated (R1, `dream.REFLECT_CANDIDATES_CAP`)
1164
+
1165
+ - **The risk check, answered.** Nothing gates promotion on the reflection: it runs in sleep
1166
+ (`sleep/consolidate.ts#runConsolidate` → `physics#promote`). But a reflection's cites are
1167
+ `reflection` returns and its feelings feed the fast lane, and physics says plainly that
1168
+ without them the lanes starve (`ReturnSource`). `candidate-not-shown` is the belief
1169
+ candidates, `coreAsks` and `becameCore` are about memories already core. So a plain cut
1170
+ would not shut the tail out by rule, only in practice: sorted felt-then-newest, an old,
1171
+ lightly felt candidate would never be shown again. Hence 20 by the order + 10 rotated.
1172
+ - **Shown is the row's `shown`**, every lane: a candidate cut from the candidates lane that
1173
+ the felt lane picks up (the felt lane filters on the CAPPED list, so it can) counts as
1174
+ shown and waits its turn. The test's first try counted only the candidates lane and
1175
+ "lost" 4 candidates that had been shown in felt.
1176
+ - **Capped before `take`**: `take` writes the fit's priority, so a slice after it would
1177
+ still have fitted the cut ones in as lines, just unnamed in the lane.
1178
+ - **The finish rebuilds `detail`** and copies only the keys it names; `chaptersAs` was not
1179
+ one, so the D1 check's query (`chaptersAs = 'summaries'`) found no finished row. Now
1180
+ `lanes` and `chaptersAs` are carried beside `fit`.
1181
+ - Replayed on the 10-24 corpus (composition only, a dream that changed nothing): candidates
1182
+ 132 → 30 (+102 counted), their lines 29.3k → 8.6k, the bundle 85.1k / 4 parts → 73.6k / 3.
1183
+ The felt lane's count went 24 → 50 (the cut candidates join its pool). The brief's ~38k
1184
+ for the candidates was an estimate; measured lines were 29k.
@@ -154,13 +154,29 @@ export const REFLECT_TUNABLES = {
154
154
  /**
155
155
  * THE LISTS, FITTED (2026-09-28, build B; the research note's P6). The
156
156
  * whole core is handed — every core memory is the page's evidence, so the
157
- * page can cite any of it — and so are every core candidate and everything
157
+ * page can cite any of it — and so are the core candidates (every one until
158
+ * R1, 2026-10-24: now `CANDIDATES`, below) and everything
158
159
  * lived in the last `CHAPTER_DAYS` days: a line each at least, the whole
159
160
  * text for the most strongly felt, ids alone when even the lines outgrow
160
161
  * the room. Was: core 20, candidates 12, recent 12, cut by count.
161
162
  */
162
163
  /** The most strongly felt memories that could be about me, marked or not — a whole-store list, so a page of it, with its full count said. */
163
164
  FELT: 10,
165
+ /**
166
+ * THE CORE CANDIDATES, CAPPED AND ROTATED (R1, 2026-10-24; switch
167
+ * `dream.REFLECT_CANDIDATES_CAP`). Every candidate was shown, a line each:
168
+ * on the live store about 130 a night, about 38k of the room, a backlog
169
+ * rather than a long view. Now at most `CANDIDATES`: the strongest felt and
170
+ * newest first, and `CANDIDATES_ROTATED` of those slots go to the rest, the
171
+ * least recently shown first (by the `shown` of the last
172
+ * `CANDIDATES_LOOKBACK` reflections; one none of them showed first) — the
173
+ * reflection's cites and feelings are the core lanes' strongest feed
174
+ * (`physics#ReturnSource`), so a candidate past the head still comes round.
175
+ * The rest are counted in one line, never listed. CAL.
176
+ */
177
+ CANDIDATES: 30,
178
+ CANDIDATES_ROTATED: 10,
179
+ CANDIDATES_LOOKBACK: 30,
164
180
  /** The room the memories' and chapters' words share, across the parts, in characters. CAL. */
165
181
  ROOM_CHARS: 80_000,
166
182
  /** The share of the room the chapters' new entries may take. CAL. */
@@ -358,8 +374,10 @@ export interface ReflectBundle {
358
374
  * Empty when none has earned the core yet.
359
375
  */
360
376
  readonly spine?: readonly ReflectSpineBelief[];
361
- /** Every core candidate, most strongly felt first. */
377
+ /** The core candidates shown (at most `CANDIDATES`, part rotated; every one with the cap off), most strongly felt first. */
362
378
  readonly candidates: readonly string[];
379
+ /** The core candidates not shown tonight, counted (R1, 2026-10-24): absent when none. */
380
+ readonly candidatesMore?: number;
363
381
  /** A page of the most strongly felt memories that could be about me; `feltOf` is how many there are. */
364
382
  readonly felt: readonly string[];
365
383
  readonly feltOf: number;
@@ -488,6 +506,12 @@ export const REFLECT_LOOKUP_ORDER =
488
506
  "dreamSaw is what the dream changed tonight and the older memories it was shown, a line each; tonight's new memories are under recent. " +
489
507
  'The rest as an excerpt, a line, or an id alone ("fidelity"; "chars" is the whole length). Read any you need whole with the recall tool, ids: [...] — several at once — before you cite, feel or mark it.';
490
508
 
509
+ /** With the candidates' cap (R1, `dream.REFLECT_CANDIDATES_CAP`): the same, the candidates said as capped. */
510
+ export const REFLECT_LOOKUP_ORDER_CAPPED = REFLECT_LOOKUP_ORDER.replace(
511
+ "every core candidate",
512
+ `the core candidates (at most ${String(REFLECT_TUNABLES.CANDIDATES)} a night, some of them rotated in; the rest counted, not shown)`,
513
+ );
514
+
491
515
  /**
492
516
  * THE LAST FEW WEEKS, A LINE A DAY (2026-10-23, lane D2): each day's line is
493
517
  * day's end's summary of it (`from: "days-end"`) — whole when it is no
@@ -861,8 +885,12 @@ export class Reflections {
861
885
  // what was offered only in part is the lookup's denominator.
862
886
  const s = composed.shownAs;
863
887
  const fitRecord = { whole: s.whole, excerpt: s.excerpt, lined: s.line, ids: s.ids, notShown: s.notShown, offered: offeredInPart(fitted), parts: packed.later.length + 1 };
888
+ // THE LANES SHOWN (2026-10-24, the D1 check): how many of the core, the
889
+ // candidates and the felt the bundle named, and the candidates the cap
890
+ // left out (R1) — kept beside `fit`, and carried through the finish.
891
+ const lanes = { core: composed.core.length, candidates: composed.candidates.length, felt: composed.felt.length, candidatesNotShown: composed.candidatesMore ?? 0, feltFromCut: fitted.feltFromCut };
864
892
  this.store.updateReflection(id, {
865
- detail: { ...(packed.later.length > 0 ? { parts: packed.later } : {}), fit: fitRecord, ...(composed.chaptersAs === undefined ? {} : { chaptersAs: composed.chaptersAs }), ...beliefsDetail(composed.beliefs ?? null), ...(composed.spine === undefined ? {} : { spine: composed.spine.map((b) => b.id) }), ...(composed.unmarked.length > 0 ? { unmarked: composed.unmarked } : {}), ...(composed.staleOpen.length > 0 ? { staleOpen: composed.staleOpen.map((x) => x.id) } : {}), ...(fitted.notCarried.length > 0 ? { notCarried: fitted.notCarried } : {}), ...(composed.reconsidering.length > 0 ? { coreOffered: composed.reconsidering.map((x) => x.id) } : {}) },
893
+ detail: { ...(packed.later.length > 0 ? { parts: packed.later } : {}), fit: fitRecord, lanes, ...(composed.chaptersAs === undefined ? {} : { chaptersAs: composed.chaptersAs }), ...beliefsDetail(composed.beliefs ?? null), ...(composed.spine === undefined ? {} : { spine: composed.spine.map((b) => b.id) }), ...(composed.unmarked.length > 0 ? { unmarked: composed.unmarked } : {}), ...(composed.staleOpen.length > 0 ? { staleOpen: composed.staleOpen.map((x) => x.id) } : {}), ...(fitted.notCarried.length > 0 ? { notCarried: fitted.notCarried } : {}), ...(composed.reconsidering.length > 0 ? { coreOffered: composed.reconsidering.map((x) => x.id) } : {}) },
866
894
  });
867
895
  writeIndex(this.store, "reflection", { ref: id, at: this.store.now(), offered: fitted.offered, looked: [], lineCap: fitted.lineCap, ...(aliases === null ? {} : { aliases: aliases.toJSON() }) });
868
896
  this.record("reflection.begun", id, { dream: dreamId, shown: shown.length, ...fitRecord });
@@ -2028,6 +2056,12 @@ export class Reflections {
2028
2056
  // And how its room was spent (2026-09-28): doctor reads it.
2029
2057
  const fitRecord = parseDetail(row.detail)["fit"];
2030
2058
  if (isRecord(fitRecord)) detail["fit"] = fitRecord;
2059
+ // The lanes it was shown and how its chapters came (2026-10-24): the D1
2060
+ // check reads them on a finished row.
2061
+ const lanesRecord = parseDetail(row.detail)["lanes"];
2062
+ if (isRecord(lanesRecord)) detail["lanes"] = lanesRecord;
2063
+ const chaptersAs = parseDetail(row.detail)["chaptersAs"];
2064
+ if (typeof chaptersAs === "string") detail["chaptersAs"] = chaptersAs;
2031
2065
  // What it was offered to mark: the next nights' rotation reads it.
2032
2066
  const offeredUnmarked = parseDetail(row.detail)["unmarked"];
2033
2067
  if (Array.isArray(offeredUnmarked)) detail["unmarked"] = offeredUnmarked;
@@ -3016,11 +3050,15 @@ export class Reflections {
3016
3050
  }
3017
3051
  const byFelt = (a: { id: string; felt: number }, b: { id: string; felt: number }): number => b.felt - a.felt || (a.id < b.id ? -1 : 1);
3018
3052
  const coreIds = core.sort(byFelt).map((c) => c.id).filter(take(P.core));
3019
- const candidateIds = candidates
3053
+ // Capped before `take` (R1, `dream.REFLECT_CANDIDATES_CAP`): a candidate
3054
+ // past the cap gets no priority here, so it is not fitted in as a line
3055
+ // either — it may still come in by another lane (felt, recent).
3056
+ const candidatesAll = candidates
3020
3057
  .sort((a, b) => b.felt - a.felt || b.at - a.at || (a.id < b.id ? -1 : 1))
3021
3058
  .map((c) => c.id)
3022
- .filter((x) => !coreIds.includes(x))
3023
- .filter(take(P.candidates));
3059
+ .filter((x) => !coreIds.includes(x) && see(x) !== null);
3060
+ const candidateIds = (DREAM_TUNABLES.REFLECT_CANDIDATES_CAP ? this.capCandidates(id, candidatesAll) : candidatesAll).filter(take(P.candidates));
3061
+ const candidatesMore = candidatesAll.length - candidateIds.length;
3024
3062
  const feltAll = felt
3025
3063
  .sort(byFelt)
3026
3064
  .map((c) => c.id)
@@ -3269,6 +3307,7 @@ export class Reflections {
3269
3307
  core: coreIds.filter(kept),
3270
3308
  ...(spine === null ? {} : { spine }),
3271
3309
  candidates: candidateIds.filter(kept),
3310
+ ...(candidatesMore > 0 ? { candidatesMore } : {}),
3272
3311
  felt: feltIds.filter(kept),
3273
3312
  recent: recentIds.filter(kept),
3274
3313
  becameCore: becameCore.filter(kept),
@@ -3288,11 +3327,15 @@ export class Reflections {
3288
3327
  ids: fitted.report.ids,
3289
3328
  notShown: fitted.waiting.length + chaptersFit.notShown,
3290
3329
  },
3291
- lookup: order ? REFLECT_LOOKUP_ORDER : REFLECT_LOOKUP,
3330
+ lookup: order ? (DREAM_TUNABLES.REFLECT_CANDIDATES_CAP ? REFLECT_LOOKUP_ORDER_CAPPED : REFLECT_LOOKUP_ORDER) : REFLECT_LOOKUP,
3292
3331
  limits: beliefs === null ? limitsWithoutBeliefs(T.LIMITS) : { ...T.LIMITS },
3293
3332
  };
3294
3333
  noteMindShown(this.store, bundle.onMind, day);
3295
- return { bundle, offered, lineCap: chaptersFit.summaryBytes, notCarried: uncarried.all };
3334
+ // How many of the felt shown are candidates the cap cut (R1's check: do
3335
+ // they crowd the felt lane's other memories out?).
3336
+ const cut = new Set(candidatesAll.filter((x) => !candidateIds.includes(x)));
3337
+ const feltFromCut = bundle.felt.filter((x) => cut.has(x)).length;
3338
+ return { bundle, offered, lineCap: chaptersFit.summaryBytes, notCarried: uncarried.all, feltFromCut };
3296
3339
  }
3297
3340
 
3298
3341
  /**
@@ -3369,6 +3412,36 @@ export class Reflections {
3369
3412
  return null;
3370
3413
  }
3371
3414
 
3415
+ /**
3416
+ * THE CANDIDATES A NIGHT SHOWS (R1, 2026-10-24): the first `CANDIDATES −
3417
+ * CANDIDATES_ROTATED` of the order (strongest felt, then newest), then
3418
+ * `CANDIDATES_ROTATED` of the rest, the least recently shown first — one
3419
+ * none of the last `CANDIDATES_LOOKBACK` reflections showed, in the order;
3420
+ * then the one shown longest ago. Kept in the order. All of them when they
3421
+ * fit.
3422
+ */
3423
+ private capCandidates(mine: string, ranked: readonly string[]): string[] {
3424
+ const T = REFLECT_TUNABLES;
3425
+ if (ranked.length <= T.CANDIDATES) return [...ranked];
3426
+ const headN = T.CANDIDATES - T.CANDIDATES_ROTATED;
3427
+ const tail = ranked.slice(headN);
3428
+ // How many reflections back each was last shown (0 the newest); absent, not lately.
3429
+ const ago = new Map<string, number>();
3430
+ const earlier = this.store
3431
+ .reflections({ limit: T.CANDIDATES_LOOKBACK + 1 })
3432
+ .filter((r) => r.id !== mine)
3433
+ .slice(0, T.CANDIDATES_LOOKBACK);
3434
+ earlier.forEach((r, i) => {
3435
+ for (const x of parseIds(r.shown)) if (!ago.has(x)) ago.set(x, i);
3436
+ });
3437
+ const rank = new Map(tail.map((x, i) => [x, i]));
3438
+ const rotated = [...tail]
3439
+ .sort((a, b) => (ago.get(b) ?? Infinity) - (ago.get(a) ?? Infinity) || (rank.get(a) ?? 0) - (rank.get(b) ?? 0))
3440
+ .slice(0, T.CANDIDATES_ROTATED);
3441
+ const chosen = new Set([...ranked.slice(0, headN), ...rotated]);
3442
+ return ranked.filter((x) => chosen.has(x));
3443
+ }
3444
+
3372
3445
  /**
3373
3446
  * Memories promoted on reflection alone that no share has named yet. A
3374
3447
  * share of `mine` (the reflection finishing again) counts as not having
@@ -4180,6 +4253,8 @@ interface Composed {
4180
4253
  readonly lineCap: number;
4181
4254
  /** Every open thread not carried tonight (`noLongerCarried`), recorded on the row; never in the bundle. */
4182
4255
  readonly notCarried: readonly string[];
4256
+ /** The felt lane's memories the candidates' cap cut (R1's check): recorded on the row as `lanes.feltFromCut`; never in the bundle. */
4257
+ readonly feltFromCut: number;
4183
4258
  }
4184
4259
 
4185
4260
  /** The bundle's other furniture, reserved from the room: ids, lists, the questions, the limits. */
@@ -4399,6 +4474,7 @@ function leanReflectLines(b: ReflectBundle, aliases: AliasMap): string[] {
4399
4474
  for (const x of b.spine) out.push(`- ${plainValue(x, aliases)}`);
4400
4475
  }
4401
4476
  out.push(`candidates: ${list(b.candidates)}`);
4477
+ if ((b.candidatesMore ?? 0) > 0) out.push(`+${String(b.candidatesMore)} more candidates, not shown`);
4402
4478
  out.push(`felt (of ${String(b.feltOf)}): ${list(b.felt)}`);
4403
4479
  out.push(`recent: ${list(b.recent)}`);
4404
4480
  out.push(`becameCore: ${list(b.becameCore)}`);
@@ -121,6 +121,13 @@ export const DREAM_TUNABLES = {
121
121
  * shape it began with.
122
122
  */
123
123
  REFLECT_ROOM_ORDER: true as boolean,
124
+ /**
125
+ * THE REFLECTION'S CORE CANDIDATES, CAPPED (R1, 2026-10-24, lightly held):
126
+ * at most `REFLECT_TUNABLES.CANDIDATES` a night, part of them rotated
127
+ * through the rest, and the rest counted in one line. Off: every candidate,
128
+ * exactly as before. Read at use (`dream/reflect.ts#compose`).
129
+ */
130
+ REFLECT_CANDIDATES_CAP: true as boolean,
124
131
  /** With `REFLECT_ROOM_ORDER`: the most OLDER memories the dream saw (neighbours, mixing, lookback) the reflection is shown, a line each. CAL. */
125
132
  SAW_OLDER: 40,
126
133
  /**
@@ -400,6 +400,22 @@ G9]. Credit is retrospective, resolved at the boundary when the reply is known [
400
400
  The ignorable tier never trains. A credited use is ALSO asked, beside this and without
401
401
  changing it, whether it is a RETURN (§5.11).
402
402
 
403
+ *Amended 2026-10-24 — lightly held (R2, Mike's go): the scar is kept and the gate moved to
404
+ its cause.* G9's cause was the WRITING session: its boundary sees the new memory's words in
405
+ the reply it just produced, so a newborn memory double-dipped on its own creation. The day
406
+ was only a proxy, and it refused other sessions too (the ping/pong memory, used by two other
407
+ sessions within minutes of its birth, kept `uses` 0). Now the caller hands physics a fact,
408
+ `ownWrite` (the crediting session is the memory's origin session, or the writer of a
409
+ write-up; `Store#reinforce` reads it off the row): on the birth day, true refuses
410
+ `own-write` and false lets another session credit it once like any other lived day. Later
411
+ days are unchanged: the writing session credits its memory as before (a session can run for
412
+ days, and its later uses are real). Unknown (no
413
+ origin session, or a credit with no session: a schemas mention, a reminder's occurrence)
414
+ keeps the birth-day refusal. A RETURN on the birth day is still refused `birth-day` for
415
+ anyone but the writer: spacing measures from birth, and a return is a coming back.
416
+ Untouched: once a lived day, spacing, `on-display`, the observer stance. Switch:
417
+ `OWN_WRITE_GATE` (off: the birth day refuses everyone, exactly as before).
418
+
403
419
  ### 5.6 Revision — declared, pressure-accumulated, no second object
404
420
 
405
421
  *(Rewritten 2026-08-25 after adversarial review finding 1: the original single-shot
@@ -746,3 +746,17 @@ The row read's support join first asked `PRAGMA table_info` on every read (5,000
746
746
  (`reads-memories.ts#hasBirthRoute`), back to 31–37 ms, recount 0.38 ms p50, and a test counts
747
747
  the PRAGMAs so it cannot quietly return. A supporting memory the owner has made dark still
748
748
  counts until the chase removes it (minor, left as is).
749
+
750
+ **R2, the writing session, not the birth day (2026-10-24, lightly held).** `creditUse` and
751
+ `creditReturn` take `ownWrite` from the caller; physics stays pure. `Store#reinforce` decides
752
+ it from the row (origin session, or `meta.writtenUpBy` for a write-up), because every credit
753
+ path ends there (recall's opens, quotes, drewOn and ratings, chapter copies, the self page's
754
+ confirm) and the store already hands physics the one other row fact, the display. Three
755
+ choices the brief left open: a non-writer's birth-day credit counts a reinforced day (the
756
+ first credit is told apart by `reinforcedDays === 0` on a memory whose `lastUsedDay` is still
757
+ its birth day); a return on the birth day stays `birth-day` for anyone but the writer, since
758
+ spacing measures from birth; and `own-write` holds on the birth day only. The first build
759
+ refused the writer on every day, and `test/settled-repeats.test.ts` caught it: one session
760
+ that wrote a memory on 10-03 and drew on it on 10-12 lost that credit. A session can run for
761
+ days (a resumed conversation, a Desktop chat), and its later uses were always credited. Dream replays, reflections, schemas mentions and
762
+ reminder occurrences pass no session, so they keep the birth-day rule.
@@ -625,6 +625,25 @@ export const TUNABLES = {
625
625
  * (scar §2.4: "did not fire" and "was never asked" are different records). */
626
626
  SYMMETRY_MIN_SAMPLE: 20,
627
627
 
628
+ // --- §5.5 the writing session's own memory (2026-10-24, R2) ---
629
+ /**
630
+ * WHO MAY NOT CREDIT A MEMORY, by its cause [v1 §10 G9]: the session that
631
+ * WROTE it, whose boundary sees the new memory's words in the reply it just
632
+ * produced. On, `creditUse` and `creditReturn` take the caller's `ownWrite`
633
+ * (the crediting session is the memory's origin session): on the birth day
634
+ * true refuses `own-write` and false lets another session credit it; left
635
+ * out (no origin session, or no crediting session) keeps the old
636
+ * `birth-day` refusal. After the birth day nothing changes: the writing
637
+ * session credits its memory as before (a session can run for days — a
638
+ * resumed conversation, a Desktop chat — and its later uses are real). Off: the birth day refuses everyone, exactly as
639
+ * before.
640
+ * Decided by Mike, 2026-10-24, lightly held (R2).
641
+ * Why: the ping/pong memory was used by two other sessions within minutes of
642
+ * its birth and every credit was refused `birth-day`; the scar's cause is
643
+ * the session, not the day.
644
+ */
645
+ OWN_WRITE_GATE: true,
646
+
628
647
  // --- §5.12 a changed fact fades once (2026-09-29, contradictions) ---
629
648
  /**
630
649
  * What a memory's DECAY is multiplied by, once, when it is settled as
@@ -1779,6 +1798,8 @@ export type ReturnReason =
1779
1798
  * prompted the use, and counting it is the rich-get-richer loop (#238). */
1780
1799
  | "on-display"
1781
1800
  | "birth-day"
1801
+ /** The crediting session wrote the memory (`OWN_WRITE_GATE`, 2026-10-24): its boundary saw its own words. */
1802
+ | "own-write"
1782
1803
  /** An awake credit below full weight (surfaced, not used): not a return. */
1783
1804
  | "not-referenced"
1784
1805
  /** An awake return already counted this lived day (or later); for a dream
@@ -1850,6 +1871,8 @@ export function creditReturn(
1850
1871
  /** v9: the last lived day a REFLECTION return was counted for this
1851
1872
  * memory (the store reads it off the `returns` table). */
1852
1873
  lastReflectionDay?: number | null;
1874
+ /** The crediting session wrote this memory (`OWN_WRITE_GATE`; see `creditUse`). */
1875
+ ownWrite?: boolean;
1853
1876
  },
1854
1877
  ): ReturnOutcome {
1855
1878
  const unchanged = {
@@ -1884,6 +1907,11 @@ export function creditReturn(
1884
1907
  // A full awake return from `AWAKE_RETURN_MIN_WEIGHT` up (2026-10-19: a
1885
1908
  // rating of 2 is one; it was full weight only).
1886
1909
  if (opts.source === "awake" && tier < TUNABLES.AWAKE_RETURN_MIN_WEIGHT) return refuse("not-referenced");
1910
+ // THE WRITING SESSION'S OWN MEMORY (2026-10-24, `OWN_WRITE_GATE`): named
1911
+ // by its cause on the birth day. Any other session that day still comes
1912
+ // back with no gap from birth (spacing, below, measures from it), so it
1913
+ // stays refused `birth-day` here: a return is a coming back.
1914
+ if (d === m.birthDay && TUNABLES.OWN_WRITE_GATE && opts.ownWrite === true) return refuse("own-write");
1887
1915
  if (d <= m.birthDay) return refuse("birth-day");
1888
1916
  if (opts.source === "awake" && opts.onDisplay === true) return refuse("on-display");
1889
1917
  // AN ENGAGED RETURN (2026-10-11, `drewOn`; ported from #371): half a
@@ -2189,6 +2217,8 @@ export type CreditReason =
2189
2217
  | "a-belief"
2190
2218
  | "ignorable-tier"
2191
2219
  | "birth-day"
2220
+ /** The crediting session wrote the memory (`OWN_WRITE_GATE`, 2026-10-24). */
2221
+ | "own-write"
2192
2222
  | "already-credited-today"
2193
2223
  | "stale-day";
2194
2224
 
@@ -2202,7 +2232,8 @@ export interface CreditOutcome {
2202
2232
 
2203
2233
  /**
2204
2234
  * Graded retrospective reinforcement (§5.5). At most ONE credited occasion per
2205
- * memory per lived day, never on its birth day [v1 §10 G9], and the ignorable
2235
+ * memory per lived day, never on its birth day by the session that wrote it
2236
+ * [v1 §10 G9; by anyone when that session is unknown — `ownWrite`], and the ignorable
2206
2237
  * (footnoted) tier never trains. Credit is resolved at the boundary, when the
2207
2238
  * reply is known — this function is the arithmetic, not the trigger.
2208
2239
  *
@@ -2218,13 +2249,40 @@ export interface CreditOutcome {
2218
2249
  * `already-credited-today`. Lightly held. Why: review 05 C2 ("a referenced use
2219
2250
  * the same day supersedes it").
2220
2251
  */
2221
- export function creditUse(m: MemoryPhysics, d: number, tier: UseTier, opts: { upgradeFrom?: UseTier } = {}): CreditOutcome {
2252
+ export function creditUse(
2253
+ m: MemoryPhysics,
2254
+ d: number,
2255
+ tier: UseTier,
2256
+ opts: {
2257
+ upgradeFrom?: UseTier;
2258
+ /**
2259
+ * THE WRITING SESSION (2026-10-24, R2; `OWN_WRITE_GATE`): whether the
2260
+ * crediting session is the one that wrote this memory — a fact only the
2261
+ * caller holds (`Store#reinforce` reads the row's origin session). On
2262
+ * the birth day — the day the writing session's boundary sees its own
2263
+ * words — true is refused `own-write`, and false (another session) is
2264
+ * creditable once like any other lived day. Later days: unchanged. Left out (the memory
2265
+ * has no origin session, or the credit came with no session): the old
2266
+ * birth-day refusal, as before.
2267
+ */
2268
+ ownWrite?: boolean;
2269
+ } = {},
2270
+ ): CreditOutcome {
2222
2271
  const w = USE_TIER_WEIGHT[tier];
2223
2272
  const days = reinforcedDays(m);
2224
2273
  const unchanged = { uses: m.uses, lastUsedDay: m.lastUsedDay, reinforcedDays: days };
2225
2274
  if (w <= 0) return { credited: false, reason: "ignorable-tier", w, next: unchanged };
2226
- if (d === m.birthDay) return { credited: false, reason: "birth-day", w, next: unchanged };
2275
+ const gate = TUNABLES.OWN_WRITE_GATE && opts.ownWrite !== undefined;
2276
+ if (gate && opts.ownWrite === true && d === m.birthDay) return { credited: false, reason: "own-write", w, next: unchanged };
2277
+ if (!gate && d === m.birthDay) return { credited: false, reason: "birth-day", w, next: unchanged };
2227
2278
  if (d < m.lastUsedDay) return { credited: false, reason: "stale-day", w, next: unchanged };
2279
+ // ANOTHER SESSION ON THE BIRTH DAY (R2): a new memory's `lastUsedDay` is
2280
+ // its birth day, so its first credit that day is not "already today". It
2281
+ // has never been credited while no reinforced day is counted; after this
2282
+ // one the day reads as credited, and the once-a-day rule holds.
2283
+ if (gate && opts.ownWrite === false && d === m.birthDay && d === m.lastUsedDay && days === 0) {
2284
+ return { credited: true, reason: "credited", w, next: { uses: m.uses + w, lastUsedDay: d, reinforcedDays: 1 } };
2285
+ }
2228
2286
  if (d === m.lastUsedDay) {
2229
2287
  const from = opts.upgradeFrom === undefined ? 0 : USE_TIER_WEIGHT[opts.upgradeFrom];
2230
2288
  if (from > 0 && from < w) {
@@ -2777,3 +2777,10 @@ the glimpse rule alone, `OPEN_CARRY_GLIMPSE_TOUCH` true.
2777
2777
  and `night show` reads that same date: never another night's summary.
2778
2778
  - The dream's header indents the summary's lines, so a `## ` line in it never reads as a
2779
2779
  section of the bundle.
2780
+ - The summary alone, then a page anyway (recorded at #606's merge, fixed 10-24): the alone
2781
+ call closed the claim, so the later page was written as day's end's but no row followed
2782
+ and the night went on reading `nothing-to-say`. The door now finds that alone row
2783
+ (`server-self-tools.ts#daysEndStood`: today, this call's session, the night's server, the
2784
+ night's newest settled row, no dream begun since) and writes a `revised` row carrying the
2785
+ summary over; a summary sent again with the page is the later telling and stands. After
2786
+ the dream begins, a page write is an ordinary amendment, as with an open claim.
@@ -41,7 +41,7 @@ import { existsSync, mkdirSync, readdirSync } from "node:fs";
41
41
  import { join } from "node:path";
42
42
  import { randomBytes } from "node:crypto";
43
43
  import type { Band, Kind, MemoryPhysics, Salience } from "../types.js";
44
- import { isModelId } from "../types.js";
44
+ import { WRITTEN_UP_BY_META_KEY, isKnownSession, isModelId } from "../types.js";
45
45
  import {
46
46
  daysBetween,
47
47
  isCalendarDate,
@@ -1651,7 +1651,7 @@ export class Store {
1651
1651
 
1652
1652
  /**
1653
1653
  * Persist one credited use. The crediting RULE is owned entirely by
1654
- * physics.creditUse (§5.5 tier weights, birth-day / stale-day / same-day
1654
+ * physics.creditUse (§5.5 tier weights, own-write / birth-day / stale-day / same-day
1655
1655
  * refusals, distinct-day counting for §5.3 promotion) — the store applies the
1656
1656
  * verdict absolutely and adds no opinion of its own. One rule, one owner:
1657
1657
  * a second implementation of this arithmetic is exactly the divergence that
@@ -1715,7 +1715,17 @@ export class Store {
1715
1715
  return { credited: false, reason: "a-belief" as const, w: 0, next: unchanged, ret: null };
1716
1716
  }
1717
1717
  const upgradeFrom = opts.upgradeFrom ?? this.partialToday(id, day, row.last_used_day, tier);
1718
- const verdict = creditUse(physics, day, tier, upgradeFrom === undefined ? {} : { upgradeFrom });
1718
+ // THE WRITING SESSION (2026-10-24, R2; physics `OWN_WRITE_GATE`): a fact
1719
+ // only the row holds, handed to physics as the display is. The session
1720
+ // that wrote it is its origin, or the writer of a write-up
1721
+ // (`writtenUpBy`), whose reply carried the words. Unknown — the memory
1722
+ // has no origin session, or the use came with no session (a schemas
1723
+ // mention, a reminder's occurrence) — physics keeps the birth-day rule.
1724
+ const ownWrite = this.ownWrite(row, opts.session ?? null);
1725
+ const verdict = creditUse(physics, day, tier, {
1726
+ ...(upgradeFrom === undefined ? {} : { upgradeFrom }),
1727
+ ...(ownWrite === undefined ? {} : { ownWrite }),
1728
+ });
1719
1729
  let ret: ReturnOutcome | null = null;
1720
1730
  if (verdict.credited) {
1721
1731
  this.ops.run(
@@ -1754,12 +1764,13 @@ export class Store {
1754
1764
  const partial = partialSourceOf(tier);
1755
1765
  ret =
1756
1766
  partial !== null
1757
- ? creditReturn(physics, day, { source: partial, since: this.spacingSince(id) })
1767
+ ? creditReturn(physics, day, { source: partial, since: this.spacingSince(id), ...(ownWrite === undefined ? {} : { ownWrite }) })
1758
1768
  : creditReturn(physics, day, {
1759
1769
  source: "awake",
1760
1770
  tierWeight: verdict.w,
1761
1771
  onDisplay: opts.cued !== true && this.shownInHints(id, day),
1762
1772
  since: this.spacingSince(id),
1773
+ ...(ownWrite === undefined ? {} : { ownWrite }),
1763
1774
  });
1764
1775
  if (ret.counted) this.writeReturn(id, day, ret, null, opts.session ?? null);
1765
1776
  // A PARTIAL CREDIT ON A DAY THAT ALREADY COUNTED A RETURN (a dream's
@@ -1769,7 +1780,10 @@ export class Store {
1769
1780
  // glimpse after the night's dream refused every later use that day.
1770
1781
  // Weight 0 adds nothing to `returns`; the lane columns read only
1771
1782
  // `awake` / `reflection`.
1772
- else if (partial !== null && ret.reason === "already-returned-today") {
1783
+ // Since R2 (2026-10-24) the same holds for a partial credit another
1784
+ // session earned on the memory's birth day (refused `birth-day` as a
1785
+ // return: no gap from birth).
1786
+ else if (partial !== null && (ret.reason === "already-returned-today" || ret.reason === "birth-day")) {
1773
1787
  this.writeReturn(id, day, { ...ret, weight: 0 }, null, opts.session ?? null);
1774
1788
  }
1775
1789
  }
@@ -1836,6 +1850,29 @@ export class Store {
1836
1850
  return outcome;
1837
1851
  }
1838
1852
 
1853
+ /**
1854
+ * Whether `session` wrote this memory (physics `OWN_WRITE_GATE`, R2,
1855
+ * 2026-10-24): its origin session, or the writer of a write-up. Undefined
1856
+ * when it cannot be told — no crediting session, or no origin session on
1857
+ * the row — and physics then keeps the old birth-day refusal. The unbound
1858
+ * server's shared id (`UNBOUND_SESSION`, "mcp") names no session, on either
1859
+ * side: a memory an unbound server wrote may be the crediting session's own
1860
+ * (its hooks know the real id), so it is unknown too (review of #610).
1861
+ */
1862
+ private ownWrite(row: { origin_session: string | null; meta: string | null }, session: string | null): boolean | undefined {
1863
+ if (!isKnownSession(session) || !isKnownSession(row.origin_session)) return undefined;
1864
+ if (row.origin_session === session) return true;
1865
+ if (row.meta !== null && row.meta.includes(WRITTEN_UP_BY_META_KEY)) {
1866
+ try {
1867
+ const meta = JSON.parse(row.meta) as Record<string, unknown>;
1868
+ if (meta[WRITTEN_UP_BY_META_KEY] === session) return true;
1869
+ } catch {
1870
+ // Unreadable meta says nothing about a write-up.
1871
+ }
1872
+ }
1873
+ return false;
1874
+ }
1875
+
1839
1876
  /**
1840
1877
  * The last day of a return the physics fields do not carry, which spacing
1841
1878
  * still measures from (the lanes never read it): a LEGACY return the v8