Skip to content

docs(architecture): split into a lean always-loaded core + on-demand area files (#2306) - #2495

Merged
vybe merged 5 commits into
devfrom
feature/2306-architecture-split
Sep 4, 2026
Merged

vybe merged 5 commits into
devfrom
feature/2306-architecture-split

Conversation

@obasilakis

Copy link
Copy Markdown
Contributor

Splits docs/memory/architecture.md into a lean always-loaded core over per-area files read on demand, mirroring the #1406 requirements split.

The problem, measured

The file is @-imported by CLAUDE.md, so every session pays it in full — while most sessions touch one or two subsystems.

docs/memory/architecture.md   573,932 B   92.6% of auto-loaded context
CLAUDE.md                      24,717 B
~/.claude/CLAUDE.md            10,962 B
.claude/TEAM_CONTEXT.md         3,685 B
                    TOTAL     613,296 B

2,973 lines against its own stated "~1000 lines max", growing ~50 lines/week (it gained 305 lines between this issue being filed and this branch being cut).

Result

before after
core architecture.md 2,973 lines / 574 KB 181 lines / 48 KB
auto-loaded total ~613 KB ~88 KB (−85%)
area files — 14 under docs/memory/architecture/, path-referenced, never imported

Core keeps: system overview + diagram, technology stack, all Architectural Invariants verbatim, network topology, dev environment, data persistence, and the new Architecture Map. Everything else moved. Nothing was summarized away or dropped.

No content was lost, and that is checked rather than asserted

The move was mechanical. A splitter routed every heading-delimited block to exactly one destination and asserted byte conservation, so no block could be dropped or duplicated. Verified afterwards against origin/dev by content-line bag comparison: the only prose removed is the two rewritten preamble lines, the three now-orphaned container headings the map replaces (## Component Details, ## Cross-Cutting Subsystems, ## API Endpoints), and one obsolete intra-file pointer. Every other differing line is an anchor rewrite with identical prose.

Two additions beyond the filed ACs

AC 1 asks the core to keep "enough of the map that an agent knows what exists and exactly which file to open". That is the right requirement, but a topic index satisfies it on paper and does not bind in practice — the failure mode is documented in this repo's own learnings: an agent that half-remembers a subsystem answers instead of reading, and strengthening the "always check" prose makes it assert having checked. Lazy loading only pays if the right file gets opened, so:

1. Index rows state a consequence, not a topic. Each row carries the owning code paths and the concrete regression that reading the file prevents. Compare:

retention — see retention.md

against the shipped row for reliability.md:

OPS_SETTINGS_DEFAULTS is a safety floor, not a policy knob. It is read at prune time and is the fallback for every install that never wrote a row, so lowering one retroactively hard-DELETEs those installs' history seconds after their next boot. #1638 cost a live instance ~3 months of data and shipped green because a test asserted the destructive default.

Every consequence is extracted from incident refs already present in the prose being moved — this is not new invention — and test_every_map_row_carries_owned_paths_and_a_consequence requires each to cite an issue or an invariant, so a future row cannot degrade back into a label.

2. A PreToolUse hook, not more prose. scripts/docs/architecture_context_hook.py maps the file being edited to its owning area and injects the pointer the first time a session touches it — so correct loading follows what the session is actually editing rather than the agent choosing to look. Same shape as the fix that worked previously when injected data beat instruction prose.

Properties, each deliberate:

  • No map of its own. It parses the core's Architecture Map table. A sidecar map is a second thing to drift; test_hook_has_no_map_of_its_own walks the AST (so comments and docstrings are exempt by construction) and fails if an area filename appears in executable string data.
  • Advisory. Emits additionalContext, never blocks. Any error — malformed table, moved doc, unreadable state — exits 0 with no output. The failure mode is "back to today's behaviour", never "cannot edit".
  • Most-specific-wins. cleanup_service.py is also matched by backend.md's broad src/backend/services/** catalog glob; citing the 90 KB catalog on every service edit is the noise that gets a hook switched off, so only the tightest owner fires.
  • Once per area per session.
  • Opt-in per clone. It ships in the public repo (reviewable, CI-tested); wiring goes in .claude/settings.json, which is core-team-only, so OSS clones simply run without it. Snippet is in the core's Hook setup section.

Also fixed

  • 79 in-page (#anchor) links the split turned into cross-file links, repointed by a resolver rather than by hand.
  • Three anchors already broken on dev: a numbered heading (#agent-mcp-keys-agent--trinity-mcp), an em-dash slug (#first-run-provisioning-honest-setup_completed-2381), and #network-topology-issue-589.
  • External anchored refs in harness-authoring-guide.md, three feature-flow docs, and tests/security/README.md.

ACs

  • Core is overview + stack + all invariants verbatim + topology + index; budget stated in the editorial rules and met (181 lines, budget 500)
  • Deep content in per-area files; every section lands in exactly one place
  • CLAUDE.md @-imports only the core (test_only_the_core_is_auto_imported)
  • Write-path rule stated in the core (editorial rule 4) and in every area-file header
  • Cross-references updated
  • enterprise-docs-guard.yml scope verified — it greps docs/ recursively, so docs/memory/architecture/ is already covered. No workflow change. Ran the guard's exact pattern locally against this tree: 0 hits
  • Skills reading this doc — see follow-up

Follow-up (not in this PR)

Skills in the private .claude submodule that consume the doc need a bump for the new layout: /validate-architecture, /update-docs, /sync-feature-flows, and /autoplan context loading. Flagged in the issue's own Technical Notes. None of them hard-fail on the new layout (the core still exists at the same path), but they will only see the core until bumped.

Tests

tests/unit/test_2306_architecture_split.py — 22 tests, all green, guarding the parts that fail silently: line budget, map/disk bijection, consequence quality, area-file headers, hook-vs-table anti-drift, routing + specificity, once-per-session, fail-open on malformed input, and dangling anchors across the new file boundary.

22 passed in 0.63s

Closes #2306

🤖 Generated with Claude Code

https://claude.ai/code/session_01NqkwYug8AWgQSz34c59oiu

…area files (#2306)

`docs/memory/architecture.md` is `@`-imported by CLAUDE.md, so every session
paid it in full: 2,973 lines / 574 KB, 92.6% of all auto-loaded context, and
growing ~50 lines a week against its own stated "~1000 lines max" budget. Most
sessions touch one or two subsystems.

Split it the way #1406 split the requirements monolith — a lean core plus
per-area files read on demand:

  core   2,973 -> 181 lines (574 KB -> 48 KB, 91.6% cut)
  areas  14 files under docs/memory/architecture/, referenced by path,
         never `@`-imported

The core keeps the system overview, technology stack, all Architectural
Invariants verbatim, network topology, dev environment, data persistence, and
a new Architecture Map. Everything else moved; nothing was summarized away.

The move was mechanical, not retyped: a splitter routed every heading-delimited
block to exactly one destination and asserted byte conservation, so no block
could be dropped or duplicated. Verified against origin/dev afterwards — the
only prose removed is the two rewritten preamble lines, the three now-orphaned
container headings the map replaces, and their obsolete intra-file pointer.

Two additions beyond the filed ACs, because a split alone does not make the
right file get opened:

1. Index lines state a consequence, not a topic. A row names the owning code
   paths and the concrete regression that reading the file prevents. "retention
   — see retention.md" gives an agent no reason to spend a tool call;
   "OPS_SETTINGS_DEFAULTS is a safety floor, not a knob — #1638 hard-DELETEd a
   live instance's history and shipped green" does. Every consequence is
   extracted from incident refs already in the moved prose, and the test
   requires each to cite an issue or invariant.

2. A PreToolUse hook, not more prose. scripts/docs/architecture_context_hook.py
   maps the edited file to its owning area and injects the pointer on first
   touch, so loading follows what the session is actually editing. Strengthening
   "always check" wording is the approach that fails here — it makes an agent
   assert having checked. The hook parses the core's own map table and holds no
   map of its own, so the two cannot drift; it is advisory (never blocks a tool
   call), most-specific-wins (so the 90 KB catalog is not cited on every service
   edit), once per area per session, and exits silently on any error.

Also fixed three anchors that were already broken on dev (a numbered heading, an
em-dash slug, and #network-topology-issue-589), and repointed 79 in-page anchors
the split turned into cross-file links.

tests/unit/test_2306_architecture_split.py guards the parts that fail silently:
the line budget, map/disk bijection, consequence quality, area-file headers, the
hook-vs-table anti-drift property, routing and specificity, once-per-session,
fail-open behaviour, and dangling anchors across the new file boundary.

enterprise-docs-guard.yml needs no change — it greps `docs/` recursively, so
docs/memory/architecture/ is already in scope. Verified locally: 0 hits.

Follow-up: skills in the private .claude submodule that read this doc
(/validate-architecture, /update-docs, /sync-feature-flows, /autoplan context
loading) need a bump for the new layout.

Closes #2306

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01NqkwYug8AWgQSz34c59oiu
@vybe

vybe commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Now conflicts with dev — and needs one approving review

Five PRs landed on dev this morning (#2498, #2489, #2485, #2496, #2500). Two of them edited docs/memory/architecture.md, so this split now conflicts. Holding it back deliberately: it was sequenced last precisely because it is the one PR every other architecture.md toucher has to rebase around.

The conflict is small and mechanically routable

The whole delta is 5 insertions / 4 deletions — four edits to existing lines plus one new table row. Each lands in exactly one area file this PR creates:

Content on dev From New home in this PR
redis_breaker_util.py row — adds agent_service/deploy (agent:deploy_op:{base_name}) to the SingleFlightLock consumer list #2060 / #2485 architecture/backend.md
Library system-install section (ent#126) — YamlEditor.vue + EditorHelpPanel.vue were deleted in the dead-component sweep; CSP rationale kept as permanent #2492 / #2496 architecture/frontend.md
agents.ts MCP tools row — deploy_local_agent embedded-manifest contract #2060 / #2485 architecture/mcp-server.md
New row POST /api/agents/deploy-local in the agents endpoint table #2060 / #2485 architecture/api-endpoints.md
Single-flight lock consolidation (#1920) — adds agent:deploy_op:{base_name} to the site list #2060 / #2485 architecture/database.md

No content needs re-writing; each edit moves verbatim into the file that already owns that section.

Heads-up on ordering

#2264 is still open and also edits architecture.md. If it merges first there will be a second, similarly small pass — worth rebasing once after it lands rather than twice.

Merge blocker

Branch protection on dev requires one approving review and this PR has none. CI is fully green (all three pytest head seeds, schema-parity, both Analyze jobs, gitleaks, regression diff), and validation found no security, packaging, or config-drift issues. It also edits CLAUDE.md and adds scripts/docs/architecture_context_hook.py, so it changes what auto-loads into every session — that is the part worth a human read rather than a rubber stamp.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

⚠️ Live-instance suite skipped — merge conflict against dev.

Resolve by merging dev locally and pushing the result; the next nightly re-tests.

Resolve the architecture.md conflict by routing dev's changes into the area
files this branch creates, rather than back into the monolith.

dev's 13 hunks land as follows — none touch content the lean core retains
(overview, stack, invariants, topology, dev env, data persistence), so the
core file is unchanged by the merge:

  backend.md       redis_breaker_util SingleFlightLock consumer list gains
                   agent_service/deploy (#2060); new runtime_secret_scrub.py
                   service row (ent#279)
  frontend.md      Library system-install section (YamlEditor.vue and
                   EditorHelpPanel.vue deleted in the #2492 sweep); Dashboard
                   Grid and List view rows
  mcp-server.md    agents.ts deploy_local_agent embedded-manifest contract
  api-endpoints.md POST /api/agents/deploy-local row; operator_response
                   stranded-for-pull-mode paragraph rewritten for #2391
  workspace.md     briefing hydration moved off the roster critical path
                   (#2163) — three edits plus the new 44-line section
  database.md      skill_sources tag-pinning site list gains
                   agent:deploy_op:{base_name}

Verified by content-line bag comparison against origin/dev: the only lines not
carried over are the same anchor rewrites and four orphaned container headings
the split already documented.

Also fix 64 relative links the split left un-rebased for the extra directory
level: feature-flows/ -> ../feature-flows/ (60), and ../{migrations,schemas,
QUERYING_LOGS.md,TRINITY_COMPATIBLE_AGENT_GUIDE.md,harness-authoring-guide.md}
-> ../../ (4). Every relative link in the architecture set now resolves. The
voice_reply_service pointer, which the split had aimed at the core's map after
its #cross-cutting-subsystems target was dissolved, now points at backend.md
where that service is actually described.

tests/unit/test_2306_architecture_split.py: 22 passed.
enterprise-docs-guard pattern run locally against this tree: 0 hits.
Full tests/unit: 13742 passed, 21 failed — all 21 are the local IPv6/DNS
mapped-address failures that reproduce identically on origin/dev.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015cMEDUYWG3KFADyxrEtfde
@obasilakis

Copy link
Copy Markdown
Contributor Author

Rebased onto dev — conflict resolved, and 64 broken links fixed

mergeable is back to MERGEABLE. More landed on dev than the last comment anticipated (#2264, #2391, #2314, #2375, #2455 and the two already noted), so the delta was 13 hunks / 67 insertions rather than 5, but the shape held: none of them touch content the lean core retains, so architecture.md is byte-identical to what this branch already had, and every hunk routed into exactly one area file.

Content on dev From Landed in
redis_breaker_util.py — SingleFlightLock consumers gain agent_service/deploy #2060 / #2485 backend.md
New runtime_secret_scrub.py service row ent#279 / #2264 backend.md
Library system-install section — YamlEditor.vue + EditorHelpPanel.vue deleted #2492 / #2496 frontend.md
Dashboard Grid + Dashboard List view rows #2519 / #2500 frontend.md
agents.ts — deploy_local_agent embedded-manifest contract #2060 / #2485 mcp-server.md
New POST /api/agents/deploy-local row #2060 / #2485 api-endpoints.md
operator_response "stranded for pull mode" rewritten — structural → a choice #2391 / #2513 api-endpoints.md
Briefing hydration off the roster critical path — 3 edits + a new 44-line section #2163 / #2518 workspace.md
skill_sources tag-pinning — agent:deploy_op:{base_name} #2060 / #2485 database.md

Checked rather than asserted, same method as the original split: a content-line bag comparison against origin/dev shows the only lines not carried over are the anchor rewrites and the four orphaned container headings this PR already documented.

Also fixed: 64 relative links the split left un-rebased

Found while verifying the merge, and it is a genuine defect in the original push rather than fallout from it. The area files sit one directory deeper than the monolith did, so every relative link needed re-basing and 64 did not get it:

  • ](feature-flows/…) → ](../feature-flows/…) — 60 links, each of which resolved to the non-existent docs/memory/architecture/feature-flows/
  • ](../{migrations,schemas,QUERYING_LOGS.md,TRINITY_COMPATIBLE_AGENT_GUIDE.md,harness-authoring-guide.md}) → ](../../…) — 4 links

Every relative link in the architecture set now resolves; verified by walking each one against disk. One pointer also got aimed better: voice_reply_service had been repointed at the core's Architecture Map when its #cross-cutting-subsystems target dissolved, and now points at backend.md, where that service is actually described.

The in-page ](#anchor) links that remain are correct — all four target headings in their own file.

Verification

  • tests/unit/test_2306_architecture_split.py — 22 passed
  • enterprise-docs-guard pattern run locally against this tree — 0 hits, no workflow change needed
  • Full tests/unit — 13742 passed, 21 failed; all 21 are the local IPv6 mapped-address / DNS failures that reproduce identically on origin/dev (test_736_a2a_outbound_*, test_ent14_registry_url_ssrf, test_ent399_ipv6_origin, test_mcp_validator), so they are environmental and unrelated to this branch
  • PreToolUse hook smoke-tested against a cleanup_service.py edit — emits the reliability.md pointer

Still needs one approving review before it can merge; deliberately not self-merging.

sim and others added 3 commits September 4, 2026 13:23
# Conflicts:
#	docs/memory/architecture.md
One conflict: docs/memory/architecture.md, because #2516 (ent#437 opt-in
telemetry) added content to the monolith this branch splits.

Resolved semantically rather than textually. The lean core is kept as-is and
all four of #2516's edits are re-homed into the area files that own them:

  backend.md         `settings.py` catalog entry (Tier-2 sharing routes)
  backend.md         new "Opt-in Instance Telemetry (ent#437)" section
  agent-lifecycle.md the First-Run "Collateral" paragraph (FinishSetupCard)
  api-endpoints.md   the /api/settings/feature-flags row

The telemetry section goes to backend.md rather than beside the neighbours it
had in the monolith (#2380/#2381 in agent-lifecycle.md, or reliability.md,
which owns the section it was inserted before). The deciding rule is that the
PreToolUse hook routes by PATH: `services/telemetry_sharing_service.py` matches
backend.md's `src/backend/services/**` glob, so an engineer sent to backend.md
must find the prose there. Placing it by monolith adjacency would point the
hook at a file that does not describe it.

Verified by the branch's own suite — 22 passed, including
test_no_dangling_anchor_links_across_the_split (which proves the re-homed
cross-references still resolve) and test_core_within_line_budget (core
unchanged at 181 lines).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HAw7x7VwACVjc58pPPi3Th
Same shape as the previous merge: the only conflict is
docs/memory/architecture.md, because #2526 (loops terminal-driven) edited the
monolith this branch splits.

Only one line changed on dev — the "Startup hook (#740)" sentence, rewritten to
describe LoopService.reconcile_after_restart() replacing
mark_orphan_loops_interrupted(). Re-homed into reliability.md, which owns
cleanup_service and carries that sentence after the split, rather than resolved
textually against the core.

Core unchanged at 181 lines. Branch suite: 22 passed, including
test_no_dangling_anchor_links_across_the_split.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HAw7x7VwACVjc58pPPi3Th
@vybe

vybe commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Rebased onto dev again — conflicts resolved semantically, not textually

My earlier hold is lifted. Two more architecture.md touchers landed while this sat (#2516 ent#437 telemetry, #2526 loops terminal-driven), so I merged dev in twice and pushed the result (a853f875).

The conflict here is not a text conflict, and resolving it as one would have silently lost content. Both PRs added prose to the monolith this branch splits, so --ours drops it and --theirs un-splits the file. Each addition is re-homed into the area file that owns it:

From Content Re-homed to
#2516 settings.py catalog entry (Tier-2 sharing routes) backend.md
#2516 new "Opt-in Instance Telemetry (ent#437)" section backend.md
#2516 First-Run "Collateral" paragraph (FinishSetupCard) agent-lifecycle.md
#2516 /api/settings/feature-flags row api-endpoints.md
#2526 "Startup hook (#740)" rewrite (reconcile_after_restart) reliability.md

One placement call worth recording. The telemetry section sat between #2380 and #2216 in the monolith, whose sections are now in agent-lifecycle.md and reliability.md respectively — so adjacency argued for either of those. I put it in backend.md instead, because the PreToolUse hook routes by path: services/telemetry_sharing_service.py matches backend.md's src/backend/services/** glob, so that is where an engineer editing it gets sent. Placing prose by monolith adjacency would point the hook at a file that does not describe the thing.

That is really an argument for the design in this PR: the map made the question answerable at all, and test_no_dangling_anchor_links_across_the_split then proved the re-homed cross-references still resolve.

Core stays at 181 lines. Branch suite: 22 passed.

Approving — merging once CI is green.

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

Validated via /validate-pr. Docs-only change (plus one hook script and its test), so the security, packaging and migration gates are all not-applicable; scan of the diff is clean (no secrets, emails, public IPs, host paths or mode changes).

What makes this worth merging beyond the line count. The measured problem is that architecture.md is @-imported by CLAUDE.md, so every session pays for all ~3,200 lines whether or not it touches the subsystem. The split takes the core to 181 lines and moves the rest behind a map.

Two design choices carry it, and both are enforced rather than documented:

  • The map's third column names the regression each file prevents, not the topic — which is what gives an agent a reason to spend the tool call. database.md's entry is literally the two-heads hazard, which #2526 hit in this same batch: two revisions sharing a down_revision apply zero revisions while git reports no conflict.
  • The PreToolUse hook parses that table and has no map of its own, so there is one source and no second copy to drift. test_hook_parse_matches_the_published_table re-parses it independently and requires agreement, and test_hook_never_blocks_an_edit pins that malformed or foreign input exits 0 — advisory, never a gate.

Coverage is the right shape for a docs refactor, where the real risks are content loss and broken cross-references: bijection between map rows and area files, test_no_dangling_anchor_links_across_the_split, a core line budget stated in the file itself rather than only in the test, and most-specific-owner routing.

I resolved the two dev conflicts myself (see the comment above) — semantically, re-homing each addition into its owning area file, since a textual resolution here silently drops content. Merging once green.

@vybe
vybe merged commit e9fa1e0 into dev Sep 4, 2026
25 checks passed
@vybe
vybe deleted the feature/2306-architecture-split branch September 4, 2026 13:42
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.

2 participants