Skip to content

feat(SUP-2219): add journal-backed session thread - #67

Merged
levineam merged 3 commits into
mainfrom
SUP-2219/session-thread
May 30, 2026
Merged

feat(SUP-2219): add journal-backed session thread#67
levineam merged 3 commits into
mainfrom
SUP-2219/session-thread

Conversation

@levineam

@levineam levineam commented May 30, 2026

Copy link
Copy Markdown
Owner

Thinking Path

SUP-2219 needs continuity across AI hosts without adding a hidden store.
The existing agent-context MCP is the shared entry point for Claude, Codex, OpenClaw, and Hermes-style clients.
The existing secondbrain note writer already creates notes, normalizes frontmatter, links today's journal, and emits knowledge sidecars.
A session thread should therefore be a normal Markdown note plus journal wikilink, not a separate state file.
Hosts need two primitives: read on entry, write compact checkpoints at decisions/task switches/artifact changes/pre-compaction.
Hydration should include the live thread when available so a new host can pick up the work alongside current Paperclip state.

What Changed

  • Added readSessionThread and writeSessionThread to @jarvos/agent-context, backed by @jarvos/secondbrain note and journal helpers.
  • Exposed MCP tools jarvos_session_thread_read and jarvos_session_thread_write.
  • Included the live session thread in jarvos_hydrate when present.
  • Documented the host reflex: read on entry, write at key continuity moments, keep entries compact and pointer-first.
  • Added library and MCP round-trip tests proving a write by one host is readable by another and appears in today's journal.

Verification

  • npm --prefix modules/jarvos-agent-context test
  • git diff --check
  • npm test

Risks

  • jarvos_hydrate now attempts a session-thread read by default; missing threads are treated as absent and do not fail hydration.
  • Thread notes append over time, so hosts should keep checkpoint summaries compact.

Model Used

OpenAI GPT-5.4 / Codex environment, code editing and local test execution.

Checklist

  • Issue identifier included in branch and commit.
  • Diff limited to intended JarVOS agent-context files.
  • Focused and full smoke tests passed.
  • No secrets or local vault content committed.

Summary by CodeRabbit

  • New Features
    • Added two new MCP tools: jarvos_session_thread_read and jarvos_session_thread_write for managing agent session threads.
    • Session threads are now persisted as markdown notes and automatically linked to daily journal entries.
    • Agents can checkpoint work progress using structured format (summary, next steps, decision).
  • Documentation
    • Updated documentation describing session thread functionality and tool usage.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@levineam, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 33 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc556ad8-7db4-4f90-beb1-6f0cbc871f15

📥 Commits

Reviewing files that changed from the base of the PR and between 443c77e and 6c3000c.

📒 Files selected for processing (2)
  • modules/jarvos-agent-context/src/index.js
  • modules/jarvos-agent-context/test/agent-context.test.js
📝 Walkthrough

Walkthrough

This PR adds session thread persistence to the jarvos-agent-context module, enabling agents to maintain and retrieve checkpoint-style entries from structured Markdown notes. Two new MCP tools—jarvos_session_thread_read and jarvos_session_thread_write—expose read/write operations, which are integrated into the hydrate() context packet and tested end-to-end.

Changes

Session Thread Feature

Layer / File(s) Summary
Core Session Thread Implementation
modules/jarvos-agent-context/src/index.js
Constants for thread title prefixes; utilities for normalizing thread keys, deriving thread titles, stripping YAML frontmatter, and truncating markdown; validation requiring summary/nextStep/decision in checkpoint entries; and readSessionThread/writeSessionThread functions that manage thread notes with metadata-rich frontmatter and rolling checkpoint entries.
Hydrate Function Integration
modules/jarvos-agent-context/src/index.js
hydrate() is extended to optionally fetch and embed the live session thread section (options.sessionThread !== false), returning rendered markdown or a "not found" placeholder and recording sources/handles or error omissions.
MCP Tool Exposure
modules/jarvos-agent-context/scripts/jarvos-mcp.js
Imports readSessionThread and writeSessionThread; adds two new tools to the TOOLS array with JSON schemas for thread identification, content limits, and checkpoint metadata; extends callTool() to dispatch the new tools and return result.markdown via textResult.
Tests and Documentation
modules/jarvos-agent-context/test/agent-context.test.js, modules/jarvos-agent-context/README.md
Updated test imports and environment isolation (JARVOS_SESSION_THREAD_ID); integration test verifying writeSessionThread creates notes and journal links, then readSessionThread retrieves content across hosts; MCP round-trip test validating tool call persistence; tool-list assertion updated to include the two new session-thread tools; README documents the tools and session continuity patterns.

Sequence Diagram

sequenceDiagram
  participant Host
  participant writeSessionThread
  participant readSessionThread
  participant NotesStorage
  Host->>writeSessionThread: checkpoint entry (summary, nextStep, decision)
  writeSessionThread->>NotesStorage: create/update note with metadata
  NotesStorage-->>writeSessionThread: markdown view
  writeSessionThread-->>Host: result with markdown
  Host->>readSessionThread: thread_key, max_lines
  readSessionThread->>NotesStorage: fetch note
  NotesStorage-->>readSessionThread: raw content
  readSessionThread-->>Host: result with rendered markdown
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • levineam/jarvOS#30: Introduced the initial @jarvos/agent-context MCP adapter and TOOLS/callTool wiring; this PR extends the same adapter with session thread read/write tools.

Poem

🐰 Thread by thread, the notes align,
Sessions woven, checkpoint-fine,
Read and write with YAML grace,
Continuity finds its place!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(SUP-2219): add journal-backed session thread' directly and clearly summarizes the main feature addition—the journal-backed session thread mechanism. It uses a standard conventional commit format with an issue identifier and accurately reflects the changeset's primary objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SUP-2219/session-thread

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 443c77e66e

ℹ️ 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".

...threadOptions,
maxChars: Number(options.sessionThreadMaxChars || threadOptions.maxChars || 2200),
});
parts.push('', '# Live Session Thread', '', thread.found ? thread.markdown : 'No live session thread found.');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fix hydration size accounting when no thread exists

When no session thread exists this still adds a new # Live Session Thread placeholder to every hydration packet, which pushes small maxChars calls into the final trim path; running npm --prefix modules/jarvos-agent-context test now fails the existing budget test because result.report.finalChars no longer matches the rendered markdown length (604 vs 606). Either avoid emitting the absent-thread section or recompute the final size after this extra content participates in trimming so hydration reports stay internally consistent.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/jarvos-agent-context/src/index.js`:
- Around line 374-414: writeSessionThread currently does a read-modify-write via
readIfExists + noteWriter.writeNoteFile which can clobber concurrent
checkpoints; update writeSessionThread (and the callsite of loadNoteWriter /
noteWriter.writeNoteFile) to perform an atomic update with retries: acquire an
exclusive lock on the target (e.g. lockfile based on thread.notePath or
journal), or implement a compare-and-swap loop that reads the current file
(readIfExists/stripFrontmatter), builds the new content/entry, writes to a temp
file and atomically renames into place only if the on-disk content hasn't
changed (or retry up to N times), and fall back to appending if the noteWriter
supports append semantics; ensure readSessionThread uses the final agreed
content and surface an error after max retries. Use the symbols
writeSessionThread, loadNoteWriter, noteWriter.writeNoteFile, readIfExists, and
readSessionThread to locate where to add locking/CAS and retry logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0699d525-5625-416c-a71c-121914c9d71e

📥 Commits

Reviewing files that changed from the base of the PR and between d8122a9 and 443c77e.

📒 Files selected for processing (4)
  • modules/jarvos-agent-context/README.md
  • modules/jarvos-agent-context/scripts/jarvos-mcp.js
  • modules/jarvos-agent-context/src/index.js
  • modules/jarvos-agent-context/test/agent-context.test.js

Comment thread modules/jarvos-agent-context/src/index.js

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b50dbd13ef

ℹ️ 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".

Comment on lines +334 to +335
process.env.JARVOS_SESSION_THREAD_ID,
process.env.PAPERCLIP_TASK_ID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prefer the Paperclip task when deriving the thread

The new MCP schemas advertise the implicit default as PAPERCLIP_TASK_ID/JARVOS_SESSION_THREAD_ID/default, but this order checks JARVOS_SESSION_THREAD_ID first. In sessions where a host sets a stable global JARVOS_SESSION_THREAD_ID and Paperclip also provides the current issue in PAPERCLIP_TASK_ID, calls that omit threadId will read and append to the global host thread instead of the issue-specific thread, so handoffs for the current issue are lost in the wrong note. Swap these two env fallbacks or make the tool/schema contract match the intended precedence.

Useful? React with 👍 / 👎.

@levineam
levineam merged commit 1041f8f into main May 30, 2026
7 checks passed
@levineam
levineam deleted the SUP-2219/session-thread branch May 30, 2026 19:32

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6c3000c405

ℹ️ 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".

maxChars: Number(options.sessionThreadMaxChars || threadOptions.maxChars || 2200),
});
if (thread.found) {
parts.push('', '# Live Session Thread', '', thread.markdown);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid hydrating the session thread twice

When today's journal already contains the session-thread wikilink, which writeSessionThread adds on every write, this inserts the live thread here and the later collectLinkedNotes(journal.content, ...) pass reads the same note again under “Notes Linked From Today”. In sessions with an active thread this duplicates the handoff content and burns the hydration budget, which can force other journal-linked notes or ontology context to be trimmed; skip the current thread when collecting linked notes or avoid adding it twice.

Useful? React with 👍 / 👎.

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.

1 participant