Skip to content

docs: propose hoisting the read ledger + a session-owned extensible state data model - #1025

Merged
jerm-dro merged 14 commits into
mainfrom
jerm-dro/01M1HJJW5XMEJHAHVFJQ0K7QE5
Sep 8, 2026
Merged

jerm-dro merged 14 commits into
mainfrom
jerm-dro/01M1HJJW5XMEJHAHVFJQ0K7QE5

Conversation

@jerm-dro

@jerm-dro jerm-dro commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This scoping document proposes moving read-before-write observation state and enforcement into the engine, where it follows the Session lifecycle.

  • introduces generic, namespaced session-scoped key-value state rather than another ledger-specific persistence family
  • makes restoring and deleting a Session naturally restore and reap its extensible state
  • applies existing Read/Edit/Write semantics through a session-bound Workspace decorator while preserving backend CAS
  • preserves independent parent/child observations and current Bash behavior
  • frames Workspace as a thin filesystem client and Environment as a bundle of clients sharing underlying file state
  • illustrates a longer-term direction in which the engine is a portable, complete agent loop with pluggable backing clients
  • sequences the cleanup after the initial Redis-backed filesystem in Add a principal-scoped Redis filesystem for mecak8s #889 and explains how it would follow up and partly supersede feat: add persistent read-before-write ledgers #946
  • remains compatible with the separate scoped-resource-grants direction

Scope

This is a working design proposal, not an implementation or frozen ADR. It deliberately defers the exact Go API, generic type shape, serialization format, and backend storage layout to an implementation ADR. It does not change existing read-before-write, stale-read, create-only, final-CAS, or Bash behavior.

Validation

  • git diff --check
  • documentation lint tests for ADR uniqueness and moved slugs
  • matlatl strict check: 0 broken links, anchors, ambiguities, orphans, or unreachable documents
  • regenerated llms.txt with the CI-pinned matlatl revision

Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
Comment thread docs/session-state-and-read-ledger.md Resolved
@jerm-dro jerm-dro changed the title docs: propose session-owned extensible state docs: propose hoisting the read ledger + a session-owned extensible state data model Sep 2, 2026
@jerm-dro
jerm-dro marked this pull request as ready for review September 2, 2026 21:51
@jerm-dro
jerm-dro requested review from JAORMX, jbeda and jhrozek and a lite review from Copilot and removed request for jbeda September 2, 2026 22:29

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

This PR adds a working-draft scoping document proposing that read-before-write observation state (“read ledger”) should be session-owned extensible state, and updates the existing scoped resource grants scoping doc and generated llms.txt corpus index to reference it.

Changes:

  • Add docs/session-state-and-read-ledger.md describing a session-owned, namespaced key/value state model and how it could host a read ledger.
  • Update docs/scoped-resource-grants.md to link to the new proposal as a companion doc.
  • Regenerate llms.txt to reflect the added document and updated corpus statistics/ordering.

Reviewed changes

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

File Description
llms.txt Regenerated corpus index including the new scoping document and updated link graph stats.
docs/session-state-and-read-ledger.md New strawman proposal doc for session-owned extensible state + read-ledger boundary.
docs/scoped-resource-grants.md Cross-links scoped resource grants scoping doc to the new session-state/read-ledger proposal.

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

Comment on lines +44 to +45
This proposal does not specify the migration sequence or implementation tasks.
In particular, it does not:
Comment on lines +97 to +99
PR #946 makes an important first separation: `Workspace` becomes content-only
and a new `tool.ReadLedger` is carried separately by `Environment`. It also
proves in-memory and Redis ledger implementations. That solves independent
Comment on lines +313 to +317
The agent-facing Read tool calls the decorator's ordinary `Read` operation:

```text
Read(path)
1. raw Workspace.ReadVersion(path) → content, version

## Extensible session state

### A generic session-scoped state facility

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't dug into how sessions are persisted, tbh. Are they saved as one big blob or are the streamed out to storage incrementally as the session progresses? What does this mean for the ledger? Does it update and persist to storage after every file operation or does it have a way to stream? I'm guessing we can start with writing the whole ledger out after each operation but perhaps move to some sort of append only log with a compact step if need be. It is likely any database already implements that so this would only save network and encode CPU cost. Probably ok for a ledger that is <100 files but if things go beyond that there may be a need to optimize.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Exact-key key-value access is the best initial contract for the ledger because it persists and retrieves one observed path without loading or serializing the whole ledger. I clarified that this minimizes read amplification, while key-value need not be the only contract the session-state facility eventually supports. The facility’s purpose is to give features one session-owned persistence and lifecycle mechanism so each feature does not have to solve backend storage independently.


### Lazy restoration

Loading a session should not require loading every observed path. Instead, the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally, when the ledger writes something out, the session also stores the current session version (turn number?) so that if things get out of sync we don't read an old ledger and assume it is good. Probably best effort there is to drop the ledger and force the agent to re-read everything before writing. That should be a rare case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I added a fail-closed requirement that restored extensible state may be used only when the persistence layer can establish that it corresponds to the restored Session state. If it cannot, ledger evidence is treated as absent and the agent must Read again. The implementation ADR will determine whether this is enforced with a revision, generation, transaction, or another mechanism.

└── attach State(session-A)
└── no ledger entries loaded yet

first lookup of file/read-ledger/v1 + "src/a.go"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This implies that there is a key in redis per file. That wasn't clear above and alleviates some of the concerns if we persist this on every file operation.

grant design. The session-state facility proposed here provides a place to
retain observations once reported, without prescribing the grant wire shape.

## Open questions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just brainstorming on a possible future direction. I know that some harnesses expose a way to edit a file based on a diff like mechanism whereby the agent describes the surrounding text and allows for edits as long as that area of the file hasn't been touched. I don't think anything here makes that harder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Moving the ledger into the engine does not prevent us from adding region- or diff-based edits in the future. That would be a separate enhancement to the editing model.

@jbeda jbeda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One last comment - as I was reading the implementation, it occurs to me that we only keep track of the latest version that the agent read but it can do partial reads. We could/might want to track which parts of the file the agent read and not let it write to parts outside of what it read. That would be an expansion of what we do today so out of scope but something to think about.

@jerm-dro
jerm-dro merged commit 7658585 into main Sep 8, 2026
27 checks passed
@jerm-dro
jerm-dro deleted the jerm-dro/01M1HJJW5XMEJHAHVFJQ0K7QE5 branch September 8, 2026 17:19
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.

3 participants