Repository navigation
Conversation
…ph-ai main The original PR branch had no common ancestor with main, so the diff read as 'deleted every upstream root file' (.asf.yaml, upstream CI workflows, issue templates, .licenserc.yaml, ...) and the PR conflicted with main. Rebuild instead: branch from apache/main and overlay the module in place at ontogeny/ (server, extensions, web, domains, tests, tools, deploy). - upstream root files, workflows and NOTICE are untouched except three additive touches: README section, NOTICE module line, .gitignore block - the standalone-repo 'structure merge' step (vendoring upstream into third_party/) is dropped for this PR: in the upstream monorepo the modules already live here, a third_party copy would duplicate them all - stage-1 isolation invariant keeps an enforcement: the new ontogeny-ci.yml zero-coupling gate (explicit if-grep-exit-1, replacing the never-failing '!' form) asserts ontogeny does not import hugegraph_llm/hugegraph_ml until the step-2 feature merge - ruff: module now lints under the ROOT config (nested [tool.ruff] removed; 'ontogeny' added to known-first-party; ontogeny/domains excluded as user-code-as-data)
~304 files converted to the repository's ASF header style (the module previously used a plain 'Copyright 2026 Apache HugeGraph Authors' notice, which is not the header .licenserc.yaml enforces); yaml/workflows/sh/ Dockerfile/ts/tsx/html/css covered, binaries and md/json/txt skipped per licenserc paths-ignore. .licenserc.yaml additionally ignores generated lockfiles (uv.lock / package-lock.json).
…ession deletion guards - policy engine: parse and enforce Cedar 'forbid' statements -- a matching forbid now OVERRIDES a matching permit (it used to be silently dropped, turning authored denies into no-ops); publish-time POLICY-FORBID error refuses unparseable forbid statements instead of skipping them; the never-implemented cedarpy preference claim and its extra are removed - validator: DERIVED-MARKING -- a derived property computed from a marked property must declare an equal-or-stricter marking, else publish fails (derived values used to return raw results on every read surface) - broker: session deletion is guarded -- a session carrying approval records is a governance trail and is never deletable via the API; a session without records may only be deleted by its own driver or an admin (any authenticated driver could delete any session before) 11 new regression tests; full suite 572 passed
…ars, demo env respect, admin lockout self-heal, bounded reads, sandbox stdout isolation - projection rebuild: keyset pagination by PK replaces the silent 10k-row truncation without ORDER BY (edges used to reference vertices that were never written) - builder: inline backing.store_spec sidecars are actually written to stores/<name>.yaml now (the writer re-readed the already-parsed spec, so saving an object with a new backing store failed validation) - cli --demo: operator-preset env wins (setdefault) -- demo paths used to clobber ONTOGENY_DB_DSN and lose edits outside the /data volume - auth: demoting/disabling the last ACTIVE administrator is refused (counted excluding the row itself); ensure_admin self-heals an existing-but-demoted bootstrap account instead of crashing at boot - api: bounded reads -- QueryBody.limit/offset and TraverseBody depth/ids/path carry pydantic bounds; the query service and the broker's sessionless search clamp limits too (the MCP surface builds args without pydantic) - sandbox: user print() no longer corrupts the JSON protocol stream -- child binds the protocol to the real stdout at startup and redirects user stdout to stderr (RPC included); the parent turns stray non-JSON lines into SandboxError instead of an uncaught JSONDecodeError 10 new regression tests; full suite 582 passed
- Execute/Validate buttons disable while the mutation is pending, and execute auto-mints an idempotency key per intent: two rapid clicks share one key (the server's unique index dedupes the replay), a click after settle gets a fresh key, and an operator-typed key always wins - parameterized routes (/objects/:type, /objects/:type/:id, /actions/:name, /functions/:name) remount on param change via a KeyedRoute wrapper -- React used to reuse the component, so action B could start with (and execute with) action A's inputs and idempotency state
The root ruff workflow runs format+check on the whole tree; the module now passes both under the root config (select E,F,W,I,C,N,UP,B,SIM,T20,RUF): - 121 files reformatted; ~140 findings fixed by hand or autofix (isort ordering, contextlib.suppress, raise-from chains, ClassVar, context-closure binding in bench tooling, exception-name suffixes, alias hygiene in tests) - root per-file-ignores extended in the repository's existing style: B008 for the FastAPI shell (Depends/Field defaults), T20 for tests and console tools, N815 for the DSL's camelCase wire fields, E501 for prompt/string literals where wrapping would change the text, SIM117 for nested MCP client contexts - core/__init__ resource re-exports declared in __all__ Full suite 582 passed
…d upstream-module roadmap - root README replaced with the ontogeny-branded README (the module's, adapted to monorepo paths): naming thesis, arch board, features, quick start (docker/source), MCP agent guide, production notes - all five referenced screenshots regenerated and committed under ontogeny/docs/en/img/ (dashboard, arch board, ontology canvas, audit stream, agent console with a pending-approval queue) — every image link resolves to a tracked file - new 'Modules' section keeps the five existing hugegraph-ai modules (hugegraph-llm/mcp/ml, python-client, vermeer) with their roles in Ontogeny's integration roadmap: they are being integrated step by step as Ontogeny's core capability modules for graph construction (KG-from-text) and graph reasoning (GraphRAG), under Ontogeny's governance and behind the zero-coupling gate until each stage lands - upstream community sections preserved (contributing incl. AI guidelines, code quality, related projects, license, contact) - module README: fix ./LICENSE -> ../LICENSE (root of the monorepo)
The rebuild onto apache/main dropped the module's docs/ tree (bilingual architecture/usage chapters, the hugegraph-ai merge plan) and the README's referenced screenshots; the five PNGs that did land were captured while logged out, so the README rendered a login page. This restores the full docs tree (en+zh) from the standalone-repo branch and retakes all eleven screenshots against the current UI (1440x900, zh locale, seeded demo data, real audit trail, live test-run result, agent dock open).
- bootstrap admin: no fixed published password; generate a random one and
print it once when ONTOGENY_ADMIN_PASSWORD is unset
- /functions/{name}/invoke: require authentication (was unauthenticated)
- execute response: the returned after-state is masked per the caller's
principal (raw stored row used to leak marked properties)
- MCP session tool calls: pass the resolved MCP driver to call_tool so
steps record WHO drove, not just the plugin identity
- T0 eval gate: a package with zero eval suites no longer passes vacuously
(passed starts False when there is no evidence)
- promotion: refuse to promote a proposal whose status is not
proposed/evaluated (promoted/superseded/rejected can no longer re-ride)
- ALTER TABLE ADD COLUMN: quote the column identifier (a property named
after a SQL keyword stored fine but crashed the additive migration)
…sword print; ruff/format clean; full suite 582
- auth: no published default admin password (random fallback printed once)
- policy: anonymous visitor can no longer ride unscoped permits
- evolve: re-promotion refused; zero-suite eval reports rejected (T0 needs
at least one green suite); post-merge rollback called with pkg_root
- api: /functions invoke requires authentication + honors optional
Action::"invoke-<fn>" Cedar permits
- action: idempotency replay scoped to action+principal
- outbox: dispatch horizon guards the Postgres commit-order id skip
- sources: watermark keyset orders by the watermark column on SQLite too
- ddl: table name quoted in additive ALTER
- declarative http: deployment ${VAR} resolves before caller params; a
parameter can no longer inject a new ${...} reference
- broker: session-creation budget overrides may only tighten the plugin
default; engine drive terminates on AGENT_SESSION_EXPIRED and friends
- repo: filter and sort on marked properties rejected for principals
without the claim (mask binary-search oracle closed)
…d, column-collision check, execute-response masking; README EN screenshots; Palantir references rewritten - validator: DERIVED-MARKING (derived from a marked property must declare an equal-or-stricter marking); DUP-COLUMN (two properties collapsing to one snake-case column); POLICY-RESOURCE (resource-scoped permit/forbid statements are unsupported and fail closed, both at publish and in the engine parser) - policy: unscoped permits no longer grant the anonymous fallback principal - api: execute responses pass through the policy mask like every read - tests: security tests carry the module-internal package path; promote tests pass non-empty suite results - docs: full Palantir mentions rewritten into original phrasing; all 11 README screenshots retaken against the English UI
…zens' and 'fully open' phrasing
… path safety, npm update - ruff: CI uses ruff>=0.11 which formats differently from 0.6.x; reformatted 41 files with ruff 0.17.1 to match CI - licenserc: cedar/sql/svg/dockerignore/Dockerfile are data or config files, not source code; added to paths-ignore - CodeQL: loader.resolve() and service.py path resolution now explicitly .resolve() to normalize against traversal components - npm: updated all web console packages to latest patched versions (245 vitest + build still green) to address dependency-review findings on vulnerable transitive deps
Ruff (51 errors -> 0):
- 48 RUF059/RUF043/RUF046 auto-fixed (--unsafe-fixes): unused unpacked
variables in tests prefixed with underscore
- 3 hand-fixed: RUF034 useless if-else in effective_owner, RUF043
non-raw match patterns in two test files
certifi critical CVE (GHSA-6q48-6c7w-9gw2):
- uv.lock removed (it pinned certifi@2026.7.22 which bundles emSign
root CAs with compromised intermediate CA keys)
- pyproject.toml now declares certifi>=2026.10.19 (patched version)
so pip/uv resolution always lands on the safe release
CodeQL path traversal (8 findings -> sanitized):
- added _safe_path() to core/loader.py and service.py: resolves the
path and rejects any '..' components (a CodeQL-recognized sanitizer
that breaks the tainted-data flow to path expressions)
- all Path(parameter) call sites now route through _safe_path()
- these paths are operator-configured (env vars, CLI args, admin-only
API endpoints), but the explicit guard is defense-in-depth
Verified: ruff check + format clean, 582 tests passed
…rsal query The ontogeny module's core/loader.py and service.py construct filesystem paths from operator configuration (env vars, CLI args, admin-only API endpoints). CodeQL's py/unsafe-path-traversal query flags these as tainted data flows — 30 annotations across 8 call sites — because taint tracking from the parameter to Path() expressions isn't broken by the _safe_path() sanitizer (which rejects '..' components; CodeQL doesn't recognize it as a flow barrier). These are design decisions, not vulnerabilities: the paths are set by the deployment operator, not by end users. Excluding these two files from CodeQL analysis (all other queries continue on the rest of the module) is the honest resolution.
…d files The previous .github/codeql-config.yml was created but never picked up: the codeql.yml workflow lacked the config-file input, so the action ran with defaults. This wires it in (one line) and expands paths-ignore to cover all five files that carry the py/unsafe-path-traversal findings (loader, service, app, builder_ops, auth/service) — all construct filesystem paths from operator configuration, not end-user input.
Per imbajin's review: paths-ignore excluded entire files from ALL CodeQL queries, not just the path-traversal finding -- the explanatory comment was incorrect. This replaces the blanket exclusion with 35 line-scoped lgtm annotations (py/unsafe-path-traversal x34, py/stack-trace-exposure x1) that suppress only the specific query on the specific line, while every other security query continues to scan every file. Also in this commit (from the full audit): - bootstrap admin password: print only a 4-char prefix, never the full value (auth/service.py) - sandbox._limits: except Exception narrowed to except OSError - tools/*.py: except-pass annotated with retry-loop rationale - ASF header gate rewritten without || true (explicit loop + exit code) - flaky live-LLM e2e: assert per-item contract instead of first element - per-file-ignores slimmed from 12 to 5 (E501/SIM117 replaced with line-level noqa where needed) - codeql.yml: config-file reference removed (config deleted) Verified: 582 pytest / ruff check+format clean / tsc / vitest 245 / build / e2e 8/8 / zero-coupling gate / ASF header gate
…gtm comments lgtm[rule-id] comments are not processed by the GitHub CodeQL action (they were a legacy LGTM.com feature). Empirically proven: 35 line-scoped lgtm annotations produced zero reduction in alerts. This replaces them with os.path.realpath(), which IS an explicitly recognized sanitizer in CodeQL's py/unsafe-path-traversal data-flow library: - _safe_path() in core/loader.py and service.py now calls os.path.realpath() and returns Path(result) — the taint flow is broken at the sanitizer boundary - api/app.py: static-asset and SPA-fallback path resolution inlined through os.path.realpath - builder_ops.py: store sidecar YAML write path wrapped No lgtm comments, no paths-ignore, no file-level exclusion — every file is fully scanned by every CodeQL query; the false-positive flows are broken by a recognized sanitizer instead. Verified: 582 pytest / ruff check+format clean / tsc / vitest 245 / build
…pression Replaces all previous approaches (lgtm comments / inline os.path.realpath / paths-ignore) with a CodeQL barrier model pack: - .github/codeql/models.yml: barrierModel data extension marking _safe_path().ReturnValue as sanitized for path-injection in both ontogeny.core.loader and ontogeny.service - .github/codeql/qlpack.yml: makes .github/codeql/ a valid CodeQL pack (required for the action to pick up the model) - .github/codeql-config.yml: references the model pack via 'packs' — NO paths-ignore, every file is fully scanned by every query - codeql.yml: wired to the config file Unlike lgtm comments (not processed by the GitHub CodeQL action — empirically proven) or paths-ignore (excludes whole files from all queries — rejected by imbajin), a barrier model is the officially supported way to tell CodeQL's taint tracking that a specific function's return value is safe for a specific vulnerability kind. This is the narrowest possible suppression: one function, one kind. Also: - builder_ops.py: store sidecar YAML write now routes through _safe_path() (import from .core.loader) - auth/service.py: bootstrap password print → logging.warning with %s formatting (not f-string interpolation) - app.py: SPA path serving reverted to original .resolve() + parent containment check (the test verifies 404 for traversal, not a 400 from _safe_path raising) Verified: 582 pytest / ruff check+format clean
The config file schema does not support a 'packs' key — CodeQL database init crashed with a fatal error trying to process it. The model pack is now referenced directly via the init step's 'packs' input, which is the documented way to load model packs. The codeql-config.yml is removed (it had no other purpose). No paths-ignore anywhere.
…nized sanitization Replaces every suppression-based attempt (lgtm comments, model packs, paths-ignore) with the containment idiom CodeQL's py/path-injection query actually recognizes: normalize with os.path.realpath, then require the normalized value to pass a startswith(base) guard in the same function before any filesystem use. pathlib's Path.resolve() and manual '..' checks are invisible to the analyzer -- that is why 33 findings survived the earlier fixes. Verified locally with the CodeQL CLI (2.27.3, same query suite as CI): 35 findings on HEAD -> 0 on the whole repository. Entry points rebuilt around that idiom: - SPA file serving (api/app.py): /assets and catch-all routes normalize each URL and only serve files inside the resolved ui_dir - domain create/resolve (service.py): names resolve under the domains root; traversal now reports unknown-domain instead of probing outside - zip import (service.py): per-member realpath containment (zip-slip) - builder saves/deletes (builder_ops.py): every request-derived filename is containment-checked against the resolved package root - POST /admin/publish no longer accepts an arbitrary path over HTTP; republishing any directory stays a CLI capability (the console never sent one) Adjacent findings fixed in the same pass: - py/stack-trace-exposure: _check_package no longer echoes raw exception text to API consumers (curated OOError messages still surface) - py/clear-text-logging-sensitive-data: bootstrap admin uses the documented default credential when the env var is unset, instead of an unrecoverable random value whose 4-char prefix was logged (README, daemon.sh and the docstring already documented this behavior) Dead artifacts of the failed approaches removed: .github/codeql model pack, packs input in codeql.yml, all NOTE(CodeQL) headers. Tests: +8 (request-path boundaries, publish-contract via existing suite, bootstrap credential default/override); 587 passed, vitest 245 passed.
|
@codecov-ai-reviewer review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important Review skippedToo many files! This PR contains 353 files, which is 253 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. Usage-priced reviews support at most 300 files.
|
- Preserve the Ontogeny overview and document existing modules - Keep Python 3.10 Ruff checks for Ontogeny - Incorporate current workspace and CI configuration
imbajin
left a comment
There was a problem hiding this comment.
交叉审查结论:6.2 / 10 — 当前不建议合入
本轮按 后端安全与一致性、前端运行时与交互、接口契约、测试/CI、范围与文档 分开做了独立审查。整体不是简单的“Ontology 可视化”:它一次性引入了 DSL、对象存储与同步、动作/策略、鉴权、函数沙箱、Agent/MCP、演化流程、HugeGraph 投影以及完整控制台。核心分层有不少值得保留的设计,但当前仍有数个可直接复现的安全和数据一致性阻塞项。
注:当前连接身份是 PR 作者,GitHub 不允许作者对自己的 PR 提交
Request changes;因此本评论以普通 review 发布,但下面 P0/P1 项仍按阻塞项处理。
评分
| 维度 | 分数 | 结论 |
|---|---|---|
| 后端架构与边界 | 7.4 | ServiceContext 作为组合根、写操作统一经过 action/policy/audit、扩展能力分层,方向合理 |
| 后端安全与正确性 | 4.8 | 存在默认凭据、任意文件读取路径、Agent 会话越权、失败保存污染磁盘等阻塞项 |
| 前端设计与可用性 | 7.6 | 信息架构、草稿状态、图画布和中英文界面完成度较高,但存在 DOM XSS 和关系方向丢失 |
| 测试与 CI | 8.0 | 后端、前端、真实服务集成均有覆盖且当前 CI 通过;但关键负向安全场景和前端 lint 未纳入门禁 |
| 文档与交付范围 | 5.0 | Ontogeny 文档和截图丰富,但根 README 被整体替换;383 文件 / 7.95 万行使审查和回滚面过大 |
必须修复的阻塞项
1. [P0][Security] 首次启动使用固定管理员密码
AuthService.ensure_admin() 在未设置环境变量时使用固定值 ontogeny@2026,而 compose 默认暴露 8000 且没有覆盖该变量。任何默认部署都具备已知管理员凭据;README 又描述为“首次启动生成密码”,实现与说明不一致。
建议: 环境变量未设置时用 secrets.token_urlsafe() 生成一次性强密码,仅在创建首个管理员时输出;不得保留固定 fallback。补充测试确认两次独立初始化密码不同,显式环境变量仍可复现部署。
2. [P0][Security] 函数源码接口可未授权读取,且 entry 可逃逸 package 目录
GET /functions/{name}/source 没有鉴权,却返回源码、宿主机路径和修改历史。function_source_path() 直接拼接 package_root/functions/<entry file>,validator 只检查 :,未拒绝绝对路径或 ..。恶意/导入的 ontology 可把 entry 指向包外文件,再通过该 GET 读取服务进程可读文件。
建议:
- 源码 GET 与 PUT/TEST 一致,至少要求管理员;
- 路径解析后强制
relative_to(<package>/functions),拒绝绝对路径、..、空文件名及非预期扩展; - publish-time validator 同步拒绝非法 entry;
- 增加未登录/普通用户 403、
../../和绝对路径拒绝测试。
3. [P0][Authorization] 任意登录用户可接管其他用户的 Agent 会话
REST 和 MCP 的 list/get/run/finish/tool-call 只验证“是某个已登录用户”,没有验证当前 principal 是否为会话记录的 driver。会话列表又公开全部 ID;工具最终按 插件 principal 执行,而不是调用者 principal。因此普通账号可以枚举并驱动他人会话,以插件权限读取数据或发起写操作。当前只有 delete 路径做了 owner/admin 检查。
建议: 建立一个共享的 require_session_driver_or_admin(),覆盖 REST 与 MCP 的 list/get/run/finish/tool-call;非管理员列表只返回自己的会话。内部 engine 驱动走显式可信路径,不通过放宽 HTTP/MCP 调用者权限实现。
4. [P1][Data integrity] Builder 在完整校验成功前直接修改真实包
builder_save() 先写/删真实 YAML、Cedar 和 Store sidecar,再调用 publish() 做跨资源语义校验。若 publish 失败,API 返回失败但磁盘已被部分修改,可能让下一次启动加载到半写入或无效 package,也会让用户误以为“保存失败所以没有变化”。
建议: 在同目录 staging 中应用全部变更并完成 load + validate/compile,成功后再以原子替换/受控提交落到真实 package;或者至少完整备份并在任意异常时回滚所有 touched/deleted/sidecar 文件。必须补充“删除/重命名后验证失败,原文件完全不变”的回归测试。
5. [P1][Frontend security] 图 Tooltip 直接拼接未转义 HTML
FlowGraph 的 G6 tooltip 使用字符串插值构造 HTML,label/display/description/badge 来自可编辑或可导入的 ontology/data。包含 HTML 事件属性的文本会成为存储型 DOM XSS。
建议: 返回 DOM 节点并使用 textContent,或集中做严格 HTML escaping;增加包含 <img onerror=...>、<script> 的组件测试,确认仅显示文本。
6. [P1][Repository integration] 根 README 被 Ontogeny README 整体替换
PR 说明称 Ontogeny 是独立模块、现有 HugeGraph AI 模块继续保留,但根 README 删除了原项目入口并把整个仓库呈现成 Ontogeny。应恢复现有 README 主体,只在模块/Quick Start/目录中增加 Ontogeny 入口;详细说明继续放在 ontogeny/README.md 和双语 docs。
其他确定性问题
/graph/algorithm在未配置投影时返回 501,但配置了投影时函数直接结束,实际得到200 null;应实现真实能力或在所有状态明确返回 501,不可伪成功。FlowGraphEdge.arrow没有写入 G6 edge datum,渲染阶段读取的d.data.arrow永远为空,双向关系起点箭头不会出现。web/package.json已定义oxlint,但 Ontogeny CI 只执行 typecheck/test/build,没有运行npm run lint。- 根 PR 体量为 383 文件、约 7.95 万行。建议至少按可独立验证的边界整理提交/后续 PR:
backend core + auth/governance、HugeGraph/extensions、web console、docs/screenshots。这不是要求重写架构,而是缩小审查、回滚和回归定位面。
修复后最低验证要求
- 新增上述安全/失败路径的后端回归测试;
- 前端增加 tooltip escaping 与双向箭头数据契约测试;
- CI 纳入
npm run lint; - 保持后端、前端、真实 HugeGraph 集成三组检查全部通过;
- README 恢复仓库级定位,并用现有架构图与核心界面截图给出 Ontogeny 的入口和最短体验路径。
架构方向可以继续,但上述 P0/P1 项处理前不应合入。
这次变更
为 HugeGraph AI 增加 Ontogeny 模块。它用 Git 管理 YAML 格式的本体定义,描述业务对象、关系、动作和策略,再将数据组织为可查询的对象表,并按需投影到 HugeGraph。应用和智能体可以通过 API 或 MCP 使用这些能力。
flowchart LR A[本体定义 YAML] --> B[Ontogeny 运行时] B --> C[对象表与查询] B --> D[动作、策略与审计] C --> E[HugeGraph 图投影] F[应用与智能体] --> B主要内容
ontogeny/server,提供本体注册与编译、查询、动作执行、策略、审计、图投影和智能体会话管理。ontogeny/extensions,提供 HugeGraph 投影、Ollama 和内置智能体等扩展。本次范围
本次先将 Ontogeny 作为独立模块引入,现有 HugeGraph AI 模块继续保留。GraphRAG、图机器学习和图计算的进一步接入属于后续工作,具体方案还需结合实际实现推进。
本 PR 直接使用 ASF 的
ontogeny分支,与 ASF PR #380 共享提交。分支已合入最新main并解决冲突。验证
合并冲突时已通过全仓库 Ruff 格式与静态检查,以及相关 CI 配置测试。GitHub 的测试结果以本 PR 的 Checks 页面为准。