Repository navigation
fix(security): an unresolved session has no write target (#152) - #157
Merged
Merged
Conversation
Reads already failed closed for a session whose repository never resolved (#127/#133): it sees global rows and nothing else. Writes did not. The stamp at the store's single choke point fell back to the module scope, so a memory_remember from an unresolvable session in repo A was stamped into whichever workspace's setup() ran last, and with no module scope at all it was stamped nothing — which every reader calls global. Auto-capture and memory_import inherited the same fallback. appendMemory now resolves the writer through writeTarget(): a session the host named but never resolved gets ok:false, and the store refuses the write instead of guessing an owner. The model-facing tools answer with the same message before the gate runs and log evidence write_refused; capture skips before spending a model call (auto_capture_refused); import resolves before reading a single row. Explicit global:true and the deliberately sessionless admin path (viewer, restore, scripts) are unchanged. Contract change, pinned by test/repo-scope-session.test.ts: a write during the server-start window is refused rather than stored as a global row.
|
🎉 This PR is included in version 0.14.14 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Contributor
|
Independent re-verification of e1256e0 after its merge into v0.14.14: the #152 findings are fixed; no blocking finding from this pass.
The separate export artifact collision found while reviewing #156 is posted there with a reproducer and a tested patch; it does not invalidate this writer-scope fix. |
This was referenced Oct 28, 2026
abogartz
added a commit
to WhollyMindless/opencode-self-improvement
that referenced
this pull request
Oct 28, 2026
Brings in abogartz#152's write-identity rule (writeTarget / UnresolvedWriterError at the appendMemory choke point) plus the release commit. No textual conflicts. Verified semantically after the merge, not just textually: the full gate is green (tsc, biome, unit 608 pass / 12 skip / 0 fail, e2e smoke+BDD 11 pass), and this PR's own abogartz#143/abogartz#153 probes stay green — restoreSnapshot publishes through writeAtomic, so abogartz#152's appendMemory refusal is not on the undo path.
abogartz
pushed a commit
that referenced
this pull request
Oct 29, 2026
memory_update's replacement candidate is built FROM the row it replaces: tags and issue carry over (an update of an imported row no longer launders away its provenance marker or issue link), and kw keeps target.kw when omitted while an explicit kw still replaces. A prose edit is not a metadata reset. runWriteGate no longer throws AFTER the append when the write_promoted audit line fails - the row is durable at that point, and a throw made memory_update's catch declare 'Nothing was written' while the replacement sat on disk un-superseded (two active rows; retry said 'Duplicate ignored' about a write that happened). The failure rides the promoted outcome as GateOutcome.evidenceError; pre-append faults keep throwing fail-closed. The update entry completes the supersession on that outcome (markSuperseded is first-call-wins, safe to complete), reports the merge_review PARTIAL shape from 156e887, catches a markSuperseded throw the same way, and gains a duplicate-aware resolution: naming a superseded row whose active successor already carries exactly this content reports the duplicate verdict instead of a dead end. Pre-write failures - lock timeout, the 152 choke-point refusal, pre-append evidence faults - stay fail-closed with the truthful Nothing-was-written message; the catch's stale 'only the lock timeout throws' premise is corrected. Rebased onto ed5ecde (0.14.14): #157's ownerless-writer refusal is a pre-write entry check and is untouched - this fix keeps it fail-closed in the catch's unmoved branch.
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 #152
What was wrong
The read side and the write side disagreed about what an unknown identity means.
Reads already fail closed (#127/#133):
readerForSessiongives an unresolved sessionglobal-only, never the module scope of whoever set up last. Writes went throughrepoScopeFor(), whose last resort is the module scope — so amemory_rememberfrom a session the host could not resolve was:No
force, no admin seat, no interleaving required.memory_update,memory_importand auto-capture all inherited the same fallback.Reproduced before fixing
Both reported cases plus the two paths the ticket did not name, on
main@91f7a56(v0.14.13), macOS / Bun 1.4.3 (the report was Windows / Bun 1.3.10):After: 10/10 green in
test/security-unresolved-write-scope.test.ts, and the 4 controls in that file (bound session, workspace-bound instance, explicitglobal:true, sessionless writer) were green before the change too — the fix did not buy them.The rule
A named session with no resolved repository has no write target. Reads and writes now answer the same question the same way: an identity that cannot read a repository cannot write one either.
repokey.ts—writeTarget(sid): named session → its own binding (firm or provisional, no module fallback) orok:false; nobody named (viewer process, restore, scripts, tests) → the module scope, includingnull. That last branch is the deliberate admin path and is unchanged.memory.ts— the stamp resolution at the single write choke point throwsUnresolvedWriterError. Covering the choke point is what protects callers that reach the store without a tool, present or future.index.ts—memory_remember,memory_update,memory_importandmemory_initanswer with the same message before the gate runs (one sharedunresolvedWriteMessage, so the two cannot drift) and record evidencewrite_refused.memory_importalso binds identity first, like the other three, so a resolvable serve-host session is never falsely refused.auto_capture_refused.portable.ts—importMemoriesresolves the writer before reading a single line, so a refusal is zero rows, not half a file.Preserved deliberately: explicit
global: true(an owner was stated), the sessionless admin path, and the provisional binding #127 introduced (an unknown session reaching a workspace-bound instance still writes there — the ordinary single-project shape stays frictionless).Contract change (the one behavior tests used to pin that flips)
test/repo-scope-session.test.ts"server-start window" asserted that an early write from a location-less setup produces an unstamped global row. That assertion is the second half of the vulnerability, so the test now asserts the new contract: the write is refused, the day file is untouched, and oncesession.execution.startedbinds the session the same write lands stamped.Consequence for operators: a plugin instance loaded with no
location.directorycan no longer store project memories implicitly. It says so on every attempt (Write refused: … pass global:true …). Configuring the plugin per project, or asking forglobal: true, are the two ways out.Test harness honesty
Eleven tests wrote through named-but-unbound sessions and leaned on the module fallback. Each now declares the workspace it simulates, which is what a real host does by handing the tool a
sessionID:test/scenarios.test.tsandtest/gated-injection.test.ts(ctx(sid)),test/helpers/scripted.ts(session factory). No assertion was weakened to get there.Evidence
bun scripts/merge-gate.ts→ all green: tsc, biome, unit612 pass / 12 skip / 0 fail, e2e smoke + BDD11 pass / 0 fail.bunx tsc --noEmitclean;biome lintexit 0 (advisory warnings only, unchanged in kind).Not in this PR
memory_undoforce rollback across repositories) and memory_export has no repo-visibility filter — any session can export every repository's rows #143 (memory_exporthas no visibility filter) are the next two in the triage and stay open — neither is reachable through this code path.memory_forget/memory_decay/memory_merge_reviewwere checked: all three already resolve their targets through aReader, so an unresolved session acts on global rows only and no cross-repo stamping exists there.