Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
84d9a37
test(docs): require canonical documentation graph
seonghobae Aug 9, 2026
0565a8e
docs: establish canonical product architecture
seonghobae Aug 9, 2026
0616dfe
docs: correct runtime evidence and source licensing
seonghobae Aug 9, 2026
e732497
docs: correct trace and runtime control claims
seonghobae Aug 9, 2026
9ae34ff
test(docs): parse supported Mermaid syntax
seonghobae Aug 9, 2026
343edac
merge: stack canonical docs on accepted security head
seonghobae Aug 9, 2026
31cbf25
docs: preserve agent authority boundaries
seonghobae Aug 9, 2026
fde04d3
test(docs): require changelog traceability
seonghobae Aug 9, 2026
f5b9acc
docs: record canonical product documentation graph
seonghobae Aug 9, 2026
c78aa35
docs: refresh live traceability evidence
seonghobae Aug 11, 2026
bee7a0c
docs: define traceability snapshot boundary
seonghobae Aug 11, 2026
33906b1
docs: add canonical release operations guide
seonghobae Aug 11, 2026
3744016
docs: record release guide in changelog
seonghobae Aug 11, 2026
d13b597
docs: refresh commercial readiness traceability
seonghobae Aug 11, 2026
d0a6ac8
docs: refresh package identity traceability
seonghobae Aug 11, 2026
3418993
docs: align README with product identity
seonghobae Aug 11, 2026
12e868b
docs: clarify independent product provenance
seonghobae Aug 11, 2026
7630125
docs: remove remaining lab qualifier
seonghobae Aug 11, 2026
8ce282d
docs: qualify enterprise auth boundary
seonghobae Aug 11, 2026
12b6570
docs: align library adoption status
seonghobae Aug 11, 2026
828ca54
docs: align agent dependency guidance
seonghobae Aug 11, 2026
62a4983
docs: status-qualify runtime guides
seonghobae Aug 11, 2026
163dcda
test(docs): require review-aligned authority contracts
seonghobae Aug 11, 2026
14487f4
docs: align canonical contracts with review
seonghobae Aug 11, 2026
1ec8337
test(docs): normalize semantic contract whitespace
seonghobae Aug 11, 2026
7254fa9
test(docs): require PR 109 in audited inventory
seonghobae Aug 11, 2026
c348c7c
docs(traceability): audit PR 109
seonghobae Aug 11, 2026
94a43c5
test(docs): require fail-closed aggregate review evidence
seonghobae Aug 11, 2026
46c92ba
docs(adr): fail closed aggregate review evidence
seonghobae Aug 11, 2026
c8ab1c2
test(docs): prove review evidence clauses fail closed
seonghobae Aug 11, 2026
66ccb67
test(docs): enforce full fail-closed review semantics
seonghobae Aug 11, 2026
97e2f13
test(docs): reject canonical trailing whitespace
seonghobae Aug 11, 2026
310ded2
docs: remove diff-check whitespace from ARCHITECTURE.md
seonghobae Aug 11, 2026
9712faa
docs: remove diff-check whitespace from docs/PRD.md
seonghobae Aug 11, 2026
2457009
docs: remove diff-check whitespace from docs/TRD.md
seonghobae Aug 11, 2026
c679de2
docs: remove diff-check whitespace from docs/TRACEABILITY.md
seonghobae Aug 11, 2026
4570cde
docs: remove diff-check whitespace from docs/THREAT_MODEL.md
seonghobae Aug 11, 2026
cf5414a
test(docs): reject canonical final blank lines
seonghobae Aug 11, 2026
4a91606
docs: remove final blank line from ADR index
seonghobae Aug 11, 2026
21dba99
docs: trace active local MLX provider slice
seonghobae Aug 11, 2026
952c21f
docs: separate volatile evidence from traceability
seonghobae Aug 12, 2026
f07ab38
test(docs): require the live open-PR snapshot
seonghobae Aug 12, 2026
3fce9bb
docs(evidence): reconcile the live open-PR ledger
seonghobae Aug 12, 2026
5543d1b
docs(evidence): reconcile draft inventory aggregate
seonghobae Aug 12, 2026
5e1505d
docs(evidence): add continuation audit ledger
seonghobae Aug 12, 2026
b62cc16
docs: mark evidence snapshot identity
seonghobae Aug 12, 2026
32ca453
docs(security): define coordinated disclosure lifecycle (#104)
seonghobae Aug 12, 2026
9179304
merge: refresh canonical docs onto accepted security head
seonghobae Aug 12, 2026
9e26f89
test(docs): reject stale stack and KV authority claims
seonghobae Aug 12, 2026
9583b8a
docs: reconcile live stack and KV authority
seonghobae Aug 12, 2026
75079a6
test(docs): reject closed trace-hardening PR as active
seonghobae Aug 12, 2026
5cd3774
docs: retire incomplete request-boundary slice
seonghobae Aug 12, 2026
7fdb02f
test(docs): distinguish reopened superseded scaffold
seonghobae Aug 12, 2026
8931039
docs: record reopened NIM scaffold without active authority
seonghobae Aug 12, 2026
63bcad6
test(docs): require live partial and duplicate-stack truth
seonghobae Aug 12, 2026
2d93ee3
docs: reconcile live partial and duplicate stack authority
seonghobae Aug 12, 2026
85cdcae
fix(docs): stop pairing PR #115 with #90's closed-unmerged phrasing
seonghobae Aug 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 54 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ push or open a PR.
code-scanning tools can't converge on one PR ref. Gating happens via the
Security **job results**; do not add tools to the `code_scanning` rule.

### Repository-writer lease and dependency authority

- Enforce **one writer per repository branch**. Before every repository write,
refetch the **exact PR head and target blob SHA**. If either changed, inspect
the intervening work and reconcile once before editing; never overwrite an
independently moved branch from stale state.
- Repositories outside `ContextualWisdomLab/contextual-orchestrator`, including
the central `ContextualWisdomLab/.github` control plane and repositories with
their own dedicated maintenance loops, are **read-only dependencies** unless
the task is explicitly assigned to that repository. Do not edit their
branches, dispatch **write-capable agents**, resolve their review threads, or
merge their PRs from this repository's loop.
- Live GitHub state is authoritative. A predecessor-head, stale-head,
cancelled, absent, failed, queued, pending, skipped-required, or
synthetic-merge result is not current-head evidence and must never be reused
to approve or merge a later tree.
- Do not create one-shot, self-modifying, encoded-patch, branch-local repair, or
temporary write-capable GitHub Actions workflows. Prefer direct reviewed
changes tied to the exact current head.

### Code exploration

- This repo has **no `.codegraph/` index**, so use normal search
Expand All @@ -56,23 +76,26 @@ push or open a PR.
- The reference implementation is xtrmLLMBatchPython's pgcrypto-encrypted
Postgres credential registry (`get_credential(name)`); reuse that pattern (a
DB-backed KV is fine) unless a dedicated KV is adopted.
- **Known deviation to migrate:** this repo currently resolves provider API
keys from env — `ModelClient` reads `os.environ.get(agent.api_key_env)` in
`contextual_orchestrator/orchestrator.py` (and `CONTEXTUAL_ORCHESTRATOR_*`
tokens in `__main__.py`). Move these to KV-backed reads; keep env only as the
bootstrap path that seeds the KV.
- Protected main resolves provider keys through `get_credential`; the legacy
`api_key_env` field is only a credential-name compatibility alias. Do not
reintroduce request-time environment fallback. Process/bind configuration
may still use explicit `CONTEXTUAL_ORCHESTRATOR_*` bootstrap inputs.

### This repo: the org LLM gateway

- `contextual-orchestrator` is the org's **LLM-communication hub** — the
OpenAI-compatible front door consumed by **gyeot** and **scopeweave**.
- **Direction:** grow it toward a **LiteLLM-class multi-provider gateway**. The
org is open to a **Rust/Python hybrid** to cut overhead.
- Its `ModelClient` currently reads `os.environ.get(agent.api_key_env)` — this
is the KV-principle deviation above. Resolve the API key (including the org
`OPENAI_API_KEY`) from the **KV / credential registry**, not env.
- The **OpenCode review pipeline is separate** and stays on **GitHub Models** —
do not change it.
- Its `ModelClient` resolves the credential name through the **KV / credential
registry**, including `OPENAI_API_KEY`; do not add ambient environment
fallback at request time.
- The **OpenCode review pipeline is separate and centrally governed** by
`ContextualWisdomLab/.github`. Do not hard-code or replace its provider pool,
reviewer identities, or credential chain from this repository. For live model
tests and autonomous development work owned by this repository, use
`NVIDIA_NIM_API_KEY`; never repurpose `COPILOT_GITHUB_TOKEN` as a model or
development-agent credential.

### This repo's role in the ecosystem

Expand All @@ -83,15 +106,15 @@ push or open a PR.
email/PIM that DOM-decomposes emails/files into a persisted knowledge graph).
Each component below is a **standalone program that must ALSO work as a git
submodule**, grown separately and together:
- **waf-ids-ai-soc** — WAF / IDS / AI SOC / LB / APIM.
- **wardnet** — WAF / IDS / AI SOC / LB / APIM.
- **clearfolio** — document viewer.
- **pg-erd-cloud** — ERD tool.
- **contextual-orchestrator** — this repo: LLM cost/perf/upstream-LB gateway
(beyond LiteLLM).
- **codec-carver** — STT / omni-modal speech-video codec.
- **fast-mlsirm** — LLM-as-a-Judge calibration + evaluation-item quality
(uses aFIPC FIPC + kaefa item-fit).
- **feelanet-adfs** — passwordless SSO (OIDC/SCIM/ADFS/LDAP/FIDO2/OAuth2.1,
- **keyverse** — passwordless SSO (OIDC/SCIM/ADFS/LDAP/FIDO2/OAuth2.1,
eliminate passwords).
- **newsdom-api** — PDF→DOM sidecar.
- **semantic-data-portal** — upper ontology / catalog / governance plane with
Expand All @@ -109,3 +132,22 @@ push or open a PR.
scheduling (e.g. LLM-cascade / model-routing and queueing/load-balancing
papers).
<!-- END cwl-agent-guidance -->

## Canonical product documentation

Start at [`docs/README.md`](docs/README.md). Root `ARCHITECTURE.md`, PRD, TRD,
ERD, UML, ADRs, threat model, test strategy, operability, incident response,
traceability, and references are one status-qualified graph. Behavior changes
must update the affected authority and documentation contract test.

## Execution continuity

- Treat prompt edits, audits, status summaries, and documentation assessments
as intermediate work when the request also authorizes repository changes.
- Continue the safe chain: verify live target state, repair the smallest
coherent authority set, run focused and full evidence, publish a reviewable
branch/PR, inspect its exact-head state, then take the next non-conflicting
authorized task while a control-plane check is pending.
- Stop only for a real authority choice, destructive ambiguity, permission
boundary, or external dependency that blocks every safe continuation. Never
turn queued, absent, stale, synthetic, or status-only evidence into success.
201 changes: 201 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Contextual Orchestrator architecture

**Document state:** `accepted_architecture`
**Canonical role:** current component, trust-boundary, and deployment authority

`docs/architecture.md` remains a research-to-product note. This document is the
system architecture authority and links detailed runtime diagrams in
`docs/UML.md` and data ownership in `docs/ERD.md`.

## Architectural intent

Contextual Orchestrator is one provider-neutral orchestration domain exposed as
a Python library, CLI, and OpenAI-compatible HTTP service. It keeps policy and
evidence inside one deployable boundary while allowing optional infrastructure
adapters. Basic operation does not require the wider CWL ecosystem.

```mermaid
flowchart TB
caller["API consumer"] --> delivery["HTTP / CLI delivery"]
operator["Platform operator"] --> admin["Admin and evidence API"]
delivery --> coordinator["CostRoutingCoordinator: sync or batch"]
coordinator --> domain["TaskOrchestrator: route or conduct"]
coordinator --> ledger["Cost ledger"]
coordinator --> batch["Local or pg-llm-batch adapter"]
delivery -. passthrough / route stream .-> domain
admin --> domain
domain --> client["ModelClient provider adapter"]
domain --> state["Optional workflow / agent stores"]
client --> provider["OpenAI-compatible provider"]
```

The dotted path is a protected-main exception: raw compatible passthrough and
route streaming bypass part of coordinator accounting. It is a documented gap,
not the target evidence architecture.

## Bounded contexts

| Context | Responsibility | Does not own |
|---|---|---|
| Delivery | Authentication, input bounds, HTTP/CLI translation, compatible response framing. | Model policy or provider credentials. |
| Orchestration domain | Route/conduct choice, workflow plan, access lists, agent selection, verification, synthesis, trace, budget. | Host identity, tenant directory, or provider network implementation. |
| Provider adapter | KV credential lookup, compatible request, timeout/retry, usage capture, transport validation. | Workflow policy or review authority. |
| Cost and batch hub | Token/count provenance, configured prices, attribution, sync/batch decision, backend lifecycle. | Route/conduct policy, fabricated prices, or external batch persistence. |
| State and credential adapters | Optional SQLite state/agent overlay, PEP-249 ledger, in-memory or pgcrypto credentials. | Legal basis, tenant authorization, or enterprise backup policy. |
| Operator evidence | Admin, trace, evaluation, access, audit, analytics, and readiness projections. | Certification, independent approval, or production SLO proof. |

## Module map

| Module | Role |
|---|---|
| `orchestrator.py` | `ModelAgent`, `WorkflowStep`, `OrchestrationPolicy`, `ModelClient`, `TaskOrchestrator`, state stores, cache, redaction, budgets, traces, and readiness reports. |
| `server.py` | Threaded stdlib HTTP delivery, bearer scopes, validation, rate/concurrency controls, routing, SSE framing, and error translation. |
| `admin.py` | Dependency-free operator console. |
| `api_contract.py` | Machine-readable OpenAPI subset and operation identities. |
| `credentials.py` | Credential protocol, in-memory backend, pgcrypto Postgres backend, and registry functions. |
| `kv_config.py` | In-memory configuration and optional `pg-llm-batch` configuration adapters. |
| `cost_ledger.py` | Price book, prompt-safe usage records, telemetry, non-blocking export, SQL store, and rollups. |
| `batch_routing.py` | Routing hints/policy, local and external chat/embedding batch contracts. |
| `cost_router.py` | Coordinates token counting, sync/batch channel choice, ledger, and backend submission/retrieval. |
| `token_counting.py` | Deterministic heuristic and optional Postgres `pg_tiktoken` adapter. |
| `conventions.py` | Two-or-more-word snake_case validation. |
| `__main__.py` | CLI completion, server, evaluation, and credential bootstrap. |

## Control plane and data plane

The control plane includes agent configuration, policy, credentials, prices,
budgets, provider exclusions, evaluation, and operator evidence. The data plane
includes validated request payloads, selected step context, provider requests,
answers, usage signals, and optional batch payload references.

Control-plane changes may affect later requests but cannot rewrite the evidence
attached to a completed run. Data-plane payloads must not be copied into broad
usage telemetry. Protected main has only admin and inference bearer scopes: no
dedicated trace scope exists, and an inference-scoped caller may request
`include_orchestration_trace: true`. Purpose- and tenant-specific trace authority
is an accepted boundary that still needs host RBAC or a dedicated runtime scope.

## Route and conduct

`TaskOrchestrator.complete()` is the stable split:

- `route` selects and calls one eligible worker. It is the only mode that can
honestly relay live provider SSE tokens on protected main.
- `conduct` creates a bounded template or validated generated workflow. Each
`WorkflowStep.access` tuple names prior step outputs deliberately included in
that worker's context. Verification precedes synthesis when policy requires
it. Any HTTP stream is framed after the answer exists.

The deterministic policy is the protected-main authority. Learned routing,
recursive coordination, and role-specific reasoning controls require
comparable-budget evidence before replacing it.

Protected-main agent choice is deterministic tag/domain/priority scoring. It is
not learned, price-aware, or load-balanced. `route_p95_seconds` is exposed but
does not currently participate in dispatch, and `cheapest_upstream()` is not
called by either routing layer.

## Trust boundaries

1. **Caller boundary:** bearer scope, bind policy, body/role/mode/rate/concurrency
validation precede orchestration.
2. **Context boundary:** access lists limit cross-step visibility. Trace exposure
defaults off, but protected-main inference authority can opt in; dedicated
purpose/tenant trace RBAC remains `planned`.
3. **Credential boundary:** provider secrets are names in model configuration
and values in KV; environment is bootstrap transport only.
4. **Provider boundary:** protected main requires HTTPS and globally routable
destinations. The stronger DNS-pinned, redirect/proxy-safe, strictly bounded
response implementation is `active_pr` in #96.
5. **Persistence boundary:** in-memory is default. Enabling a file or database
creates an operator obligation for access, encryption, retention, backup,
deletion, and recovery.
6. **Evidence boundary:** a local report, check status, automated review, human
approval, and protected merge are different authorities.
7. **Host boundary:** a CWL host retains identity, tenancy, legal basis,
business data, and deployment unless a versioned contract delegates them.

## Data ownership

- In-memory workflow, evaluation, audit, analytics, circuit, and cache state are
process-owned and ephemeral.
- Optional SQLite stores provide standalone durability, not a normalized
enterprise data plane.
- The cost ledger has an in-memory default and a portable PEP-249 SQL store.
- The active `PriceBook` reads ConfigStore, not the SQL
`llm_price_entries` table. That table is created but dormant.
- Provider credentials may be in-memory for development or pgcrypto-encrypted
in Postgres.
- `docs/database_design.sql` is a normalized production target and must not be
confused with runtime-created SQLite schemas.
- External batch/config/secret objects accessed through `pg-llm-batch` are
owned by that service or adapter.

## Deployment forms

### Standalone

One process serves CLI or HTTP, mock or configured providers, in-memory state,
and optional SQLite/SQL/KV adapters. Loopback binding is the safe default.

### CWL composition

An ingress or host authenticates the user and supplies a purpose-bound request.
Contextual Orchestrator selects and executes models. `pg-llm-batch` may execute
latency-tolerant work. naruon, inkspan, Clearfolio, and other systems consume
explicit interfaces and retain their own data and authorization boundaries.

## Failure domains and degraded behavior

| Domain | Isolation and degraded behavior |
|---|---|
| One provider/model | Bounded transient retry, eligible failover, circuit breaker; permanent errors fail fast. |
| Credential registry | Non-mock execution fails closed; mock/offline operation remains available. |
| Optional state store | Persistence evidence is unavailable; the service must not claim durable history. |
| Cost export | Non-blocking store may degrade while prompt-safe health exposes the loss. |
| External batch service | Interactive route remains independently usable; process-local job lookup is lost on restart even when an external job survives. |
| Admin integration | Inference and library paths remain independently usable. |
| Automated review/control plane | Protected merge waits; repository-local development and verification continue. |

## Architecture invariants

- Agent pools are data, not provider-specific branches in domain logic.
- Access is explicit; a worker never receives all previous outputs by default.
- Credentials are resolved by name at the provider boundary.
- Estimates are labeled and unknown prices remain unknown.
- Optional integrations do not break standalone behavior.
- No repository-local result claims certification or independent approval.
- New scientific arithmetic owned by this service is Rust-first with
parity-verified CPU/GPU paths; currently such arithmetic is `out_of_scope`.
- Database identifiers use two-or-more-word snake_case unless an external
standard fixes the field name.

## Known protected-main divergences

- Workflow-derived spend/budget and the independent cost ledger are not
synchronized. Missing ledger price becomes zero while spend analytics labels
it unknown; this violates the accepted unknown-price invariant.
- Raw passthrough records analytics but no workflow or ledger row. Route
streaming bypasses the coordinator and durable `_StateStore`; a mid-stream
failure can leave no retained run.
- Coordinator batch handles are process-local. Restart loses lookup, and chat
result replay can duplicate usage; embedding idempotency is also process-local.
- Static OpenAPI, runtime dispatch, scopes, and endpoint prose are separate
authorities and have drifted.
- Optional config and token-count adapters may silently fall back to memory or
heuristic counting. Degraded authority needs explicit operator evidence.
- Commercial/readiness responses are derived documents, not persisted domain
entities or external attestations.

## Status-qualified evolution

- PR #96: `active_pr` provider transport and response trust boundary.
- PR #90: `active_pr` NIM discovery/benchmark evidence.
- PR #94: `active_pr` free-first fallback.
- PR #99: `active_pr` adaptive reasoning controls stacked on #94.
- PR #82: `active_pr` dependency bootstrap stacked on #96 and not independently
mergeable first.

No active pull request is architecture authority until its exact head passes
repository policy and reaches protected main. See `docs/TRACEABILITY.md` for the
dated repository snapshot and `docs/adr/README.md` for decision status.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and

### Documentation

- Status-qualify the analytics, REST API, and internationalization guides, replacing legacy prototype labels and distinguishing current standalone paths from optional planned framework adoption.
- Align Claude and conductor guidance with the current provider-neutral product and status-qualified dependency-adoption boundary, removing legacy lab and internal gate names.
- Replace stale lab/prototype and internal-name language in library research with machine-checked current-stack and adoption-status boundaries for the stdlib HTTP/admin path and optional API/database extras.
- Correct the supporting product plan's enterprise-auth boundary: the standalone runtime has coarse admin/inference bearer scopes, not tenant-aware RBAC, while the host owns enterprise identity and tenancy.
- Remove the remaining stdlib-lab qualifier from spend observability and describe the evidence boundary as a standalone deployment without promoting local signals to billing or compliance evidence.
- Replace the competitor-centric README disclaimer with an affirmative independent-implementation, third-party-model-weight, proprietary-artifact, and provider-boundary statement for commercial provenance review.
- Replace legacy lab framing in the root README with the current buyer-facing provider-neutral orchestration-control-plane identity and local-deployment boundary.
- Add a canonical release, migration, and rollback guide that binds protected-source identity, reproducible build and artifact provenance, state migration, publication, rollback, and protected-main operational acceptance without presenting Draft evidence as shipped.
- Establish a canonical status-qualified product documentation graph spanning PRD, TRD, architecture, UML, ERD, ADRs, threat model, test strategy, operability, incident response, traceability, standards/research references, and machine-checked authority boundaries without promoting active or planned work as shipped.
- Add APA 7 doctoring for Python environment-marker semantics, Atheris artifact availability and hashes, and the supported-platform uncertainty boundary.
- Add provider-response resource-bound doctoring covering the 8 MiB fail-closed limit, HTTP framing preflight, `text/event-stream` media-type enforcement, bounded SSE reads, OpenAI-compatible `[DONE]` completion evidence, malformed-event and premature-EOF handling, batch-output partitioning, incident handling, and operational rollback.
- Add provider-stream UTF-8 doctoring grounding strict SSE/JSON decoding and redacted malformed-input handling in the WHATWG HTML Standard and RFC 8259, with verification, failure, rollback, and authority boundaries.
Expand Down
Loading
Loading