refactor(core): keep raven's state out of the workspace structurally
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with raven/agent/workdir.py and raven/agent/loop/checkpoint.py, then review the three proposal blocks and the referenced writer paths. The issue describes multiple independent changes, safety boundaries, and a separate owner sign-off for the data-directory change, so first identify which block is being picked up and its requirements. Done means that block has its own PR and the state leakage and working-directory cases it addresses are covered.
Written by the indexing model from the issue text.
Description
Summary
Local commands launched from Raven's own state can adopt it as the working directory, and the per-turn checkpoint then runs add -A over it, copying credentials and transcripts into the shadow repo. #867 set out to fix that and was closed without merging (2026-10-21) because the fix had grown too complex. Nothing on main addresses the bug today, so this issue now records the bug itself as well as the structural change that would make a fix simple.
The root of the complexity is layout. Raven writes more than twenty kinds of its own state into a directory that may belong to the user. The data directory is get_data_dir() = get_config_path().parent, so --config <proj>/config.json puts credentials/, cron/, media/, subagent_instances.json and the rest into the project, and the shadow repo lives inside the working tree (.raven/shadow.git). In that layout the only way to tell Raven's state from the user's files is by name, which is what #867 did: two name lists plus an AST scanner test, and every new state file needed another entry.
The question asked about #867 was: "Do we really have to list every key to protect it?" In the current layout the answer is yes. It only becomes no once Raven's state stops sharing a directory with the user's files.
Current state
Refs: main at c42988358. The closed #867 is cited only as a reference, at its last head 6779d0a50.
What one checkpoint commits on main
main has no state-aware exclusion by name or by path. The checkpoint's only Raven-specific exclude is the .raven/ name in _DEFAULT_EXCLUDES (raven/agent/loop/checkpoint.py:71, .raven/ at :76), and a work-tree .gitignore can re-include it.
Probe: a throwaway HOME and RAVEN_HOME, the config file pointed into a throwaway project (<proj>/config.json, written with save_config), each state file below written through its production path helper (_credentials_dir(), get_cron_dir(), get_media_dir("web"), the three sub-agent path helpers), the user's own main.py, cache/user_cache.txt and plugins/user_plugin.py, and a project .gitignore of !.raven/ and !.raven/**. Then one CheckpointService(<proj>).commit_turn(). The shadow repo's HEAD tree:
.gitignore
.lock/config.json.lock
.lock/config.migrations.json.lock
.raven/NOTICE.txt
.raven/shadow.git/... (18 entries: HEAD, config, hooks/*, index.lock, info/exclude)
cache/user_cache.txt
config.json
config.migrations.json
credentials/mcp/srv.json
cron/jobs.json
main.py
media/web/upload.png
plugins/user_plugin.py
subagent_acp_capabilities.json
subagent_instances.json
subagent_test_state.json
Two objects in the store hold the probe's fake secrets (the MCP token and the cron job). The probe's config.json is a default Config with no keys; a real one holds provider keys, and it is committed the same way. Everything Raven keeps in the data directory is committed, and the shadow repo commits its own files.
Five files a name-based fix missed
On main these are committed like everything else in the data directory. They are listed because they are the ones a name list misses: the closed #867's scanner did not recognise these path forms, and its last round had to add the three JSON names and derive the sidecars by hand.
| File | Path built at (main) | Why a name list misses it |
|---|---|---|
subagent_instances.json |
raven/agent/subagent/instances.py:60 |
get_config_path().parent / _FILENAME, a form the scanner did not anchor |
subagent_acp_capabilities.json |
raven/acp_client/capabilities.py:348 |
same |
subagent_test_state.json |
raven/agent/subagent/probe_state.py:57 |
same |
config.migrations.json |
raven/config/loader.py:203 |
config_path.with_name(...) |
.lock/<name>.lock |
raven/utils/atomic_io.py:35 |
created beside any atomically replaced file, config.json included |
None of these five holds a raw secret; subagent_test_state.json stores a truncated digest whose input includes the sub-agent's api_key (probe_state.fingerprint, raven/agent/subagent/probe_state.py:171), so the risk is low but not zero. The real exposure on main is the rest of the tree above.
RAVEN_TRACING_DIR (raven/tracing/config.py:74-76) can place trace state anywhere, a project included. Every trace file sits under logs/, so the generic default excludes (logs/, *.log) catch it; a work-tree .gitignore that re-includes logs/ would let it through.
The working-directory rule on main
validate_override (raven/agent/workdir.py:96) refuses a relative path, agent home itself, any ancestor of agent home (so the default ~/.raven), and the user_memory, skills and sessions subtrees (_PROTECTED_SUBTREES, :23). It does not refuse the rest of Raven home: in the probe, <RAVEN_HOME>/credentials, <RAVEN_HOME>/cron and <RAVEN_HOME>/oauth are all accepted.
The launch directory is not validated at all. Under WorkdirPolicy.LAUNCH_DIR the default is the process's working directory (raven/agent/workdir.py:200-201; raven/core/engine_stack.py:106-113 passes Path.cwd() in unchecked; only -w goes through validate_override), so cd ~/.raven/credentials && raven agent makes that directory the working tree. That is the original #867 bug, and it is unfixed.
The checkpoint itself refuses only $HOME and its ancestors (raven/agent/loop/checkpoint.py:242-243).
User directories that share a state name
With the config file inside a project, the project's own cache/ and plugins/ sit beside Raven's cache/ and plugins/ and cannot be told apart. On main they are committed along with Raven's state, and validate_override(<proj>/cache) accepts them. Any fix that works by name has to choose between leaking Raven's directories and dropping the user's: the closed #867 dropped the user's cache/user.txt and plugins/user.txt from the checkpoint without any message, and refused those directories as working directories. A structural fix does not have to choose.
Two fences that disagree
With the config file inside a project:
raven/rpc/files.py:108_raven_state_roots()treats the whole data directory as state, so the file viewer refuses every file in the project: in the probein_state_dir(<proj>/main.py)isTrue.- The working-directory rule accepts the same project:
validate_override(<proj>)accepts it.
One question, "is this Raven's state?", has two answers today.
Writers that bypass raven_home()
These write under the literal ~/.raven whatever RAVEN_HOME says, so any state check has to cover that path too (the closed #867 did, in _state_roots(), raven/agent/workdir.py:201 on 6779d0a50):
raven/browser/driver.py:119(browser-profile)raven/routing/cache.py:24(routing/benchmark-cache.json)raven/routing/knn_router.py:133(knn_embcache)raven/skill_hub/client.py:131(skills/hub)
What #867 covered, and is now unfixed
The closed #867 had three layers. With it closed, all three are gaps on main:
- Working-directory validation against the state boundary, at every place a working directory enters: the launch directory (with a warning and a fall-back to the per-channel directory), the explicit
-woverride, the persisted per-session override,channels.<name>.workspace, and ACP session working directories. - Exclusion by absolute path before staging hashes any bytes, so a project
.gitignorecannot re-include it: Raven home, agent home, the active config file and its lock and temporary sidecars, and the shadow repo itself. - The git-argument handling that layer 2 needs: pathspec excludes passed before any hash is written,
-z(NUL-separated) parsing of changed lists, names with newlines or invalid UTF-8, and filesystem-identity comparison so that case and Unicode-normalization spellings of one path match.
The structural change below does not replace any of this. Moving the shadow repo and the data directory removes the name layer only; the config file and its lock can still sit in a project, and a user can still launch from inside Raven home, so layers 1 to 3 are needed under every proposal block. #867's head 6779d0a50 is a reference for how they were built and tested.
The name layer, closed with #867 (reference only)
None of the following exists on main (checked at c42988358): no state name lists, no state_within() or state_refusal(), and no scanner block in tests/test_agent_workdir.py. On the closed head 6779d0a50:
raven/agent/workdir.py:37-73_STATE_ENTRIES: 33 names (state directly under Raven home).raven/agent/workdir.py:80-107_DATA_DIR_STATE: 24 names (state beside the config file).- Helpers that exist only to match those names:
_fold(:215),_folds_case(:269),_names_state(:287);state_within()(:384) combined Raven home, the config file, the_DATA_DIR_STATEnames and agent home. tests/test_agent_workdir.py:564-747, the scanner block, about 184 lines:_HOME_FILES(16 names),_HOME_WORK(1), the AST walker_entries_created_under_the_home(:609-699) with its helpers,test_every_directory_raven_creates_in_its_home_is_known_state(keeps the lists equal to what the walker finds) and a self-test of the walker.
Adding a state file there meant changing the writer, one or two lists, and relying on the walker to recognise how the path is built. A form it did not recognise was not reported.
Proposal
Three blocks, each its own PR, plus layers 1 to 3 above, which can land first and on their own.
(a) Move the shadow repo out of the working tree
Default location under Raven home, keyed by the workspace, for example <RAVEN_HOME>/checkpoints/<key>/shadow.git. Touches CheckpointService.__init__ (today shadow_dir must resolve strictly inside the workspace: raven/agent/loop/checkpoint.py:257), the exclude for the legacy location, the config field and the docs.
This fixes the shadow repo tracking itself (reproduced on main above: a work-tree .gitignore with !.raven/ makes the in-tree repo commit its own files, growing every turn). It removes no leak by itself: with the shadow outside and no state excludes, credentials are still committed.
The key must be stable across spellings of one directory (macOS Proj vs proj): use filesystem identity or the inode, not the resolve() string.
(b-home) Allow-list inside Raven home, fix the bypassing writers
Inside Raven home, accept a working directory only where Raven hands out work (the per-channel root and the configured channel workspaces) instead of refusing state by name. Route the four writers above through raven_home() so the literal ~/.raven check can go.
(b-data) A dedicated data directory under --config
When --config names a file, derive a dedicated directory owned by Raven from the config path (for example a sibling directory named after the config file) instead of using the config file's parent, so a project never holds Raven's state other than the config file and its lock. Existing instances keep working through a legacy-layout check with a warning (see Migration).
This block moves subagent_instances.json and subagent_test_state.json. subagent_instances.json is read by spawn_tool, dag_tool and dag_runner (through raven/agent/subagent/instances.py); subagent_test_state.json by the sub-agent probe and the sub-agents RPC methods. b-data needs a separate owner sign-off before work starts.
Evaluated and rejected
- (c) Snapshot only the files the user's git tracks. The per-channel working directories (the gateway and web default) are not git repositories, so checkpoints would stop working there entirely, and new files would never be snapshotted.
- (d) Explicit pathspecs, snapshotting only the paths a turn wrote.
exec's before/after directory listing must still skip state Raven writes while a command runs (cron, sessions), so the name list only moves; the pre-write snapshot would also need a redesign.
With #867 closed and main unprotected, (c) and (d) can look like cheaper stopgaps. They are not: neither validates the launch directory, so a session launched from ~/.raven/credentials still adopts it, and the user's git does not track that directory at all, so (c) would only disable checkpoints there rather than protect it. Both conclusions were checked during #867 and still hold on main.
Acceptance criteria
- No name-based state exclusion is added to
mainfor this problem: no list of state names and no scanner that keeps one complete. The structural change lands directly onmain. - A launch directory,
-woverride, persisted session override, channel workspace or ACP session working directory inside Raven's state (for example~/.raven/credentialsor~/.raven/cron) is refused or falls back to the per-channel directory with a warning; a valid project launch keeps its directory. - With the config file inside a project, the only Raven paths excluded from that project's checkpoint are derived from configuration (the config file and its lock and temporary sidecars), by absolute path; no entry is matched by name.
- The
credentials/,cron/,media/,subagent_*.json,config.migrations.jsonand.lock/files from the probe above no longer appear in a project's checkpoint, and no object in the store holds their contents. - With a work-tree
.gitignorethat re-includes.raven/(!.raven/and!.raven/**) and zero name excludes, the shadow repo does not track itself over several turns. - A user's own
cache/,plugins/andlogs/inside a project are accepted as working directories, and no Raven state rule drops them from the checkpoint (the generic default excludes such aslogs/and*.logapply as they do to any project). -
credentials/andcron/of Raven home and of the dedicated data directory are refused as working directories and never committed. - The file viewer fence (
raven/rpc/files.py) and the working-directory rule give the same answer for a file in a project that holds the config file. - The spelling-variant tests (case and Unicode normalization) are run once on a native macOS volume, not only simulated on Linux.
Migration
- An existing
.raven/shadow.gitinside a working tree is not deleted automatically: it may already hold committed credentials. Keep excluding it by absolute path while it exists and point the user at it, as the closed #867 did. Nothing onmaindoes this today. - An explicitly configured
shadow_dirkeeps its current meaning (inside the workspace) and logs a deprecation warning; only the default moves. - b-data does not move existing data automatically: a project's
credentials/may be the user's own, the same ambiguity the closed #867's lists existed for. Detect the legacy layout and warn. How that layout is protected during the window, without adding the name list the first criterion rules out (for example by the absolute paths Raven's own path helpers return, or by refusing to checkpoint a legacy root until it is migrated), is decided in b-data's design; whatever it is ends with the window. - Shadow repos under Raven home whose workspace was deleted or moved need reclaiming: write a marker file naming the workspace into each repo so a sweep can tell which are orphaned.
Related
#867 (closed without merging on 2026-10-21) attempted the fix with name lists and was closed as too complex, with this issue recording the problem. Its head 6779d0a50 remains a reference for layers 1 to 3 and their tests; its name layer is not to be revived. Its description also named two adjacent gaps as deferred and outside checkpoint storage: plugin replacements of exec need agent home propagated to them, and Stint commits to the user's own repository need their own state exclusion.
- Dominant language
- Python
- Stars
- 4.1k
- Forks
- 94
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 216
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EverMind-AI/Raven
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
EverMind-AI/Raven#1413 ·
Maintainers usually reply within 1 day
-
feat: allow users to build ui-web and ui-tui with `bun`May be free again @0warning0error claimed this 8 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
EverMind-AI/Raven#1283 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
EverMind-AI/Raven#121 ·
Maintainers usually reply within 1 day
-
fix: Feishu channel status wrongly reports missing credentials and "not connected" while WebSocket is livePossibly taken @pcbeingused333 claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 18/100
EverMind-AI/Raven#1399 · 1 comment ·
Maintainers usually reply within 1 day
-
WebUI tab froze silently while gateway stayed healthy (heartbeat stopped 1h49m); reproducible /auth refresh dead-end fixed in #1392Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 22/100
EverMind-AI/Raven#1393 · 2 comments ·
Maintainers usually reply within 1 day
All issues in EverMind-AI/Raven
Similar issues
-
bug docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
comp/tools P2 tool/skills type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#159541 ·
Maintainers usually reply within 1 day