Skip to content

Commit 0824936

Browse files
authored
Merge pull request #5 from QSOLKCB/phase-5/ollama-reference-adapter
Phase 5–6: local Ollama adapter and real-model CI
2 parents bdcf2db + a40a942 commit 0824936

10 files changed

Lines changed: 3445 additions & 8 deletions

File tree

‎.github/workflows/ollama.yml‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: ollama
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "provenance_adapters/**"
7+
- "tests/test_ollama_adapter.py"
8+
- "tests/test_ollama_transport.py"
9+
- "scripts/ollama_smoke.py"
10+
- "OLLAMA.md"
11+
- ".github/workflows/ollama.yml"
12+
push:
13+
branches: ["main"]
14+
paths:
15+
- "provenance_adapters/**"
16+
- "tests/test_ollama_adapter.py"
17+
- "tests/test_ollama_transport.py"
18+
- "scripts/ollama_smoke.py"
19+
- "OLLAMA.md"
20+
- ".github/workflows/ollama.yml"
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: read
25+
26+
env:
27+
OLLAMA_VERSION: "0.34.0"
28+
OLLAMA_INSTALL_SHA256: "25f64b810b947145095956533e1bdf56eacea2673c55a7e586be4515fc882c9f"
29+
30+
jobs:
31+
adapter-unit:
32+
runs-on: ubuntu-24.04
33+
timeout-minutes: 3
34+
steps:
35+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
36+
with:
37+
persist-credentials: false
38+
- name: Run Ollama adapter unit tests
39+
run: >-
40+
python3 -m unittest
41+
tests.test_ollama_adapter
42+
tests.test_ollama_transport
43+
-v
44+
45+
ollama-smoke:
46+
needs: adapter-unit
47+
strategy:
48+
fail-fast: false
49+
max-parallel: 2
50+
matrix:
51+
include:
52+
- lane: qwen25-05b
53+
model: "qwen2.5:0.5b"
54+
- lane: qwen2-05b
55+
model: "qwen2:0.5b"
56+
57+
runs-on: ubuntu-24.04
58+
timeout-minutes: 15
59+
60+
env:
61+
OLLAMA_HOST: "http://127.0.0.1:11434"
62+
OLLAMA_MODEL: ${{ matrix.model }}
63+
64+
steps:
65+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
66+
with:
67+
persist-credentials: false
68+
69+
- name: Install pinned Ollama
70+
shell: sh
71+
run: |
72+
set -eu
73+
curl -fsSL https://ollama.com/install.sh -o /tmp/ollama-install.sh
74+
printf '%s %s\n' "$OLLAMA_INSTALL_SHA256" /tmp/ollama-install.sh | sha256sum -c -
75+
OLLAMA_NO_START=1 OLLAMA_VERSION="$OLLAMA_VERSION" sh /tmp/ollama-install.sh
76+
ollama --version
77+
78+
- name: Start independent Ollama instance
79+
shell: sh
80+
run: |
81+
set -eu
82+
OLLAMA_HOST=127.0.0.1:11434 OLLAMA_NUM_PARALLEL=1 OLLAMA_MAX_LOADED_MODELS=1 nohup ollama serve >/tmp/ollama.log 2>&1 &
83+
echo "$!" >/tmp/ollama.pid
84+
85+
python3 - <<'PY'
86+
import time
87+
import urllib.request
88+
89+
url = "http://127.0.0.1:11434/api/version"
90+
for _ in range(120):
91+
try:
92+
with urllib.request.urlopen(url, timeout=1) as response:
93+
if response.status == 200:
94+
print(response.read().decode("utf-8"))
95+
raise SystemExit(0)
96+
except Exception:
97+
time.sleep(0.25)
98+
raise SystemExit("Ollama server did not become ready")
99+
PY
100+
101+
- name: Pull small reference model
102+
shell: sh
103+
run: |
104+
set -eu
105+
ollama pull "$OLLAMA_MODEL"
106+
107+
- name: Run real PROVENANCE observation
108+
shell: sh
109+
run: |
110+
set -eu
111+
out="$RUNNER_TEMP/provenance-ollama-${{ matrix.lane }}"
112+
mkdir -p "$out"
113+
python3 -m scripts.ollama_smoke --model "$OLLAMA_MODEL" --host "$OLLAMA_HOST" --output "$out"
114+
115+
- name: Upload evidence
116+
if: always()
117+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
118+
with:
119+
name: provenance-ollama-${{ matrix.lane }}
120+
path: ${{ runner.temp }}/provenance-ollama-${{ matrix.lane }}
121+
if-no-files-found: warn
122+
retention-days: 7
123+
124+
- name: Show Ollama log on failure
125+
if: failure()
126+
shell: sh
127+
run: |
128+
test ! -f /tmp/ollama.log || tail -n 200 /tmp/ollama.log

‎ARCHITECTURE.md‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ Presentation may use RFC3339/base-60 clock notation, but custody time calculatio
824824

825825
# 17. Ollama Reference Adapter
826826

827-
The first AI adapter should be Ollama.
827+
The first AI adapter is Ollama.
828828

829829
Reasons:
830830

@@ -837,14 +837,54 @@ easy request/response capture
837837
small models available
838838
```
839839

840+
The Phase 5 reference implementation is:
841+
842+
```text
843+
provenance_adapters.OllamaAdapter
844+
adapter id = provenance-adapter:ollama/v1
845+
transport = loopback HTTP only
846+
endpoint = /api/generate
847+
stream = false
848+
dependencies = Python standard library + existing PROVENANCE modules
849+
```
850+
851+
It retains the exact request bytes prepared by the adapter before transport and retains any HTTP response body bytes before parsing.
852+
853+
The transport boundary is enforced by an adapter-owned urllib opener with environment proxies disabled and redirects rejected. The documented localhost spelling is canonicalized to a literal loopback address to avoid DNS.
854+
855+
Prepared request evidence does not independently prove peer receipt. Transport and parse failures are recorded with COLLECTION_FAILED events and finalized evidence rather than silently disappearing.
856+
857+
Phase 5 uses one fresh evidence store/custody pair per exchange. Each unique evidence root is reserved with a same-process mutex plus a POSIX fcntl advisory record lock on an operational .ollama-observation.lock file. Roots are acquired in stable filesystem-identity order, and the reservation is held across freshness validation through complete observation/failure finalization. Freshness is re-read from disk after acquiring the reservation. This prevents concurrent threads, adapter instances, or cooperating processes that share either evidence root from both passing the freshness gate, and prevents deterministic event identities from collapsing repeated byte-identical calls until the core has an evidence-supported occurrence discriminator.
858+
859+
Adapter-retained HTTP payload bytes use one role-neutral artifact media type. Transport role is represented by events/custody so identical bytes can legitimately appear as both prepared request and observed response without rebinding content identity metadata.
860+
861+
Every finalized failure binds a canonical failure-detail artifact containing a stable adapter category, optional observed HTTP status, and diagnostic detail. Zero-length observed HTTP bodies remain distinct from no observed body.
862+
863+
The response model field is treated as a declaration by Ollama. It is not promoted into independently verified model provenance, and it is not used as the custody actor.
864+
865+
Capture times are expressed through custody observations rather than by adding provider-specific timestamp fields to the universal event core.
866+
840867
The Ollama adapter exists primarily to test the evidence architecture.
841868

842869
It must not define AI provenance semantics for every other provider.
843870

871+
Ollama's OpenAI-compatible endpoints are intentionally not used to redefine Phase 5. OpenAI-compatible HTTP remains a later generic interoperability surface behind the adapter boundary.
872+
844873
---
845874

846875
# 18. Ollama CI Contract
847876

877+
The initial real-model lane uses a GitHub Actions matrix with separate clean runners. Each matrix job starts its own Ollama server and pulls one small reference model.
878+
879+
Current reference matrix:
880+
881+
```text
882+
qwen2.5:0.5b
883+
qwen2:0.5b
884+
```
885+
886+
The Ollama runtime is version-pinned in the workflow and its downloaded installer script is checksum-verified before execution.
887+
848888
A real inference test should verify the chain rather than exact generated language.
849889

850890
Example flow:
@@ -870,8 +910,9 @@ VERIFY
870910
Assertions should cover:
871911

872912
```text
873-
request retained or intentionally omitted
874-
response retained
913+
prepared request retained
914+
successful or error response bytes retained when observed
915+
failure evidence finalized on transport/parse failure
875916
request identity recomputes
876917
response identity recomputes
877918
adapter identity recorded

0 commit comments

Comments
 (0)