Repository navigation
Realize add-notebook-projection-identity: the sync binds to a declared account, and the migration is sequenced for Brett's login - #277
Conversation
…unt or refuses Tasks 1.1-1.5, 2.1-2.3 and 4.1 of the ratified add-notebook-projection-identity. The declaration lives at examples/notebook-projection-hosting.yaml, beside the workspace registry for this same projection, and carries Opensoft's Case A on [email protected] plus the share-out roster. TWO CLI FACTS CHANGED THE DESIGN, both verified against the installed nlm rather than assumed. Of the verbs this sync issues — notebook, source, alias, tag, chat — NONE accepts a per-invocation --profile; only the newer share and login verbs do. Profile selection is process-global, through auth.default_profile. So the sync VERIFIES the binding instead of passing it, and refuses when the active profile is not the declared one, carrying the exact remediation command. It never switches the profile itself: that is shared user state and other sessions race on it. A declaration is not a migration. While migration.state is pending the run binds to the account that still HOLDS the books and says so, because flipping the binding before the books move would break every sync rather than move anything. An undeclared install is reported as a transition state, never as a third legitimate case. --parity proves the live books against THE CORPUS SCAN — per-book title-set equality plus a union reconciliation — and mutates nothing, which a test asserts by checking no mutating verb was issued. The roster is validated outside contracts/ by a dedicated script; uniqueness is the stable (hosting_account, user, book_or_alias) triple, so a re-decision updates the one live entry. The reasoning for staying outside contracts/ is written into both files. Co-Authored-By: Claude Fable 5 <[email protected]>
…gin starts Tasks 3.1-3.3 and the procedural halves of 4.2/4.3. Section 1 now names the declared hosting identity and its two cases; section 9 attributes the quota ceiling to the install's one declared account rather than to "one shared account", keeping the capacity point intact; section 6's runbook gains a step 0 that reads and binds the profile, and a --parity step. A new section 12 carries the mechanics: where the declaration lives, why it is not under contracts/, how a run is bound, and what is actually verified — the profile NAME, not the address, because the CLI stores no email for a profile. A PLATFORM CORRECTION is recorded rather than buried. The proposal reasoned that NotebookLM exposes no share or admin API. That holds for the half it was about — there is still no pending-request queue and no approval surface, so the approval stays a human act — but it is not true of sharing generally: nlm share status/invite/batch exist and DO take --profile. So a recorded grant can be applied by tooling and the roster can be reconciled against the live account. Neither changes who decides, and the ratified requirement already permits automating detection and relay, so the correction is documented instead of being folded into ratified text. The migration runbook sequences what only Brett can start: nlm login --profile company as [email protected], then bind, flip the pending flag, re-derive (~40 min), migrate each live session notebook one at a time, replace each workspace record, prove parity against the corpus scan, and retire the legacy books by recorded act WITHOUT retiring the record the replacement just made current. The open operational item stays OPEN by its own terms and now points at the runbook: it closes on the migration, not on the rulings. Co-Authored-By: Claude Fable 5 <[email protected]>
|
@codex review |
There was a problem hiding this comment.
Hi @brettheap! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
There was a problem hiding this comment.
Pull request overview
This PR realizes the ratified add-notebook-projection-identity change by introducing a governed hosting declaration + share-out roster, enforcing that sync runs bind to the declared nlm profile (or refuse), and adding a non-mutating parity-report mode plus supporting docs and tests.
Changes:
- Add
examples/notebook-projection-hosting.yamland a dedicated validator script to enforce the hosting declaration + share-out roster invariants. - Update
scripts/sync-notebooklm-books.pyto read/enforce the declared hosting profile and add--parityreporting against the corpus scan. - Add/extend tests and documentation, including a migration runbook and updated projection operational docs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/notebooklm/test_validate_hosting.py | New unit tests for the hosting/roster validator behavior. |
| tests/notebooklm/test_sync_notebooklm_books.py | New tests for enforcing the declared hosting profile and --parity behavior. |
| scripts/validate-notebook-projection-hosting.py | New validator for examples/notebook-projection-hosting.yaml and share-out roster uniqueness rules. |
| scripts/sync-notebooklm-books.py | Enforces declared hosting profile; adds --parity reporting mode. |
| README.md | Adds link to the new hosting migration runbook doc. |
| openspec/changes/add-notebook-projection-identity/tasks.md | Marks realized tasks and records the design adjustments. |
| examples/notebook-projection-hosting.yaml | Adds the governed hosting declaration and placeholder roster/denied lanes. |
| docs/notebooklm-sync-open-item.md | Updates the open operational item status and points to the runbook. |
| docs/notebook-projection-migration-runbook.md | New step-by-step migration procedure and evidence sequencing. |
| docs/lifecycle-notebook-projection.md | Documents declared hosting identity, binding mechanics, sharing-out behavior, and parity proof. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| run = runner or nlm | ||
| try: | ||
| out = run("config", "get", "auth.default_profile", parse=False) | ||
| except Exception: # noqa: BLE001 - an unreadable profile is "unknown" | ||
| return None | ||
| return out.strip() or None if isinstance(out, str) else None |
There was a problem hiding this comment.
Refuted as a bug — but the line was hard enough to read that a reviewer misparsed it, so it is rewritten anyway and now has a regression test.
Python's conditional expression binds LAST: out.strip() or None if isinstance(out, str) else None parses as (out.strip() or None) if isinstance(out, str) else None, so the isinstance check is the condition and is evaluated FIRST. The true-branch .strip() only runs when out is already a string. Demonstrated against the real function:
runner returns {} -> None
runner returns [] -> None
runner returns None -> None
runner returns 42 -> None
runner returns " company " -> "company"
runner returns "" -> None
No AttributeError on any non-string path, including the {} your comment names — that is exactly what FakeNlm returns for unknown verbs, so the existing suite was already exercising it.
Changes made regardless, because "correct but misread" is worth fixing in a guard whose whole job is to refuse cleanly:
- the expression is now an explicit early return (
if not isinstance(out, str): return None); - a new subtest asserts
{},[],Noneand42all yieldNonerather than raising, since an exception here would escape the guard instead of becoming the governed refusal.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f315952d4b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # reaches the CLI — session notebooks and imports are created in the same | ||
| # account as the lifecycle books, so they are bound by the same rule. A run | ||
| # that cannot prove which account it writes to must not write at all. | ||
| enforce_hosting_profile(args.root) |
There was a problem hiding this comment.
Keep the profile binding stable for the whole run
When another terminal runs nlm login switch after this one-time check, every subsequent nlm() subprocess can read the new process-global default and add or delete sources in the wrong account. The recorded CLI semantics explicitly acknowledge that same-host sessions race on this setting (docs/lifecycle-notebook-projection.md:395-402), while the governing delta requires every invocation to remain bound (openspec/changes/add-notebook-projection-identity/specs/lifecycle-notebook-projection/spec.md:143-147). A single check before a roughly 40-minute apply therefore does not bind the run; use isolated profile configuration or otherwise prevent/recheck profile changes at each invocation boundary.
AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Accepted — and you caught it with my own documentation, which is the right way to lose an argument. Section 12 says same-host sessions race on the process-global setting, and I then shipped a one-time check in front of a forty-minute apply. That binds nothing.
Fixed: nlm() now re-asserts the binding BEFORE EVERY invocation. It reads auth.default_profile straight from ~/.notebooklm-mcp-cli/config.toml rather than shelling out — a stat, not a subprocess, cached on the file's own (mtime_ns, size) stamp, so the per-call cost is negligible across thousands of invocations. On drift it refuses the NEXT invocation before the subprocess runs, names the re-bind command, and relies on the sync being idempotent so a resumed run is a no-op over whatever finished.
Isolated profile configuration was the other option you offered; I did not take it because the CLI exposes no config-path or profile environment override I could verify, and inventing one would have been a guess. Detect-and-refuse is provable today.
Production now reads the profile from ONE source — the same file the assertion re-reads — since two readers of one fact can disagree and this one gates the other.
Five tests cover it, and the revert-test earned its keep: neutering the drift check failed 2 tests, but REMOVING the assert_still_bound() call from nlm() left all of them passing. A detector nothing invokes is decoration, so there is now a test that drives the real nlm() with a drifted config and a stubbed subprocess.run, asserting both that it raises and that subprocess.run was never reached.
| _HOSTING_SCALARS = ("case", "account", "nlm_profile") | ||
| _HOSTING_MIGRATION_SCALARS = ("state", "from_account", "from_nlm_profile") |
There was a problem hiding this comment.
Validate the declaration before accepting it
When the declaration says operator_hosted but names a consumer or service account, this narrow reader ignores account_type and domain, and enforce_hosting_profile() proceeds whenever the named profile is active. The separate validator would reject that configuration, but a repository-wide search found no sync caller or workflow that invokes it, so the normal operational path does not enforce the refusal required by openspec/changes/add-notebook-projection-identity/specs/lifecycle-notebook-projection/spec.md:23-29. Run the validator before any CLI operation or enforce the relevant fields directly in the sync.
AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Accepted. The repository-wide search is correct: nothing the sync runs invoked the validator, so an operator-hosted declaration naming a consumer or service account would have sailed through an ordinary --apply. A refusal that only fires in a script nobody calls is not a refusal.
Fixed by enforcing the load-bearing rules INLINE on the operational path, in _refuse_unusable_declaration(), called from enforce_hosting_profile() before any CLI work: the two-case vocabulary, account_type: google_workspace_user for the operator-hosted case, the service-account refusal stated on the platform constraint (no API, and a service principal cannot drive the consumer web UI), and the account-must-be-in-the-declared-domain check. Dependency-free, so the sync keeps carrying no YAML requirement.
I did not run the validator as a subprocess from the sync, which was your other suggestion, because it would add a PyYAML dependency to a script deliberately without one and make the refusal conditional on that import succeeding. The split is now explicit in both files: the sync enforces what a run must not proceed without; the validator remains the authority on the rest, including the roster shape a sync never reads.
Four tests assert the refusals fire from enforce_hosting_profile() itself, and the revert-test confirms it — deleting the inline call fails 4 of them.
…n where runs happen Codex's two findings on PR #277, both real. P1: a single check before a forty-minute apply does not bind the run. Profile selection is process-global, and my own section 12 says same-host sessions race on it — so another terminal running nlm login switch mid-run would have redirected every later add and delete into a different account. nlm() now re-asserts the binding before every invocation, reading auth.default_profile from the CLI's config file directly: a stat rather than a subprocess, cached on the file's own (mtime_ns, size) stamp. On drift it refuses the next invocation before the subprocess runs, names the re-bind command, and leans on the sync being idempotent so a resumed run is a no-op over what finished. P2: the validator was invoked by nothing the sync runs, so an operator-hosted declaration naming a consumer or service account would have passed an ordinary --apply. The load-bearing rules are now enforced inline and dependency-free on that path — the two-case vocabulary, the Workspace-user requirement, the service-account refusal on the platform constraint, and the account-in-declared- domain check. The validator stays the authority on what a sync never reads. Production now reads the profile from ONE source: the same config file the per-invocation assertion re-reads, since two readers of one fact can disagree and this one gates the other. Thirteen more tests, and all three new guards are revert-tested. The third caught something the first two did not: removing the assert_still_bound() call from nlm() left every test passing, so the wire — not just the check — is now asserted by driving the real nlm() with a drifted config and a stubbed subprocess, proving the refusal lands BEFORE anything is written. Copilot's AttributeError report is refuted on the record (the conditional binds last, so the isinstance check runs first), but the line was rewritten as an early return anyway and now has its own regression subtest. Co-Authored-By: Claude Fable 5 <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
scripts/validate-notebook-projection-hosting.py:161
validate()returns errors that are already prefixed with the fullpath(e.g.f"{path}: unreadable"), butmain()prints each error asf"{path.name}: {error}". This yields duplicated paths likenotebook-projection-hosting.yaml: /abs/path/...: unreadable ..., making CLI output noisier and harder to scan.
try:
record = yaml.safe_load(path.read_text(encoding="utf-8"))
except (OSError, yaml.YAMLError) as exc:
return [f"{path}: unreadable ({exc})"]
if not isinstance(record, dict):
| found[key] = value | ||
| elif indent == 4 and in_migration and key in _HOSTING_MIGRATION_SCALARS: | ||
| found[f"migration_{key}"] = value | ||
| return found or None |
…rivation, not after One blocking finding and five should-fixes, each reproduced before it was fixed. B1, blocking. The alias store is ONE flat, profile-independent file, and resolve_or_create_book() registers an alias on the FOUND path as well as the created one. So the runbook's re-derivation would have repointed xf-canon, xf-drafts and every xf-ideation-* to the new notebooks before the operator ever reached the step that must DELETE those aliases rather than repoint them — by which time the ratified rule could not be honoured and the legacy notebook ids were no longer recoverable from the store. The runbook now records the ids and deletes the aliases in step 1, before any --apply, which is the 2026-08-10 order; the remaining steps are renumbered and the stranding window between binding the host and flipping the state is stated as deliberate. S1: --parity issued three alias set calls while its docstring and two doc sections promised it never mutates. Alias binding is now off for the read-only caller and the test's blocklist covers alias set and alias delete. S2: a hosting file this narrow reader could not parse — flow style, four-space indent, tabs, all valid YAML that the validator passes — took the UNDECLARED branch, so the sync bound nothing and ran the entire job unbound. An existing file now always yields a dict, and an empty one refuses. Present-but-unreadable is not absent. S3: migration.state: in_progress failed the validator and passed the sync, which then bound the declared profile while the books were still in the previous account. The sync now owns the state vocabulary and the pending-requires-from_nlm_profile rule, so one rule has one owner. S4: "the CLI stores no email for a profile" was simply false — profiles/<name>/metadata.json carries it, populated by a recent login and null by an older one. The sync now compares it to the declared account when present, reports null as unknown rather than as a match, and the claim is corrected in the docstring, section 12 and the runbook gate. S5: the runbook's step references were off by one exactly where an operator could strand a host between profiles. Notes recorded, not fixed: the workbench's own unbound nlm path (named inside task 4.2's deferral), the microsecond TOCTOU that cannot be closed without a per-invocation flag the CLI does not offer, the validator's absence from CI, the self_hosted and denied: field-discipline gaps, and the two share-lane descriptions now reconciled as one act with two interfaces. All five new guards revert-tested individually. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Adversarial round taken — 1 blocking + 5 should-fix, each REPRODUCED before it was fixed, all on this branch ( B1 (blocking) — the re-derivation repointed the aliases the retirement had to delete. Reproduced: S1 — S2 — fail-OPEN on an unparseable declaration. Reproduced for flow style, four-space and tabs: reader returned S3 — state vocabulary enforced by one gate. Reproduced: S4 — the no-email claim was false. Verified live: S5 — off-by-one at the stranding point. Fixed, and the refuse-window between binding the host and flipping Notes recorded, not fixed (N1-N5) — in All five new guards revert-tested individually — and the revert-test caught my own sloppiness once: my first attempt mutated an unrelated Gates: Not merging — the orchestrator gates it. |
| if not isinstance(migration, dict): | ||
| _err(errors, "hosting.migration: must be a mapping when present") | ||
| elif migration.get("state") == "pending": | ||
| for field in ("from_account", "from_nlm_profile"): | ||
| if not migration.get(field): | ||
| _err(errors, f"hosting.migration.{field}: a PENDING " | ||
| f"migration must name where the books still " | ||
| f"live — the sync binds there until they move") | ||
| elif migration.get("state") not in (None, "complete"): | ||
| _err(errors, f"hosting.migration.state: {migration.get('state')!r} " | ||
| f"is neither 'pending' nor 'complete'") |
| unsolved about authenticating a Workspace user to the CLI rather than | ||
| implying it is routine. | ||
| - [ ] 3.3 Cross-link the two-case custody rule to `credential-contracts` so the | ||
| - REALIZED 2026-08-23: §6 gains step 0 (read and bind the profile) and step 2b (`--parity`), and says plainly that profile selection is process-global and what is verified is the profile NAME, not the address — the CLI stores no email. |
Direct realization of the ratified
add-notebook-projection-identity(Brettruled both the ratification and the DIRECT mode on 2026-08-23; record:
openspec/changes/add-notebook-projection-identity/review/ratification-2026-08-23.md).Everything here lands and gates green WITHOUT the migration having run. The
live cutover is gated on an interactive
nlm loginonly Brett can perform; itis sequenced as a runbook, not attempted here. The change stays ACTIVE and is
NOT archived —
target_release: implementation_pendingarchives it on themigration evidence.
Two verified CLI facts changed the design
Both checked against the installed
nlm, not assumed:--profileon the verbs this sync issues.notebook,source,alias,tag,chat— none of them take it; only thenewer
shareandloginverbs do. Profile selection is process-global,through
auth.default_profile. So the sync verifies the binding ratherthan passing it: it refuses to run when the active profile is not the
declared one, and prints the exact
nlm login switchremediation. It neverswitches the profile itself — that is shared user state and other sessions on
the host race on it.
nlm shareexists —status --json,invite --role,batch, and theydo take
--profile. The proposal reasoned that "NotebookLM exposes no shareor admin API". That holds for the half it was about — there is still no
pending-request queue and no approval surface, so the approval stays a human
act — but it is not true of sharing generally. A recorded grant can therefore
be applied by tooling and the roster can be reconciled against the live
account. Neither changes who decides, and the ratified requirement already
permits automating detection and relay, so this is documented as a
correction (§12 of the projection doc) rather than folded into ratified
text on my own authority.
The roster form decision — and the ritual that did NOT fire
Decided: a governed YAML OUTSIDE
contracts/, atexamples/notebook-projection-hosting.yaml, validated by a dedicatedscripts/validate-notebook-projection-hosting.py.Reasoning, written into both files rather than left implicit: the record is the
operator's own governance artifact for one install's tooling account — no
other repository, install or domain consumes it and nothing pins it, which is
what
contracts/membership is for. Its siblingexamples/lifecycle-notebook-workspaces.yaml, the workspace registry for thissame projection, read and written by the same script, sits there for exactly
that reason.
The decision is made on the consumer/ownership test, not on the cost of the
ritual. Promoting the shape into
contracts/remains available as a laterdeliberate act if a second install ever needs to interoperate on it — and that
act, not this one, would carry the release ritual.
contracts/is untouched, asserted in the gates. No CHANGELOG allocation, nomanifest row, no
contract_bundle_versionbump, no inventory rebuild, noverify-commit, no tag. The bundle stays at
contract-v1.40.What landed
examples/notebook-projection-hosting.yaml): Opensoft'sCase A on
[email protected], a Workspace user inopensoft.one,profile
company, with the migration recorded aspendingfrom[email protected]/personal, plus the share-out roster and adeniedlane.
enforce_hosting_profile): a declared install whoseCLI points elsewhere refuses with the remediation command. An undeclared
install is reported as a nonconforming transition state, never a third
case, and still runs. A declaration is not a migration — while
migration.state: pendingthe run binds to the account that still HOLDS thebooks and says so, because flipping the binding before the books move would
break every sync rather than move anything.
--parity: per-book title-set equality plus a union reconciliationagainst the corpus scan — never against the legacy books, which are the
artifact whose fidelity is in question — reporting
0 pending ADD/DEL/UPDorthe exact misses. A test asserts it issues no mutating verb.
refusal on the platform constraint, domain match, the profile the sync binds
through, pending-migration fields, and roster uniqueness on the stable
(hosting_account, user, book_or_alias)triple.a
--paritystep), §9 (the quota belongs to a named account), and a new §12with the mechanics and the platform correction. A new migration runbook.
The open operational item stays OPEN by its own terms and points at it.
tests/notebooklm/(sync guards, per-invocationbinding, and the validator), every new guard revert-tested.
What is deliberately NOT done
Tasks 4.2 and 4.3 are annotated, not ticked. The runbook carries the explicit
per-session procedure and the record-replacement step; the code-level bulk mode
and teaching
ensure_workspace_record()to replace belong with the migrationrun, not before it. Tasks 4.4–4.7 and 5.1 are the migration itself.
The command Brett runs to start the migration
In a host shell with a browser, signing in as
[email protected]:(add
--wslon WSL2 without a Linux browser). Thennlm login switch company,flip
migration.statetocomplete, and the re-derivation is one--applyrun of roughly 40 minutes (the 2026-08-10 precedent moved 314 sources in about
that). Full sequence, including the live-session and workspace-record steps that
the lifecycle run does not cover:
docs/notebook-projection-migration-runbook.md.Review round
Codex — two findings, both real, both fixed.
PR's own documentation: §12 says same-host sessions race on the
process-global profile, and I shipped a single opening check.
nlm()nowre-asserts the binding before every invocation, reading
auth.default_profilefrom the CLI's config file directly — a stat, not asubprocess, cached on the file's
(mtime_ns, size)stamp — and refuses thenext call the moment it drifts, before
subprocess.runis reached. Isolatedprofile configuration was the alternative; the CLI exposes no config-path or
profile env override I could verify, so detect-and-refuse is what is provable
today.
operator-hosted declaration naming a consumer or service account would have
passed an ordinary
--apply. The load-bearing rules are now enforced inlineand dependency-free on that path; the validator stays the authority on what a
sync never reads, including the roster shape.
Copilot — refuted, and the line rewritten anyway. It reported an
AttributeErrorinactive_nlm_profile(); Python's conditional expressionbinds last, so the
isinstancecheck is the condition and runs first —demonstrated against the real function for
{},[],Noneand42, allreturning
None. The expression is now an explicit early return regardless,with a regression subtest, because a guard whose job is to refuse cleanly should
not be misreadable.
All three new guards are revert-tested, and the third earned it: neutering
the drift check failed 2 tests, but removing the
assert_still_bound()callfrom
nlm()left every test passing. A detector nothing invokes is decoration,so there is now a test driving the real
nlm()with a drifted config and astubbed subprocess, asserting the refusal lands before anything is written.
Gates
pytest tests/ideation-dashboard— 3983 passed, 15 skippedpytest tests/notebooklm tests/doc-health tests/ideation_dashboard— 890passed, 10 subtests
openspec validate --all --strict— 69 passed, 0 failed (69 items)origin/main(0ce4f6f8) baseline — 0 newfindings (4 critical / 6 error / 77 warning / 3 info both sides)
scripts/validate-ideation-dashboard-contracts.py— 0 errors, 4 warningsscripts/validate-notebook-projection-hosting.py— 0 errorscontracts/untouched — no contract-release ritual🤖 Generated with Claude Code