Skip to content

Record a session's own writes in a CLI journal; report a deleted item apart from a failed read (#3642) - #3662

Merged
malibio merged 2 commits into
mainfrom
issue-3642-cli-write-journal
Oct 6, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-3642-cli-write-journal

Conversation

@malibio

@malibio malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #3642.

The CLI now journals node writes (id, database, new version) to <home>/.nodespace/journals/<session>.jsonl when NODESPACE_WRITE_JOURNAL names a session. The Claude Code plugin sets that variable at session start and after a /clear, and reads the journal only when the watched item's version moved: a version the journal holds is the session's own. The shell-line write attribution (mayWrite, isRead, the forced check before a write, the re-read after one, in-flight counters) is deleted. node context --version-only --json on a missing node prints {"error":"not_found","node_id":...} and exits non-zero; the plugin refuses tool calls for that, and still says nothing for any other failed read. A hidden journal end <session> removes a session's journal and journals idle for an hour.

Tests: CLI unit and integration tests, test:plugin (script, loop, background, nodespace-tool writes through the journal; concurrent foreign write; deleted item; unreadable journal).

🤖 Generated with Claude Code

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

Review Type: Initial review (no prior reviews or comments on PR #3662).

The design is sound and small. The CLI records {node_id, database, version} as a single O_APPEND write, with failures swallowed. The plugin reads the journal only when the version differs, and mayWrite, isRead, writesInFlight and ownMoves are gone from the Claude Code plugin. The session id is validated on both sides, with the same regex in Rust and in TS, so it cannot name a path. The not_found output is narrowly matched on code and on the exact Not found: <id> message. There are no backward-compat shims, lint suppressions or Pro markers. There are no blockers, but a few attribution and spec-fidelity gaps are worth fixing before merge.

Requirements Check

  • ✅ Plugin sets the session-naming env var at session start and after /clear (nameSession, test at register.test.ts:392)
  • ✅ Node writes (create, update, set-status, move, reorder, delete, batch-update) append id, database and version, and write nothing without the variable. ⚠️ See finding 1 on batch-update's version read-back.
  • ✅ Script, loop and background writes each have a test. The writes are simulated in the fake world, so the CLI-side proof is every_node_write_is_journaled....
  • 🟡 "Another process's change during the session's own write is still reported": covered only when the other write is the node's final version (see finding 2)
  • ✅ The Claude Code plugin holds no read/write command list and makes no extra CLI calls around the agent's commands. The shared Pi/OpenCode module plugins/shared/nodespace-session.ts still has mayWrite/isRead, which is out of scope here (Ship Pi and OpenCode plugins that list NodeSpace's skills in the session, and an instructions block for harnesses without one #3546).
  • ✅ The journal holds ids and versions only, lives under <NodeSpace home>/.nodespace/journals, and is removed on session.end
  • ❌ "A journal left by a crashed session is removed at the next session start": it is removed only once idle for 1 hour (finding 3)
  • ✅ Journal failures never fail the command or block a tool call (quietly, ignored IO errors, own === null is treated as "report nothing")
  • ✅ A missing-node context read prints {"error":"not_found","node_id"} with --json and exits non-zero. 🟡 The stdout is not asserted (finding 4).
  • ✅ A deleted item refuses tool calls, and other failures say nothing
  • ✅ README no longer says a script write stops the session; cli.md is updated
  • ⚪ test:plugin, quality:fix and test:changed were not re-run by this reviewer

Findings

Critical Issues

None.

Suggested Improvements

  1. 🟡 packages/cli/src/commands/node.rs record_batch: attribution race (correctness). The batch response carries ids and not versions, so the CLI re-reads them with get_nodes_batch. If another process writes one of those nodes between the batch and the read-back, the other writer's version is journaled as the session's own and the change is silently absorbed. That is the false negative this issue exists to remove. Prefer returning the new versions in UpdateNodesBatchResponse (the daemon has them at write time, and the issue says "a write's new version is in the response"). Otherwise document the window.
  2. 🟡 register.ts checkItem (own.get(item.id)?.has(now.nodeVersion)): attribution is by the node's final version only. If someone else writes v5 and the session then writes v6 between two checks, v6 is in the journal and v5 is absorbed. The issue's "latest-version" rule has the same limit. The cheap mitigation is to require that the journal's lowest version for that node, above the baseline's, equals item.nodeVersion + 1, or to say in the comment that only the final version is attributed. Please at least make the limit explicit.
  3. 🟡 packages/cli/src/journal.rs end_in / STALE_AFTER: the acceptance criterion says a crashed session's journal is removed at the next session start. The code removes it only when idle for at least 1 hour, so a crash followed by a quick restart leaves it until a later start or end. The same rule can also delete a live session's journal after an hour of idleness, for example while a long background command is still running. If the 1-hour rule is a deliberate decision, update the issue and docs. Otherwise the plugin could prune journals whose session id is not in the live set.
  4. 🟡 packages/cli/tests/it/cli_integration.rs a_context_read_of_a_missing_node_is_an_error_naming_it: it calls node_run with json=true but asserts only the error text, not the {"error":"not_found","node_id"} stdout, which is the contract the plugin depends on. Capture stdout (or test context through the built binary), and also assert that a node reached through --path that is missing does not take the not_found shape.
  5. 🟡 register.ts refuse / delete path: when the session itself deletes the watched item, the CLI journals the delete (response.existed branch in delete), but checkItem only asks isDeleted and never consults the journal. The session is then stopped over its own deliberate delete. Either check the journal for the deleted version before refusing, or drop the delete journal entry, which is dead data today.
  6. 🟢 isOwnPart uses Number(part.stamp). Skill parts are stamped with modified_at, so this is NaN and a session's own skill edit is always reported as a change. Harmless today, but the Journal type implies it works for all parts.
  7. 🟢 relationship create/delete and other writers (import, schema, mention) are not journaled. The criterion is scoped to commands that change a node's version, so this is acceptable. Please confirm none of them bumps the watched node's version, or the session will still false-stop on them.

Nitpicks

  • Nit: register.ts nameSession doc comment line exceeds the file's usual wrap width.
  • Nit: the STALE_AFTER doc comment says "An entry is only read until the plugin next compares the item". That is true, but it undersells the live-session risk in finding 3.

Recommendation

COMMENT: there are no merge blockers. Findings 1, 3 and 5 would be worth fixing in this PR, since each one either contradicts an acceptance criterion or reintroduces the mis-attribution the change is meant to remove.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: COMMENT (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review:

  • 5 (own delete): addressed. A delete no longer writes a journal entry (it was dead data); a deleted item is reported by the not-found read.
  • 1 (batch-update read-back window): documented on record_batch. Returning versions in UpdateNodesBatchResponse is a wire change to a shared RPC, out of scope; the window matches the batch's own unversioned read-then-write.
  • 2 (final-version attribution): documented in checkItem. Contiguity checks would false-stop on commands that bump a node more than once.
  • 3 (1h staleness): kept, deliberately. Other live sessions on the machine share the directory, so clearing everything at a start would break them; a crashed session's journal (ids and versions only) goes at the first start or end an hour after its last write. Revisit if the plugin API gains a way to list live sessions.
  • 4 (stdout assertion): skipped. missing_node_json/is_missing_node unit tests pin the shape and the path-reached case; capturing stdout in-process isn't supported by these tests.
  • 6, 7: no change. Skill parts are stamped with timestamps, so a session's own skill edit is reported, which is correct; relationship/import/schema/mention writes are outside this issue's scope.

Also fixed an unused-parameter clippy failure that removing the delete entry exposed. Tests: CLI 308 passed, test:plugin 56 passed, clippy clean.

🤖 Generated with Claude Code

malibio and others added 2 commits October 6, 2026 11:03
…gin stops reading shell lines, and report a deleted item apart from a failed read (closes #3642)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3642-cli-write-journal branch from e045a01 to df7b243 Compare October 6, 2026 09:03
@malibio
malibio merged commit ceba3f2 into main Oct 6, 2026
@malibio
malibio deleted the issue-3642-cli-write-journal branch October 6, 2026 09:03
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.

Record a session's own writes in a CLI journal so the Claude Code plugin stops reading shell lines, and report a deleted item apart from a failed read

1 participant