Skip to content

fix: detach claimed drafts from agent-held inodes - #12

Merged
404Dealer merged 1 commit into
masterfrom
fix/detach-claimed-drafts
Nov 6, 2026
Merged

404Dealer merged 1 commit into
masterfrom
fix/detach-claimed-drafts

Conversation

@404Dealer

Copy link
Copy Markdown
Owner

Summary

Salvages the watcher and startup-check portion of #11, without its deployment-profile and privilege-detector changes.

Bug on master: the watcher renames the agent-owned inbox inode into pending/. An agent that keeps a hard link or an open descriptor to its own submission can rewrite the pending draft. The hash check catches a change before approval, but after approval the bot rewrites the same inode, renames it to approved/, awaits a Telegram edit, and the executor then re-reads approved/ without rechecking the hash. That leaves a window to swap an approved email's content.

Fix:

  • The watcher opens the inbox entry with O_NOFOLLOW | O_NONBLOCK, requires the opened inode to match the lstat'd entry, and reads a bounded snapshot (max + 1 bytes).

  • It writes the snapshot to a new exclusive 0600 service-owned file in pending/, then removes the inbox entry only if it is still the same inode.

  • Failure evidence is written exclusively (wx). If it can't be written, the inbox source is preserved instead of being lost.

  • Startup isolation checks (enforceProductionPermissions) now also require:

    • service UID ownership of the inbox;
    • service UID/GID ownership of the private state directories;
    • a real, root-owned draft root.

    A failed draft-root stat is now an error, not a warning.

  • Unlike feat: add deployment isolation modes #11, the draft root's group is not checked, so existing root:root installs from master's installer keep starting without a reinstall.

  • README / deployment / Hermes docs now describe the detached copy instead of "moves it to pending".

Tests

  • Two behavioral tests: a hard-link holder and an open-descriptor holder each rewrite their original inode after the claim, and pending/ must keep the original content. Both fail on master's watcher (pending shows the agent's rewrite) and pass here.
  • Added verifier tests for service ownership and the missing-root error, plus a malformed-source preservation test.
  • Watcher tests wait 250 ms after start(). A fresh chokidar polling watcher can miss a file created right after ready until the next directory change, which made per-test watchers flaky on Node 20. A single long-lived watcher was checked separately: 8/8 sequential drafts were seen even with identical inode reuse.
  • npm test 158/158 and npm run build pass on Node 20 and 22, in containers with rsync and acl like ubuntu-latest.

Not included from #11

The standard/strict profiles and --acknowledge-agent-host-admin-risk detector were left out. A live run against real sudo 1.9.13p3 and opendoas found missed root-equivalent policies and false aborts; details are on #11.

🤖 Generated with Claude Code

The watcher renamed the agent-owned inbox inode into pending/. An agent
that kept a hard link or an open descriptor to its submission could
rewrite the pending draft after preview, and after approval: the bot
rewrites the same inode, renames it to approved/, and the executor
re-reads it after an awaited Telegram call without rechecking the hash.

The watcher now opens the inbox entry with O_NOFOLLOW, requires the
opened inode to match the inspected entry, captures a bounded snapshot,
writes it to a new exclusive 0600 service-owned file in pending/, and
only then removes the unchanged inbox entry. Failure evidence is written
exclusively, and the inbox source is preserved if it cannot be.

Startup isolation checks now also require service ownership of the inbox
and private state directories, a root-owned real draft root, and treat a
failed draft-root stat as an error. The draft root's group is not
checked, so existing root:root installs keep starting.

Salvaged from #11 without its deployment-profile and privilege-detector
changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 110557cf-ba24-435c-ada9-e29f34a4b0e2
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@404Dealer
404Dealer merged commit aa0ca3b into master Nov 6, 2026
3 checks passed
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