Skip to content

fix(opencode): rule-store writes take a machine-wide lock; a skipped store is logged (#217) - #226

Merged
Alter-Igor merged 4 commits into
devfrom
learning-store-followups
Oct 17, 2026
Merged

Alter-Igor merged 4 commits into
devfrom
learning-store-followups

Conversation

@Alter-Igor

@Alter-Igor Alter-Igor commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #217 (the rest of it, after #221).

What changes

Validation

  • I can't run the real suite locally, because bun install panics (dev env: bun install panics on Windows (Bun 1.3.14 internal assertion), so fresh worktrees cannot install #201). I ran a stubbed scratch copy of observer.ts and observer.test.ts instead. It uses the real core Flock, and drops only the tests that need SynapseAuthPlugin. Results:
    • 38 pass, 0 fail.
    • With the lock, the two-process test passed 5 out of 5 times.
    • With the lock removed, it failed 3 out of 3. So the test really catches the lost update.
  • The SynapseAuthPlugin tests, including the new global list-rules test, run only in CI. Fast tier: observer.test.ts and 3 more plugin tests.

Not covered: the owner decision on mirroring (#211).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Reliability
    • Learning rules are better protected from being lost when multiple processes save changes at the same time.
    • Saves can proceed if cross-process locking is unavailable, with a diagnostic recorded.
    • Store updates are more resilient to temporary file-system errors.
  • Bug Fixes
    • Unreadable learning stores are reported once until they can be read again.
    • Listing rules from a readable project store continues even if the global store is unreadable.
    • Forgetting rules now uses the same coordinated update process as recording them.

Alter-Igor and others added 2 commits October 18, 2026 05:34
…store is logged (#217)

- recordLearning and forgetLearningResult take a Flock lock next to the
  global store (#75 pattern), so a TUI and `opencode serve` writing at
  once no longer drop each other's rule. If the lock is not free within
  10 s the write goes ahead under the in-process lock, with a
  LEARNING_STORE lock_failed diagnostics line.
- Prompt injection writes one LEARNING_STORE skipped_unreadable line when
  it reads an unreadable store as empty (again only after a good read).
- Tests: two processes recording at once lose no rule (fails 3/3 without
  the lock), the diagnostics line, and synapse_list_rules marking the
  global group as skipped (CodeRabbit on #221).
- AGENTS.md: a learning-store note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 81dae004-fa31-4d81-9a4c-46e8196c4aec
📥 Commits

Reviewing files that changed from the base of the PR and between 0abdd32 and 70e66de.

📒 Files selected for processing: 3
  • AGENTS.md
  • packages/opencode/src/plugin/observer.ts
  • packages/opencode/test/plugin/observer.test.ts
🚧 Files skipped from review as they are similar to previous changes: 1
  • AGENTS.md

Limit details: You’ve used all 5 included reviews currently available. Your 55 included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

📝 Walkthrough

The observer now reports unreadable learning stores through diagnostics and skipped-store results. Record and forget operations attempt machine-wide locking. Atomic writes retry selected rename failures. Tests cover unreadable stores, lock failures, and concurrent writers.

Changes: Learning store reliability

Layer / File(s) Summary
Unreadable store reporting
packages/opencode/src/plugin/observer.ts, packages/opencode/test/plugin/observer.test.ts
Unreadable stores are reported as skipped. Diagnostics are deduplicated until a readable result clears the report state. Tests cover skipped results and diagnostic deduplication.
Mutation coordination and atomic writes
packages/opencode/src/plugin/observer.ts, packages/opencode/test/plugin/fixture/record-rules.ts, packages/opencode/test/plugin/observer.test.ts, AGENTS.md
Record and forget operations use a machine-wide lock attempt. If lock acquisition fails, the observer logs a diagnostic and continues with the mutation. Atomic writes retry selected rename failures. Tests cover lock failure and concurrent writers. AGENTS.md documents store behavior and the observer test command.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 70e66

The change adds machine-wide locking for learning-store writes, diagnostics for unreadable stores, and rename retries. It has tests for the main behaviors, and no concrete merge-blocking risk was identified in the supplied context.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly identifies the primary changes: machine-wide locking for rule-store writes and diagnostics for skipped stores.
Description check Passed The description clearly explains the issue, implementation, limitations, and validation results. It omits the template's Type of change and Checklist sections, but the main required information is pre…
Linked Issues check Passed The PR satisfies the coding requirements in directly linked issue #217. selectInjected and rule listing report unreadable stores with LEARNING_STORE skipped_unreadable diagnostics, and the obser…
Out of Scope Changes check Passed The changes stay within #217. The lock, unreadable-store diagnostics, skipped listing state, atomic-write cleanup, fixtures, and tests support the linked rule-store requirements. AGENTS.md documents…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 …
Full details: Description check

Explanation

The description clearly explains the issue, implementation, limitations, and validation results. It omits the template's Type of change and Checklist sections, but the main required information is present.

Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in directly linked issue #217. selectInjected and rule listing report unreadable stores with LEARNING_STORE skipped_unreadable diagnostics, and the observer tests cover skipped global listing and repeat logging after recovery. recordLearning and forget operations use mutateStores with a machine-wide Flock, a 10-second timeout, and lock_failed diagnostics; the concurrent child-process test covers lost updates. writeJsonAtomic removes its temporary file in the failure path after rename retries.

Full details: Out of Scope Changes check

Explanation

The changes stay within #217. The lock, unreadable-store diagnostics, skipped listing state, atomic-write cleanup, fixtures, and tests support the linked rule-store requirements. AGENTS.md documents the implemented behavior. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

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

Alter-Igor and others added 2 commits October 18, 2026 05:47
…oment (#217)

On Windows a rename onto learnings.json fails with EPERM/EBUSY/EACCES
while another handle has the file open, so a rule was silently not
saved (QA on #226). writeJsonAtomic now retries those codes up to 5
times (20 ms doubling). QA's 3-writer harness, 10 runs: 15 bad results
without the retry, 0 with it.

Adds a test for the lock_failed path: a write whose lock folder cannot
be made still saves where it can and logs lock_failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ied on Windows only (#217)

Architect on #226: without a note the retry could be dropped in a
cleanup or an upstream sync. Off Windows EACCES is a real permission
error, so it now throws at once there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Alter-Igor

Copy link
Copy Markdown
Owner Author

Gate A record, head 70e66de

  1. Reviewers. CodeRabbit reviewed 0abdd32..70e66de: "No actionable comments were generated".
  2. Threads. There are no threads. The QA and architect findings are dispositioned:
    • Fixed in bad329e: QA low, a Windows rename EPERM lost rules even with one process. renameWithRetry fixes it. In QA's 3-writer harness over 10 runs: 15 bad results without the retry, 0 with it.
    • Fixed in bad329e: QA low, the lock_failed path had no test. There is now a test, and a negative check confirms it.
    • Fixed in 70e66de: architect, AGENTS should name the retry; EACCES is now retried on Windows only.
    • Follow-up in the next loop run (the observer: code-mode MCP failures, retrospective re-reporting, and other #208 follow-ups #209 PR also edits the same AGENTS area): QA and architect nit, the AGENTS wording says "On Windows", but EPERM and EBUSY retry on every OS.
    • Accepted, low: the two-process test does not prove the writers overlapped on Linux. On Windows the no-lock copy fails 3 out of 3 runs.
    • Accepted, low: a lock left by a crashed writer stalls writes for 10 s, for up to about 60 s, then falls back.
    • Accepted, architect nits: a fallback write is not visible to the caller, and reads queue behind a waiting write.
  3. CI on 70e66de. fast passed: 116 pass, 0 fail, all 6 observer: silent skipped rule store, cross-process lost update, orphan tmp file (#216 follow-ups) #217 tests. full and shards 1/4 to 4/4 passed.
  4. Fresh QA. QA: PASS head=70e66de67d29725097501a4c21140e2c83ec83c2 findings=0 blocking
  5. Architect. ARCH-GATE-02: ALIGNED head=70e66de67d29725097501a4c21140e2c83ec83c2 reviewer=claude-subagent-architect docs=none findings=EACCES retry limited to win32; AGENTS sentence matches the code; nit: AGENTS says On Windows but EPERM/EBUSY retry on all platforms (harmless)
  6. Base and merge. The branch is 0 commits behind dev. The merge is pinned with --match-head-commit, under the owner's standing approval for the gated loop.

@Alter-Igor
Alter-Igor merged commit 20ced99 into dev Oct 17, 2026
7 checks passed
@Alter-Igor
Alter-Igor deleted the learning-store-followups branch October 17, 2026 18:54
Alter-Igor added a commit that referenced this pull request Oct 17, 2026
…ger hides server errors (#209) (#227)

- finalizeSessionRetrospective returns null and writes/sends nothing
  when there are no records (a turn with no tool calls, a session.deleted
  right after an idle). It used to write a file and POST 0 calls.
- ABORTED matches "The|This operation was aborted" only at the start
  (optionally after "Error: ") or right after "AbortError: ". An MCP
  server's own error that mentions an aborted operation further in now
  counts as a failure.
- AGENTS.md: the #18 note names ABORTED separately from NOT_A_FAILURE,
  says empty retrospectives are skipped and that native failures are
  marked isError; the learning-store note no longer says "On Windows" for
  the EPERM/EBUSY retry (QA and architect nit on #226).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

observer: silent skipped rule store, cross-process lost update, orphan tmp file (#216 follow-ups)

1 participant