Repository navigation
Description
Symptom
test/repokey-path.test.ts (#92) fails depending on which test file ran before it. Two tests:
a session dir containing a space stamps repo= as an unquoted hash, repoPath stays rawrows written before the hash (repo= was the path) stay visible through repoPath
Minimal repro (macOS and Linux, Bun 1.4.3) — order is the whole bug:
bun test ./test/update-targeting.test.ts ./test/repokey-path.test.tsExpected to contain: "repo=39fb4455edb0"
Received: "ts=… type=learning scope=s content="the build runs from a folder with a space" repo=7f336c009f10 repoPath=/tmp/osi-upd-H5OLSA/repo"
(fail) … a session dir containing a space stamps repo= as an unquoted hash, repoPath stays raw
(fail) … rows written before the hash (repo= was the path) stay visible through repoPath
19 pass / 2 fail
Reproduced on origin/main at 9caed07 (0.14.12). The same two files in the same order pass on the pre-#133 revision cf9b73c (21 pass / 0 fail), so this is a regression introduced by #133, not a pre-existing flake.
Root cause
#133's entry binding made session identity sticky, and test/update-targeting.test.ts never releases it:
- It
setCurrent({ sessionID: "upd", … })(test/update-targeting.test.ts:62) and loads the plugin withliveRoot = <osi-upd-*/repo>. - Dispatching a tool now runs
toolIds(context)→bindSessionProvisional(sid, instanceDir)(src/index.ts:361-363), sobySession["upd"] → <osi-upd-*/repo>is registered. Before fix(security): session-scoped reads, evidence credential scrub, viewer origin preservation (#127 #128 #129) #133 only host identity events populated that map, which is why the test never leaked. - Its
afterEach(test/update-targeting.test.ts:47-51) does not callresetState()orresetSessionScopes(), so both the ambient sid"upd"and its binding survive into the next test file (module-globalbySession). test/repokey-path.test.ts'sbeforeEachonly callssetRepoScope(null)(test/repokey-path.test.ts:31-36). It has no session reset, and it relies on the ambient module scope for both directions:- write:
appendMemoryresolvesrepoScopeFor(input.sessionID ?? getCurrent().sid)(src/memory.ts:273) → the stale"upd"entry outranks thesetRepoScope(resolveRepo(projDir))the test just set → the row is stamped with the deadosi-upd-*repo; - read:
relevantKnowledge→ ambient reader → same stale scope → the legacy row is filtered out, so the hit string comes back empty.
- write:
This is the same class as the two hygiene findings already fixed on #133 (injection-framing, negative-eval) — update-targeting.test.ts is the third instance and was missed. It passed CI on #133's own head, and a full local bun test, purely because of file ordering.
Verified fix (2 lines + 2 lines, defense in depth)
# test/update-targeting.test.ts
- import { setRepoScope } from "../src/repokey.ts";
+ import { setRepoScope, resetSessionScopes } from "../src/repokey.ts";
afterEach(() => {
+ resetState();
+ resetSessionScopes();
delete process.env.OPENCODE_MEMORY_DIR;
# test/repokey-path.test.ts (relies on ambient module scope; should assert it owns it)
beforeEach(() => {
…
setRepoScope(null);
+ resetState();
+ resetSessionScopes();Confirmed on 9caed07: the failing order goes 19 pass/2 fail → 21 pass / 0 fail; the reverse order stays green; full bun test ./test/ stays 578 pass / 12 skip / 0 fail.
Two things worth deciding beyond the hygiene patch
- Order-independence of the gate command. This is the third occurrence of the same leak. A single global reset in a shared test setup (a
bunfig.tomlpreload or atest/support/*helper that every file imports) would stop the whack-a-mole; per-file patches keep depending on someone remembering. - Should a provisional binding outrank an explicitly set module scope?
setRepoScope(x)followed by a write currently resolves throughrepoScopeFor(ambientSid), which honors a provisional guess (src/repokey.ts:143-149). Product-wise "session identity wins" is the intended rule, but a stale provisional guess silently defeating an explicit scope assignment is surprising to any caller — including out-of-plugin ones. Worth an explicit decision (and a doc line) rather than an accident of lookup order.
Blast radius
mainis red under some test orderings as of 0.14.12, so any new PR based on main can inherit a spurious redtestcheck.- This blocked PR fix(security): date-shaped evidence reads, ownership-checked merges, redact-before-crop capture (#130 #131 #132) #135 after
gh pr update-branchreordered its files.
Activity
WhollyMindless commentedon Oct 28, 2026
Independent Windows confirmation for this issue: on #135's
da64f63, Windows / Bun 1.3.10 reproduces the same ordered pair:bun test ./test/update-targeting.test.ts ./test/repokey-path.test.tsUnmodified: 19 pass / 2 fail, with the wrong
osi-upd-*/repostamp and missing legacy-row recall. With reset hygiene in both files: 21 pass / 0 fail, and type-checking passes. The Linux CI failure is on Bun 1.4.4, so this is separate from the earlier Windows export/version-skew failures.The complete tested patch is already on #135. It also clears session bindings in
update-targeting's setup so the reusedupdid cannot retain a previous test's workspace, and resets state/session scopes in the consumer's setup and teardown. No product code or assertions changed; no branch push from this review.My recommendation: land the test-isolation fix on main, then update #135 and rerun its gates. A shared test reset is a sensible durable follow-up, with this ordered pair retained as a validation case. Keep the provisional/session-vs-module precedence decision separate: the hygiene repair should preserve the session-isolation behavior we just verified, rather than changing production identity resolution to accommodate leaked test state.
Merge pull request #151 from abogartz/fix/149-test-isolation
test: release session identity between tests (abogartz#149)
test: make the re-ingested-row identity check deterministic
abogartz-opencode-self-improvement commentedon Oct 28, 2026
🎉 This issue has been resolved in version 0.14.13 🎉
The release is available on:
Your semantic-release bot 📦🚀
fix(#35): batch tombstone writes into one lock and one append
chore(release): 0.14.25 [skip ci]