Skip to content

fix(opencode): atomically install status plugin entrypoints - #24610

Merged
nwparker merged 7 commits into
mainfrom
fix/opencode-campaign-atomic-plugins
Oct 3, 2026
Merged

nwparker merged 7 commits into
mainfrom
fix/opencode-campaign-atomic-plugins

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​709 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​707
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​261 $\color{#cf222e}{\Huge{\mathbf{−}}}$​109 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​152

ELI5

OpenCode could read Orca's status plugin while it was being rewritten. Install complete files with an atomic rename so a reload sees either the old or new plugin.

What Changed

Canonical server and TUI plugin files now use a sibling temporary file and rename, preserving user symlinks and target permissions. An explicit chmod before rename retains existing permissions even when the process umask is stricter. Temporary overlay entries use atomic replacement that detaches mirrored user links without modifying their targets. Native and relay installation use the same bounded Windows retry operations; Codex keeps its existing retry behavior through a mechanical extraction. Legacy userData server/TUI writes also retain the main-side Windows permission repair: grant the canonical directory (or its existing parent after denied creation), then retry once through the same atomic writer.

Why

Removing the existing file or writing directly into it exposes missing or incomplete source. Atomic rename retains the old working file if replacement fails and cleans up the temporary file. This ports Ahmed Nagy's #24131 with canonical relay symlink preservation and TUI installation coverage.

Linked Issue

Fixes #24121

Visual Proof

N/A — filesystem installation has no visual UI change. Private raw PTY captures show real OpenCode 2.0.16 reloading during concurrent rewrites. A concurrent reader observed 4,524 incomplete reads with direct writes and zero with atomic writes; neither run caught an OpenCode loader exception, so the evidence establishes file integrity rather than a reproduced loader outage.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

macOS: real installed OpenCode 2.0.16 standalone reload stress with isolated config/data/state and a private model endpoint. Seven focused suites passed (107 tests), plus an isolated child-process umask regression (10/10 atomic and permission tests), covering canonical and overlay symlinks, permissions, failed replacement cleanup, TUI no-op timestamps, installers, existing Codex retries and session binder. pnpm tc:node, changed-code quality and all relay bundle builds passed. Windows/Linux execution and live SSH need CI or host testing; shared helpers preserve platform checks and avoid an in-place Windows fallback.

Review

Credits: original atomic implementation and tests by Ahmed Nagy (@AhmedNAgy25), preserved as commit author. The missing-store fix is merged; this PR targets main. The Windows permission recovery review finding is credited to @pullfrog. #24124 contains unrelated SSH retry work and should remain open for independent review.

Agent skill upstream boundary

  • Not applicable, or this change follows the upstream boundary.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A with reason for visual proof
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote and path impact considered
  • Full lint/typecheck/test/build — focused checks pass; CI covers broader gates

Current review correction

Head a92d0dabd08f7917a337e5cef56b911f017bb58d retains the reviewed correction 9acea30efbe0cd3a8554d1328fe8b7327b9a78d5 against named main 84a4e8a9b0a1a0bd938528aa2dc6e49636917a47. All13 atomic/permission-repair paths match reviewed source, and every unrelated main entry and mode is unchanged. The generated plugin order, canonical writer, symlink behavior and SSH retry layering are preserved.

144 focused tests across9 files, Node typecheck and the13-file changed-code gate pass on the prepared head, including32 mocked Windows ACL cases. Installed OpenCode2.0.16 privately loaded both repaired legacy variants and canonical plugins on macOS; this proves real plugin loading with controlled local credentials, and does not claim physical Windows execution. Fresh full-head CI runs after this update.

@nwparker
nwparker marked this pull request as ready for review October 2, 2026 08:36
@nwparker
nwparker force-pushed the fix/opencode-campaign-atomic-plugins branch from 313a75f to a63e5eb Compare October 2, 2026 08:54
@nwparker
nwparker force-pushed the fix/opencode-campaign-missing-store branch from 47096a5 to 65b5778 Compare October 2, 2026 09:42
@nwparker
nwparker force-pushed the fix/opencode-campaign-atomic-plugins branch from a63e5eb to 4713bae Compare October 2, 2026 09:42
@nwparker
nwparker force-pushed the fix/opencode-campaign-atomic-plugins branch from b68ac71 to 08fbcfc Compare October 2, 2026 12:02
@nwparker
nwparker changed the base branch from fix/opencode-campaign-missing-store to main October 2, 2026 12:03
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7facab29-b7ce-4489-9a76-71370f8aa4a0
📥 Commits

Reviewing files that changed from the base of the PR and between 84a4e8a and a92d0da.

📒 Files selected for processing (13)
  • src/main/codex-accounts/fs-utils.ts
  • src/main/opencode/hook-service-legacy-acl.test.ts
  • src/main/opencode/hook-service.ts
  • src/main/opencode/legacy-plugin-acl-retry.ts
  • src/relay/opencode-canonical-config.ts
  • src/relay/plugin-overlay.test.ts
  • src/relay/plugin-overlay.ts
  • src/shared/opencode-plugin-atomic-write.test.ts
  • src/shared/opencode-plugin-atomic-write.ts
  • src/shared/opencode-plugin-permissions.test.ts
  • src/shared/opencode-tui-plugin-install.test.ts
  • src/shared/opencode-tui-plugin-install.ts
  • src/shared/windows-retry-file-operations.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds shared atomic writers for canonical and overlay OpenCode plugins, with canonical writes resolving symlinks and overlay writes targeting the supplied path. TUI installation now selects behavior by ownership. Windows file-operation retries are shared, and legacy plugin writes can grant an ACL and retry after a Windows permission denial.

Priority: ⬆️ High

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to a92d0

The plugin installation changes appear ready to merge after normal checks; no specific remaining failure is established.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to a92d0

Atomic replacement improves plugin reload safety. However, Windows recovery can grant broader permissions to a linked directory outside managed plugin storage, and those permissions can remain after installation fails. Exposure depends on local filesystem control and the application's existing permission-changing authority.

Retained concerns

  • Medium · security · inferred: New legacy recovery grants inheritable full control on the resolved plugin target's nearest existing directory without establishing that the directory is application-owned. A canonical symlink can redirect this authorization change outside managed plugin storage. If the grant succeeds but the subsequent write fails, the old plugin may remain while the broader ACL persists. This is an authority-scope and recovery concern, not a verified privilege-escalation exploit; attacker influence requires control of the relevant filesystem path, and the process must already be authorized to change the selected directory's ACL.
Security review details

Security Blast Radius

  • inferred — The authorization change concerns the selected directory and objects inheriting its ACE, rather than only the plugin file. Canonical link resolution can select a directory outside userData. The command uses the application's execution context; successful changes still require Windows authorization to modify that directory's ACL.

Security Findings and Attack Paths

  • inferred — A locally influenced canonical plugin link can connect legacy refresh to an external target. If the write produces a qualifying permission error and the directory ACL grant succeeds, recovery changes authorization beyond the managed plugin entry. Failure of the retry does not undo that grant. This conditional path is supported by the source, but a working cross-identity exploit was not demonstrated.

Trust Boundaries and Controls

  • observed — Recovery requires a readable existing legacy server plugin and a Windows EACCES or EPERM write failure, and permits only one ACL-assisted retry. Relay overlays use the separate overlay writer. Overlay currentness checks require a regular file, preventing a matching file symlink from being retained as the owned entry.

Resilience and Maintainability Implications

  • observed — Failed recovery rethrows the original permission error, while the atomic writer attempts to remove its temporary file. Neither path restores an ACL changed by a successful grant, so preserving old plugin content does not preserve the complete pre-install security state.

Hardening Proposals

  • proposed — Separate permission-repair authority from canonical symlink preservation. Limit automatic grants to explicitly owned directories and necessary rights; require explicit authorization for external targets. Define restoration of prior ACL state when installation fails after a grant.
  • proposed — Treat target metadata failures other than ENOENT as replacement failures rather than assuming absence. This would make the permission-preservation guarantee fail closed; successful replacement after such a metadata failure was not established as an observed vulnerability.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.84% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 13 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #24121 requires atomic replacement at the main and relay plugin installation paths, preservation of canonical symlinks and their targets, and replacement of overlay links without writing through…
Out of Scope Changes check ✅ Passed The Windows retry helper extraction preserves Codex retry behavior and supports atomic plugin replacement. The legacy ACL retry changes preserve permission recovery for related OpenCode plugin writes.…
Title check ✅ Passed The title clearly and concisely describes the primary change: atomic installation of OpenCode status plugin entrypoints.
Description check ✅ Passed The description covers the change, motivation, linked issue, visual-proof exception, testing, review context, upstream-boundary checklist, and platform limitations. It is substantially complete agains…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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

Comment @coderabbitai help to get the list of available commands.

@pullfrog

pullfrog Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Pullfrog stalled

The agent stopped emitting events for 125s and was killed by the activity-timeout watchdog. The model produced no output at all before the stall — the request was sent but nothing came back. This is usually transient; re-running often succeeds.

Recent agent stderr
timestamp=2026-10-02T11:48:15.850Z level=ERROR run=2f2758f4 message="stream error" providerID=openrouter modelID=deepseek/deepseek-v4.1-flash session.id=ses_f039ca6f1ffep7I9fdb5OjT8YW small=false agent=build mode=primary error.error="Error: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()"

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog

pullfrog Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Pullfrog stalled

The agent stopped emitting events for 125s and was killed by the activity-timeout watchdog. The model produced no output at all before the stall — the request was sent but nothing came back. This is usually transient; re-running often succeeds.

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Preserves all 11 reviewed PR source/test blobs exactly; main owns the workflow package-variable contract fix.
@nwparker

nwparker commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Updated to 0a6f9ad687ca2610eba41916fdc1bf2baee09c26 with current main's E2E package-variable contract fix. All 11 reviewed product/test post-blobs remain byte-identical. The repeated shard failure checked package names in the installer script after the workflow moved them to ORCA_E2E_APT_PACKAGES; this update retains main's corrected contract test. New-head CI is running.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

One Windows regression: the legacy shared-plugin refresh lost its Protected-DACL EPERM recovery. Details inline.

Reviewed changes — no prior Pullfrog review existed, so this run reviewed the full 11-file PR against main (1fc24d3114), head 0a6f9ad687:

  • Extracted the Windows retry helpers into src/shared/windows-retry-file-operations.ts and re-exported them from codex-accounts/fs-utils.ts.
  • Added opencode-plugin-atomic-write.ts with resolveCanonicalPluginWritePath (follows dotfile symlinks, including dangling readlinkSync chains) plus temp-file + rename writers that preserve the target's mode via an explicit chmodSync.
  • Routed OpenCode installs through the atomic writers in hook-service.ts, relay plugin-overlay.ts, and opencode-canonical-config.ts; writeOpenCodeTuiPlugin gained an ownership flag so overlay entries detach mirrored links.
  • Added focused tests for atomic temp writes, canonical/overlay symlink behavior, dangling chains, loops, rename-failure cleanup, and umask-restricted permission retention.
  • Merged current main (0a6f9ad687); the merge does not touch the PR's 11 source/test blobs.

The atomic-write, symlink-resolution, and permission-preservation logic is otherwise correct and the new tests exercise real failure modes.

ℹ️ Nitpicks

  • The manual visited/40-depth loop guard in resolveCanonicalPluginWritePath (src/shared/opencode-plugin-atomic-write.ts:45-66) is unreachable: a real cycle makes realpathSync.native throw ELOOP (re-thrown at line 40), and a dangling chain cannot form a cycle. The 'throws on symlink loop' test (src/shared/opencode-plugin-atomic-write.test.ts:261) therefore passes via Node's native ELOOP, not the guard it appears to cover.
  • Every symlink case is skipIf(process.platform === 'win32'), so realpathSync.native/readlinkSync handling of Windows junctions and symlinks is unverified despite being a supported target.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/opencode/hook-service.ts Resolved
Keep the shared canonical writer and restore one main-side Windows permission retry for legacy userData server and TUI repairs. Credit pullfrog for identifying the lost backstop in the PR 24610 review.
Keep reviewed atomic plugin replacement and Windows permission recovery unchanged while retaining current process scheduling and redraw fixes. Credit pullfrog for the permission-recovery finding.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — re-reviewed the two commits pushed since Pullfrog's prior review (0a6f9ad6), which restore the Windows ACL backstop flagged there:

  • Restored per-write ACL recovery for legacy userData plugin writes via the new main-side writeLegacyOpenCodePluginWithAclRetry wrapper: on win32 + isPermissionError it grants the canonical destination directory (or the nearest existing ancestor after a denied mkdir) and retries the writer once, rethrowing the original error if the grant or retry fails.
  • Routed both legacy writes through it — the TUI copy write and the canonical server write in hook-service.ts — while writeCanonicalOpenCodePluginAtomically stays the only bytes writer.
  • Added hook-service-legacy-acl.test.ts covering EPERM/EACCES retry ordering, denied mkdir, TUI-before-server recovery, non-win32 and unrelated-errno passthrough, grant/retry failure preserving the original error with temp cleanup, canonical symlink target repair, and the current/absent-install no-op path.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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.

[Bug]: The OpenCode status plugin is written in place, so a reload can see it missing or truncated

2 participants