Skip to content

[014] Mind facade: the in-process facade over a Mind (layer 1/2) - #55

Merged
btspoony merged 23 commits into
mainfrom
iteration-stack/014-minds-facade-and-serving/s01
Nov 26, 2026
Merged

btspoony merged 23 commits into
mainfrom
iteration-stack/014-minds-facade-and-serving/s01

Conversation

@btspoony

Copy link
Copy Markdown
Member

What this layer is

Iteration 014-minds-facade-and-serving, layer 1 of 2 (iteration-stack/014-minds-facade-and-serving/s01). Accountable plan: mind-facade (I-000132). Base: main at 3cb29a7.

What it changes

  • mindcore_runtime::Mind — a handle over one Mind: open resolves the registry row once, then capture, review, recall, knowledge_get/put/list, cognition_read and deliberate each re-check the live grant on their own transaction and compose the existing adapter entry points. No transaction, Principal, wire request or MemoryStage in the caller.
  • mindcore_runtime::journal_dir — the durable publisher the review fold uses: host-owned root, canonicalized confinement, atomic write-temp-sync-rename, fsync of the file and of every directory entry it creates.
  • deliberate takes no subject_id; an absent subject skips the snapshot recall and runs the space-level revalidation and unsettled-intent checks. A judgement's assessment_context.context_id carries the Mind id.
  • .agents/specs/architecture/facade.md (new), the facade section of mind-model.md, docs/quickstart.md's Mind path and a runnable example.

Evidence

  • cargo test -p mindcore-runtime --test mind 29/29, --test loopback 30/30 unchanged; cargo check --workspace --all-targets clean.
  • The example runs and prints the recalled record and the derived MindState.
  • Plan QC tri: Approve with residuals (qc1, qc2, qc3). PM Acceptance: pass.

Residuals (open, low)

  • I-000145 — a refused republish on the pending-receipt path answers the publisher's retryable code although staging is durable.
  • I-000146 — the settle continuation does not require receipt.state == Pending.

Not covered

Real power-loss durability of the journal publisher, and Windows directory-sync portability, were not exercised; both are documented in facade.md.

- mindcore_runtime::Mind: open is the one minds::get call, the registry refusal passes through
- carrier_entry_id; no grant cached, no status acted on
- tests: foreign Mind refuses NotFound, frozen Mind opens
…e roots at the current directory (mind-facade T2 third review)
- move the binding's require_knowledge_grants onto
  MemoryAdapter::require_space_grants; the binding calls it
- knowledge_get/knowledge_put/knowledge_list admit under it on their own
  transaction, then read or write through read_entry,
  read_entry_at_revision, write_entry and list_entries_in on the cached
  collection; revisions and refusals are the store's own
- read_entry_at_revision is the private read_entry_revision made public
- tests: write then read by revision, StoredRevisionStale on a stale
  base, no-write grant refused with the row untouched, no-read grant
  reads nothing
- Make DeliberateRequest's subject optional and branch the binding's snapshot and commit on it: no subject skips the memory page and takes the space-wide recall revalidation and the space-wide unsettled-intent withhold.
- Add MemoryAdapter::read_cognition, withhold_space_if_unsettled, revalidate_space, the space unreconciled refusal and MemoryRepository::has_unsettled_intent_in_space.
- Add MemoryWorkflowBinding::with_carrier_collection so a bound Mind resolves its carrier without a route map.
- Add Mind::cognition_read and Mind::deliberate with with_providers; deliberate stamps the Mind's id as assessment_context.context_id.
- Make the identity digests carry an absent subject as null, and refuse a record whose context is neither named nor derivable.
- Refresh the sqlx offline cache for the space-level intent query and cover the goal in the mind selector.
- Refuse a holder that does not name a binding's bound carrier at both the snapshot and the commit, before any carrier read or write, and cover it with a mismatch test plus the bound-carrier control.
- Validate a request naming neither a subject nor an assessment context at the start of `deliberate`, before the reasoner and the snapshot, so a `none` verdict can no longer let it succeed; cover the no-change case with a reasoner that must never run.
- Add the missing space-level settlement coverage: a facade verdict that settles with the Mind's id as its context and derives its state, and a commit-time refusal when an intent arrives after the snapshot.
…rt path

Task 5 of plan mind-facade: .agents/specs/architecture/facade.md states the
facade contract — the handle, the eight operations with what each composes,
the review fold, the subjectless deliberate — and its non-goals; mind-model.md
records the optional judgment subject and the Mind-id assessment context a
facade deliberate stamps. crates/mindcore-runtime/examples/mind_facade.rs is
the documented example: create a Mind, capture, review, recall, write and read
the carrier with one cognition record, read the derived MindState — with no
transaction, principal, wire request body or stage fold in it. docs/quickstart.md
leads its Mind path with the facade.
The create/open snippet unwraps each call through the example's own ok
helper — verbatim — and the capture snippet binds the Capture struct and
extracts the candidate id from the response value, so both compile as
written. Snippet compile-verified as a scratch example.
B1: a settled key's replay reaches the adapter's receipt probe regardless
of unsettled intents in the space — the facade reads candidate revision
and status as metadata instead of the content-read get_candidate whose
subject withhold says nothing about receipts; regression covers both the
same subject's and another subject's unsettled intent.

B2/A1/A2: cognition_read binds the collection the row resolved at open,
derives in the facade over read_entry, and reuses the one validated
record vector derive_mind_state owns instead of extracting it twice.

B3: the publisher refuses absolute paths and any path carrying '..' or a
root/prefix component before the first byte, with a confinement test.

B4: durability sync is anchored at the journal root — never ancestors
above it — and the write-only-root permission requirement is stated in
journal.rs and facade.md.

B5: publication runs on tokio's blocking pool; a deterministic parked-
publisher test proves executor progress continues and nothing commits
before the publication confirms.

A3: the futures dev-dependency is gone; the interference handshake polls
with a plain std::future::poll_fn. A4: the private durable_chain unit
tests are removed with the helper; public behavior tests cover the
publisher.

D1: facade.md and the plan record that the facade is convenience, not a
sandbox, and cite the real store boundary read_entry/write_entry/
list_entries_in rather than the adoption port. D2: facade.md states the
OUTCOME_UNCERTAIN recovery contract, with a pending-replay test. D3:
reflections-off is recorded in facade.md with its reason.
…nement, B4 root-entry durability, B5 cancellation ownership, F-007 fresh-review withhold

B2: the unused MemoryAdapter::read_cognition — the public read that admits
one space and reads an independently supplied collection — is removed
from mindcore-spoke; the facade's own bound implementation stands.

B3: confinement is filesystem resolution, not spelling: the root and
every target parent are canonicalized, and a parent resolving outside
the canonical root through a symlink below it is refused before anything
is created or written; regression plants a symlink escape and proves the
external destination is never written.

B4: the durability chain ends at the deepest pre-existing ancestor of
the target's parent, inclusive — the entry that names a freshly created
journal root is synced before Ok(()), so a settled record can never
outlive its projection tree.

B5: the staging transaction moves into the blocking publication task
and returns with the result, so dropping the review future can never
release the writer before the started publication ends; a same-key retry
queues behind the first attempt's rollback. The progress regression is
rebuilt honestly: one async worker, an asynchronously awaited entry
signal, the probe spawned after entry and before release, and a
pre-opened observer store.

F-007: fresh work — a pending or absent candidate — reads through the
adapter's get_candidate again, restoring the UNRECONCILED withhold for
fresh reviews while a consumed candidate's replay still reaches the
receipt probe; regression pins both.
…ement

F-002 (qc2): a same-key repeat that meets its own still-pending receipt no
longer stops at the probe's uncertain answer — it resolves the key to the
receipt, republishes the intent's targets and runs the settlement leg, so
the repeat actually settles. OUTCOME_UNCERTAIN remains the answer when
settlement itself fails. Regression: settle refused through the
interference handshake, intent restored to pending, the same-key review
settles it with exactly one record and one intent, and a further repeat
is the ordinary committed replay. facade.md's recovery contract now
describes this continuation.

F-005 (qc2): the stray repeated fragment of the host-provisioning entry
after the reflections paragraph is deleted.
…B5 regressions

B4: the publisher requires its root to exist — durable — before the first
publication and never creates it: the entry that names the root lives in
its parent and is the host's to persist. A missing root is refused with
the requirement named. The sync chain ends at the root itself, inclusive,
a pure function of the target's path, so a retry is never weaker than the
failed attempt. The example creates its journal root; the missing-root
tests now assert the refusal and a separate test covers a nested subtree
under an existing root; facade.md states the contract.

B3 (target symlink): a symlink — or any non-file entry — at the target
file itself is refused before the first byte, closing the last path the
write could follow outside the root; regression plants the target
symlink and proves nothing lands outside.

B5 evidence: the single-worker progress case waits for publisher entry
under a hard timeout that fails naming the missing progress instead of
parking forever; the cancel case now spawns the retry while the first
publication is still parked, yields it every chance to race, and asserts
the retry never enters its publication while the cancelled attempt's
flush is live — only after release does the retry settle the key.
…, handshake B5 evidence

F-003: the write itself can no longer follow a symlink at the target —
bytes land in a temp file in the target directory, are synced there, and
rename replaces the target entry atomically instead of writing through
whatever the entry points to. A symlink at the target is no longer
refused but replaced; regression publishes once, swaps the target for a
symlink to an outside victim, publishes again, and proves the outside
destination is never written while the target lands as a regular file.
The residual window — a hostile writer replacing a directory in the
parent chain during one publication — is documented in facade.md as a
trust-the-host-tree limit, because resolution-before-write is not a
filesystem lock.

F-008: the example syncs the journal root's parent after creating it,
the quickstart carries one sentence on the host's duty to create and
make durable the root before the first publish, and facade.md states the
parent-sync explicitly.

B5 evidence: both proofs are rebuilt on handshakes on the single-threaded
runtime, where one yield runs every ready task exactly once — scheduling
is control, not timing. The publisher signals entry and parks on a
blocking-channel rendezvous; the probe is spawned after the entry signal
and its completion is observed after one deterministic yield; the retry
is provably parked at its pool acquisition when the negative assertion
is read, and its instrumented publisher records whether the cancelled
attempt's flush had finished when the retry entered its own. Hard
watchdog threads are the only hang guard, each naming the signal that
never arrived. No sleeps, no yield counts, no async timeouts.
…mplete host durability

Watchdogs are disarmed on success: an atomic flag the watchdog thread
checks before firing, so a passing test leaves nothing armed.

The retry's instrumented publisher samples the first publication's finish
flag before writing anything — the ordering evidence reads the world as
it was before the retry's own bytes existed.

The single-yield scheduling assumption is gone: loops advance only on
observed state — JoinHandle::is_finished on the probe and on a sentinel
task spawned behind the retry — with yield_now as a politeness hint
inside the loop, never the ordering proof. A tick bound fails the test
naming what never happened if the runtime never polls the tasks.

F-003: the temporary file is created exclusively with create_new, which
fails on any existing entry, so a symlink pre-placed at the temporary
name is refused rather than followed; a leftover regular file — this
target's own crashed attempt — is removed and retried, anything else is
refused. Regression pre-places a symlink at the temp name and proves the
outside victim is never written.

F-008: the example now syncs the TempDir's own parent entry as well, the
same way it syncs the journal root's parent.
… has teeth

The witness replaces the retry as evidence: the pool has exactly one
connection, so a bare acquisition observes the invariant itself — the
connection is free while the first publication is parked only if the
cancelled attempt released its transaction early. The witness is provably
at its acquisition when the negative assertion reads it (the sentinel
behind it finishing is the observed state of its first poll), the
negative assertion is read while the first publication is still parked
with nothing between the read and the release, and the positive side is
asserted too: the witness must acquire after the publication ends, which
is when the correct implementation's rollback releases the connection.

Teeth proven: with the transaction moved back out of the blocking task
(the pre-fix shape), the test fails in 0.07s with 'the witness acquired
the connection while the cancelled attempt's publication was still
parked: the transaction was released before the publication ended'; the
implementation file was then restored byte for byte (cmp-verified) and
the suite re-run green.
…nippet runs

F-011: facade.md and journal.rs's module doc no longer say a symlink at
the target file is refused — since the write-temp-sync-rename change the
target entry is replaced atomically and the publish succeeds; refusal
applies to a symlink at the temporary name and to an escaping parent
chain, and both documents now say exactly that.

F-012: the quickstart snippet prepares the journal root the way the
publisher requires — create_dir_all plus a sync of its parent — so the
printed example runs against the host-owned-root contract.
…ility from existence

- The journal publisher's sync set is a function of the target path, not of what the filesystem contains.
- Bounds the contract at a host-owned durable root and normalises an empty parent to the current directory.
- Recorded from the facade plan's B4/F-006/F-008 rounds.
devin-ai-integration[bot]

This comment was marked as resolved.

@m-inspector

m-inspector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Verdict: ship it · Score 94% (mergeable)

Findings Count
🔴 must-fix 0
🟠 should-fix 0
🟡 may-fix 1
🔵 nit 0

📋 Review

What this PR does: This PR adds a mindcore_runtime::Mind facade that resolves a Mind's registry row once and exposes capture, review, recall, knowledge get/put/list, cognition_read and deliberate as single calls that each re-check the live grant on their own transaction, so callers never touch a transaction, Principal, wire request or MemoryStage. It also adds journal_dir, a durable atomic journal publisher with canonicalized confinement and file/directory fsync, and drops subject_id from deliberate so an absent subject skips snapshot recall and runs space-level revalidation. The accompanying docs and runnable example are updated alongside the facade section of the architecture spec.

Findings

🟡 New recall test's bound assertion cannot fail: no record exists, so max_items bounding is unverified

  • Evidence:

    [TEST-01] New recall test's bound assertion cannot fail: no record exists, so max_items bounding is unverified

    • Evidence: crates/mindcore-runtime/tests/mind.rs:322-333 — the added test captures two candidates via capture_candidate and then asserts records.len() <= 1 with the comment "One item bounds the page to exactly one record even though more exist". No candidate is ever promoted (handle.review(&..., &promote(), ...)), so the subject has zero memory_records and page["records"] is []; 0 <= 1 holds whatever the facade sends for max_items (10, 1, or a wrong value), so the assertion cannot fail.
    • Evidence: crates/mindcore-runtime/tests/mind.rs:242-282 — the sibling test that does produce a record interposes handle.review(&candidate_id, &promote(), ...) between capture_candidate and recall, confirming records come only from review/promotion while capture yields candidate_ids only (crates/mindcore-runtime/tests/mind.rs:184-196).
    • Evidence: crates/mindcore-runtime/src/mind.rs:266-282 — max_items is rendered into the wire budget unconditionally; the only meaningful check the second half performs is that the rendered max_items: 1 is accepted by the wire (the ok(...) call), not that the page is bounded.
    • Impact: The test advertises verification of the new non-optional max_items bound (the reason the field changed from Option<u64> to u64) while the assertion's premise ("more exist") is false; a regression that made the facade ignore max_items on the read path would ship green. Reader-facing false assurance, not a runtime defect.
    • Effort: XS — promote the captured candidates (or capture via review(promote)) before the bounded recall and assert records.len() == 1; otherwise delete the dead second half.
    • Risk: LOW — test-only change; the handle already carries journal_dir(dir.path()), so promoting in this test needs only a promote() decision and idempotency keys.
    • Confidence: …
  • Location: crates/mindcore-runtime/tests/mind.rs:329-333

  • Category: TEST

  • Merge class: may-fix

Revalidated findings

Reassessed 2/2 prior finding(s) this round · 0 invalid-output · 0 omitted · 0 over cap · 2 recheckable · context coverage: complete

finding disposition evidence thread
Facade recall always sends budget, but max_items is optional here and required on the wire addressed (verified-fix) current-code not yet resolved
capture commits before validating the adapter stage, then reports the post-commit anomaly as retryable addressed (verified-fix) current-code not yet resolved

Linked-issue AC

none — the PR links no GitHub issue (issues: []); the only referenced work item is the internal plan/accountable id I-000132 (mind-facade), which states no acceptance criteria to check.

✅ Verified

- The facade recall concern (always sending budget while max_items is optional on the facade and required on the wire) — revalidated as addressed (verified-fix) in the prior-finding table; the non-optional max_items field now carries the wire member.
- The capture concern (committing before validating the adapter stage, then reporting the post-commit anomaly as retryable) — revalidated as addressed (verified-fix).
- New recall test at crates/mindcore-runtime/tests/mind.rs:300-333 read directly: both halves drive capture_candidate only, so the subject holds no memory_records when the bounded page is taken.
- Sibling test crates/mindcore-runtime/tests/mind.rs:242-282 read directly: it interposes handle.review(&amp;..., &amp;promote(), ...) between capture and recall, confirming records are created solely by review/promotion and capture_candidate returns candidate ids.
- crates/mindcore-runtime/src/mind.rs:266-282 read directly: max_items is rendered into the wire budget unconditionally, so the second half's real effect is only that the rendered request is accepted (ok(...)), not that the page is bounded.
- ❓ cargo test -p mindcore-runtime --test mind 29/29, --test loopback 30/30 and cargo check --workspace --all-targets clean are asserted in the PR body only; the review document shows no command execution evidence for them.

🗑️ Considered & rejected

none

🛠️ Plan to fix

Expand fix plan
Only `may-fix` [TEST-01] remains (vacuous `max_items` bound assertion); the PR is mergeable without it.

1. **Promote before bounding** — in `crates/mindcore-runtime/tests/mind.rs` (test `a_recall_with_only_max_items_and_no_other_budget_fields_is_a_valid_wire_request`, ~line 322-333), review both captured candidates with `promote()` and distinct idempotency keys (e.g. `rev-min-budget`, `rev-min-budget-two`) instead of only capturing them, mirroring the promotion pattern in the sibling test at lines 248-252.
2. **Make the assertion falsifiable** — replace `records.len() <= 1` with `records.len() == 1` for `max_items: 1`, and assert the unbounded `recall_all()` page holds `>= 2` records from the same subject, so an ignored `max_items` on the read path fails the test.
3. **Keep the wire-contract half** — retain the `page["records"].is_array()` check and the comment about the non-optional `max_items`; the test then covers both the minimal-budget wire acceptance and real bounding.
4. **Alternative (if the bound is out of scope for this test)** — delete the dead second half (lines ~322-333) rather than leaving the unfalsifiable assertion, and leave bounding verification to a dedicated test.

Verification gates: `cargo test -p mindcore-runtime --test mind` (currently reported 29/29) must stay green; if the promotion is added, confirm the new assertions fail when `max_items` is temporarily ignored on the read path, then revert that probe.

Review 4 · commit 2380631 · since 6589b99

m-inspector[bot]

This comment was marked as resolved.

- cargo fmt --all output across the workspace (no behaviour change)
- facade.md: add the required ## Change obligations section
- specs README: link architecture/facade.md
- mind.rs: replace manual unwrap_or match on observed_revision
- tests/mind.rs: drop the unit-value rebind of the poll_fn result
…on order

- journal.rs: compute the durability sync chain from the target's resolved
  parent up to the canonical root — an in-root symlink no longer skips the
  real intermediate directories (PR #55 thread 4703486448)
- mind.rs: Recall::max_items is non-optional u64 — the wire budget requires
  the member, so every recall the facade sends is a valid wire request;
  regression test for the minimal budget shape (thread 4703518092)
- mind.rs: capture validates the adapter stage as Ready before the commit;
  a post-commit decode anomaly answers uncertain, not retryable
  (thread 4703518100)
- mind.rs + facade spec: state knowledge_list's 512-entry bounded contract
  instead of pagination (thread 4703486519)

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 4 · 2380631

Comment thread crates/mindcore-runtime/tests/mind.rs Resolved
@btspoony
btspoony merged commit 5f7ac3f into main Nov 26, 2026
12 checks passed
@btspoony
btspoony deleted the iteration-stack/014-minds-facade-and-serving/s01 branch November 26, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant