Skip to content

fix: refuse incomplete lsof discovery and measure attribution - #115

Merged
abruption merged 3 commits into
mainfrom
research/100-lock-attribution
Oct 9, 2026
Merged

abruption merged 3 commits into
mainfrom
research/100-lock-attribution

Conversation

@abruption

@abruption abruption commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Investigate whether a held native flock plus one visible lsof opener is sufficient holder attribution. The research harness uses real guarded flock and disposable same-user, inherited-descriptor, foreign-UID, and Linux namespace fixtures, recording raw diagnostic status and independent kernel observations. It never sends process signals or touches a real Codex home.

Refs #100.

Explicit lsof warnings now make opener and per-PID lock-set discovery incomplete even on exit zero. Two real-lock regressions verify recovery refusal, zero SIGTERM, and the still-live fixture owner. Visible records remain in diagnostics. The macOS baseline confirms that a nonlocking opener appears in lsof, a forked descriptor retains the lock after its acquirer exits, and the optional lsof lock field is blank even for real holders.

Completed Linux/macOS research jobs in run 37862990217 measured a foreign-UID holder silently omitted by lsof: exit 0, empty stderr, sole visible nonlocking opener, held guarded probe. Linux's PID-namespace fixture also reports a held lock with no matching global row and only the nonlocking observer visible. Inherited Linux descriptors retain positive fdinfo evidence despite a different original acquisition PID. These are synthetic OS attribution observations, not reproductions of a wrong-target Codex signal.

This PR is research plus partial warning hardening; the clean omission remains unresolved and #100 stays open. The document proposes Linux descriptor-level FLOCK evidence tied to device/inode and process instance, and explicitly requires a reviewed macOS holder/visibility contract before adoption. No new native dependency, force mode, silent macOS downgrade, or unguarded probe is added. Prerequisites are checked before optional privileged measurements; failed launched helpers/observers now fail the job instead of being skipped. Seven no-sudo self-tests cover that distinction.

Validation: installation, type checking, lint, 220 tests, package smoke, local Darwin/Python/lsof baseline, harness self-tests, and git diff --check passed. Research files are repository-only; runtime and packaging safety boundaries remain covered by the real-lock suite. Current-head CI/review results must be distinguished from the recorded initial measurement jobs. No release or publication is requested.

CI run 37863804534 for head 59c1b46 completed successfully, including both platform research jobs and the supported runtime matrix. The visible Codex review summary still names initial head 4a84b3f, so its findings/coverage are not represented as a review of 59c1b46. Both reported findings have implementation changes and regression checks described in their reply threads; no additional reviewer mentions were posted.

Additional source cross-check: Codex writer_lock.rs at 22ebb0f opens temporary thread descriptors under coordination and closes failed-acquisition/cleanup/publication descriptors before releasing that guard; normal drop also closes the held thread descriptor before releasing coordination. This file is identical at the earlier c2d2f422 design snapshot. These paths do not demonstrate a persistent ordinary Codex nonholder FD outside coordination.

That protocol alone is not a current-owner proof: inspection queries lsof and the native probe independently, and final lock-set discovery is awaited before a later process sample and synchronous guarded probe. A transient descriptor observed earlier may have closed before the later held probe. No actual Codex execution satisfying every repeated observation and policy check was reproduced, and the source inspection does not prove that such an execution is impossible. Holder evidence collected at the guarded observation (or a supported owner-cooperative primitive) and the macOS contract remain adoption requirements.

A bounded additional Darwin 27.0.0 / lsof 4.91 synthetic experiment rejects lsof -F G as current-holder proof: the 0x4000 flag persists after successful unlock and after failed reacquisition, so a former holder and an independent current holder both report 0x4003. Inherited descriptors also retain the flag after unlock. F_GETLK observed the synthetic flock conflict but reported PID -1. Published XNU flag definition, flock implementation, and conflict reporting explain these limits. The public source is XNU 12377, not asserted to match the measured XNU 13432 kernel build. No actual Codex, process signals, repository edits, or new native dependencies were used for this additional experiment; its private synthetic scratch was cleaned up. This rules out these two candidate attribution shortcuts, not all possible macOS APIs.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T00:11:31.734274Z 4a84b3f PR opened
🔒 Security Review ✅ Completed 2026-10-09T00:08:39.600590Z 4a84b3f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a84b3f7c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/process.ts
const processes = parseLsofProcesses(result.stdout);
// Exit zero does not prove that every process was visible. Preserve visible
// records for diagnostics, but explicit warnings never authorize recovery.
if (result.stderr.trim()) return { processes, error: result.stderr.trim() };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply warning refusal to owner lock-set discovery

When the opener query is clean but the later per-PID lsof -F0fDin query emits a warning while returning zero—for example, while omitting another thread-lock descriptor—this new guard never sees it: lockFilesOpenedByProcess() still accepts its partial stdout, so both inspection and final revalidation can conclude that the PID owns exactly one lock and send SIGTERM. Apply the same successful-stderr refusal to that query and cover a warning specific to -F0fDin.

AGENTS.md reference: AGENTS.md:L31-L34

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 59c1b46: successful-stderr refusal now also applies to the per-PID -F0fDin lock-set query. A dedicated real-lock fixture injects the warning only for that query and verifies refused, safeToUnlock false, SIGTERM null, and a still-live owner. All 220 local tests and package smoke pass.

Comment thread scripts/research-lock-attribution.py Outdated
Comment on lines +312 to +314
report["cases"].append({"case": "holder_outside_observer_pid_namespace",
"status": "measured" if result["exitStatus"] == 0 else "skipped",
"result": result})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail the job on privileged fixture execution errors

When unshare starts but the namespace observer exits nonzero because of a fixture or script defect, this branch labels the result skipped and the research job still succeeds; the foreign-UID fixture similarly catches every RuntimeError from startup and converts it to a skip. This contradicts the documented distinction between unsupported capability and fixture failure, allowing the dedicated CI job to go green without producing the evidence it was added to collect. Detect unsupported privilege explicitly, but propagate unexpected child failures.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 59c1b46: optional capability/policy checks run before measurements; launched helper/observer errors and malformed evidence now fail. Seven no-sudo self-tests include an actual failed startup child and are run in CI. Known unavailable prerequisites are still explicitly skipped.

@abruption
abruption merged commit 1fcb13e into main Oct 9, 2026
28 checks passed
@abruption
abruption deleted the research/100-lock-attribution branch October 9, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant