Skip to content

feat: support a sampling seed for built-in Ollama requests - #4168

Closed
oleksii-tumanov wants to merge 1 commit into
Graphify-Labs:v8from
oleksii-tumanov:codex/feat-ollama-seed-20261006
Closed

oleksii-tumanov wants to merge 1 commit into
Graphify-Labs:v8from
oleksii-tumanov:codex/feat-ollama-seed-20261006

Conversation

@oleksii-tumanov

Copy link
Copy Markdown
Contributor

What does this PR do?

Refs #3988

Add an optional validated GRAPHIFY_OLLAMA_SEED for every built-in Ollama request while preserving the default request shape when it is disabled.

Keep custom providers and non-Ollama backends isolated, and document the semantic-cache and repeatability limits.

The setting accepts ASCII decimal values from 0 through 9223372036854775807. Both structured extraction and plain-text built-in Ollama calls send the value as a top-level seed without changing the existing extra_body behavior.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

When the setting is disabled, built-in Ollama requests keep their existing shape. When enabled, both request paths send the validated seed while custom aliases and other backends remain unchanged.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

.venv/bin/pytest tests/test_llm_backends.py -q -k ollama_seed
.venv/bin/pytest tests/test_llm_backends.py -q
.venv/bin/pytest tests/ -q --tb=short
.venv/bin/ruff check .
.venv/bin/pyright --outputjson
.venv/bin/graphify update .

22 seed regressions and all 132 backend tests passed.

Full offline all-extras suite: 6,639 passed and 15 skipped; Ruff and graph update checks passed.

Pyright introduced no diagnostics relative to the exact base.

Limitations

No live Ollama or other provider/model call was made; request shape was verified with mocked clients.

A fixed seed improves repeatability but does not guarantee identical output across runtime, model, hardware, or concurrency changes.

Semantic cache identity remains unchanged; users need one --force run after enabling or changing the seed when fresh semantic output is required.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no generated skill sources changed; generation guards passed.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

AI assistance is disclosed separately in the commit's AI-Assistance metadata.

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for the pull request, @oleksii-tumanov. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 error).

Not verified on this run: \_call\_llm (vacuous: never exercised), \_call\_openai\_compat (error).


Graphify review — findings

Adds an opt-in GRAPHIFY_OLLAMA_SEED env var whose value both _call_openai_compat and _call_llm send as a top-level seed on every built-in ollama request, leaving extra_body untouched; other backends and custom providers pointed at an Ollama URL ignore it. _resolve_ollama_seed accepts only ASCII integers in 0..9223372036854775807, treats blank as off, and raises ValueError before any client construction or API-key lookup. The semantic cache isn't keyed by seed, so the README tells users to run with --force after setting or changing it.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 978 functions depend on the 350 functions this change touches.

Health — this change adds coupling hotspots:

  • new: deduplicate_entities() — 82 callers, 26 callees
  • new: build_merge() — 85 callers, 14 callees
  • new: extract_files_direct() — 17 callers, 20 callees
  • new: build() — 56 callers, 6 callees
  • new: main() — 102 callers, 3 callees
  • new: _call_claude_cli() — 33 callers, 9 callees
  • new: extract_corpus_parallel() — 26 callers, 11 callees
  • new: _call_llm() — 14 callers, 19 callees
  • …and 19 more — each is listed as a finding

Verification — 978 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 615 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

334 of 334 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_analyze.py — full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — full-run-safety
  • tests/test_astro_import_ids.py — full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — impact, full-run-safety
  • tests/test_backend_extras.py — impact, full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_blade_extractor.py — full-run-safety
  • tests/test_build.py — impact, full-run-safety
  • tests/test_build_located_semantic_identity.py — impact, full-run-safety
  • tests/test_build_merge_dedup_scope.py — impact, full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — impact, full-run-safety
  • tests/test_build_merge_shrink_guard.py — impact, full-run-safety
  • tests/test_builtin_global_type_refs.py — full-run-safety
  • tests/test_cache.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — impact, full-run-safety
  • tests/test_case_sensitive_resolution.py — full-run-safety
  • tests/test_charmap_encoding.py — impact, full-run-safety
  • tests/test_chunking.py — impact, full-run-safety
  • tests/test_cjs_module_extension.py — full-run-safety
  • tests/test_claude_cli_backend.py — impact, full-run-safety
  • tests/test_claude_md.py — full-run-safety
  • tests/test_cli_broken_pipe.py — full-run-safety
  • tests/test_cli_export.py — full-run-safety
  • tests/test_cli_help.py — full-run-safety
  • tests/test_cluster.py — full-run-safety
  • tests/test_cluster_exclude_hubs.py — full-run-safety
  • tests/test_cobol_extractor.py — full-run-safety
  • tests/test_codebuddy.py — full-run-safety
  • tests/test_community_hub_labels.py — full-run-safety
  • tests/test_community_labels_skill.py — full-run-safety
  • tests/test_confidence.py — full-run-safety
  • tests/test_corrupt_graph_json.py — impact, full-run-safety
  • tests/test_cpp_method_declarations.py — full-run-safety
  • tests/test_cpp_nested_and_cli.py — full-run-safety
  • tests/test_cpp_objc_cross_file_calls.py — full-run-safety
  • tests/test_cpp_preprocess.py — full-run-safety
  • … and 284 more

non-code file(s) changed (README.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

changed code file(s) with no mapped test (README.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

Formal verification

Could not verify: Could not verify \_call\_llm.

The verifier did not have enough to check \_call\_llm, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 40 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly TypeError — names the real obstacle, not a sampling gap)

Verification did not run: Verification did not run for \_call\_openai\_compat.

The verification could not execute (an environment/toolchain issue, not a statement about the code).

Guarantee: No guarantee, the check itself did not complete.

Note: Detail: harness produced no verdict (rc=124): timeout after 30s

· 27 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.86 (now on PyPI), authorship preserved. The code applied cleanly; the README doc hunks were dropped because that section moved to docs.graphify.com in the README trim — worth adding the Ollama seed note to the config docs there. Thank you, @oleksii-tumanov!

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