Skip to content

docs(planning): Phase 1 architecture-refactor window (Steps 1.1a–1.1f) + ADRs 0005–0009 - #41

Merged
officialCodeWork merged 1 commit into
mainfrom
planning/phase-1-architecture-refactor
May 23, 2026
Merged

docs(planning): Phase 1 architecture-refactor window (Steps 1.1a–1.1f) + ADRs 0005–0009#41
officialCodeWork merged 1 commit into
mainfrom
planning/phase-1-architecture-refactor

Conversation

@officialCodeWork

Copy link
Copy Markdown
Owner

Summary

Inserts a six-step refactor window (1.1a–1.1f) between Phase 1 Step 1.1 and Step 1.2 to lock in architecture + optimization decisions that are very expensive to retrofit later. Also inserts Phase 2 Step 2.11 (agent-loop validation spike). Adds 5 new ADRs and 4 new architecture docs. Updates the HLD to v1.1 to reflect the new patterns.

No code changes — planning + docs only. Implementation begins on the 1.1a branch.

What changes

New Phase 1 steps (planning/phases/phase-1-ingestion.md)

  • 1.1a — Core type & SPI refactor. `RequestContext` threaded through every SPI; typed `tenant_id` + `acl_labels` on `Chunk`/`Embedding` (not metadata dict); `trust_level` for prompt-injection defense; `Embedding.dtype` (float32/int8/binary); `BlobRef` for lazy chunk text; `QueryPlan` + `ChunkRef` types; typed `StageEvent`.
  • 1.1b — SPI split. `RetrievalBackend` / `IndexBackend` separation; `bulk_embed`/`bulk_index`/`bulk_delete`; async-iterator ingest variants; `retrieve_ids` + `hydrate` pair; `IndexHint` parameter.
  • 1.1c — PolicyEngine package (`rag-policy`). Single PDP for ACL / PII / quotas / redaction. Coverage linter blocks bypasses at CI. Supersedes Step 6.4 (ACL egress verifier).
  • 1.1d — Pipeline + Batcher primitives in `rag-core`. Async DAG with bounded queues; DataLoader-pattern coalescer under Embedder / Reranker.
  • 1.1e — Cache SPI split. Three caches (`EmbeddingCache`, `RetrievalCache`, `AnswerCache`) with distinct invalidation rules. Hot-path discipline doc. Async telemetry with drop-on-overflow.
  • 1.1f — ADRs 0005–0009 + reviewer checklist.

New Phase 2 step

  • 2.11 — Agent-loop validation spike. 50-query harness validates retrieval design against agent access patterns before Phase 3.

Milestone counts

  • Phase 1: 10 → 16 steps
  • Phase 2: 10 → 11 steps
  • Total: 77 → 84 steps

New ADRs (docs/adr/)

ADR Decision
0005 PolicyEngine as central PDP; supersedes Step 6.4
0006 Two-stage reranker as default SPI shape from day 1
0007 `Chunk.text: str | BlobRef` enables lazy hydration + tiering
0008 Cost-aware planner; fallback before dispatch, not after timeout
0009 Vector index strategy by scale tier + int8 / binary quantization

New architecture docs (docs/architecture/)

File Topic
request-context.md Per-request envelope threaded through every SPI
policy-engine.md Central PDP design, usage, extension points
caching.md Three caches, three invalidation rules
performance.md Hot-path discipline, per-SPI p99 budgets, reviewer checklist

HLD update (v1.0 → v1.1)

  • §4.2 components table expanded (PolicyEngine added; Knowledge Store split into Retrieval + Index).
  • New §4.2.1 cross-cutting runtime primitives table.
  • §10 governance rewritten around PolicyEngine PDP; `trust_level` documented as prompt-injection foundation.
  • §11 observability adds `StageEvent` stream + async telemetry.

Planning doc updates

  • EXECUTION-PLAN.md — §3 phase summary updated; v1.2 changelog entry.
  • PROBLEM-TRACEABILITY.md — governance + latency entries hardened; new prompt-injection entry; 22 → 23 entries.
  • RISK-REGISTER.md — R2, R4, R5, R11 mitigations hardened with ADR pointers.

CLAUDE.md

  • Phase / step pointer updated.
  • Repo layout: `rag-policy` + `rag-backends` packages added.
  • New sections: RequestContext threading, PolicyEngine, hot-path discipline.

Why this PR, why now

After review with the team, the V1.0 plan had three architectural risks that were going to surface as expensive Phase-4/Phase-7 rework:

  1. Governance scattered across 5 steps → one missed call site = leak. (Step 6.4 already a tacit admission.)
  2. SPIs single-item shaped → no path to million-doc ingest without rewriting every backend.
  3. Hardcoded ivfflat + no quantization story → 1M-vector wall in Phase 2; embedded cost in Phase 7.

These are fixed cheaply before the 6 connectors + 4 retrieval backends + agent loop are written. After that point, the cost is 4–6× higher.

Documentation

Per CLAUDE.md per-PR doc rule, every affected file is updated in this PR:

  • `TRACKER.md`
  • `planning/EXECUTION-PLAN.md`, `planning/phases/phase-1-ingestion.md`, `planning/phases/phase-2-retrieval.md`
  • `planning/PROBLEM-TRACEABILITY.md`, `planning/RISK-REGISTER.md`
  • `docs/architecture/RAG-Platform-HLD.md` (v1.1)
  • `docs/architecture/{request-context,policy-engine,caching,performance}.md` (new)
  • `docs/adr/ADR-{0005,0006,0007,0008,0009}-*.md` (new)
  • `docs/README.md` (index)
  • `CLAUDE.md`

Cross-references between TRACKER, planning, architecture, and ADRs are bidirectional.

Test plan

  • No code changes in this PR — planning + docs only.
  • Implementation work begins on a separate `build/phase-1/step-1.1a-core-type-refactor` branch after this lands.
  • CI on this PR should be doc-only (path filters: no Python jobs trigger).
  • Maintainer review focuses on ADR correctness + planning-doc consistency.

🤖 Generated with Claude Code

…1a–1.1f) + ADRs 0005–0009

Locks in architecture + optimization decisions before Phase 1.2 (connectors)
that are very expensive to retrofit. Defers no implementation; updates all
affected planning + architecture docs in one coherent pass.

## What changes

### TRACKER.md
- Inserts Phase 1 Steps 1.1a–1.1f (refactor window) between 1.1 and 1.2.
- Inserts Phase 2 Step 2.11 (agent-loop validation spike).
- Milestone counts: Phase 1 10→16, Phase 2 10→11, Total 77→84.
- Next action updated to 1.1a.

### Phase 1 plan (planning/phases/phase-1-ingestion.md)
Six new detailed step plans with Goal / Inputs / Deliverables / Test plan /
Acceptance criteria:
- 1.1a — Core type & SPI refactor: RequestContext threaded through every SPI;
  typed tenant_id + acl_labels on Chunk/Embedding; trust_level for
  prompt-injection defense; Embedding.dtype (float32/int8/binary); BlobRef for
  lazy chunk text; QueryPlan + ChunkRef; typed StageEvent.
- 1.1b — SPI split: RetrievalBackend / IndexBackend; bulk + streaming +
  retrieve_ids/hydrate + IndexHint.
- 1.1c — PolicyEngine package (rag-policy): single PDP for ACL / PII / quotas /
  redaction. Supersedes scattered checks. Coverage linter blocks bypasses.
  Step 6.4 (ACL egress verifier) marked redundant.
- 1.1d — Pipeline + Batcher primitives in rag-core.
- 1.1e — Three-cache SPI split (EmbeddingCache / RetrievalCache / AnswerCache),
  hot-path discipline doc, async telemetry with drop-on-overflow.
- 1.1f — ADRs 0005–0009 + reviewer checklist.

### Phase 2 plan (planning/phases/phase-2-retrieval.md)
- Step 2.11 — Agent-loop validation spike at end of Phase 2 to validate
  retrieval design against agent access patterns before Phase 3.

### Architecture docs (new)
- docs/architecture/request-context.md — the per-request envelope.
- docs/architecture/policy-engine.md — central PDP design + usage + extension.
- docs/architecture/caching.md — three caches, three invalidation rules.
- docs/architecture/performance.md — hot-path discipline, per-SPI p99 budgets,
  reviewer checklist.

### ADRs (new)
- ADR-0005 — PolicyEngine as central PDP.
- ADR-0006 — Two-stage reranker as default SPI shape from day 1.
- ADR-0007 — Chunk.text: str | BlobRef enables lazy hydration + tiering.
- ADR-0008 — Cost-aware planner; fallback triggered planner-side before
  dispatch, not by post-hoc timeout.
- ADR-0009 — Vector index strategy by scale tier + int8/binary quantization;
  resolves ADR-0004 §2 "ivfflat hardcoded" gap.

### HLD (docs/architecture/RAG-Platform-HLD.md)
- v1.0 → v1.1.
- §4.2 components table expanded: PolicyEngine added; Knowledge Store split
  into Retrieval + Index; runtime primitives table added (RequestContext,
  QueryPlan, Pipeline, Batcher, PolicyEngine, StageEvent, ChunkRef, BlobRef).
- §10 governance rewritten around PolicyEngine PDP; trust_level documented as
  prompt-injection foundation; Step 6.4 (egress verifier) marked redundant.
- §11 observability adds StageEvent stream + async telemetry path.

### EXECUTION-PLAN.md
- §3 phase summary updated (Phase 1 + refactor window; Phase 2 + spike).
- §9 change log: v1.2 entry.

### PROBLEM-TRACEABILITY.md
- Cross-tenant, ACL, PII entries route through PolicyEngine PDP.
- Latency entry adds 1.1b/1.1d/1.1e + ADRs 0006/0008/0009.
- Step 6.4 marked superseded.
- New entry: prompt injection → trust_level + LLM adapter isolation strategy.
- 22 → 23 entries.

### RISK-REGISTER.md
- R2, R4, R5, R11 mitigations hardened with explicit pointers to ADRs 0005,
  0006, 0008, 0009 and the PolicyEngine coverage linter.

### CLAUDE.md
- Current phase / next step updated to 1.1a + refactor window context.
- Repo layout: rag-policy and rag-backends packages added.
- Python packages table: rag-policy added; rag-core + rag-observability
  descriptions updated for Pipeline / Batcher / async exporter.
- New sections: RequestContext threading, PolicyEngine, hot-path discipline.
- Standing constraints expanded.

### docs/README.md
- Indexes the four new architecture docs and five new ADRs.

## Documentation

Every affected file is updated in this single PR per the standing
per-PR-documentation rule. Cross-references between TRACKER, planning,
architecture, and ADRs are bidirectional.

## Test plan

No code changes in this PR — planning + docs only. Implementation work begins
on a separate branch for Step 1.1a.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@officialCodeWork
officialCodeWork merged commit 98fdcee into main May 23, 2026
8 checks passed
officialCodeWork added a commit that referenced this pull request May 23, 2026
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