oficina / memoria Public

Clone
git clone https://amadan.net/oficina/memoria

Plain git — no account needed to clone.

Download

Download this file

1# Bounded delegated local note editing
2
3Status: specification and final implementation/evidence approved by independent
4GPT-6 Astra review on 2026-11-01. Local CI and race checks passed. Not deployed.
5Extends the existing agent-access branch without changing v1 search/create wire
6contracts. Existing authority, custody, guarded-response and roster requirements
7remain binding.
8
9## Operations
10
11`notes_get`, scope `notes:read`, takes `{team,id}` and returns
12`{id,title,body,revision,url}`. IDs and revision are positive integers; revision
13is the existing `Document.Revision`. It reads only locally authored paste notes
14(browser, native or agent), identified by `source='paste'`, empty sibling item
15coordinate and zero sibling revision. Other sources and missing/deleted rows
16return `not_found`, even when they are searchable. No imported upload, connector
17or sibling content becomes editable through this API. Notes remain team-shared;
18there is no invented creator-only permission rule.
19
20`notes_update`, scope `notes:write`, takes
21`{team,id,client_id,expected_revision,title,body}` and returns
22`{id,revision,indexed,url}`. Title/body replace the complete note, with create's
23512-byte title and 1-MiB body bounds and existing trimming/nonblank rules.
24`client_id` is a canonical nonzero UUID; `expected_revision` is a positive
25integer. Unknown fields are refused. No delete, source move, custody change,
26attachment edit, or partial text splice is introduced.
27
28## Transaction and retries
29
30Reserve SQLite's writer before reading the target, authority or receipt. Check
31the original delegated credential, Home person identity, current admission and
32captured roster lease inside that transaction, before and after all work.
33Validate the immutable receipt authority marker. Reuse the existing ingestion
34implementation for sealing, chunk replacement, provenance and derived indexing,
35with a private existing-document target bound to ID and external coordinate;
36never derive a new key from the edited title and never recreate a deleted target.
37
38An additive receipt table stores a keyed coordinate over authority, subject,
39client, team, operation and client UUID; a keyed fingerprint binds all supplied
40fields including target and precondition. Resource update and completed receipt
41(target, resulting revision) commit atomically. Same UUID with changed request
42is `conflict`. For an identical completed retry, first recheck current identity,
43write authority and exact live local-note coordinate, then return the original
44receipt revision without applying old content or requiring the old precondition
45to equal the latest revision. Later edits survive; deletion is `not_found`.
46New requests with a stale precondition return `conflict` and change nothing.
47An unresolved/malformed receipt fails closed instead of repairing by replay.
48
49For local paste notes, title changes must also advance Document.Revision; the
50existing body-only counter cannot protect full-note replacement from concurrent
51renames. Make this narrow domain correction for all paste ingestion writers;
52sibling/import revision semantics stay unchanged. Byte-identical normalized
53saves keep the existing revision. Body changes keep the ordinary chunk lifecycle.
54
55Indexing is postcommit derived work under WithoutCancel. A Store mutation lock
56serializes ingest/delete/rebuild through their derived-state completion, so an
57older refresh cannot overwrite a newer revision. A committed update
58reports indexed false on index failure; a retry must never reindex request text
59over a newer note. `indexed` describes completion of this receipt's indexing,
60not proof the current revision is indexed. A reader obtains current state through
61notes_get; the update's revision is explicitly the committed receipt revision.
62
63## Response and evidence
64
65Capture ID, source, external coordinate, sibling-coordinate absence and revision
66for reads. Before headers and each chunk, revalidate the current person/lease and
67exact note coordinate/revision; suppress a body selected from an older revision.
68Mutation receipts contain no title/body; response emission revalidates live local
69custody and identity, while allowing a later revision to coexist with the receipt.
70
71Tests must prove create/get/update and browser/search effects; browser/native
72paste support; imported and sibling refusal; title-only conflicts; simultaneous
73updates with one winning precondition; replay after later edit/deletion; changed
74payload conflicts; receipt/body/chunk rollback on injected failure; index failure
75and recovery; authority/revocation while waiting and at final commit; response
76identity/custody/revision loss including a multi-chunk body. Run app CI and race
77tests. Independent review selects adversarial mutations; record model and evidence.
78No merge, deployment, credentials or infrastructure changes are included.
79
80## Independent review and mutation evidence — 2026-11-01
81
82Independent GPT-6 Astra reviewed the spec and source. Source review required
83explicit signed-counter overflow refusal; Calendar additionally rechecks mutation
84write permission at emission, standing after database reads, and samples wall
85time before the remaining-lease calculation. Those corrections are implemented.
86Source approval and deployment status are separate from these test results.
87
88The independent reviewer selected these mutations; each was applied separately,
89failed its behavioral assertion, and was reverted before final checks:
90
91- `stale-revision`: `TestAgentNoteEditLifecycle` — detected.
92- `reapply-receipt`: `TestAgentNoteEditLifecycle` — detected.
93- `custody`: `TestAgentNoteEditCustodyAndConcurrency` — detected.
94- `final-authority`: `TestAgentNoteUpdateRetryFinalGuardWithoutResponse` — detected.
95- `rename-revision`: `TestAgentNoteEditLifecycle` — detected.
96- `old-index-publication`: `TestAgentNoteOlderRefreshCannotReplaceNewerIndex` — detected.
97
98The index ordering test holds an older refresh after it selects its document,
99allows a concurrent writer to compete, and verifies the newest title is the only
100one indexed. The socket-deadline test observes actual HTTP server deadlines
101under a near-expiry roster lease. No mutation result rests on a compiler failure.
102
103Concurrent identical updates serialize on the existing agent-note mutex through
104the final indexed acknowledgement. Lock order is agentNotes then Store.mutationMu;
105ordinary ingestion takes only the latter. A replay cannot observe a transient
106false acknowledgement while the original request is still completing indexing.
107The reviewer requested a controlled pause before the indexed receipt write; the
108replay waits, and both calls return the same immutable acknowledgement.
109
110Final evidence: `make ci` passes; `go test -race ./internal/memoria -run
111"Agent|Ingest|Delete|Rebuild" -count=1` passes, followed after the acknowledgement
112fix by the focused `AgentNoteConcurrentRetry|AgentNoteEdit|AgentNoteUpdate|
113AgentNoteOlderRefresh` race selection and another full CI pass. A seventh mutation
114omitting agentNotes serialization fails the controlled concurrent-replay test
115with the original transient indexed=false acknowledgement. Final independent
116review approved that correction.
117