Skip to content

Let a Content chat leave out the pages above, your instructions or your memory - #10257

Open
3mdistal wants to merge 4 commits into
mainfrom
content-agent-gets-leave-out
Open

3mdistal wants to merge 4 commits into
mainfrom
content-agent-gets-leave-out

Conversation

@3mdistal

@3mdistal 3mdistal commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#10028 added the "Agent gets" line above Content's message box: the open page, "+ N more", and a list of everything else that goes with the next message. It shows what the agent gets, but people can't do anything about it. If the pages above a post, your own instructions, or your memory would steer a chat the wrong way, the only option is to edit them for every chat.

The line also says nothing when a page was shared with you without the page it sits in. The server's walk up the page tree stops at the first page you can't read, so the agent quietly gets no pages above, including any writing rules kept there, and nothing tells you.

#10028 left three smaller gaps:

  • A page in two collections, opened from the one the server wouldn't pick on its own, listed one collection while the agent got the other.
  • The list folded when a send failed after it started, and stayed open after a send with only an attachment.
  • With the list open, Escape in the message box could close the whole agent panel.

Approach

Three lines in the list get a "Leave out" button, which applies to this chat only:

  • The pages it's in. The agent's screen snapshot and get-document stop listing the pages above the open page, and say they were left out.
  • Your instructions. Your personal AGENTS.md and instruction files (Custom instructions in Settings) stop going with each message.
  • Your memory. The memory index and the per-message memory search stop going with each message.

A left-out line is struck through, reads "left out of this chat", and its button turns into "Restore", once the server has saved the change; the button is disabled until then. A list read still under way when the change saves is dropped, so it can't undo it. The folded line adds "· 1 left out". The open page itself and the workspace's instructions can't be left out; the workspace line's detail now says so. A new chat starts with nothing left out.

Memory preferences (memory/INSTRUCTIONS.md) still go when memory is left out: they say what the agent may save, and the agent can still save memories in that chat. So "Your instructions" now means Custom instructions only. In #10028 it covered both.

The choice is stored on the server per chat and per person, so it holds when the page reloads and applies to every message in that chat. It reuses Context X-Ray's per-chat directives table rather than adding one: a left-out item is an evict row with the segment id leave-out:<item>. X-Ray matches segments by their real ids, so these rows don't touch its own pins and evictions. When a message starts, the agent loads the chat's set once into the run context, and the prompt loader and Content's actions check it through isContextLeftOut(item). If that read fails, the message goes with everything, as it did before, and a warning is logged.

When the page it's in isn't shared with you, the list shows a locked "Pages it's in" line that reads "not read: one isn't shared with you", with no button, and the folded line adds an amber "· its pages not read". It never names the unshared page or who owns it. get-document and the screen snapshot report the same thing as parentNotShared, and the agent's instructions tell it to say so if rules up there might matter, without guessing what they say. This shows only when the page it's in can't be read. A shared folder inside someone's private space still lists the folder, with no warning, since that is normal. A page at the top of someone's private space doesn't warn either: it sits in their space, not in a page.

To get this right, the walk up the page tree changed in two ways:

  • get-document gave no path at all to any page shared out of someone's private space. Every page in a space also belongs to that space's Files collection, and the reader can't open the owner's, so get-document skipped the walk. It now walks like the screen snapshot does, and both list a shared folder.
  • The walk ends at the first page you can't read. Before, it still added the page's collection after that stop, so a page under an unshared parent in a space you can read listed the space as the page it's in.

The gaps from #10028:

  • The screen snapshot now gets the collection the page was opened from (?databaseId= in the URL), so the list and the agent agree.
  • The list folds when a send starts a run. A send that fails before it starts adds no run, so the list stays open. A message that waits in the queue folds it when its run starts, since the queue can show a message the server later turns down. An attachment-only send starts a run like any other. A message sent with Send now joins the reply already running, so it doesn't fold the list.
  • While the list is open, Escape anywhere in the message box folds the list first and stops there. The next Escape does what it did before.

Separately, context_directives stored its timestamps as INTEGER, which is a 32-bit column on Postgres, while the store writes millisecond timestamps (Date.now()). Every write failed with "value out of range for type integer". That broke X-Ray's pin and evict on Postgres before this PR, and it broke Leave out in tests and in the local sandbox. A new migration widens both columns to BIGINT on Postgres, the same fix as agent_harness_sessions got earlier.

What changed

Core (@agent-native/core, minor changeset):

  • agent/context-xray/leave-out.ts: isContextLeftOut(item), the leave-out:<item> segment ids, and the core items personal-instructions and memory (in shared/context-xray.ts). isContextLeftOut is exported from @agent-native/core/server for apps.
  • agent/context-xray/directives-store.ts: loadContextLeaveOut and setContextLeaveOut.
  • agent/context-xray/actions/context-leave-out-list.ts and context-leave-out-set.ts: actions only the person can call (agentTool: false), allowed when you own the chat or it doesn't exist yet, since the list can be used before the first message. They are registered wherever X-Ray's other actions are.
  • agent/run-ownership.ts: callerOwnsOrMayStartThread.
  • agent/context-xray/run-leave-out.ts, agent/production-agent.ts and server/request-context.ts: load the chat's set into the run context once per message, before the prompt is built.
  • server/agent-chat/prompt-resources.ts: skip personal instructions and the memory index and memory search when they are left out.
  • agent/context-xray/migrations.ts: migration 1204, Postgres only, widens created_at and updated_at to BIGINT. The store migrations lock and schema snapshot are regenerated.

Content:

  • server/lib/document-context.ts: readDocumentContextPath returns the path and whether the page it's in couldn't be read. The walk ends at the first page it can't read, and a space's Files collection never counts as the page it's in.
  • actions/view-screen.ts and actions/get-document.ts: drop the pages above when they're left out (only for the page on screen) and report pagesAboveLeftOut or parentNotShared. view-screen passes the collection from navigation. get-document no longer skips the walk for a page whose collection you can't open.
  • actions/_database-utils.ts: a collection open on screen drops its own path when the pages above are left out, so view-screen's collection section and get-content-database agree with the page. view-screen says the collection is on screen rather than letting it read navigation a second time, which could find another page if you moved on mid-read.
  • app/hooks/use-navigation-state.ts: navigation state carries databaseId.
  • app/components/layout/AgentContextLine.tsx and agent-context-line.ts: the buttons, struck lines, the locked line, the folded counts, fold on send, and Escape.
  • server/plugins/agent-chat.ts: two sentences in the agent's instructions about pagesAboveLeftOut and parentNotShared.
  • app/agent-context-messages.ts: the new copy in all 11 locales.

Safety and operations

  • Migration. On Postgres, ALTER COLUMN ... TYPE BIGINT rewrites context_directives under a lock. The table holds only X-Ray directives, and every write to it has failed on Postgres until now, so it should be empty or close to it. SQLite doesn't run it; its INTEGER already holds 64-bit values. Rolling back the code leaves the wider columns, which older code reads fine.
  • Data. New rows in an existing table, one per left-out item per chat and person. Restore marks the row inactive rather than deleting it, as X-Ray's own restore does.
  • Permissions. Both actions check that you own the chat (or that it doesn't exist yet), and rows are keyed by owner, so a row made for a chat id you don't own yet affects only you. The agent can't call them.
  • Load. One extra indexed query per message. It fails open.
  • Limits. Leave out changes what goes with each message. The agent can still read memory or the pages above with its tools if you ask it to. Memory preferences still go, as above.
    • A change applies from the next message the agent starts. A reply already running keeps what it started with, and so does a message sent with Send now into that reply.
    • The pages above are left out for the page on screen when the agent reads it. If you open another page during a reply, the agent's later reads follow that page.
    • The walk checks each page above with the share check view-screen already used. A parent you can open only through Content's space access for an organization other than your active one reads as not shared, so the lock can show for it.
    • Not changed here: for a row shared out of a collection you can't open, view-screen's databaseMembership still gives the agent that collection's title, and both actions return the page's raw parentId. The line itself never names it.
  • To roll back, revert the PR.

Verification

Checks on a cloud machine at this branch's commit:

  • Core and Content type checks, core build, formatting on the changed files, and all 112 repo guards pass (the PR-title guard skips outside a PR).
  • Core tests over the touched areas pass: 64 files, 1,926 tests. They include leave-out.spec.ts (the actions, ownership, a chat that doesn't exist yet, the run context, and the prompt loader leaving each item out), and the schema snapshot specs. That spec failed against Postgres before the migration with the out-of-range error, and passes with it.
  • Each changed Core file has a spec beside it, including the two actions, the migration, and the run's read of what's left out (run-leave-out.spec.ts), so the mutation check on changed Core lines runs on all of them: 92% of 143 mutants killed, against a 50% threshold. Those touched specs pass (13 files, 928 tests), along with integrations/plugin.spec.ts, whose request-context mock now has getRequestRunContext, and the release-schema upgrade spec, which now expects migration 1204 to run as a step on an upgraded database.
  • Content tests: 12 files, 142 tests. They cover the rows and counts, the locked line, parentNotShared only when the page it's in can't be read, view-screen with each item left out (including a collection on screen when you move on mid-read), navigation carrying the collection, and the component: Leave out showing only once saved, a list read from before it answering late, Restore, fold on a run but not on a failed send or a queued message, Escape in the editor folding before the panel sees it, and focus going back to the line. The collection read tests run too, since getContentDatabaseResponse changed.
  • The context path tests now give pages a membership in their space's Files collection, as real pages have. Four of them, and five component and unit tests, fail on the code before these fixes: a page in a shared folder got no path and a false warning, a page under an unshared parent in a readable space lost its lock, a collection on screen kept its path when left out, or when you moved on while view-screen read it, the line showed a change before it was saved, a list read from before a Leave out undid it, and a queued message folded the list.

One CI check fails here and on main alike: default-catalog-preservation flags Clips, whose MCP connector catalog #9932 left implicit. #10246 fixes it.

QA in a local Content sandbox (made-up pages, two local users) at the agent panel's real width (about 380px) and at a 390px phone width:

  • Leave out on "Blog" (the page above "Launch day") strikes it through with Restore, and the folded line reads "Agent gets Launch day + 1 more · 1 left out". The page's calls show context-leave-out-set returning ["pages-above"] and the list reading it back, and the stored row has a millisecond timestamp.
  • Each new chat starts with nothing left out.
  • Restore appears only after context-leave-out-set answers, and the line takes the saved list from that answer without reading it again.
  • A post shared by a second user without its parent page reads "Agent gets Spring menu + 1 more · its pages not read". The open list shows the locked line with no button, and the parent's title appears nowhere. get-document for that post returns an empty contextPath with parentNotShared: true.
  • A post in a folder that user shared ("Recipes", inside their private "Rowan's drafts") lists Recipes as the page it's in, with no warning, and get-document returns [Recipes]. A page at the top of their space shows no warning either.
  • Escape from inside the message box folds the list and keeps the panel open. The next Escape closes the panel.

Not covered in the browser: the sandbox can't connect a model, so the message box stays disabled. A real send, a failed send, and Escape pressed in the editor itself rely on the component tests. A page in two collections relies on the unit tests. What the agent receives with a real message needs checking on beta.

Review focus

  • Reusing X-Ray's directives table for Leave out, rather than a new table. It keeps one per-chat store and one ownership model, at the cost of leave-out: rows living beside X-Ray's own.
  • Memory preferences always going, which narrows "Your instructions" to Custom instructions.
  • Allowing Leave out on a chat that doesn't exist yet. Rows are per person, so someone who later owns that chat id isn't affected.
  • When the locked line shows: only when the page it's in can't be read. A stop higher up lists what was read and doesn't warn, and neither does a page at the top of someone's private space.
  • get-document now walks the pages above for a page shared out of a collection or space you can't open, as view-screen already did. It costs one ancestor query for those pages, and it lists only pages the reader can open. The walk's share check counts an organization share without rechecking that you're still in that organization; that isn't new, but get-document now reaches it for these pages.
  • The BIGINT migration on existing Postgres databases.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
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