Skip to content

feat(index): record and report the latest index attempt - #1727

Open
liuchong wants to merge 7 commits into
DeusData:mainfrom
liuchong:feat/index-attempt-record
Open

liuchong wants to merge 7 commits into
DeusData:mainfrom
liuchong:feat/index-attempt-record

Conversation

@liuchong

@liuchong liuchong commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1726. A fork PR must target a branch in this repository, so the diff below also contains the commits under it. Head c6e31f3a. Once #1726 merges, this diff shrinks to the attempt-record work on this branch.

Related to #1347.

Problem

Everything the previous PRs add can fail an index attempt, and a failed attempt is currently a log line. A watcher-triggered rebuild that dies on a resource limit leaves the previously published graph in service and nothing durable behind it. index_status reports a healthy generation, and the operator has no durable record that the last rebuild failed.

That gap is what makes the limits usable or dangerous: a limit whose enforcement is invisible converts a loud failure into a quiet wrong answer.

What this changes

One attempt record per project under the cache directory, updated under a file lock across queued, running and terminal states, carrying the origin, timestamps, the effective profile source and the resource failure when there is one. index_status returns it as last_index_attempt, and delete_project removes a matching record when no database was published.

index_status does not add a freshness string. #1561 owns a freshness object, and a second string under the same name would clash with it. Generation snapshots stay inside last_index_attempt. A dirty tree is never treated as evidence of freshness or staleness. index_status does not probe Git just to emit the dropped field.

Daemon startup fails attempts whose worker no longer exists. Liveness is judged by process identity rather than the pid alone, so a recycled pid cannot keep a dead attempt alive; when a start time cannot be read the code falls back to plain liveness rather than declaring the worker gone.

Projects with no attempt record keep the previous response shape.

Testing

make -f Makefile.cbm test and make -f Makefile.cbm lint-ci on macOS. New coverage: record lifecycle and locked transitions, resource-failure metadata in index_status, the absence of a freshness string, generation snapshots kept inside the attempt record, abandoned-attempt recovery at daemon startup, and record removal on delete_project.

Stack

  1. feat(index): add opt-in discovery resource limits #1723 — discovery limits (merged)
  2. feat(index): add worker resource watchdogs #1724 — worker watchdogs (merged)
  3. feat(index): enforce opt-in storage resource limits #1725 — storage limits
  4. feat(index): add opt-in index resource profiles #1726 — resource profiles
  5. this PR — attempt record
  6. feat(mcp): warn on answers served from a failed rebuild #1728 — failed-attempt notice on graph answers

@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

@liuchong
liuchong force-pushed the feat/index-attempt-record branch 4 times, most recently from a50585d to da55fd1 Compare August 19, 2026 20:18
@liuchong
liuchong marked this pull request as ready for review August 20, 2026 03:38
@liuchong
liuchong requested a review from DeusData as a code owner August 20, 2026 03:38
@liuchong
liuchong force-pushed the feat/index-attempt-record branch 2 times, most recently from e5eb0b7 to 93ae432 Compare August 22, 2026 03:23
@liuchong liuchong closed this Aug 22, 2026
@liuchong liuchong reopened this Aug 22, 2026
@DeusData

DeusData commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Reviewed slice 5. The attempt record is the right idea and I want it. There is a collision to resolve first, and the decision does not go your way on one field — so let me be specific about which part and why.

The collision

#1561 also adds a top-level freshness to index_status, by a different contributor, and the two are not merely different — they are different types:

#1561 this PR
shape object string
values verdict ∈ current / stale / unknown, plus reason, reasons[], recommended_action fresh / stale / unknown
evidence indexed_checkout_sha recorded in a new column at the staged-generation boundary, vs live HEAD and bounded worktree status matching clean snapshots before and after indexing, worktree still clean at that HEAD

Whichever merged second would overwrite the other, and a client parsing freshness would get an object or a string depending on merge order. Neither of you could have seen this: the PRs are independent and git would merge them without a conflict.

Maintainer decision: #1561's object stands, and this PR drops its freshness field. The reason is output richness rather than correctness — a caller that learns why the graph is stale and what to do about it is better served than one that gets a single word, and #1561 already carries reason, reasons[] and recommended_action. It is also standalone and already reviewed clean, so it can land without waiting on a six-PR stack.

Keep last_index_attempt. That is the genuinely new contribution here and nothing else provides it. A durable per-project record under a file lock, carrying origin, timestamps, effective profile source and the resource failure, is precisely what turns "the limits fired" from a log line into something an operator can query. Your own framing is the argument for it:

a limit whose enforcement is invisible converts a loud failure into a quiet wrong answer

That is exactly right, and it is why the record matters more than the verdict word.

Two things from your design that should survive into the merged shape

"A dirty tree is never treated as evidence in either direction." Reporting stale for every dirty tree makes the field noise; reporting fresh is a lie. #1561 reaches the same conclusion by a different route, and your sentence states it better than anything currently in that PR. Worth carrying into the documentation.

Read-only Git probing — rev-parse plus status --porcelain --no-optional-locks — is the right way to look at a repository you are only reporting on. --no-optional-locks in particular is the detail most people miss.

The rest of the slice

Judging worker liveness by process identity rather than pid alone, so a recycled pid cannot keep a dead attempt alive, is the same instinct as #1724's handle-based watchdog and #1874's SYNCHRONIZE handle — and falling back to plain liveness when a start time cannot be read is the right direction for that failure. Failing abandoned attempts at daemon startup closes the loop.

Preserving the previous response shape for projects with no attempt record is the correct default.

Status

Please drop the freshness field and rebase once #1726 lands. Your reds are security / codeql-gate, test-windows-guards and ci-ok — the middle one is a lane-wide precondition failure we have now confirmed on four unrelated PRs, and is not yours.

Sorry to ask you to remove working code. The field genuinely can only exist once.

@DeusData DeusData added enhancement New feature or request ux/behavior Display bugs, docs, adoption UX priority/normal Standard review queue; useful PR with ordinary maintainer urgency. labels Sep 3, 2026
@liuchong
liuchong force-pushed the feat/index-attempt-record branch 4 times, most recently from 94119b3 to 579336c Compare September 9, 2026 08:08
@liuchong
liuchong force-pushed the feat/index-attempt-record branch 2 times, most recently from 9e753e1 to f7b50aa Compare October 21, 2026 03:05
@DeusData

Copy link
Copy Markdown
Owner

Thank you for separating the attempt record from the freshness verdict and keeping generation snapshots inside last_index_attempt. That addresses the earlier field-collision request. This remains behind the stack’s maintainer follow-up; sorry for the delay, and I’ll follow up soon.

An index that fits in memory and finishes in time can still fill the disk.
Publication needs room for the staging artifacts and the final database at
the same time, and running out of space during publication is the one
failure that can cost a working index.

Add index_cache_max_mb and index_min_free_disk_mb, measured before staging
and again before publication, together with internal ceilings on the final
database, the staging artifacts and the task temporary directory. Those three
have no public keys because they are only meaningful as part of one composed
decision. Crossing any of them fails the attempt before the old database is
touched, so atomic publication is unchanged and the previous index keeps
serving.

Staging cleanup is scoped by a private per-task token, so a worker removes
only the artifacts it created and never a concurrent run's. An old database
is treated as replaceable only after an integrity verdict distinguishes real
corruption from a transient busy error. A probe that cannot complete fails
closed. Both public keys default to off.

The shell fixture that stands in for the supervisor names them too, so the
worker still recognises the policy it is handed.

Signed-off-by: 刘冲 <[email protected]>
The extra indent is the only clang-format failure on the storage slice.

Signed-off-by: 刘冲 <[email protected]>
The storage start path takes the per-request clock. This probe is not about
duration, so the origin stays unset.

Signed-off-by: 刘冲 <[email protected]>
Six independent keys are an honest interface and a poor default. An operator
who only wants indexing to stay within reason has to learn all six, choose a
value for each, and keep them consistent as the machine changes.

Add index_resource_profile, accepting off, balanced or strict. Balanced
guards the host: it lets an index use what the machine can spare and stops a
runaway worker before the host is exhausted. Strict holds indexing to the
daemon's own budget, so a repository that needs more fails fast and
attributed instead of finishing at the host's expense. Any individual key,
including an explicit off, replaces that dimension of the selected profile,
so a profile is a baseline rather than a lock.

The balanced worker ceiling is derived from detected host memory instead of
being tabled. Large-repository indexing peaks in the tens of gigabytes, so
any round number low enough to feel safe would reject repositories that index
successfully today. When host memory cannot be read, balanced falls back to a
fixed floor.

Profiles also bound directory count, entry count, traversal depth and
discovery time. These have no individual keys for the same reason as the
storage internals: they are only meaningful inside a composed decision. The
resolved profile travels through the same trusted worker contract as the
individual limits, so every entry point enforces the same decision.

That contract now also carries the resolved profile and the override mask, so
the shell fixture standing in for the supervisor sends both.

The coverage that proves a forged policy cannot fork a second job asserts
that an explicit request joins the auto-index job already running for the
same root, and that assertion found the join broken on Windows. A project
root reaches the daemon through the platform canonicalizer, which answers in
backslash form there, while every tool handler normalizes the separators of
the path it canonicalizes. One directory therefore had two spellings, and
they met in comparisons that are exact: whether an index request may join the
running job, and whether a watch is still live for that root. Both were
wrong on Windows, in opposite directions, so aligning either one alone moved
the failure rather than removing it. The session context now stores the
normalized spelling, and the daemon canonicalizes project roots through a
single function that normalizes on the way out.

Only the storage side is directly assertable off Windows, since separators
are folded on every platform; the watch-liveness side is held by the existing
watcher-ownership tests, which is where the second half of this surfaced.

Signed-off-by: 刘冲 <[email protected]>
@liuchong
liuchong force-pushed the feat/index-attempt-record branch from f7b50aa to c6e31f3 Compare November 6, 2026 11:46
Strict is defined against the slice main budgets for one worker. An explicit
charged-memory limit above 80% of host memory is lowered, and that tightening
is logged.

Signed-off-by: 刘冲 <[email protected]>
A failed index is currently a log line. A watcher-triggered rebuild that dies
on a resource limit leaves the previously published graph in service and
nothing durable behind it, so index_status reports a healthy generation and
the operator has no way to learn that it is no longer the tree.

Record one attempt per project under the cache directory, updated under a
file lock across queued, running and terminal states, carrying the origin,
timestamps, the effective profile source and the resource failure when there
is one. index_status returns it as last_index_attempt, and delete_project
removes a matching record when no database was published.

Freshness is reported alongside it and is deliberately conservative. A
generation is comparable only when matching clean Git snapshots were observed
before and after indexing, and it is fresh only while the worktree is still
clean at that HEAD. A different clean HEAD is stale. Non-Git roots, dirty
trees, a tree that changed during indexing, a failed probe and a corrupt
record are all unknown, because a dirty tree is evidence of neither freshness
nor staleness.

Daemon startup fails attempts whose worker no longer exists. Liveness is
judged by process identity rather than the pid alone, so a recycled pid
cannot keep a dead attempt alive, and an unavailable start time falls back to
plain liveness rather than declaring the worker gone. Projects with no record
keep the previous response shape.

Signed-off-by: 刘冲 <[email protected]>
index_status keeps last_index_attempt. The freshness name belongs to the
checkout-evidence object, so this slice no longer publishes a competing string.

Signed-off-by: 刘冲 <[email protected]>
@liuchong
liuchong force-pushed the feat/index-attempt-record branch from c6e31f3 to 3b3adf2 Compare November 9, 2026 04:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request priority/normal Standard review queue; useful PR with ordinary maintainer urgency. ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants