command-cli research note
command-cli research note (#156)
Historical. Research done before the
command-climission; the operator ruled on 2026-10-31 (see the outcome block below). Kept as the record of the research, not as current documentation.
Outcome. The operator ruled on 2026-10-31. #156 delivered the runnable service and its native and jar release; #160 and #161 then landed the write core: the durable status appender (
service/event-log,adapter.out.statuslog), the public Python encoder (spec_kitty_events.status_log), the parity corpus, and the lane authority inservice/command-cli(domain.authority,application.write,adapter.out.mission,adapter.out.statuslog).checkout_appendis served;coordination_ref_commitwaits for migration step 4. The rulings above still hold: loopback HTTP with a bearer token on Spring Boot 4 AOT; one service per git common dir with an 1800 s idle timeout; the contract on the1.0.Zline (1.0.1-SNAPSHOTnow); the/api/v1prefix;SERVICE_DRAINING; and a torn tail refused.Everything below is the research as written before those rulings, including its then-current plan that the write operations answer a fail-closed refusal in PR 1. It is history, not current behaviour. The current documentation is
service/command-cli/README.mdand write-service protocol.
Read-only research done before the command-cli mission. The local paths are in this repository. The core paths are in spec-kitty/spec-kitty at d75e0bc5fe.
Core issues #6194, #6195 and #6117 could not be read from this session. GitHub API
access to core was not granted. Core’s code, ADRs and plan were read from a clone instead.
1. What core expects (the binding interface)
- Port. The binder is
bind_event_bridge(*, emitter_factory, transition_port), at coresrc/runtime/next/_internal_runtime/events.py:304. It binds both halves or neither.- The write half is
WorkPackageTransitionPort.record_work_package_transition(transition) -> None(coresrc/runtime/next/event_bridge.py). It is synchronous: it persists one unit or raises. WorkPackageTransitioncarrieswrite_location,rows(the transition first, then its annotations) and an opaquewrite_contract.- The emitter half,
RuntimeEventEmitter(events.py:73-95), has no operation in protocol major 1 (core ADR 2026-10-27-1 D-3). The client can satisfy it with a no-op. - Plan §4 step 7 (core
docs/plans/events-domain-move/plan.md:145): “command-cliwrite service released → core bumps the write-service pin → #6195 bindsbind_event_bridgeto the client”. That binding is out of scope here.
- The write half is
- Wire shapes. Core
src/specify_cli/status/write_service_protocol.py:transition_unit_from(line 300) builds the request;TransitionBatchtakes at most 64 units;SUPPORTED_PROTOCOL_VERSIONS = (1,);repository_id(gcd) = sha256(gcd.resolve().as_posix());- the
endpoint.jsonreader is at lines 611-649.
- Pin and resolution.
- Pin model: core
src/kernel/service_pin.py. The write-service asset prefix iscommand-cli(DEFAULT_ASSET_PREFIXES, lines 61-70). Targets:linux-x64,linux-arm64,macos-arm64,windows-x64andjvm. - Asset names:
command-cli-<ver>-<target>[.exe]andcommand-cli-<ver>.jar. - Host target selection: core
src/kernel/service_hosts.py:24-58. A pinned native build is used if one exists for the host, otherwise the jar under Java 25 (services/host.py,find_java(25)). - Resolution order (core
src/specify_cli/services/resolution.py:1-35):- env override;
- entry point;
- the cached native binary, fetched on first use and digest-checked;
- the jar;
- a refusal.
verify_before_execre-hashes the binary just before spawn.
- Pin model: core
- Launch. Core
src/specify_cli/services/policies.py:44-58andlauncher.py:- Command:
<argv_prefix> serve --git-common-dir <abs> [--idle-timeout <s>], run detached. - stdin is DEVNULL. stdout and stderr are appended to
<gcd>/spec-kitty-write-service/service.log. - For the jar,
JAVA_TOOL_OPTIONS,JDK_JAVA_OPTIONSand_JAVA_OPTIONSare stripped. - The CLI passes no port.
- Readiness: a valid
endpoint.json, thenGET /handshakewith the bearer token (instance,repositoryIdand the protocol majors must intersect), thenGET /healthreadsready. The launcher allows 15 s and polls every 50 ms, with a 2 s client timeout and a 64 KiB body cap. - Stop:
POST /shutdownwith the protocol header. After 10 s,SIGTERMorTerminateProcess, sent only once the process is proven to be the published instance.
- Command:
- Locks.
- The per-Mission status lock is
<gcd>/spec-kitty-locks/<feature_dir.name>.status.lock(corestatus/locking.py:179-191). - Until the Python writers are removed, the service must take the same files with
flock(2)semantics (core ADR 2026-10-22-1 D-4).
- The per-Mission status lock is
- Encoding.
- Status rows:
json.dumps(sanitize_event_for_log(row), sort_keys=True)(corestatus/store.py:293-300; sanitizerevents/sanitizer.py:126). The service never writes the bytes as it received them (ADR 2026-10-22-1 D-7).
- Status rows:
2. What the contract here already fixes
contracts/mission-write/openapi.yamlis1.0.0-SNAPSHOT, protocol major 1.- Six operations, bearer auth on all of them.
- The
Spec-Kitty-Write-Protocolheader is required on all but/handshakeand/health. - Checks run in this order: 403 guard, 401 token, 400 protocol, 413 size, 400 shape, then the domain (404, 409, 422).
contracts/mission-write/LAUNCHER.md(accepted 2026-10-29) sets the start command, the single-instance lock (exit 0 if held),endpoint.jsonby rename,service.log, the three-part readiness check, and the provisional/shutdown.docs/architecture/services/write-service-protocol.mdandevent-log-lock-and-append.mdset the token (32 random bytes, base64url), theendpoint.jsonfields (0600 file in a 0700 directory) and the lock interop rules (flock through FFM on POSIX,FileChannel.lockon Windows).- Durability: a unit is one
O_APPENDwrite of full lines plusfsyncbefore the 201. A batch is one write and one fsync. A refusal writes nothing.event_idis the idempotency key, so a retry is a replay (provisional) andEVENT_ID_CONFLICTis 409. - The service is authoritative. It validates each unit against the lane state machine, its
guards and dependency gating (core ADR 2026-10-27-1 line 76). Parity is proven by the #6194
corpus (line 80). Core’s source for this is
status/wp_state.py(769 lines, about 90 functions and classes),transitions.pyanddependency_verdict.py.
3. What this repo already has to build on
service/event-log(adapter.out.ledger):FlockLedgerLock, which uses FFM flock with per-architecture constants. The native-image downcall is not registered yet (FlockLedgerLock.java:18-30).ChannelLedgerLock, for Windows.LedgerLocks.forThisOs().TornTailRepair.StatusReducer,LaneandWpState(indomain-model), for the current-state fold.- These are checked against Python by the
lock-interopCI job.
- No Java code writes event rows yet. There is no appender, no encoder that matches Python’s bytes, and no lane state machine.
src/spec_kitty_events/persistence.py, the Python reference appender, andconformance/fixtures/ledger_append/(20 valid and 7 invalid cases, byte-exact) cover contract rows. Nostatus_appendfixture family exists here yet.- Native build pattern:
service/build.gradle.kts(Spring Boot with AOT,org.graalvm.buildtools.native,toolchainDetection=false)..github/workflows/service.ymlruns thenativematrix (lines 216-343) with GraalVM CE 25.0.2 on four targets.scripts/release/service-release-assets.sh:24-46hardcodesmission-status-api-*asset names.service.ymlpaths andtests/test_service_workflows.pyhardcode:mission-status-api.- ADR-0003 says a future deployable follows the same scheme (lines 129-130). Adding one is additive (lines 95-96).
- Locally, JDK 25 is at
/usr/lib/jvm/temurin-25. GraalVMnative-imageis not installed, so native builds are verified in CI only.
4. Inconsistencies found
- Path prefix. The contract’s
serversentry is/api/v1. Core’s launcher client sends bare/handshake,/healthand/shutdown(coresrc/specify_cli/services/client.py:94,107,121). - Draining code.
schemas/HealthStatus.yaml:3-4says draining refuses withSERVICE_BUSY.WriteRefusalCode.yamlandresponses/ServiceBusy.yamlsaySERVICE_DRAINING. - Byte rule. The
ledger_appendbyte rule (Python’s default separators) is asserted to equal core’sserialize_event_lineoutput (persistence.py:189-190), but no status-row fixture proves it.
5. Size
The deliverable has four parts, each a reviewable change on its own:
- the launcher and process contract;
- the native and jar release;
- the byte-exact durable appender with lock interop;
- the port of the lane state machine, guards and dependency gating, with a parity corpus.
Together they do not make one reviewable PR. Section 6 proposes a stack.
6. Proposed slicing (stacked PRs, one mission)
- PR 1, the runnable service. A new
:command-climodule (service/command-cli).serve --git-common-dir [--idle-timeout],service.lock(exit 0 if held),endpoint.jsonby rename,service.log, the loopback bind guard, the Host and Origin guard, the bearer token and the protocol header./handshake,/health,/shutdown(drain) and the idle timeout.- The native matrix and release assets for
command-cli, the jar, and FFM reachability. - The write operations answer a fail-closed refusal until PR 2.
- PR 2, the canonical writer. The append path in
event-log.- The sanitizer plus a sorted-key encoder, with a new
status_appendconformance family. O_APPENDplusfsync, the status lock taken through flock, torn-tail refusal, replay andEVENT_ID_CONFLICT, batch and annotation, and verification of the write location.
- The sanitizer plus a sorted-key encoder, with a new
- PR 3, authority. The lane state machine, guards and dependency gating, ported from core
wp_state.py, with the 15 refusal reasons and a parity corpus.