Skip to content

A session notebook never outlives its session: reconcile the namespace - #163

Merged
brettheap merged 2 commits into
mainfrom
change/session-notebook-reconciliation
Aug 10, 2026
Merged

brettheap merged 2 commits into
mainfrom
change/session-notebook-reconciliation

Conversation

@brettheap

Copy link
Copy Markdown
Contributor

Brett, 2026-08-10: "fix the session teardown notebook gap" — the gap PR #161's
brainstorm captured after two orphans had to be deleted by hand.

Through the protocol rather than straight into the code, because this is
GOVERNED DELETION on an account shared across the family: brainstorm ->
ideation/staging/session-notebook-reconciliation/ (+ INDEX row) ->
add-session-notebook-reconciliation (deltas to lifecycle-notebook-projection
and ideation-dashboard) -> realization here.

THE GAP. Both governed endings retire the session notebook. Sessions also end a
third way — a probe clears up, crash residue is swept, someone runs
git worktree remove — and that way retires nothing. --session-ref --session-retire cannot clean it up BY DESIGN: it resolves liveness first and
refuses a dead branch, which is exactly what stops it inventing a session and
retiring a LIVE one's notebook. So the dead case gets its own door, and it
establishes death differently: from no live session anywhere claiming the
notebook.

--session-sweep, report-only by default:

  • FORWARD-DERIVED. notebook_alias is injective but not invertible (the
    readable half strips draft/ and lowercases; the key half is a digest), so
    a title can never be resolved back to a (repository, branch). The mode
    computes every live session's alias and treats an xf-session- notebook
    matching none as dead.
  • FAIL CLOSED. A repository it cannot enumerate looks exactly like one whose
    sessions have ended, and the difference is unrecoverable after a delete. Any
    such repository refuses the whole run and retires nothing.
  • WORKSPACE-SCOPED, by PREFIX not by parsing: repository names and flattened
    branches both contain hyphens, so any title parse is ambiguous exactly where
    being wrong deletes someone else's notebook.
  • retire, never a scratch delete — the same operation both governed
    endings take, with its own session-prefix guard. An adapter without it
    refuses loudly.

THE LIVE DRY RUN EARNED ITS PLACE IN THE TASK LIST. Its first run reported BOTH
of Brett's live sessions as dead:

DEAD xf-session-openxfactory-subject-document-estate-… (discards 10 sources)
DEAD xf-session-openxfactory-company-provisioning-… (discards 11 sources)

With --apply that retires two live sessions' notebooks over unmerged work. The
cause: a session's container is keyed on the checkout it was OPENED FROM
(<checkout>-worktrees/sessions/), and both were opened from a FEATURE
WORKTREE — not the canonical checkout the enumeration asked. Fail-closed could
not fire and never could: "no sessions in this checkout" is a legitimate answer,
indistinguishable from "the sessions are in another worktree". No unit test
could see it either, because they all stub the enumeration.

The enumeration is now COMPLETE — every worktree git lists for the repository,
which is readable precisely because linked worktrees share one git dir — and a
failure to read that list is an error, not an answer. Second run:

KEEP xf-session-openxfactory-subject-document-estate-… (a live session claims it)
KEEP xf-session-openxfactory-company-provisioning-… (a live session claims it)
2 live session(s); no orphans

Pinned by test_a_session_opened_from_a_feature_worktree_is_seen_as_live
against a real repository with a real linked worktree, and stated as a
requirement in the delta.

A second fail-safe fell out of writing the tests and is pinned too: a workspace
resolving NO session repositories retires nothing — pointing this mode at the
wrong root is inert rather than destructive.

live_session_branches_of lands in branch_session.py, beside
live_session_worktree, so the projection tooling still cannot invent a second
liveness rule (PR #49 finding 12). It returns (branches, errors) because every
failure mode yields FEWER branches, and a bare list would make a broken checkout
look like a clean one.

Runbook §4a: which mode cleans up after a hand teardown, why the targeted route
still refuses a dead branch, and the run-from-the-workspace-root rule.

Suites: tests/ideation-dashboard + tests/ideation_dashboard + tests/notebooklm —
2945 passed, 19 skipped (exit 0). openspec validate --all --strict 57/0.
doc-health exit 0, errors unchanged at 5 pre-existing.

Also lists the change in openxFactory README's OpenSpec Records (its own
commit).

🤖 Generated with Claude Code

brettheap and others added 2 commits August 10, 2026 11:07
Brett, 2026-08-10: "fix the session teardown notebook gap" — the gap PR #161's
brainstorm captured after two orphans had to be deleted by hand.

Through the protocol rather than straight into the code, because this is
GOVERNED DELETION on an account shared across the family: brainstorm ->
`ideation/staging/session-notebook-reconciliation/` (+ INDEX row) ->
`add-session-notebook-reconciliation` (deltas to `lifecycle-notebook-projection`
and `ideation-dashboard`) -> realization here.

THE GAP. Both governed endings retire the session notebook. Sessions also end a
third way — a probe clears up, crash residue is swept, someone runs
`git worktree remove` — and that way retires nothing. `--session-ref
--session-retire` cannot clean it up BY DESIGN: it resolves liveness first and
refuses a dead branch, which is exactly what stops it inventing a session and
retiring a LIVE one's notebook. So the dead case gets its own door, and it
establishes death differently: from no live session anywhere claiming the
notebook.

`--session-sweep`, report-only by default:

  * FORWARD-DERIVED. `notebook_alias` is injective but not invertible (the
    readable half strips `draft/` and lowercases; the key half is a digest), so
    a title can never be resolved back to a (repository, branch). The mode
    computes every live session's alias and treats an `xf-session-` notebook
    matching none as dead.
  * FAIL CLOSED. A repository it cannot enumerate looks exactly like one whose
    sessions have ended, and the difference is unrecoverable after a delete. Any
    such repository refuses the whole run and retires nothing.
  * WORKSPACE-SCOPED, by PREFIX not by parsing: repository names and flattened
    branches both contain hyphens, so any title parse is ambiguous exactly where
    being wrong deletes someone else's notebook.
  * `retire`, never a scratch `delete` — the same operation both governed
    endings take, with its own session-prefix guard. An adapter without it
    refuses loudly.

THE LIVE DRY RUN EARNED ITS PLACE IN THE TASK LIST. Its first run reported BOTH
of Brett's live sessions as dead:

  DEAD xf-session-openxfactory-subject-document-estate-…  (discards 10 sources)
  DEAD xf-session-openxfactory-company-provisioning-…     (discards 11 sources)

With --apply that retires two live sessions' notebooks over unmerged work. The
cause: a session's container is keyed on the checkout it was OPENED FROM
(`<checkout>-worktrees/sessions/`), and both were opened from a FEATURE
WORKTREE — not the canonical checkout the enumeration asked. Fail-closed could
not fire and never could: "no sessions in this checkout" is a legitimate answer,
indistinguishable from "the sessions are in another worktree". No unit test
could see it either, because they all stub the enumeration.

The enumeration is now COMPLETE — every worktree git lists for the repository,
which is readable precisely because linked worktrees share one git dir — and a
failure to read that list is an error, not an answer. Second run:

  KEEP xf-session-openxfactory-subject-document-estate-…  (a live session claims it)
  KEEP xf-session-openxfactory-company-provisioning-…     (a live session claims it)
  2 live session(s); no orphans

Pinned by `test_a_session_opened_from_a_feature_worktree_is_seen_as_live`
against a real repository with a real linked worktree, and stated as a
requirement in the delta.

A second fail-safe fell out of writing the tests and is pinned too: a workspace
resolving NO session repositories retires nothing — pointing this mode at the
wrong root is inert rather than destructive.

`live_session_branches_of` lands in `branch_session.py`, beside
`live_session_worktree`, so the projection tooling still cannot invent a second
liveness rule (PR #49 finding 12). It returns `(branches, errors)` because every
failure mode yields FEWER branches, and a bare list would make a broken checkout
look like a clean one.

Runbook §4a: which mode cleans up after a hand teardown, why the targeted route
still refuses a dead branch, and the run-from-the-workspace-root rule.

Suites: tests/ideation-dashboard + tests/ideation_dashboard + tests/notebooklm —
2945 passed, 19 skipped (exit 0). openspec validate --all --strict 57/0.
doc-health exit 0, errors unchanged at 5 pre-existing.
…ords

The convention every active change follows (CLAUDE.md working rules): a new
active change is listed in openxFactory's README so the record is discoverable
without walking `openspec/changes/`.

Carries the finding worth reading before running the mode: the owed live dry run
called two LIVE sessions dead, because a session's container is keyed on the
checkout it was opened FROM and both were opened from a feature worktree the
enumeration never asked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings August 10, 2026 15:09

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @brettheap! 👋

Your private repo does not have access to Sourcery.

Please upgrade to continue using Sourcery ✨

@brettheap
brettheap merged commit 1b964ba into main Aug 10, 2026
1 check passed
@brettheap
brettheap deleted the change/session-notebook-reconciliation branch August 10, 2026 15:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a governed “session notebook reconciliation” path so xf-session-* notebooks can be safely retired when their underlying branch session has already ended (e.g., probe/crash cleanup or manual git worktree remove), while failing closed on incomplete workspace knowledge and scoping decisions to the current workspace’s repositories.

Changes:

  • Introduces --session-sweep mode in scripts/sync-notebooklm-books.py to report (default) and optionally retire (--apply) orphaned xf-session-* notebooks based on forward-derived live-session aliases.
  • Extends session liveness enumeration to cover every git-linked worktree of each repository, and adds live_session_branches_of() to expose (branches, errors) for fail-closed callers.
  • Adds OpenSpec change record + staging docs/runbook updates and regression/unit coverage for the new reconciliation behavior (including the “feature worktree” near-miss).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/notebooklm/test_sync_notebooklm_books.py Adds end-to-end unit coverage for session sweep classification, refusal modes, and apply/report behavior.
tests/ideation-dashboard/test_branch_session.py Adds tests for the new (branches, errors) shape from live_session_branches_of().
scripts/sync-notebooklm-books.py Implements --session-sweep, forward-derived classification, fail-closed refusal, and complete worktree enumeration for liveness.
scripts/ideation_dashboard/branch_session.py Adds live_session_branches_of() to enumerate live sessions on a checkout and surface enumeration errors.
README.md Registers the new OpenSpec change and summarizes its rationale/constraints.
openspec/changes/add-session-notebook-reconciliation/tasks.md Tracks the change’s tasks, coverage, and evidence obligations.
openspec/changes/add-session-notebook-reconciliation/specs/lifecycle-notebook-projection/spec.md Specifies reconciliation requirements and fail-closed/workspace scoping rules.
openspec/changes/add-session-notebook-reconciliation/specs/ideation-dashboard/spec.md Specifies the new governed retirement route for already-ended sessions.
openspec/changes/add-session-notebook-reconciliation/proposal.md Captures motivation, safety properties, and impact for the change.
openspec/changes/add-session-notebook-reconciliation/.openspec.yaml Adds OpenSpec metadata for the change record.
ideation/staging/session-notebook-reconciliation/session-notebook-reconciliation.md Adds staged topic capturing the gap, decisions, and exit path.
ideation/staging/INDEX.md Indexes the new staged topic and summarizes its scope/status.
docs/ideation-dashboard-session-runbook.md Documents the operational runbook for cleaning up after hand teardowns via --session-sweep.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 1443 to 1444
if __name__ == "__main__":
unittest.main()
Comment on lines +1406 to +1409
# The session namespace's prefix, spelled ONCE and taken from the module that
# owns it rather than re-typed: `workbench.SESSION_NOTEBOOK_PREFIX` is what the
# adapter's own listing and prefix guards use.
SESSION_ALIAS_PREFIX = "xf-session-"
Comment on lines +1416 to +1417
class SessionSweepRefused(RuntimeError):
"""The reconciliation refused: it could not account for every repository."""
Comment on lines +1544 to +1551
wb = _dashboard_module("workbench")
rows = {}
for nb in listing.rows:
title = wb._notebook_title(nb)
if title:
rows[title] = nb
verdicts = classify_session_notebooks(rows, aliases,
session_repository_slugs(pairs))
brettheap pushed a commit that referenced this pull request Aug 13, 2026
…her four

`release-realization`'s archive gate says a change with a non-empty code surface
archives when realization evidence exists — merged on the implemented target,
plus a green run — and that promoted specs then describe what the code does. Six
active changes were ratified (not seven; my earlier count was wrong). Checked one
at a time against the gate rather than archived as a batch, because they do not
all pass it:

ARCHIVED — evidence exists, no task left open:

  * align-doxbench-contract-pin-to-publisher — 0 open tasks, `Realized:` recorded
    (5d8e963, PR #164, green + live browser proof). Promotes 1 requirement each
    into `ideation-dashboard` and `shared-contract-ownership`.
  * add-session-notebook-reconciliation — its ONLY open task was 4.3, "Archive on
    realization evidence per release-realization", so archiving is the act that
    closes it. Realization is 1b964ba (PR #163) with the suite green; the evidence
    is now recorded as a `Realized:` line, because the gate requires it to EXIST
    rather than merely to be true. Promotes 1 requirement each into
    `ideation-dashboard` and `lifecycle-notebook-projection`.

LEFT ACTIVE, with the reason:

  * add-shared-identity-seeds — task 5.1 is unbuilt WORK (promote the detector to
    a fifth neutrality-drift signal), not a dogfood step. Not realized.
  * add-hermes-customer-subject-runtime-contract — 10 of 13 tasks open.
  * add-lens-document-selection — one open task, and it is Brett's own first real
    staging seed from the lens.
  * add-composed-view-authoring — same shape: Brett's first real create from a
    project view.

The last two are a DISPOSITION CALL rather than a gate failure: their code is
merged and green, and what remains is a human validation. Archiving them would
promote their deltas while the person who asked for the feature has not yet used
it once, so they stay active until Brett says otherwise.

Two defects the gate caught, both mine:

  * The change I authored had NO `.openspec.yaml`, so it carried no origin
    declaration and `proposal-origin` failed the moment it archived (errors 5 ->
    6). Added at the archive gate, declared ad_hoc with the real authoring dates
    and an explicit note that only the file is late — the alternative, back-dating
    silently, would have made the record lie about itself.
  * The README still listed both changes under "Active changes". Retired both
    entries; 45 lines.

Also flagged, not fixed: `target_release: none` is not a legal value — the axis
allows `implemented` or a named release, and `none` belongs to `code_surface`.
Five sibling changes carry the same mis-spelling, so it is recorded in the
archived task ledger rather than corrected under cover of an archive commit.

Gates: `openspec validate --all --strict` 56 passed / 0 failed; doc-health back
to its pre-existing 5 errors with 0 new regressions.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants