feat(windows): native Windows kernel runtime — Contract/Ports/Adapters across the reviewed capability DAG#988
Merged
Conversation
…bility DAG Implement the reviewed Windows blocker/parallelism DAG as one integrated change-set behind Contract + Ports & Adapters: msvcrt byte-0/length-1 WorkdirLease (the frozen TUI-probe interop range), the Windows refresh-watcher trio (CIM observation, OpenProcess liveness, .suspend graceful stop), the CLI lifecycle host (AgentProcessScanPort, platform stop signals, CPR detached spawn, matcher separator parity), the daemon lane (byte-range ledger-lock seam, Job-Object process port, inherited-handle capsule supervisor with entrypoint mirrors, creation-time process identity), the avatar launcher with its honest forceful-terminate mapping, the shell sandbox os.sep containment fix and state-lock exact-argument pins, portable-transport UTF-8 fixes, the new agent-runtime.v1 contract, a per-capability Windows support matrix, and a windows-latest CI lane. POSIX adapters remain the first implementations of every Port and are re-verified: the full suite shows only the one pre-existing baseline failure. ConPTY/interactive terminal and the WeChat poller lock remain fail-loud unsupported by design. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The first native kernel-lane run exposed three test-side platform couplings: the lease rollback test pre-acquired the adapter it handed to BaseAgent (only ever tolerated by BSD flock same-process semantics; Windows byte-range locks honestly conflict across handles); the ps-row duplicate-guard tests fed POSIX ps fixtures through the platform scan selector (the Windows CIM adapter speaks JSON, so they silently parsed to nothing); and the .gitignore encoding pin compared raw bytes against LF while write_text produces platform-native line endings. Pin the POSIX scan adapter explicitly for guard-policy tests, drop the pre-acquire while preserving the rollback-then-reacquire proof, and normalize newlines in the byte comparison. No production code changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
test_agent_creates_lock_file imported the POSIX flock adapter directly (fcntl import fails on Windows) and the daemon teardown-order pin constructed PosixDaemonProcessPort explicitly; both tests' observable purpose is platform-neutral, so route them through the production selectors instead. POSIX behavior is byte-identical. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
huangzesen
force-pushed
the
mimo/windows-kernel-native-full-20260718
branch
from
July 19, 2026 08:32
dafe64b to
1ecf527
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(windows): native Windows kernel runtime — Contract/Ports/Adapters across the reviewed capability DAG
Summary
Implements the reviewed Windows kernel blocker/parallelism DAG as one integrated change-set: every suitable Windows capability lands behind its owning Contract with a platform-neutral Core Port, a native Windows adapter, the preserved POSIX adapter, and shared contract tests. The construction frontier (
C0+L1+W1 → K0) and CLI lifecycle host (R1) are complete; the refresh (W2/R2), daemon (D1–D3), avatar (A1), shell residuals (S1/S2), and portable-transport certification (P1–P7) lanes land as independent capability rows. Support is published only as a per-capability matrix (docs/references/windows-support.md) — never one boolean claim.WindowsWorkdirLeaseAdapter—msvcrtbyte 0/length 1 on.agent.lock, the frozen TUI-probe interop range (TUI PR docs(email): remove stale schedule API manual content #687: conflict→Block, missing→Allow, error→Unknown). Exact-argument pin runs on every platform; native contention/crash-release/probe tests run on Windows CI.os.kill, which terminates on Windows;.suspendcooperative graceful stop; exact-PID forced stop). Core policy/renderer unchanged and platform-neutral.AgentProcessScanPort(POSIXps/ Windows CIM) behind the duplicate-launch guard; platform-honest stop signals (SIGTERM/SIGINT vs SIGINT/SIGBREAK →.suspend); CPR relaunch via shared detached creation flags; canonical matcher accepts both path separators (doctor copy kept in parity)..daemon-state.locktransaction lock gains a capability-localmsvcrtbyte-range seam (POSIX flock byte-for-byte unchanged);WindowsDaemonProcessPortmapsPRIVATE_PROCESS_GROUPto per-spawn Job Objects (suspended spawn → assign →NtResumeProcess, no kill-on-close, mirroring POSIX survival semantics) andINHERITED_SUPERVISOR_GROUPto exact-child-only termination;WindowsDaemonSupervisorAdaptercarries the one-shot secret capsule as an inherited pipe HANDLE viaSTARTUPINFO.lpAttributeList["handle_list"](env holds only the handle number — bytes never touch disk/argv/env), with three Windows entrypoint mirrors that adopt the handle onto the shared fd wire and reuse the POSIX read/dispatch logic verbatim; Windows process-incarnation identity (windows:<creation_filetime>) keeps every ownership-guarded signal path fail-closed; interactive Claude stays fail-loud unsupported on Windows.WindowsAvatarLauncherAdapterwith the documented honest terminate mapping — on Windowsterminateandforce_terminateare both forcefulTerminateProcess; no fake graceful tier.os.sep(was hardcoded/, rejecting every legitimate nestedworking_diron Windows);msvcrtstate-lock byte range now exact-argument-pinned.mail.py,git_cli.pywrites lackedencoding="utf-8"); certification runs on the new Windows CI lane.src/lingtai/kernel/base_agent/CONTRACT.md(lingtai.kernel.agent-runtime.v1, 8 clauses) composing the capability contracts; cross-repo clauses explicitlyproposed, nothing marked mutually accepted unilaterally.Architecture / Contracts
Every Windows implementation follows Contract + Ports & Adapters: Core never branches on platform; selectors fail loudly for genuinely unsupported platforms; no catch-all
Platform/ProcessSupervisorobject exists. Capability-local locks stay separate (.agent.locklease ≠ shell.state.lock≠ daemon.daemon-state.lock). New/updated Contracts: workdir_lease, refresh_watcher, base_agent (new), tools/avatar, tools/bash, tools/daemon, kernel/daemon_supervisor. ConPTY/interactive terminal remains unsupported (fail-loud) by design; the WeChat poller lock likewise.Capability matrix
See
docs/references/windows-support.md— per-capability rows with owning contract, state (supported/implemented, native-CI-gated/unsupported (fail-loud)), mechanism, and evidence. The Windows CI lane (.github/workflows/kernel-windows-pr.yml, windows-latest/py3.12) executes the platform-marked tiers natively on this PR.Validation
All runs on a fresh py3.12 venv in an isolated worktree at base
5f3c1733(origin/main; unmoved at push time).python -m pytest tests/ -q→1 failed, 5787 passed, 9 skipped— the one failure istests/test_skills.py::test_skills_setup_hard_copies_standalone_intrinsic_skills(pre-existing content assertion on main, unrelated to this PR).python -m pytest tests/ -q→1 failed, 5857 passed, 28 skipped in 223s— the same single pre-existing failure only. Net +70 passing tests; the additional skips are the newwindows_mechanismnative tiers, inert on POSIX.tests/test_architecture_documents.py,tests/test_docs_governance.py,tests/test_anatomy_drift_checker.py,tests/test_environment_variable_catalogue.py;git diff --checkclean.msvcrtbyte ranges (lease, shell state lock, daemon ledger lock), exact detached-spawn shapes (refresh, avatar, supervisor capsulehandle_listwire), selector routing, and the boot-path import graph withfcntl/termios/pty/grpblocked.dafe64b2):Kernel Windows PR contractrun 29679309133 — contract tiers237 passed, 15 skipped, lifecycle smoke56 passed(test_agent.py+test_lifecycle_daemon_shutdown.pyentirely green on windows-latest, i.e. the real construct→start→presence→stop path natively).Shell PowerShell PR contractrun 29679309116 — pass. Two earlier red rounds were test-side platform couplings (fixed in the two follow-up commits, production code untouched) plus one pre-existing flaky native shell test (test_native_job_object_cancel_after_root_exit_terminates_descendant_tree: pass → fail on an unrelated-tests-only commit → pass on rerun; the Job-Object mechanism was identical throughout).Residuals
test_skills.py::test_skills_setup_hard_copies_standalone_intrinsic_skillscontent assertion (baseline failure); Windows durable-state fsync boundary is file-level by design; mail claim-protocol directory-replace edge under adversarial concurrency (guarded, observed under native CI).killpg(identity-guarded exact PIDs only; grandchildren outside the execution Port's Job are not swept — seetools/daemon/CONTRACT.md§Windows invariants).CREATE_BREAKAWAY_FROM_JOBattempt; breakaway permission cannot be assumed).lingtai-agent.execonsole form is not matched by the duplicate-launch scan (runtime relaunches always use the module form; the workdir lease remains the exclusion authority).Non-goals
UnsupportedPlatformErrorpreserved).Posix*adapters (historical names; portable transports certified as-is).agent-runtime.compat.v1staysproposeduntil both repos' contract revisions cross-reference; the two-repo one-host native interop run is an explicitly recorded outstanding receipt.🤖 Generated with Claude Code