Jelajahi Sumber

docs: eviction does NOT touch _created_by - narrowing a claim I relayed an hour ago

The database owner retracted their own report, having checked the store instead
of inferring from the handler. Replacing rather than appending, since the claim
was wrong.

What is true: _created_by means "the creator" on every version, with ONE
exception - a row that was a ghost and got written before 2.20.2, where the
write took the insert path and re-created the row at version 1 with a fresh
createdAt and the writer as _created_by. From 2.20.2 that path is closed and
the field is reliable without the exception.

What was wrong: that the same happened to EVICTED rows since 2.12.1. The upsert
handler does set createdBy = actor when it believes the row is new, but the
store's upsert then reloads the evicted row, takes its update branch and
overwrites that with "doc.createdBy = it->second.createdBy; // Preserve
original creator". For an evicted row the bug reached only the isNew flag and a
spurious history diff on unchanged sensitive fields.

The handler looked like the layer that decided and was not, which is the same
shape as reading a flag instead of the bytes. Worth keeping because the wrong
version was far more alarming: "ordinary eviction corrupts provenance" against
"a pathological row somebody overwrote".

Two caveats recorded with the right level of confidence, because the owner
marked the second unverified: the 2.20.2 boot audit lists CURRENT ghosts, so a
ghost already clobbered is indistinguishable from a normal row by it; and its
history file MAY hold the earlier versions since the overwrite bypassed the
update path that saves history - unchecked, so a lead and not a fact.

The sequence is the part to carry. A consumer said out loud that they had made
this field load-bearing; the owner, prompted by that, reported a bug that would
have undermined it; checking their own code narrowed it to a case the consumer
cannot reach. Three messages, two corrections, and the field is better
understood than any single party could have made it - and the only reason the
collision surfaced early is that each side stated what it was relying on.
fszontagh 1 bulan lalu
induk
melakukan
4b9aef6411
1 mengubah file dengan 4 tambahan dan 4 penghapusan
  1. 4 4
      CLAUDE.md

+ 4 - 4
CLAUDE.md

@@ -169,10 +169,10 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
 - **Wall time has TWO ceilings** (`functions/wall_budget.hpp`): an HTTP one (~2 s, which `RunnerPool::readTimeoutSec` must exceed) and a JOB one, which is exempt because a queue-claimed run holds no socket. `RunService::run` takes the kind as a PARAMETER, never inferred from the descriptor, and defaults to Http - the narrow budget - so a caller that forgets is slow rather than dangerous. Precedence: `min(descriptor timeoutMs or default, project max or kind ceiling, hard ceiling)`, resolved by the pure `resolveWallBudget()`. **The project cap is per kind** (`{http, job}` on `PUT /projects/{p}/settings/functions`): one number could not express "10 s for routes, 60 s for jobs", so capping a project's routes also cut its cron work and the only safe setting was no cap. `FunctionView` carries BOTH and `RunService::run` selects, because `lookup()` does not know how a run was triggered. The engine's `JsLimits::wall_time_ms` is raised to the highest ceiling at construction, or the clamp inside `JsRuntime::run` would kill every job at the HTTP value.
 - **Job runs draw from their OWN pool lane.** A lease is held for a run's whole duration, every `ctx.fetch` included, so without a lane N slow jobs leave one runtime for every interactive route and the second overlapping HTTP run blocks until the read timeout fires - a 503 from a healthy runner. Worst-case memory is `(pool + job_pool) x memory_limit_bytes`, so the two lanes ADD.
 - **The database-event loop guard reads the event's actor** (client 2.12.0). Every write a function makes is stamped `fn:<project>/<id>:<depth>` via the `actor` parameter, and `Event::actor` carries it back - so provenance costs nothing and lives in the audit trail, NOT in a field inside user documents (which would travel into every export forever). A chain is refused past `events.max_depth` generations and logged at error.
-  **AND `_created_by` IS ADVISORY RATHER THAN AUTHORITATIVE BEFORE DATABASE 2.20.2: AN UPSERT AT AN EVICTED ID RE-STAMPED IT AS IF THE ROW WERE NEW, SINCE 2.12.1.** Told to us by the database owner 2026-10-22 while describing the ghost-document fix, as a second bug found alongside it: at an id absent from MemoryStore the upsert answered `isNew = true`, stamped `createdBy` as if new, and re-encrypted unchanged sensitive fields - and **eviction is an ordinary occurrence, not a pathology like a ghost**. So on any version from 2.12.1 to 2.20.1 the field's real meaning is **"the creator, OR the most recent upserter after an eviction"**, and a collection written by more than one actor across an eviction may carry historical mis-attribution on disk.
-  **This matters precisely because of the consumer dependency recorded below, and the two facts arrived from opposite directions within an hour.** A consumer had just told us they rely on that field to distinguish a chat-mediated write from a direct anonymous one; the database owner then told us the field could have been overwritten by a later writer. Neither party could have seen both halves. Relayed to both rather than left to collide later.
-  **We are immune and it is worth knowing why, because the reason is also why it survived four years of releases: nothing of ours ever READS `_created_by`.** It appears in `dbMetadataFields()` as a name to STRIP from write bodies and nowhere else. We upsert heavily across the whole control plane - `key_store` x4, `settings_store` x3, `function_registry` x3, the run log, the job queue, both registries - so we exercised the bug constantly and could not observe it. A defect in a field everyone writes and nobody reads is invisible by construction.
-  **`isNew` is also safe for us, re-verified rather than asserted when the change was announced:** exactly two call sites destructure the returned pair, `collection_registry.cpp:42` and `function_jobs.cpp:132`, and both discard the flag. That is the whole of our exposure to a semantic the database has now corrected in both directions.
+  **`_created_by` MEANS "THE CREATOR" ON EVERY VERSION, WITH ONE EXCEPTION: A ROW THAT WAS A GHOST AND GOT WRITTEN BEFORE DATABASE 2.20.2.** Before 2.20.2 an upsert or insert at a DISK-ONLY id took the insert path and re-created the row at version 1, with a fresh `createdAt` and the writer as `_created_by` - so that row's provenance now names whoever clobbered it, not its creator. From 2.20.2 the path is closed (upsert updates, insert refuses) and the field is reliable without the exception.
+  **Two caveats on recovering such a row, both from the database owner and the second one explicitly unverified:** the 2.20.2 boot audit lists CURRENT ghosts, so **a ghost already clobbered is no longer distinguishable from a normal row by it**; and its version history file *may* hold the earlier versions, because the overwrite did not go through the update path that saves history - they have not checked, and said not to rely on it. Treat the second as a lead, not a fact.
+  **THIS ENTRY PREVIOUSLY SAID THE SAME HAPPENED TO EVICTED ROWS SINCE 2.12.1, AND THAT WAS WRONG - EVICTION DOES NOT TOUCH `_created_by`.** The claim came to us from the database owner and they retracted it within the hour, having checked the store instead of inferring from the handler: the upsert handler *does* set `createdBy = actor` when it believes the row is new, and the store's upsert then reloads the evicted row, takes its update branch and overwrites that with `doc.createdBy = it->second.createdBy; // Preserve original creator`. For an evicted row the pre-2.20.2 bug reached only the `isNew` flag and a spurious history diff on unchanged sensitive fields. **The handler looked like the layer that decided and was not** - the same shape as reading a flag instead of the bytes, and worth keeping because the wrong version was far more alarming: "ordinary eviction corrupts provenance" against "a pathological row that someone overwrote".
+  **The sequence is the part to carry.** A consumer told us they had made this field load-bearing for a security check; the database owner, prompted by that, reported a bug that would have undermined it; checking their own code then narrowed the bug to a case the consumer cannot reach. Three messages, two corrections, and the field ended up better understood than any single party could have made it. **Neither of them could see both halves, and the only reason the collision surfaced early is that each said out loud what they were relying on.**
   **A CONSUMER NOW DEPENDS ON THAT STAMP AS A SECURITY ATTRIBUTION CHANNEL, WHICH IS NOT WHAT IT WAS BUILT FOR: `_created_by` MUST KEEP NAMING THE WRITING FUNCTION AND MUST NOT BE COLLAPSED TO THE PROJECT.** Flagged by novitax 2026-10-22, deliberately, as a dependency rather than left to be discovered by breaking it. Assessing whether the unauthenticated `/fn` exposure (SV-19) had been used, they could tell a chat-mediated write from a direct anonymous one ONLY because `_created_by` reads `fn:novitax/aliz-chat` rather than `fn:novitax`: a direct call to the request-taking function would read `fn:novitax/aliz-take-request` and be distinguishable. All 29 rows named the chat function, which is what established that nothing had exploited it. **Granularity we added for a loop guard turned out to be the only after-the-fact attribution available for an authentication gap**, so a refactor that kept the project and dropped the function id would look lossless and would silently remove it. Their discipline is worth copying too: they turned the finding into a one-command check and **proved its control fires** (an empty expected-writer set flags all 29 rows and exits 1), because "probably unused" written in a document decays into an assumption while a script does not.
 - **Delivery is at-least-once.** A claim that goes stale is reclaimed and the job runs again, so cron and db functions must be idempotent. `singleFlight` (default true for cron) skips a tick while the previous run is still going, which bounds stacking but is not exactly-once.
 - **`jobs.enabled` is OFF by default in the runner**, so a runner upgrade never starts draining a queue in a deployment whose server has no scheduler. On a host that wants cron it MUST be turned on, or the scheduler enqueues work nothing ever runs - the most confusing possible way for cron to look broken.