Repository navigation
fix(host-kit): pin ps lstart reads to the C locale so daemon stop finds a live daemon - #4682
pcbeingused333 wants to merge 5 commits into
Conversation
ps -o lstart prints weekday and month names in the caller's locale, so a daemon and a client under different LC_TIME compared one start time as different lifetimes and daemon stop orphaned a live daemon on macOS. Run the ps identity reads with LC_ALL=C and treat a C-form start time against a localized one as unknown instead of reassigned. Fixes callstack#4656
|
The locale pin in 70f0b17 is too wide: it also changes how command text is read, and that breaks managed-process ownership for non-ASCII paths. The pin applies to every host-kit Not blocking, and fine to take or leave: the new test checks the env argument on mocked Could the fix be smaller? Pin only the The Coverage check is failing, but its log ends mid-run in the react-native companion worker tests with no assertion or error line, so it does not point at this PR. Please re-run it. No conflicts. Before merge, narrow the pin to the A separate security cross-check of this head, run because process identity decides which process gets signalled, adds two more items before merge:
Signal authorization still requires an exact identity match, so neither item lets the CLI signal the wrong process. Both make it give up on a live daemon, which is the orphaning bug #4656 reports, now coming from another direction. |
…tamps unverified Addresses the blocking review on callstack#4682: - The LC_ALL=C pin now applies only to ps reads whose output carries lstart (HOST_PROCESS_IDENTITY_PS_ARGS sync/async and readProcessField('lstart=')). The pid=,command= batch read and readProcessField('command='/'state=') keep the caller's locale, so command text reads with one encoding from every host-kit caller, matching the unpinned listHostProcesses scan. BSD/macOS ps escapes non-ASCII argv bytes under LC_ALL=C (/tmp/é-ü -> /tmp/M-CM-)-M-CM-<), which broke managed-process ownership for non-ASCII paths. - The pin is a final override on top of the effective child environment (new effectiveChildEnv in exec.ts), so TZ and the rest of the child env survive: replacing the whole env dropped TZ and rendered lstart in the host zone under the pin (verified live: TZ=Pacific/Kiritimati record Thu Nov 19 09:29:21 2026 vs no-TZ read Wed Nov 18 20:29:21). - processStartTimesDiffer proves a different lifetime only when both sides share one verified format (linux: token, C-form lstart, Windows invariant stamp). A legacy localized record — with or without a colon-separated clock, e.g. mer. 18 nov. 20:29:43 2026 or 18 nov. 2026 — is unverified: never declared exited at daemon stop, never a signal authorization. Regressions: pin scope + UTF-8 command reads + TZ retention in host-process-liveness.test.ts, legacy verdicts in host-process.test.ts and owner-identity*.test.ts, and at the daemon stop boundary in daemon-process-takeover.test.ts (legacy record -> retained identity-unverified with the daemon alive; non-ASCII argv reads as UTF-8). Token-based reuse tests now use verified-format tokens. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…heck the lstart helpers Move the start-time format classification and processStartTimesDiffer into ps-start-time.ts (re-exported through the process barrel) so host-process.ts stays under 1000 lines, and use non-null match groups in the takeover test's locale helpers. Also replaces hex escapes with Unicode escapes in the liveness test. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…wn-env word The layering guard (R86 process-globals) forbids reading process.env outside declared process entries, so the pin cannot be materialized from process.env in exec.ts. ExecOptions gains envOverrides, which resolveSpawnEnv applies as the final word over the bound host scope's environment plus the request env: LC_ALL=C is pinned while TZ and the rest of the effective child environment survive. Outside a scope an explicit env still takes the overrides on top, and with neither the child inherits natively. The TZ regression moves to exec.test.ts, which spawns a real child: withCommandHost(host TZ=Pacific/Kiritimati) + envOverrides LC_ALL=C observes 'Pacific/Kiritimati|C', and the override also wins over a request-env LC_ALL. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
|
Progress at The cross-time-zone case remains open. The current C-form timestamp has no time-zone provenance. Coverage on this exact head also reports eager-closure growth from |
|
This review covers f88ff09. The newer head 7ef7ebb changes how the locale pin reaches the spawn environment and will get its own delta review; the time-zone and evidence items below do not depend on it. At f88ff09, the earlier command pin and environment replacement findings are fixed, but birth identity and live validation still need work. The real dotted-clock fixture and full macOS run remain outstanding. Could the process owner give birth tokens locale- and time-zone-independent, identifiable provenance? Starting a daemon in Pacific/Kiritimati and stopping it with TZ=UTC produces different C-shaped strings for the same PID, so the comparison can report a live daemon as exited. Conversely, a recycled PID held by a matching daemon can have the same local clock value and pass signal authorization. Both comparisons must treat old unqualified renderings as unknown unless the original lifetime is independently established; keep argv probes separate. Please remove the redundant non-ASCII assertion and cover this through the environment-sensitive process reader and real-child stop test. It compares the same constructed string on both sides and passes even when the command read still has the reported regression. The takeover test uses a stub executable and synthetic timestamps, so it does not establish graceful stop or live resource ownership. At the fixed head on macOS, start a real detached daemon under fr_FR.UTF-8 in a fresh state directory, capture its PID and token, and run daemon stop --state-dir --json under LC_TIME=C; show stopped:true, mode:graceful, and PID exit. Repeat across different TZ values. With a separate pre-fix registration from an actual non-C locale, show typed identity-unverified refusal, a live PID, and retained metadata and lock. Run Apple simulator record start and stop through the daemon and show the recorder stops and releases its resource. If the snapshot change remains, show successive requests across provider locales retain the same live snapshot generation.Not blocking: these can be taken or left: use a valid 21-digit CIM sample for stale Windows fixtures and remove unreachable platform branches; resolve scoped environment overrides once at spawn; bind an installed UTF-8 locale for the real-child Unicode test; use a recorded nb_NO.UTF-8 dotted-clock value; and keep the existing table case instead of the duplicate one-second reuse assertion. Could the already loaded process capability own POSIX birth-token construction and its sync and async probe policy, with exec resolving scoped overrides once at spawn and the cancellable snapshot provider reusing that policy? A versioned token could identify comparable clocks while historical raw values remain unknown, preserving Linux /proc and Windows CIM tokens; choosing provenance and the legacy refusal rule at the process boundary comes first, while preserving Apple provider cancellation and routing, removing the extra eager import, and consolidating fixtures. No ADR amendment is needed for that ownership. Android Smoke Tests passed, but Linux normally uses /proc and does not exercise macOS lstart. Repo Guards reports R86 on the added process.env capture, and Coverage reports ten eager-closure assertions with one extra module each. There are no known conflicts. Before merge, fix birth-token ownership and scope, clear R86 and the eager-closure checks at their source, and provide the exact-head macOS receipts. |
…ost-process module Move the ps-start-time logic into the already-loaded host-process.ts so the eager-closure budget is unchanged, and give newly produced POSIX birth tokens explicit comparable provenance: a pinned C-form lstart is parsed in the reader's zone and recorded as posix:<epochMs>, so identity survives a cross-TZ stop. Historical raw renderings stay unqualified: they yield unverified identity and never prove exit or authorize a signal. Linux /proc and Windows CIM routes, unpinned argv reads, and cancellation are unchanged. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
|
At 7ef7ebb, the locale pin no longer applies to argv reads, but the process birth identity and SDK startup issues remain from the earlier review. Could the host-kit observation owner emit one locale- and timezone-independent birth identity with provenance? A daemon registered under Pacific/Kiritimati and stopped under UTC gets different C-shaped lstart strings for the same PID, and the classifier treats the shared shape as a shared clock. The exit wait can report exit before signaling, so detached stop can report not-running and retire a live daemon's lock and metadata. Claim, lock, and managed-process observations also treat the difference as reuse. Old raw POSIX values need to remain unknown unless the lifetime is independently established. Identity classifier Could every live signal authorization gate require a positive match between comparable birth identities, with command matching independent? A recycled PID can have the same raw local-second string under a different timezone, bypass the mismatch check, and pass the daemon entry-path check. That can authorize a signal to a different process lifetime. Legacy raw POSIX values need to remain unknown for equality too. Signal gate Could scoped and unscoped launch and observation routes use the same clock, with the captured host bound at declared entrypoints for probes that need its environment? An unscoped lstart probe receives only LC_ALL=C, while Node ensureDaemon passes the captured TZ to the child. With a nondefault TZ, the parent can reject its live child during readiness. The scoped real-child test does not cover this route. Please verify a fresh Node ensureDaemon call with a nondefault TZ. Probe environment Could the Unicode test remove the self-comparison and retain the environment-sensitive reader regression and real-child stop test? It supplies the same constructed argv to both sides without invoking ps, so it stays green with the earlier overbroad pin. Test Could the valid and stale process birth fixtures be shared in test-kit? The same values appear in three test files, so each identity format change requires three updates. Fixture Could you attach exact-head macOS receipts for the CLI and recording routes? The takeover test uses a stub process and synthetic timestamps, and the progress comment reports partial real macOS validation without the underlying transcript. At the fixed SHA, start a detached daemon in a fresh state directory under fr_FR.UTF-8, record its PID and birth identity, and run daemon stop --state-dir --json under LC_TIME=C; show stopped:true, mode:graceful, and that PID exiting. Repeat with different explicit TZ values, and show a fresh Node ensureDaemon call under a nondefault TZ recognizing its child. For a genuine pre-fix non-C registration, show details.terminationReason=identity-unverified, the live PID, and retained metadata and lock. Through an Apple simulator daemon session, run record start and record stop and show the recorder exiting and its owned resource released. Include the SHA, commands, and outputs. Takeover testNot blocking: the stale CIM fixtures could use valid distinct 21-digit samples, the Unicode child test could bind an installed UTF-8 locale, the stop regression could use a recorded nb_NO.UTF-8 dotted-clock value, and the redundant one-second reuse test could be removed; please take or leave these suggestions. Could comparable POSIX identities live in the already loaded host-kit process capability alongside the Linux and Windows producers, with sync and async paths sharing one probe policy and the existing exec resolver owning spawn overrides? Could argv reads stay separate, qualified observations yield positive and negative lifetime judgments, and the extra eager import be collapsed? First, the canonical POSIX clock, provenance discriminator, and unknown legacy behavior for both matches and differences need definitions; saved-state structural equality should remain intact. Apple snapshot provider routing can stay separate, and no ADR amendment is needed. The Coverage failure most likely comes from the added eager module, since its inbound static imports remain; please confirm from the job log. No conflicts are known. Before merge, please fix birth identity and the unscoped SDK route, repair the regressions and eager closure growth at their source, and provide passing exact-head checks and the macOS receipts above. |
|
Round 2 at head Eager-closure / Coverage failure — fixed at the seam, no baseline changes. The Cross-TZ identity — closed with provenanced birth tokens. New POSIX reads canonicalize the pinned C-form Live macOS verification at exact head
Checks receipt: No device proof was run — no device is assigned to this task via T3. Not merged, not watched; readiness labels untouched. |
Fixes #4656
On macOS (and BSD
ps), process identity is the pid plus theps -o lstart=start time, compared as exact strings.psspells weekday and month names in the caller's locale, so a daemon spawned underLANG=fr_FR.UTF-8recordsmar. 17 nov. 19:42:27 2026while a client underLC_TIME=CreadsTue Nov 17 19:42:27 2026for the same pid.processStartTimesDifferthen reports two renderings of one start time as different lifetimes, sodaemon stopanswersstopped: false, deletesdaemon.jsonand the lock, and leaves the daemon alive.Fix
psidentity reads inhost-process.tsnow run withLC_ALL=C(sharedpsReadOptionsin a newps-start-time.ts, which also keepshost-process.tsunder themax-lineslimit).processStartTimesDiffertreats a C-form start time against a localized one (both carrying a clock time) as unknown evidence rather than proof of a different lifetime, so records written by an older version in another locale do not orphan daemons that are already running.Test
Two tests in
host-process-liveness.test.ts: everypsread passesenv.LC_ALL === 'C', and a localized start time against its C-locale rendering does not differ (while a real one-second difference still does). Both fail on main and pass with the change.Reproduction
Spawn a daemon with
LANG=fr_FR.UTF-8, then runLC_TIME=C agent-device daemon stop --state-dir <dir> --jsonas in the issue. Not reproduced on a macOS host for this PR; the unit tests pin thepsenvironment and the comparison instead.Disclosure
This change was prepared with the help of an AI coding assistant (Claude Code) and submitted by the account holder.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.