Repository navigation
drop한 lock을 descriptor를 닫기 전에 풀어 다른 thread의 child가 lock을 붙잡지 않는다 - #821
Merged
Merged
Conversation
Under flock a lock belongs to the open file, and a child another thread starts holds a copy of the descriptor until it starts its program, so a Lock that only closed its descriptor stayed held for that moment and a one-try lock elsewhere read it as busy. The delivery claim takes its lock with no wait, so its unit test failed when another test thread started a child between two claims (issue 820). Lock now unlocks when it is dropped. A contract test holds a child after its fork and before its program while the lock is dropped and retaken with one try; without the unlock it reads TimedOut. The lock tests' 10 s retake wait, which only absorbed this, is gone.
yansfil
added a commit
that referenced
this pull request
Oct 8, 2026
Related: #769 (adapter declarations this builds on), #810 (no agent row draws an in-process subagent count yet) ## Summary OpenCode has no command hook, so inside Hide it got none of Hide's collaboration: no letters on its prompt, no spawn guard, no Memory, no subagent count. This adds a Hide-owned OpenCode plugin, `~/.config/opencode/plugins/hide.js` beside Herdr's, written and removed only by `hide-agent-hooks` and installed as OpenCode's hook piece in the kit. Inside a Hide-managed Herdr pane it adds guidance, Project Memory and waiting letters to a root session's prompt as one synthetic part, and confirms the letters only after OpenCode reports that part stored. It also refuses `herdr agent start` with the spawn guard's reason, refuses `question` in a Factory worker pane, and reports subagent counts from child-session events. OpenCode stays unbelled, since its resume picker reads `done`. Outside a managed pane the plugin registers nothing. Settings now name OpenCode's piece `Plugin`, drop its `Basic` chip, and say on any agent's row why its hook could not be put in (for example, the agent's config folder does not exist yet). ## Review - **판단해 주세요**: the agent row now shows one quiet line when a hook is Absent with a reason, for every agent (B14). On Windows, Cursor's row says its hook is not written there. - **판단해 주세요**: the subagent count reaches Herdr's pane tokens and the snapshot (`children.subagents`), as Claude Code's does. No row draws it yet for any agent: #810. - **조심해서 볼 파일**: `hide-agent-hooks/src/opencode/plugin.js` - runs inside the operator's OpenCode. Every hook has a budget and fails open except the refusal. - **조심해서 볼 파일**: `herdr-core/src/delivery/mailbox.rs` - an unbelled kind with a prompt hook now takes letter bodies on any prompt. The plugin confirms later. - **조심해서 볼 파일**: `herdr-core/src/runtime/memory.rs` - receipts from OpenCode's label read are recorded on one owned thread off the lock, with queues capped at 64 and 256. - **조심해서 볼 파일**: `.github/workflows/pr.yml`, `herdr-update.yml` - the rust lane installs Node 22, because `hide-agent-hooks` runs the plugin under Node in its tests. - **비용 검토**: - Per OpenCode prompt: one helper process, plus one count report after it. - Per child status change: at most one running report, with only the newest waiting. - Session bookkeeping is capped at 512, evicting finished children first. - Nothing is added on hided's high-frequency paths. The lineage pass reads one kit status instead of cloning the kit. ## Evidence - **확인한 것**: sealed suite `verify-cargo.sh test` and `lint` PASS on the final head, merged with main at #821. - **확인한 것**: Node plugin test, run with OpenCode 1.18.30's hook and event shapes: - root and child prompts; - deferred confirm and an unstored prompt; - budgets, plus slow, failing and garbled helpers; - spawn and question refusal, including a subagent's question; - background child counts; - more than 512 sessions. - **확인한 것**: `web/e2e/opencode-plugin.spec.ts` on a private pinned Herdr 0.9.3, where the kit writes the plugin and a stand-in OpenCode in two panes loads it: - a letter rides the next prompt and is confirmed only once stored; - `herdr agent start` is refused; - Herdr's tokens and the snapshot's `children.subagents.working` go 1 then 0. - 9/9 over 3 repeats, 6/6 over 2 repeats after the last fix; with `agent-adapter-layer.spec.ts` (OpenCode no longer Basic) 4/4 on the merged head. - **확인한 것**: unit tests for every file state (current, stale, edited, foreign, config folder absent, Windows); kit apply, Reinstall and switch-off; Memory receipts from synthetic parts; mailbox next-prompt pull. - **확인하지 못한 것**: the live check with a real OpenCode (PRD D-13) ran but measured nothing (exit 3, every cell UNKNOWN): - run: `scripts/agent-live-check.py --agents opencode`, OpenCode 1.18.30, `opencode-go/deepseek-v4.1-flash`, private pinned Herdr 0.9.3, this branch's hided; - Herdr saw OpenCode idle and ready in every scene, but every screen read came back empty, so all ten scenes timed out at arrival; OpenCode draws a full-screen interface the tool's read does not return; - the tool loads Herdr's integration, not Hide's plugin, so the letter cell is UNKNOWN as well; - nothing unsafe was seen, cleanup was confirmed, and no login or operator setting was changed; - still unproven live: a letter and a refusal reaching the model, B8 after repeated refusals, coexistence with Herdr's plugin, Bun. - The event samples in `tests/fixtures/opencode/events-1.18.30.json` are built from OpenCode's source, not captured. - **확인하지 못한 것**: a machine whose OpenCode reads `$XDG_CONFIG_HOME` loads neither Hide's nor Herdr's plugin from `~/.config/opencode` (a limitation shared with Herdr). <details><summary>Follow-up improvements (not needed for this contract)</summary> - Claude Code's hook is silenced inside OpenCode even where Hide's plugin is not working (Windows, a foreign `hide.js`). - `hide inbox` offers no `ack_command` to OpenCode; letters are confirmed by the plugin only. - Guidance is read once when OpenCode loads the plugin. - A failed confirm can deliver a letter again (at least once); SIGKILL of a helper can orphan its grandchildren; no symlink tests for `hide.js`. - `done` stops growing once finished children are evicted at 512. - No e2e for the question guard (B19) or for an idle pane receiving no input (B5); both are covered below e2e. - A bash command over the helper's 256 KiB input, or a call past the 8 running helpers, passes the spawn guard unchecked (it guards accidents, not a sandbox). - A subagent's `question` from a session the plugin never saw created asks about the subagent's own id, which the Factory guard does not know. - On a timeout the helper is killed but the `hide` call it started ends at its own deadline. - Letter ids are not checked for a leading `-` on pull or confirm; they come from Hide's own ledger. - `herdr-update.yml` takes `actions/setup-node@v4` by tag, as the rest of the repository does. </details> <details><summary>Verification record</summary> - PRD: `agents/prd/opencode-plugin/prd.md` (sha256 91a061f42e55e18f8f0834a17d9b98c8623e8e8cdf3e8d579208af0e8b9d9448) - Base b33fb57 → head bb7bf9d, verified 2026-10-08T20:08:54.127Z: PASS - Verification report: `agents/runs/opencode-plugin/verification-report.json` and `agents/runs/opencode-plugin/verification-report.md`; source fingerprint 01745cef3e161c615ddbf9ebbd8a6d16fb839f090be81b6040ff408874b81036 - Suites: - S1: GREEN `bash scripts/verify-cargo.sh test` (exit 0) - S2: GREEN `bash scripts/verify-cargo.sh lint` (exit 0) - Reviews: - Fidelity (full contract, earlier head): Fix now items fixed before the follow-up rounds; closure confirmed, nothing blocking. - Code (full contract, then follow-ups through the merge with main): Fix now items fixed (plugin eviction, report coalescing, root lookup for question, receipts off the lock); nothing blocking on the merged head. - Security (on the merged head): Fix now 1, a letter or Memory line could close the plugin's own reminder tags; fixed with a test that fails without the fix. Six hardening follow-ups listed above. - Code follow-up (after merging #815/#816/#817): Fix now 1, the OpenCode tests copied or wrote the programs they start, against TESTING.md rule 8; converted to the build's stand-ins. Merge resolutions confirmed. - Evidence: none registered separately. - Changed paths: 63 (see Files changed) - Delivery: mode pr, branch `feat/opencode-plugin`, base `main` </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #820
Summary
Unix의
flock은 open file에 붙고, 다른 thread가 시작하는 child는 자기 프로그램을 시작할 때까지 descriptor 사본을 쥡니다.hide_platform::fs::lock::Lock은 drop할 때 descriptor를 닫기만 해서 그 순간 lock이 남았고, 0초 대기로 lock을 잡는delivery::claim이 그것을 바쁜 lock으로 읽어 unit test가 가끔 실패했습니다.이제
Lock은 drop할 때 lock을 먼저 풀고 닫습니다.herdr-core의 label generator lock이 같은 이유로 이미 하던 일을 공용 lock으로 옮긴 것입니다.lock 테스트가 이 현상을 흡수하려고 두던 10초 재획득 대기(
RELEASED_WITHIN)는 지웠습니다.Review
hide-platform/src/fs/lock.rs- 모든fs::lock사용자(listener, save, kit account lock, device helper sync)의 해제 시점이 "child exec 뒤"에서 "drop 즉시"로 당겨집니다. lock을 child에 넘겨 쥐게 하는 호출자는 없습니다(descriptor는 close-on-exec).Evidence
fs::a_dropped_lock_is_free_while_a_child_started_meanwhile_still_holds_its_descriptor가 child를 fork 뒤 exec 전(pre_exec)에 pipe로 붙잡은 채 lock을 drop하고 0초로 다시 잡습니다. unlock을 빼면expected the lock, got TimedOut로 실패하는 것을 먼저 확인했습니다.verify-cargo.sh test-scoped -p hide-platform -p hide-agent-hooks -p hide-kit3번(load 21-31),nextest같은 세 crate 568개 통과(load 33),verify-cargo.sh lint통과.delivery.rs:303)는 드물어 수정 전후 빈도를 비교하지 못했습니다. 원인 모델은 이슈의 추정과 새 계약 테스트로만 뒷받침됩니다.spawn_guard::a_daemon_that_cannot_be_asked_lets_the_call_run_and_leaves_one_diagnostic이 "nothing on the hook's stderr either"에서 한 번 실패했고 8번 다시 돌려 재현하지 못했습니다. 이 PR과 무관한 부류로 보이며 메시지를 잡지 못했습니다.