Skip to content

fix(platform): repair the agent document listing, read, and indexing - #3112

Merged
larryro merged 1 commit into
mainfrom
fix/agent-document-vertical
Aug 31, 2026
Merged

larryro merged 1 commit into
mainfrom
fix/agent-document-vertical

Conversation

@larryro

@larryro larryro commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

A user asking the chat assistant to list their documents got column f.path does not exist — and behind that first wall stood two more defects on the same vertical. All three are 0.5-port regressions; all three are fixed here, each with a guard that would have caught it.

1. Listing: a phantom column killed both doors

Both shim ports of the agent document listing selected coalesce(d.folder_path, f.path), but app.folders has no path column — folders are a name + parent_id tree — so Postgres rejected the whole statement and the chat document tool and sandbox document_find (binding and user doors) failed 100% since the cutover. The port had also silently dropped the fileName/extension filters the sandbox bridge passes, and forked the two doors' near-identical SQL.

The 0.4 semantics (folderPath = the row's own value, else the folder breadcrumb) now live in one Postgres-native helper, domains/documents/agent-list.ts: a root-down recursive CTE (depth-capped; a cycle can never enter a root-down walk) joined onto folder_id, with both filters restored — one helper behind two doors, which was the 0.4 contract.

2. Read: un-shimmed on the chat door, content-less on both

documents/internal_queries:findDocumentByFileId was registered only in the sandbox shim map, which spreads the chat map one-way — so the chat rag_fetch inline fallback died as [convex-shim] un-shimmed. A sweep of every internal.* name the chat tools call against the chat map found exactly this one gap. The handler moves to the chat map (sandbox inherits) and now also selects content, which both doors' inline-document lane checks but the old handler never fetched — hub-authored inline documents were silently unreadable through the sandbox door too.

3. Indexing: completed after one slice, corpus stuck processing

0.4 indexed in 64-chunk slices because a Convex action has a budget: indexDocument commits one slice, answers partial: true, and the caller reschedules until the last slice stamps the corpus completed. The 0.5 indexUploadedFile called it once, ignored partial, and stamped the app row completed — a 2.7 MB PDF read "Indexed" after ten seconds with 64 of 936 chunks stored and the corpus row stuck processing, where both corpus readers (keyword + dense filter on status = 'completed') and the corpus-text read could never see it. The watchdog cannot heal a wrongly-completed row (it only adopts queued/running/failed).

The 0.5 worker owns the whole job, so it now drains the slices in-process: every slice stays committed and resumable (the plan resumes after the stored prefix), a zero-progress slice fails loud instead of spinning, and the per-slice Embedding… N/total progress write doubles as the watchdog's liveness signal. IndexDocumentResult gains a cumulative chunksStored (unit-asserted), and skipped: 'unchanged' — the corpus already holds all of this exact content — maps to completed instead of failed, which is where a retry on an indexed document lands.

Why nothing caught any of it

The chat shim's only exercised document leg was knowledge-entries; neither listing door, the read row, nor a document wider than one slice had ever run against real Postgres.

Guards

  • The documents integration check gains an agent-listing leg: breadcrumb Contracts/2026 through both doors, fileName narrows to one, a bogus extension empties, and the read row is reachable through the chat map.
  • The RAG loop gains a multi-slice leg: a ~158KB upload must reach completed with corpus chunks stored == planned and > 64 — the mirror of the truncation this fixes.
  • The webdav check's rag === 'queued' assertion raced the worker's pickup (the property was always "the PUT entered the pipeline") and is widened to any live pipeline state.
  • convex/knowledge/indexing.test.ts asserts chunksStored across the slice, resume, and unchanged paths.

Verification

  • Integration check 263/263 against a fresh throwaway Postgres + MinIO.
  • Indexing unit tests 19/19.
  • Observed end-to-end on a dev stack: the stuck 64/936 PDF re-indexed to 936/936 through retry-rag (the resume path), after which the assistant listed the document with its folder path, searched it, and quoted § 90 BGB verbatim from page 43 with a source reference — the exact flow that produced the original error screenshot.

MIGRATION.md carries this as inc 146; the README's stale integration-check count is refreshed.

Three 0.5-port defects stacked on the chat/sandbox document vertical:

- The agent document listing selected folders.path, a column that does
  not exist (folders are a name+parent_id tree), so the chat "document"
  tool and sandbox document_find failed 100% since the cutover. Both
  shim doors now share one helper (documents/agent-list.ts) that
  derives the folder breadcrumb with a root-down recursive CTE
  (depth-capped) and restores the silently dropped fileName/extension
  filters the sandbox bridge passes.

- documents/internal_queries:findDocumentByFileId was registered only
  on the sandbox shim map, which spreads the chat map one-way, so the
  chat rag_fetch inline fallback died as "[convex-shim] un-shimmed".
  The handler moves to the chat map (sandbox inherits) and now also
  selects content, which both doors' inline-document lane reads but
  the old handler never fetched.

- The RAG ingest called indexDocument once and ignored `partial`: 0.4
  committed one 64-chunk slice per scheduled invocation (the Convex
  action budget) and rescheduled until done, so the 0.5 port stamped
  rag_status=completed after slice one and left the corpus row
  'processing' — a 936-chunk PDF read "Indexed" with 64 chunks stored,
  invisible to search and fetch (corpus readers filter on completed).
  The worker now drains every slice in-process (each slice committed
  and resumable, per-slice "Embedding… N/total" progress doubling as
  the watchdog's liveness signal, a zero-progress slice fails loud),
  and skipped:'unchanged' maps to completed instead of failed — a
  retry on an indexed document lands there. IndexDocumentResult gains
  a cumulative chunksStored, unit-asserted.

Guards: the documents integration check gains an agent-listing leg
(breadcrumb through both doors, fileName narrows, bogus extension
empties, the read row reachable through the chat map) and the RAG loop
gains a multi-slice leg (a ~158KB upload must reach completed with all
chunks stored, > 64). The webdav check's rag === 'queued' assertion
raced the worker's pickup and is widened to any live pipeline state.
Integration 263/263.
@larryro
larryro merged commit c7f46ac into main Aug 31, 2026
48 checks passed
@larryro
larryro deleted the fix/agent-document-vertical branch August 31, 2026 01:18
Israeltheminer added a commit that referenced this pull request Sep 3, 2026
Three legs the port left returning nothing, each under a comment saying no
0.5 table existed. All three tables existed.

kind="website" answered []. Migration 0045 created app.websites with every
column 0.4's reader projected, and listWebsites already existed.

kind="mail-attachment" answered {attachments: [], truncated: false}, while
migration 0037 shipped conversation_id and mail_received_at_ms and the email
binder writes both. truncated:false means "the walk reached the end of the
mail index", so the stub was also making a false claim. The new reader gates
every row on conversationAssignmentAllows against the conversation's current
assignment, resolving the caller's role and team ids rather than taking them
as arguments — a listing that skipped that would serve the whole inbox.

Migration 0064 adds the arrival index. The only existing index leads with
conversation_id, so it orders by conversation, which is the shape #3035
recorded as rejected: a by-arrival page reads most of its budget to return
one row, and above the budget reports "most recent" from an arbitrary window.

The task and project legs also lost their zero-hit listing fallback, leaving
listedSource unreachable. Restored in both.

Adds the reachability gate the chat map never had: every internal ref
reachable from the turn now needs a handler, using the walker the sandbox
bridge already had rather than a second copy. That absence is how #3112's
and #3128's missing handlers shipped.
Israeltheminer added a commit that referenced this pull request Sep 3, 2026
Three legs the port left returning nothing, each under a comment saying no
0.5 table existed. All three tables existed.

kind="website" answered []. Migration 0045 created app.websites with every
column 0.4's reader projected, and listWebsites already existed.

kind="mail-attachment" answered {attachments: [], truncated: false}, while
migration 0037 shipped conversation_id and mail_received_at_ms and the email
binder writes both. truncated:false means "the walk reached the end of the
mail index", so the stub was also making a false claim. The new reader gates
every row on conversationAssignmentAllows against the conversation's current
assignment, resolving the caller's role and team ids rather than taking them
as arguments — a listing that skipped that would serve the whole inbox.

Migration 0070 adds the arrival index. The only existing index leads with
conversation_id, so it orders by conversation, which is the shape #3035
recorded as rejected: a by-arrival page reads most of its budget to return
one row, and above the budget reports "most recent" from an arbitrary window.

The task and project legs also lost their zero-hit listing fallback, leaving
listedSource unreachable. Restored in both.

Adds the reachability gate the chat map never had: every internal ref
reachable from the turn now needs a handler, using the walker the sandbox
bridge already had rather than a second copy. That absence is how #3112's
and #3128's missing handlers shipped.
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