Skip to content

fix(agent): lock stops the agent promptly; calmer mlock note - #132

Merged
arimxyer merged 2 commits into
mainfrom
fix/agent-lock-stops-promptly-and-mlock-warning
Jul 1, 2026
Merged

fix(agent): lock stops the agent promptly; calmer mlock note#132
arimxyer merged 2 commits into
mainfrom
fix/agent-lock-stops-promptly-and-mlock-warning

Conversation

@arimxyer

@arimxyer arimxyer commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Two rough edges found during hands-on testing of the agent.

1. `lock` left a locked-but-running agent (~30s dead window)

After `pass-cli lock`, the agent zeroed its secrets but kept running until the next expiry tick. During that window:

  • the socket still answered, so `exec`/`export`/`inject` hit "agent is locked" with no fallback, and
  • `pass-cli agent` refused to restart ("an agent is already running").

There is no in-place re-unlock by design. Per the owner-chosen model, the server now stops as soon as a request leaves the agent locked (explicit `lock`/shutdown, or idle/max-TTL enforcement during a request), freeing the socket. Commands then fall back to direct-open, and a fresh `pass-cli agent` can rebind. `lock` help + the `MethodLock` doc now say it stops the agent; unlock = run `pass-cli agent` again.

2. Alarming/misleading mlock warning

`Warning: could not harden agent memory ... continuing without mlock` fired for every interactive user (default 8 MB `RLIMIT_MEMLOCK` < a Go runtime), and wrongly implied no hardening — even though `PR_SET_DUMPABLE=0` had already succeeded. Reworded to a calm note: memory not locked into RAM, core-dump/ptrace protection still active, raise `RLIMIT_MEMLOCK` (or use the systemd unit) to enable mlock.

Tests

  • `TestServer_LockStopsServerPromptly` (unit) — after a lock request, the server stops and the socket goes unreachable.
  • `TestIntegration_Agent_LockThenFallback` — the socket is freed and `exec` falls back to direct-open (password on stdin).
  • Full agent + integration suites green; `golangci-lint` 0 issues on linux and darwin.

🤖 Generated with Claude Code

arimxyer and others added 2 commits July 1, 2026 13:01
Two rough edges found during hands-on testing:

1. `pass-cli lock` left a locked-but-running agent for up to one expiry tick
   (~30s): the socket kept answering, so commands hit "agent is locked" with no
   fallback, AND `pass-cli agent` refused to restart ("already running"). There
   is no in-place re-unlock by design. Fix (owner-chosen model): the server now
   stops as soon as a request leaves the agent locked (explicit lock/shutdown, or
   idle/max-TTL enforcement during a request), freeing the socket. Commands then
   fall back to direct-open and a fresh `pass-cli agent` can rebind. lock help +
   MethodLock doc updated to say it stops the agent.

2. The mlock failure warning was alarming and misleading ("could not harden agent
   memory ... continuing without mlock") even though PR_SET_DUMPABLE=0 succeeded.
   Reworded to a calm note that states core-dump/ptrace protection is active and
   only the swap-lock is unavailable (expected without a raised RLIMIT_MEMLOCK).

Tests: TestServer_LockStopsServerPromptly (unit — server stops on lock) and
TestIntegration_Agent_LockThenFallback (socket freed + exec falls back to
direct-open with the password on stdin). Full agent + integration suites green;
golangci-lint 0 issues on linux and darwin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014kVLjbUL4F4CkoA7RbMYy8
Testing showed the natural reach is 'pass-cli agent lock' (next to 'agent stop'
/'agent status'), not the top-level 'pass-cli lock'. Register lock under 'agent'
too, sharing one run function; keep the top-level shortcut as well. Also handle
ErrNoAgent gracefully ('no agent is running (nothing to lock)') instead of
surfacing a raw error. Integration test now drives 'agent lock' end-to-end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014kVLjbUL4F4CkoA7RbMYy8
@arimxyer
arimxyer merged commit 35ba4b3 into main Jul 1, 2026
7 checks passed
@arimxyer
arimxyer deleted the fix/agent-lock-stops-promptly-and-mlock-warning branch July 1, 2026 17:26
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