Repository navigation
Description
Context
The pi backend still carries in-process copies of brain write operations that production never calls. This issue is the sole owner of deleting them: #1398 migrates only the internal imports that survive this deletion, and #1434 no longer repairs these writers.
BrainAccess.updateis a near-verbatim copy of core'supdateDocumentFields, and it has drifted:- The copy is
updateatpackages/ui-backend-pi/src/brain-access.ts:283-344; core's original isupdateDocumentFieldsatpackages/core/src/lib/ops/write.ts:77-122. - The copy writes with plain
writeFileSync(brain-access.ts:335). Core writes throughwriteFileSafely, a staged rename (packages/core/src/lib/ops/write.ts:118).
- The copy is
addandarchiveduplicate core too.BrainAccess.add(brain-access.ts:260) andarchive(:346) duplicate core'saddDocument(write.ts:42) andarchiveWithReindex(write.ts:125).- None of them runs in production.
- The worker always installs a bridge with
applyBrain(packages/ui-backend-pi/src/worker-entry.ts:196-201, commented "No missing-route fallback may execute a legacy brain writer"). - The routed application tools take the legacy body only when
applyBrainis missing (if (!bridge?.applyBrain),packages/ui-backend-pi/src/tools.ts:872-874). - The only way to reach them is through the
sessionFactorytest seam. - The same holds for the local
write_file/edit_filebodies when they are reached as the application-tool fallback. Those bodies themselves stay: withdirectWritesthe routed list omitswrite/edit(tools.ts:858) and governed native writes run them (tools.ts:498,:535). Their atomic-write repair belongs to backends, modules: document writes outside core still truncate before writing #1434.
- The worker always installs a bridge with
Tests that exercise brain_add/brain_update/brain_archive through a fake session therefore check code that will never write a user's brain. Deleting the writers first removes that part of #1398's migration, which is why #1398 is blocked by this issue.
Scope
- Remove the legacy fallback from the routed application tools in
tools.ts. With noapplyBrain, they refuse with the existing "No authoritative server application route is available for this turn." error. - Delete
BrainAccess.add,updateandarchive, the localexecutepaths ofbrain_add/brain_update/brain_archivethat call them (tools.ts:601,:738,:818; the routed tool reads onlylegacy?.labelfrom them, which must survive), and any helpers and@schlessera/brain/internalimports left unused afterwards (for exampleingest,archiveDocument,updateDocument,relevanceOnArchiveif nothing else uses them). - Point the affected tests at a fake
applyBrainthat records the request, so they assert what pi sends to the server route.
Out of scope
- Brain read operations (
search,context,read,list,graph) and the internal imports that survive this deletion (backends: the pi backend still reads the brain through core's internal entry #1398). - The native
write_file/edit_filebodies used for governed direct writes, and their atomic-write repair (backends, modules: document writes outside core still truncate before writing #1434). - Removing the
sessionFactoryseam itself (the sibling issue in this epic). - Any change to the server application route or to tool schemas.
Acceptance criteria
-
grep -nE "async (add|update|archive)\(" packages/ui-backend-pi/src/brain-access.tsreturns nothing. -
grep -n "legacy.execute" packages/ui-backend-pi/src/tools.tsreturns nothing. - A test calls
brain_updatewith noapplyBrainon the bridge and asserts the refusal, with no file written under a temporary fictional brain. It fails on the tree before the change, where the legacy writer edits the file. - Tests for
brain_add,brain_updateandbrain_archiveassert the exactapplyBrainrequest (operation, path, expected base hash). - Governed native
write_file/edit_filewithdirectWritesstill write through their own bodies, shown by an existing or added test. - The pi package suite and root
tests/pi-worker-runtime.test.tspass.
Verification
bun run test packages/ui-backend-pi
bun run test tests/pi-worker-runtime.test.ts
bun run typecheckContract impact
None. Production behaviour is unchanged, because the removed paths are unreachable there. A patch changeset is needed only if the @schlessera/brain-backend-pi declaration surface changes.
Found by a repository review on 2026-10-22.
2026-10-24: made this issue the sole owner of deleting pi's unused application writers (removed from #1398 and #1434), kept the native direct-write bodies out of scope, and refreshed citations to a6b945b.
Activity
schlessera commentedon Oct 23, 2026
2026-10-24 restructuring: raised to p2. It now solely owns deleting pi's unused application writers, and #1398 (p2) is sequenced after it, so the blocker must carry at least that priority.