SIFTRCODE V2 • SYSTEM ARCHITECTURE & OUTCOME OPTIMIZATION

How SiftrCode Works

A deep engineering overview of SiftrCode V2: multi-channel candidate recall, point-in-time versioned features, explainable ContextRank, submodular bundle composition, safe variable-resolution degradation, and constrained knapsack budget solving.

Execution Latency
<100ms Local
Edit Targets
100% Body
Balanced Savings
−78.6% Tokens
Network Egress
0 Outbound Bytes
Live Architecture Triage Explorer

How SiftrCode Triages Repository Context

Profile:

SiftrCode intercepts agent queries locally, evaluating repository candidates in <100ms before model inference to deliver outcome-optimized context with variable resolution.

PHASE 01 • INPUT 85,000 tok

Candidate Bloat

Lexical and graph discovery recalls 42 repository candidate files. Without Siftr, flooding all 42 full files into context causes latency and attention loss.

PHASE 02 • RESOLUTION <100ms CPU

6-Stage Optimization

Runs point-in-time features, transparent ranking, submodular bundle composition, and knapsack solving to partition candidates into 3 optimal resolution tiers.

PHASE 03 • PAYOFF 18,200 tok (−78.6%)

Outcome-Aware Bundle

Agent receives full implementation bodies for edit targets, typed AST interface skeletons for dependencies, and filtered distractor tokens.

Inspect Resolution Channels

Click a channel to inspect how SiftrCode assigns resolution, preserves types, and suppresses noise.

THE 6-STAGE OUTCOME PIPELINE

The 6-Stage Optimization Engine

SiftrCode V2 replaces naive single-file token stripping with a formal multi-stage context pipeline designed to maximize first-turn task completion rates while cutting context costs.

01

Multi-Channel Candidate Recall

Subsystem: CandidateGenerator • 5 Orthogonal Discovery Channels

Coding agents frequently fail when initial search misses non-obvious callers or pulls in hundreds of irrelevant results. SiftrCode V2 runs Multi-Channel Candidate Recall across 5 orthogonal channels in parallel:

1. Exact Symbol / Path Matching

Identifies exact symbol names, functions, classes, and file paths referenced in the prompt or error report.

2. BM25 Lexical Retrieval

Probabilistic keyword ranking over exported docstrings, parameter names, and error string tokens.

3. Stack Trace Diagnostic Parser

Directly parses stack traces, runtime exceptions, and test failure outputs to pinpoint exact file and line offsets.

4. Context Graph & Git Co-Change

Traverses AST import/export caller graphs and mines git history for files that frequently co-modify together.

02

Point-in-Time Versioned Features

Subsystem: ContextFeaturesV1 • Strict Temporal FeatureCutoff Invariant

Context optimization must be scientifically reproducible and immune to evaluation leakage. SiftrCode models every candidate file as an immutable versioned feature vector (ContextFeaturesV1) with a strict featureCutoff timestamp.

No post-task commits, downstream edits, or runtime test outputs can leak into feature calculation. Features capture lexical affinity, graph centrality, error proximity, line count, and edit recency with deterministic provenance.

03

Deterministic ContextRank & 7-Gate Model Governance

Subsystem: ContextRank • Deterministic Production Baseline • Fail-Closed Promotion Gates

Black-box neural rankers introduce non-deterministic ordering and unpredictability into production workflows. SiftrCode V2 maintains deterministic ContextRank as the sole production decision-maker, calculating an explicit finalScore alongside auditable reasons and component breakdowns:

ContextRank Scoring Formulation:
Score(c) = w_exact * s_exact + w_bm25 * s_bm25 + w_stack * s_stack + w_graph * s_graph - Penalties
Stack Trace Hits: +0.40 boost
Exact Identifier: +0.30 boost
Vendor / Build Dir: -0.50 penalty
Shadow Evaluation & Background Calibration

To evaluate candidate ranking signals safely, Siftr forks candidate signals to a shadow JudgmentProvider in the background. Shadow evaluation analyzes continuous relevance, edit target probability, and root cause localization without altering production ContextPlans (bit-for-bit plan identity in shadow mode). Candidate evaluations run with strict decision budgeting, fail-closed probability validation, and zero hidden retries.

Scientific Model Governance & 7-Gate Promotion Criteria
Inspect Gates →

Before any learned model can be promoted to production, it must pass 7 strict promotion gates, including offline holdout NDCG@10 across 40 tasks on 4 independent repositories (Commander, Express, FastAPI, SiftrCode). In canonical holdout evaluations, candidate model gbdt_pairwise_v1 achieved 0.5034 NDCG@10 vs frozen V2 baseline's 0.5200 (delta -0.0166; 95% CI [-0.0478, +0.0076]). Because the candidate failed to beat the baseline, SiftrCode's fail-closed governance rejected promotion, preserving the deterministic production baseline.

04

Submodular Synergy Composition

Subsystem: BundleComposer • Marginal Coverage Maximization & Synergy Boosts

Selecting context files independently leads to severe redundancy: multiple files defining identical helpers, or omitting the single type contract required to understand a causal function.

SiftrCode's BundleComposer applies submodular function optimization: each candidate added to the bundle is evaluated by its marginal utility gain relative to already-chosen files. Co-requisites (e.g. an interface file paired with its primary caller) receive a synergistic boost, while redundant utility mocks are quickly suppressed.

05

3-Stage Resolution Lineage & Discrete Method Slicing

Subsystem: ResolutionRank • Discrete Method BODY Isolation • Lineage Invariants

The fatal flaw in pure skeletonization is stripping the code the agent actually needs to rewrite. SiftrCode V2 eliminates this with 3-stage resolution lineage and discrete method body slicing:

3-Stage Resolution Lineage:
1. rankerResolution → 2. budgetedResolution → 3. finalResolution

Every ContextUnit tracks this immutable progression through solver budget allocation and post-render degradation. When an agent invokes siftr_expand to BODY, the Discrete AST Slicer isolates precisely the target function/method body while strictly excluding sibling methods, preventing context pollution.

Full (100%)

Direct edit targets. 0 lines stripped.

Method Body

Exact target method. Sibling methods pruned.

AST Skeleton (-88%)

Exported types, classes, interfaces.

Signatures (-95%)

Transitive dependencies & contracts.

Drop (-100%)

Non-causal distractors eliminated.

06

Constrained Budget & Truthful Accounting

Subsystem: BudgetSolver & TokenizerRegistry • Knapsack Optimization

Context windows have hard operational ceilings. SiftrCode's BudgetSolver solves a constrained knapsack problem over candidate representations, maximizing cumulative utility per token without violating prompt budget limits.

Integrated with TokenizerRegistry, Siftr enforces pre-flight bounds calibrated against Claude BPE (~3.7 chars/tok) and GPT cl100k/o200k (~3.6 chars/tok), preventing context overflow and ensuring billing integrity.

⚡

Prompt Caching & Prefix Invariance Architecture

Context Hierarchy • 90% Cache Discounts • Cold Turn Invalidation Protection

Frontier LLMs (Anthropic Claude 3.7, OpenAI GPT-4o, Google Gemini 2.0) offer prompt caching discounts of up to 90% on repeated input prefixes. However, standard coding agents constantly edit files, invoke tools, and inspect outputs. Each code modification invalidates prompt caches, causing costly cold turns where all input tokens are re-billed at full write rates. SiftrCode eliminates this penalty through a two-tier context hierarchy:

TIER 1 • DETERMINISTIC PREFIX Hot Cache • 90% Discount

Invariant AST Interface Skeletons

Exported types, method signatures, and structural interfaces are ordered deterministically by canonical file path at the head of the prompt. Because structural contracts rarely change during edit loops, this prefix stays bit-for-bit invariant across dozens of agent turns, sustaining continuous 90% cache hits.

TIER 2 • ISOLATED SUFFIX Dynamic Tail • Zero Upstream Invalidation

Target Bodies & Tool Returns

Full implementation bodies for files the agent is actively editing are placed strictly at the tail of the context bundle. When edits happen, only the small dynamic tail invalidates, preventing cache eviction of the large structural codebase skeleton.

Cache-Miss Insurance for Cold Turns
When cache misses are unavoidable (e.g., initial turn or git checkout), raw repositories pay write costs on 85,000 tokens ($0.255/turn on Sonnet). SiftrCode V2 cuts cold payloads to ~18,200 tokens, slashing cache-write dollar overhead by 78.6% and cutting time-to-first-token by 4.7x.

Token Economics by Budget Profile

Modeled on 85k-token raw repository payload at 50 turns/day (1,400 turns/mo per dev).

Interactive Calculator →
Profile Optimized Payload Token Reduction Sonnet 3.7 / Turn Monthly Savings 10-Dev Team / Yr
Balanced (Default) 18,200 tok −78.6% $0.055 Save $280 / mo +$33.7k / yr
Aggressive 10,500 tok −87.6% $0.032 Save $313 / mo +$37.5k / yr
Thorough 32,000 tok −62.4% $0.096 Save $223 / mo +$26.7k / yr
Claude 3.7 Sonnet ($3.00/M)
$0.055 / turn
was $0.255 (−78.6%)
OpenAI GPT-4o ($2.50/M)
$0.046 / turn
was $0.213 (−78.6%)
Claude 3.7 Thinking / o1 ($15/M)
$0.273 / turn
save $1.00 / turn
Gemini 2.0 Flash ($0.10/M)
$0.0018 / turn
was $0.0085 (−78.6%)

SiftrBench: Holdout Benchmark & Paired Core-Thesis Verification

Phase 21A • 40 Holdout Tasks

Before any model-based ranking signal can influence production ContextPlans, it must survive rigorous scientific evaluation. SiftrBench validates optimization across 40 holdout tasks on 4 independent repositories (Commander, Express, FastAPI, SiftrCode) and executes a Paired Core-Thesis Experiment Harness (Phase 21A) measuring live agent task outcomes:

Holdout Benchmark
40 Tasks / 4 repos

10 tasks each on Commander, Express, FastAPI, SiftrCode. Continuous offline NDCG@10 validation.

Paired Agent Trials
Phase 21A

Side-by-side agent runs tracking success rate delta, token reduction, and CPVST efficiency.

Statistical Rigor
McNemar p < 0.05

Requires statistically significant task win margin or demonstrable CPVST cost reduction.

Shadow Identity
0 Divergence

Bit-for-bit plan identity in shadow mode (0% fallback rate, zero orphan signals, sub-10ms CPU).

Zero-Egress & Data Rights Technical Guarantees

Authoritative Rights • Phase 20.4

SiftrCode V2 is governed by authoritative granular operation rights, fail-closed remote processing, and closed-loop data flywheel integrity:

1. trainingAllowed: false

Zero machine learning training on customer code. RightsFilter export gate strictly blocks raw source tables.

2. operationRights: Authoritative

operationRights.*.retention.local governs every durable SQLite write; 0 raw source strings stored.

3. remoteProcessing: Fail-Closed

Strictly forbidden by default; requires explicit createJevPermittedDataRights policy.

4. Tri-State UNKNOWN Labels

Unexposed code emits label: null with tri-state verifiedSuccess; never forced to negative 0.

5. WeakSet Sanctioned Export

Direct arbitrary persistence is rejected; only genuine exports bearing a cryptographically sanctioned WeakSet token can persist.

6. Gate 4 Rights & Provenance

Dataset V2 training pool validates canonical eligibility; unpermitted, UNKNOWN provenance, or orphan rows fail closed.

7. WorkspaceChangedError

Snapshot immutability guards trigger structured replanning if files mutate mid-task on disk.

8. Egress Gateway & Redaction

Automated regex redaction for AWS keys, Stripe secrets, and Bearer tokens prior to external dispatch.

9. Multi-Language AST Parsers

Syntax-verified AST parsers for TypeScript, JavaScript, Python, Go, and Rust with line-span accuracy.

10. Method BODY Isolation

AST slicing isolates target method bodies strictly, excluding all adjacent sibling class methods.

11. Post-Render Budget Ladder

Hard token gate: dynamic degradation (FULL → BODY → SKELETON → SIGNATURE → NAME → OMIT).

12. Truthful Token Accounting

TokenizerRegistry calibrated against Claude BPE (~3.7 chars/tok) and GPT cl100k/o200k (~3.6 chars/tok).

13. Strict Model Governance

Deterministic ContextRank baseline defaults in production; candidate models require 7 passed gates to promote.

14. Local-First Processing

Sub-100ms CPU execution with 0 outbound network bytes via CLI and standard Model Context Protocol (MCP) stdio.

Closed-Loop Learning Plane Architecture .siftr/observations.sqlite (Local Only)
Candidate Recall → ContextRank & Features → BudgetSolver → siftr_expand → siftr_outcome → TrainingEvidenceRecord
MCP

Model Context Protocol (MCP) & CLI Tools

Standard stdio Integration with Claude Code, Cursor, and Antigravity

SiftrCode V2 implements the official Model Context Protocol (MCP) specification. Register it once and your coding agent automatically invokes siftr_context before writing code:

Register MCP Server in Claude Code CLI: RECOMMENDED
$ claude mcp add siftrcode -- npx -y siftrcode mcp
Direct CLI Outcome Optimization:
$ npx siftrcode context "fix webhook invoice race condition" --profile balanced -o context.xml
Available V2 MCP Tools: 10 TOOLS AVAILABLE
siftr_context

Full 6-stage outcome optimization for task prompt within token and cost limits.

siftr_optimize

Alias for siftr_context for outcome-aware context bundle optimization.

siftr_expand

Progressive disclosure tool expanding skeletons into full implementation bodies.

siftr_outcome

Reports downstream verification signals (tests, builds, regressions) to close learning loop.

siftr_session

Inspects multi-turn session telemetry, trajectory events, and budget burn rate.

siftr_rank

Diagnostic heuristic ranking with transparent scores and primary reasons.

siftr_skeleton

AST interface extractor for TypeScript, Python, Go, and Rust source files.

siftr_batch_skeleton

Concurrent AST interface extraction across multiple target files.

siftr_audit

Audits codebase token footprint and calculates potential team ROI savings.

siftr_pack

Generates whole-directory pruned context packs for task-focused areas.

Ready to test it on your codebase?

Run a 5-second audit or register SiftrCode directly with your agent.

Run audit:
$ npx siftrcode audit