Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions FORK_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,61 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Fixed


- **daemon-strict `mempalace mine` sent `mode: null` and every mine 422'd** (`HEAD` — pending resolution)
Upstream v3.8 made `--mode` default to `None` so an unset flag could
inherit a per-source default. `cmd_mine` normalizes it once at the top —
`mode = getattr(args, "mode", None) or "projects"` — under a comment
saying every branch below *and the daemon payload* read it.

⭐ **One branch did not.** The daemon-strict call passed `args.mode` raw,
128 lines after the normalization, while the sibling payload eight lines
earlier used the resolved value. So the daemon's `MineBody` rejected
every daemon-strict mine:

422 {"loc": ["body", "mode"],
"msg": "Input should be a valid string", "input": None}

That is why a grep cannot find this class of defect: the token
`args.mode` is identical at a correct site and a broken one, and only the
*distance from the normalization* differs. The audit was an AST walk over
every dict literal carrying a `"mode"` key and every call passing
`mode=`, which found four sites where the report named one.

Measured before the fix, daemon-strict with no `--mode`: **every input
shape that reached the POST sent null** — a directory with or without
`--wing`, with `--background`, with `--no-tunnels`, and a prose file. The
one shape that did not was a `.jsonl` transcript, and only because it
never reached the daemon: the mineable-path guard stops it locally at
exit 2, which is separate and intended.

Four sites, one class:

* the daemon-strict call now passes the resolved `mode`;
* `_forward_mine_to_hub` normalizes too — it posts to a `mempalace serve`
hub rather than the daemon, so it is a different consumer and a latent
case rather than the reported one;
* `_post_daemon_mine_cli` **refuses** `None` instead of substituting its
default. Substituting would trade a loud 422 for a silently wrong
corpus: a caller meaning "projects" would mine in "convos" and nothing
would say so;
* ⚠️ `pending drain`'s poster used `request.get("mode", "convos")`, and a
`.get` default does **not** fire on a present-but-null key. With the
seam now refusing `None`, a queued `"mode": null` would have raised
inside `pending_queue.replay`'s loop and taken every remaining request
with it. The seam's strictness created that hazard two files away,
which is why the fix audited the seam's CALLERS and not only the sites
that build its payload.

The tests assert on what goes **on the wire** — the producer is `cli.py`
and the consumer is the daemon's `search_models.MineBody`, in another
repository — because a unit test reading a local variable would have
passed throughout the outage. A structural test walks the AST and fails
if any payload reads `args.mode` raw again.

*Tests:* 12 (test_cli_mine_mode_payload.py: 5 input shapes against a real stub HTTP daemon recording the body, explicit-mode control, seam refusal x2, AST guard; test_pending_drain_null_mode.py: null/missing/explicit queued mode). 4 mutations, each killing its own tests: revert the call site (6), the hub payload (1), the seam guard (2), the drain fallback (1).
*Files:* `mempalace/cli.py`


- **check-docs examines every mention of a PR, not just the first, and matches state words as words** (`HEAD` — pending resolution)
`scripts/check-docs.sh` step 4 did `grep … | head -1` per document, so only
the FIRST line mentioning a PR number contributed to that document's claimed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ The full enumeration of fork-ahead changes. The canonical source is [`docs/fork-

| Description | Upstream PR | Fork commit |
|---|---|---|
| daemon-strict `mempalace mine` sent `mode: null` and every mine 422'd | — | `HEAD` — pending resolution |
| check-docs examines every mention of a PR, not just the first, and matches state words as words | — | `HEAD` — pending resolution |
| a daemon outage exits 2 (palace unavailable), not 1 (no results) | — | `HEAD` — pending resolution |
| check-docs must not match a PR number against a commit-sha prefix | — | `HEAD` — pending resolution |
Expand Down
61 changes: 61 additions & 0 deletions docs/fork-changes/2026-09-17-mine-mode-never-null.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
seq: 158
id: mine-mode-never-null
date: '2026-09-17'
bucket: Fixed
commit: HEAD
area: CLI
summary: 'daemon-strict `mempalace mine` sent `mode: null` and every mine 422''d'
body: |
Upstream v3.8 made `--mode` default to `None` so an unset flag could
inherit a per-source default. `cmd_mine` normalizes it once at the top —
`mode = getattr(args, "mode", None) or "projects"` — under a comment
saying every branch below *and the daemon payload* read it.

⭐ **One branch did not.** The daemon-strict call passed `args.mode` raw,
128 lines after the normalization, while the sibling payload eight lines
earlier used the resolved value. So the daemon's `MineBody` rejected
every daemon-strict mine:

422 {"loc": ["body", "mode"],
"msg": "Input should be a valid string", "input": None}

That is why a grep cannot find this class of defect: the token
`args.mode` is identical at a correct site and a broken one, and only the
*distance from the normalization* differs. The audit was an AST walk over
every dict literal carrying a `"mode"` key and every call passing
`mode=`, which found four sites where the report named one.

Measured before the fix, daemon-strict with no `--mode`: **every input
shape that reached the POST sent null** — a directory with or without
`--wing`, with `--background`, with `--no-tunnels`, and a prose file. The
one shape that did not was a `.jsonl` transcript, and only because it
never reached the daemon: the mineable-path guard stops it locally at
exit 2, which is separate and intended.

Four sites, one class:

* the daemon-strict call now passes the resolved `mode`;
* `_forward_mine_to_hub` normalizes too — it posts to a `mempalace serve`
hub rather than the daemon, so it is a different consumer and a latent
case rather than the reported one;
* `_post_daemon_mine_cli` **refuses** `None` instead of substituting its
default. Substituting would trade a loud 422 for a silently wrong
corpus: a caller meaning "projects" would mine in "convos" and nothing
would say so;
* ⚠️ `pending drain`'s poster used `request.get("mode", "convos")`, and a
`.get` default does **not** fire on a present-but-null key. With the
seam now refusing `None`, a queued `"mode": null` would have raised
inside `pending_queue.replay`'s loop and taken every remaining request
with it. The seam's strictness created that hazard two files away,
which is why the fix audited the seam's CALLERS and not only the sites
that build its payload.

The tests assert on what goes **on the wire** — the producer is `cli.py`
and the consumer is the daemon's `search_models.MineBody`, in another
repository — because a unit test reading a local variable would have
passed throughout the outage. A structural test walks the AST and fails
if any payload reads `args.mode` raw again.
fork_pr: 527
tests: '12 (test_cli_mine_mode_payload.py: 5 input shapes against a real stub HTTP daemon recording the body, explicit-mode control, seam refusal x2, AST guard; test_pending_drain_null_mode.py: null/missing/explicit queued mode). 4 mutations, each killing its own tests: revert the call site (6), the hub payload (1), the seam guard (2), the drain fallback (1).'
files:
- mempalace/cli.py
39 changes: 36 additions & 3 deletions mempalace/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,15 @@ def _post_daemon_mine_cli(
was asked for and its absence cannot creep back in. A daemon predating
the field ignores it and blocks as before.

⚠️ ``mode`` is annotated ``str`` and defaults to ``"convos"``, and
**neither is a guard against an explicit ``None``**: a default applies
only when the argument is OMITTED, and an annotation is not enforced at
runtime. A caller passing ``mode=None`` therefore put ``"mode": null``
on the wire and the daemon's ``MineBody`` answered 422 for every
daemon-strict mine (#525). That is why this function now raises rather
than quietly substituting the default — substituting would trade a loud
422 for a silently wrong corpus.

Note what "success" means with ``background=True``: the daemon has taken
the request into its durable pending-mines queue, not that the mine has
finished. That is the right contract for a replay — the queue's job is a
Expand All @@ -547,6 +556,17 @@ def _post_daemon_mine_cli(
import urllib.error
import urllib.request

if mode is None:
# Refuse rather than substitute the default. A caller that reaches
# here with None has skipped its own normalization (#525 was exactly
# that), and quietly mining in "convos" when the caller meant
# "projects" would trade a loud 422 for a silently wrong corpus —
# the worse half of the same trade.
raise ValueError(
"_post_daemon_mine_cli: mode must be a string, not None — "
'resolve it at the call site (`args.mode or "projects"`)'
)

headers = {"content-type": "application/json"}
api_key = os.environ.get("PALACE_API_KEY", "").strip()
if api_key:
Expand Down Expand Up @@ -1817,7 +1837,10 @@ def _forward_mine_to_hub(args, palace_path: str) -> bool:

arguments = {
"source": os.path.abspath(os.path.expanduser(args.dir)),
"mode": args.mode,
# Normalized, never the raw attribute: --mode defaults to None
# upstream, and a null here reaches the hub's own validator
# the same way it reached the daemon's in #525.
"mode": getattr(args, "mode", None) or "projects",
"agent": args.agent,
"limit": args.limit or 0,
"dry_run": bool(args.dry_run),
Expand Down Expand Up @@ -2214,7 +2237,12 @@ def cmd_mine(args):
ok = _post_daemon_mine_cli(
directory,
wing=wing,
mode=args.mode,
# `mode`, not `args.mode`: upstream v3.8 made --mode default to
# None and this function normalized it at the top for exactly
# this reason. Passing the raw attribute put `"mode": null` on
# the wire and the daemon's MineBody rejected every daemon-strict
# mine with 422 body.mode (#525).
mode=mode,
background=getattr(args, "background", False),
)
sys.exit(0 if ok else 1)
Expand Down Expand Up @@ -5216,7 +5244,12 @@ def post(request: dict) -> bool:
return _post_daemon_mine_cli(
request["dir"],
request["wing"],
request.get("mode", "convos"),
# `or`, not a .get default: a queued line may carry an explicit
# `"mode": null` (the hooks write whatever they were given), and
# `.get("mode", "convos")` returns None for that, not the
# default. Since #525 the poster REFUSES None, so the difference
# is a crashed drain versus a drained queue.
request.get("mode") or "convos",
background=True,
)

Expand Down
Loading
Loading