This file is the entry point for AI coding agents working in this repository.
Before changing code, read docs/DEVELOPMENT_PRINCIPLES.md
for durable engineering rules and regression lessons, then read
docs/AI_CONTEXT.md for the current refactoring focus,
verified findings, open gaps, and next actions. Follow the relevant architecture
page, roadmap, tests, and evidence links.
| Topic | Start here |
|---|---|
| Durable engineering principles and regression-prevention rules | docs/DEVELOPMENT_PRINCIPLES.md |
| Current AI handoff and ongoing refactoring state | docs/AI_CONTEXT.md |
| Runtime entry points, lifecycle, configuration, and task dispatch | docs/source/runtime_architecture.rst |
| Runtime refactoring stages and acceptance criteria | docs/plans/runtime-refactoring-roadmap.md |
| Documentation ownership and consolidation | docs/plans/oneflow-documentation-consolidation-plan.md |
| Kunshan/DCU cluster workflow and verified environments | ci/kunshan/README.md |
| Report conventions, naming, publication boundary | docs/reports/README.md |
| Current 1D Euler CPU/DCU performance data | docs/reports/performance/oneflow-euler-performance-current.md |
| 2026-09-13 measurement method and baseline audit | docs/reports/performance/oneflow-euler-performance-20260913.md |
| CPU regression suite and residual baselines | test/README.md, test/baselines/README.md |
| GoogleTest contract tests | tests/README.md |
| Current Phase Plan slice, checkboxes, and acceptance evidence | docs/plans/oneflow-development-todo.md |
| Long-term phase plan (milestones, gates, open decisions) | docs/plans/oneflow-development-plan.md |
| 3D device-residency architecture design (A.4 / LU-SGS residency) | docs/architecture/oneflow-3d-device-residency-design.md |
| Session handoff (living: environment, fixed paths, traps) | docs/handoff/oneflow-current-handoff.md |
| Kunshan workspace layout, job submission and cleanup rules | docs/runbooks/oneflow-kunshan-workspace-runbook.md |
| Document index and retention policy | docs/README.md |
- For the ongoing OneFLOW runtime, mesh, and Workbench refactoring, base work on
the latest
hexinHEAD unless the user explicitly gives a different target. Do not develop on, push to, or submit this work tomaster. - Before editing, inspect the actual checked-out branch and current commit. The AI context page is a curated snapshot and may lag behind the repository.
- When records disagree, the current source and tests plus CI evidence for the exact commit determine implementation status. Architecture pages explain intended boundaries; plans and handoff notes are not proof that a feature or test exists.
- Keep changes compatible with
hexinand avoid rewriting published history.
Contributions normally arrive from a fork, so a checkout can have two remotes:
origin (the fork) and upstream (this repository). Keep three kinds of
branches separate:
- Baseline branch (
masterin the usual layout) — kept identical to the upstream default branch and treated as a read-only PR baseline. Do not develop on it. Runscripts/sync-master.shmanually to fast-forwardorigin/mastertoupstream/master. The script never changes localmasterordev; iforigin/masterhas diverged, it stops for manual review. - Working branch (
dev, when the checkout has one) — the long-lived branch for daily work, in-progress features and notes. Pushing it to the fork is the backup step. Keep it current by merging the upstream default branch into it (git merge upstream/master); do not rebase it once it has been pushed, since that rewrites public history. - Topic branches — short-lived, created from the upstream default branch only when a PR is explicitly authorized, by cherry-picking the function commits and excluding notes and unpublished docs. Delete them once the PR is done.
When working on a dev branch, read docs/plans/oneflow-development-todo.md
on that branch for the current working state — it lives on dev only.
- Trace the concrete entry point, direct callers, state/resource ownership, and failure/cleanup path before changing interfaces.
- Prefer a focused change for a demonstrated behavior or maintenance problem. Do not refactor solely to introduce a pattern or a new abstraction.
- Search for existing helpers, contracts, and regression tests before
implementing path, process, filesystem, UI, mesh, or workflow behavior.
Follow
docs/DEVELOPMENT_PRINCIPLES.md; do not reintroduce a solved local workaround or duplicate an existing policy. - Add or update tests for the changed contract at the narrowest meaningful boundary, followed by relevant integration or regression checks.
- Report test commands, outcomes, failures, and platform limitations honestly. A build alone is not full validation; do not claim CI passed without checking the exact commit's workflow results.
- Keep C++ source files ASCII-only. Preserve existing behavior unless an intentional behavior change is documented and tested.
- At a meaningful milestone, update
docs/AI_CONTEXT.mdand the relevant architecture/roadmap entry with the verified base commit, change summary, evidence, remaining gaps, and next action. If a fix reveals a reusable lesson, update the owning durable principle or architecture page in the same logical change. Do not create a command-by-command diary or duplicate full architecture documents. - Keep README and user/developer guidance consistent with current behavior. Clearly distinguish implemented, partial, planned, and unverified work.
Use this protocol for every continuation request. It is intended to be executable by this assistant or another coding agent without relying on conversational memory.
- Inspect the current
hexinHEAD, recent commits, working-tree/source state where available, and relevant CI results. Never assume that a handoff note or an old commit is still current. - Read
docs/DEVELOPMENT_PRINCIPLES.md,docs/AI_CONTEXT.md, the relevant architecture/design page, the roadmap or stage record, and the directly related tests. Follow the real entry point and callers; do not scan or rewrite the whole repository without a reason. - Treat a user-reported test count as the pre-change baseline unless the user explicitly says otherwise. It is not evidence that new changes pass.
Before editing, identify one concrete mainline and explain briefly:
- the observed defect, risk, missing contract, or costly maintenance boundary;
- why addressing it now has greater system-level value than nearby alternatives;
- the exact behavior/acceptance criteria and the evidence that could prove or disprove it.
Prefer the change that closes a meaningful end-to-end gap, removes a real dependency or ownership problem, or improves numerical confidence. Do not select work merely because it is easy to rename or document. Keep the system-level goal visible while limiting the patch to one coherent, independently reviewable slice. Do not start a second mainline in the same turn unless the user explicitly asks.
- State the intended behavior contract before changing implementation.
- Inspect ownership, initialization, mutation, error propagation, and cleanup paths.
- Add the smallest discriminating test at the narrowest useful layer; add integration, regression, or numerical checks when the contract crosses component boundaries.
- Make the implementation change and update only the documentation that the change makes inaccurate or materially improves. Capture generalizable lessons in the owning principle or architecture page rather than relying on chat history.
- Preserve compatibility unless a behavior change is intentional, documented, and tested. Avoid broad rewrites and abstractions without a demonstrated need.
For a substantial numerical method or physical model, connect:
- governing problem, assumptions, units, symbols, sign conventions, and validity range;
- the formula actually implemented, including meaningful variants and limiting cases;
- original papers/books and suitable authoritative specifications or maintained manuals;
- OneFLOW source entry points and the difference, if any, between the reference and code;
- tests and cases that check invariants, analytic/manufactured solutions, conservation, convergence, benchmarks, or regression tolerances;
- known limits and evidence not yet collected.
Prefer primary papers, DOI/publisher pages, official project documentation, and stable versioned sources. Other open-source implementations and public manuals are comparative evidence, not automatic proof of correctness; record version/commit, relevant section or file, and license. Use closed-source manuals only when lawfully available, cite edition and section, and do not reproduce restricted code or prose. Do not add citations to trivial helpers merely for appearance. A reference does not prove OneFLOW's implementation correct, and a passing unit test does not prove the numerical model physically valid.
Use the loop: theory/reference -> OneFLOW formulation -> implementation -> focused tests and representative cases -> discrepancy analysis -> updated explanation and evidence. AI may help formulate hypotheses and propose tests, but must not silently change scientific assumptions or treat its own generated output as independent validation. Changes to equations, model variants, tolerances, and reference baselines require explicit review and reproducible evidence.
- Run the most targeted feasible build/test first, then broader tests appropriate to the changed contract. Run representative CFD/grid cases when numerical or end-to-end behavior is affected.
- State exact commands and observed outcomes. Separate user-reported baseline, tests run locally, CI results for the exact commit, and checks that were not run or are blocked.
- Never infer a pass from compilation alone, an unrelated green suite, a queued workflow, or an old CI run.
- Use the status labels in
docs/AI_CONTEXT.md: Verified, Implemented, unverified, Partial, Planned, Blocked, or Deferred, with evidence and remaining gaps.
- Commit by logical work slice, not by file. Normally group implementation, its contract tests, and directly related architecture/roadmap/handoff updates into one commit.
- Use a second commit only when a change is independently useful, independently testable, intentionally reversible, or needs a distinct review boundary (for example, a separate fix discovered while validating the main slice).
- Do not create a separate commit for every file or every command. Do not combine unrelated changes just to reduce the commit count.
- Use concise messages describing the behavior or architectural outcome. Do not rewrite
published history. Keep all work on
hexinunless the user explicitly authorizes another branch.
At a meaningful milestone, update docs/AI_CONTEXT.md and the relevant architecture/roadmap
record in the same logical change where practical. Record the inspected base/commit, chosen
mainline and rationale, files/contracts changed, evidence, remaining gaps, and the next
single recommended action. Keep the handoff concise; do not duplicate the full design guide
or write a command-by-command diary.
The goal is not to maximize code churn, test count, citations, or commit count. The goal is to make OneFLOW easier to understand, test, validate, and improve from one evidence-backed iteration to the next.
- Regression before pull request. Numerical-kernel or backend changes
require the CPU five-case suite (normal
1e-8and strict1e-15) and, for DCU/HIP changes, the HIP contract test. A change is not validated until the relevant suite passes and CI is green. - Same-basis comparisons only.
lifecycle_*_msin benchmarks sums overrepeats. Never divide datasets recorded with differentrepeatsvalues, and state the basis whenever numbers are quoted. - Markdown is the source of truth. When a report has a matching HTML file, update both in the same change.
- Publication boundary. Committed reports must not contain raw CI/Slurm
logs, credentials, unredacted absolute paths, hostnames, account or job
metadata. See
docs/reports/README.md. - Cluster work follows the standard suites. Use the four suites defined in
ci/kunshan/README.md(cpu-regression,dcu-single,cpu-mpi,dcu-mpi) with the documented workspace layout and resource tuples. - Keep the port and the main solver separate. The 1D Euler HIP code lives
in
ports/kunshan/oneflow_1d_hipand is built standalone with the DTK toolchain; the root build is CPU-only today. Do not claim a DCU capability from a root-build result. - One fixed cluster workspace. Kunshan work lives in a single
<workspace>/root:src/OneFLOWis overwritten each round,build/appis the only incremental build, gate evidence goes toevidence/<gate>/<jobid>/, job logs go tologs/, and deprecated material goes to_attic/<date>/. Do not create per-job build/run directories or write logs to$HOME; seedocs/runbooks/oneflow-kunshan-workspace-runbook.md. - Documents describe the current state only. Living documents are edited
in place: the handoff is a single
docs/handoff/oneflow-current-handoff.md(update its §4/§5 each session, never add a dated one), one-off plans and checklists are deleted when done, and published reports are kept but marked historical. Rules and the per-round checklist live indocs/README.mdanddocs/DOCUMENT_NAMING.md§4.5.