Skip to content

feat(assistant): share append-only context between discovery and judgement - #6244

Merged
xxhZs merged 10 commits into
apache:mainfrom
xxhZs:test/discovery-split-20261020
Oct 24, 2026
Merged

xxhZs merged 10 commits into
apache:mainfrom
xxhZs:test/discovery-split-20261020

Conversation

@xxhZs

@xxhZs xxhZs commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Give proactive discovery and judgement separate persistent Sessions backed by one append-only notebook. Both read the notebook from a file; discovery adds observations across life and work, and judgement investigates directions from the whole notebook before handing useful messages to the assistant Bot. Preserve occurrence times, sources and user-defined feedback scope without imposing a candidate count or recommendation-quality approval.

Link feedback to actual delivered discovery messages. Bot SendUser records discovery Inbox IDs and successful publication receipts; DiscoveryFeedback associates a real user reply with a delivered message. Ordinary conversation is no longer automatically imported as feedback or notebook history. Legacy unlinked records remain stored but do not affect current feedback state.

Keep failed submissions recoverable. Invalid drafts return their error and retained output file to the same worker for repair, explicitly stating that the transaction was rolled back and its messages were not queued. Persist the operation across interruptions and restarts. Once committed, retry Bot handoff with the same IDs without another model generation or duplicate notebook writes. Provider and I/O errors remain visible execution failures; there is no three-rejection pause limit. Bot acceptance and actual delivery remain distinct.

Replace archived workers when necessary. Keep task overview/status responses compact with an AI-written progress summary of at most 30 characters, avoiding detailed task payloads in the floating status list. Preserve existing histories, index coverage and the configured discovery cadence.

Validation

  • Full workspace build passed; runtime-host typecheck passed.
  • 255 assistant regression tests passed: 83 memory, 51 initiative/notebook, 84 continuous-task and 37 Bot tests.
  • 6 desktop task-float tests passed; changed-file formatting and git diff --check passed.
  • Recovery coverage includes atomic rollback, immediate same-worker repair, provider interruption during repair, restart/reconfiguration, malformed JSON, missing output, stable-ID handoff retries, and native Bot SendUser delivery exactly once.
  • Replayed the actual failed draft from the live experiment through the native pipeline with controlled model responses: correcting the invalid feedback association preserved the original reminder and delivered it once. This is a controlled regression, not a new live-model quality result.
  • Prior isolated five-round GPT-6.1 Sol / medium experiment produced 30 notes and three actual messages, with no automatic conversation/feedback imports. It exposed the submission failure fixed here. The five-round live experiment has not been repeated after this repair; recommendation quality and index-body usage remain limitations.

No private histories, databases, notebook contents, or experiment scripts are committed. No test records are imported into the user's profile.

Review follow-up

  • Updated the settlement-context fixture to include the required progress summary; all 11 tests now reach the intended settlement behavior.
  • Fixed the feedback regression wait to inspect status.state.active and status.state.lastError, and delayed the second discovery draft to exercise the race.
  • Runtime-host build and typecheck passed. The combined settlement-context, Bot and desktop task-float run passed all 54 tests. These follow-ups change tests and attribution only; product behavior is unchanged.

Generative tooling disclosure

OpenAI Codex substantively contributed to the assistant implementation, regression tests, debugging, and PR documentation in this contribution. Each of the three implementation commits and the review-fix commit includes Generated-by: OpenAI Codex; retain that attribution in the final squash commit. The human contributor remains responsible for reviewing and submitting the contribution.

@github-actions github-actions Bot added the effort/M Under 500 readable lines label Oct 22, 2026
@xxhZs xxhZs changed the title feat(assistant): split proactive discovery and judgement into persistent sessions feat(assistant): share append-only context between discovery and judgement Oct 22, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 3a98a0b against main 59f61cf, including all 15 changed files. This replaces direct discovery reports with separate persistent discovery/judgement Sessions, a new append-only SQLite notebook, per-wake file output, feedback provenance checks and a durable Bot handoff.

One P2: recovering a failed Bot handoff can enqueue the same recommendation twice. The inline finding describes the recovery path. With the actual controller, notebook, bridge and BotStore, one simulated mailbox failure followed by one retry produces two distinct inbox entries for the same recommendation. The same result survives reopening the stores. Replaying the already committed handoff before rerunning judgement produces one entry in both controls. This establishes duplicate Bot input, not a measured duplicate user-visible notification.

A fresh dependency install/patch pass, normal full test build, runtime-host typecheck, all 207 assistant feature tests and 56 Bot/initiative/access-boundary tests passed. ASF headers, formatting and whitespace checks passed. The new notebook's rollback, feedback validation and reopen cases are included. The static merge with current main is clean. There is no wire-protocol change; the actual epoch guard passes with 227 unchanged.

P3: add the required explicit generative-tool contribution declaration to the PR description; if a tool contributed substantively, retain its Generated-by trailer in the final commit.

The exact-head CI test failed in the unchanged ShellRun process-crash recovery fixture: JSON.parse read an incomplete ready.json marker. That fixture is byte-identical to current main and writes the marker with non-atomic writeFile; its narrow case passes locally on this head. This is consistent with the existing marker write/read race, rather than a demonstrated regression from this change; I do not describe CI as green. I did not run paid/live models, deploy or restart a production profile, assess recommendation quality, or independently verify the prompt text against the external “approved experiment” mentioned in the description. Controlled fixtures exercise production TypeScript and SQLite but do not establish those product-quality claims.

const status = (await agent.snapshot())?.agent?.status;
if (['aborted', 'blocked', 'waiting_for_user'].includes(status))
throw Error(`Heartbeat ended with ${status}; inspect before resuming`);
await this.execute(agent, state);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Replay a committed Bot handoff before rerunning judgement

If forwardPrepared() throws after commitDraft() has persisted a recommendation (for example, a temporarily unavailable Bot or failed mailbox write), finish(id, error) retains pendingJudgement but clears the active wake. The next claim gets a new wake ID and reaches this execute() again, rather than replaying the committed handoff first. The notebook view does not include unreported prepared messages. When judgement returns the same recommendation on that retry, it is saved under a second ID, and forwardPrepared() posts both entries; BotStore deduplicates by ID, so it accepts both.

I reproduced two inbox rows after one mailbox failure and one retry using the actual controller/notebook/bridge/BotStore, both with and without reopening the stores. A control that forwards the existing prepared message before generating another draft leaves one row. Keep a durable handoff/replay phase (with the existing message identity), or explicitly reconcile/supersede pending recommendations before asking judgement to generate replacements.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 198dfe4, including its complete two-file increment from 3a98a0b. It removes the unused experimental importer and changes its tests to use normal note appends. The controller, scheduler and prompt code are unchanged.

The previously reported Bot handoff P2 remains. On this head, one mailbox failure followed by a judgement retry still creates two distinct inbox entries for the same recommendation, both with and without reopening the stores. Replaying the committed handoff before generating another draft yields one entry. See the original finding. I found no additional P0–P2 issue in this cleanup increment.

The normal clean full test build, all 207 assistant feature tests, runtime-host typecheck, scoped formatting, whitespace and the actual protocol guard passed; epoch 227 is unchanged. Dependency manifests/lockfile match the freshly installed baseline. The static merge with current main is clean.

Exact-head CI again fails in the unchanged ShellRun crash-recovery fixture while parsing an incomplete ready.json marker. The fixture is byte-identical to current main, and its narrow case passes locally on this head. This is not a demonstrated new regression from removing the importer; CI is still not green. The AI-contribution declaration remains a P3 omission.

I read the added live-check/deployment notes in the description but did not independently reproduce those model-quality experiments, inspect the deployed profile or restart any production service. This increment does not establish the general recommendation-quality claim.

@github-actions github-actions Bot added effort/XL Under 2500 readable lines and removed effort/M Under 500 readable lines labels Oct 23, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed the 33-file increment from 198dfe4c7e631312473d5c30ffc4a943ad56f866 to 8201fde335d7861b466c419cab9f6d83bd5a5c9d (+1101/−139). The previous duplicate-Inbox P2 is fixed. I found no new confirmed runtime P0–P2 issues; a new test synchronization problem is noted inline as P3.

The controller persists a draft-operation identity before model execution and reuses the committed notebook operation/message IDs when Bot handoff fails. In both normal retry and restart recovery, the actual controller, notebook and Bot store now produce one judgement and one Inbox item; replacing only the controller with the previous module produces two of each. Invalid drafts remain available for same-worker repair. Delivered discovery IDs and explicitly linked owner replies now drive notebook feedback; ordinary conversation is excluded. The added Bot tables are created idempotently, and task progress previews remain optional in existing stored records while new tool submissions validate their length.

Fresh dependencies/patches, normal root npm run build:test, renderer build, 218 assistant tests, changed-file Biome/ASF checks, notices from the renderer build, static merge and the epoch guard passed (227; no wire-protocol change). The unmodified Bot/task-float test run passed 42 of 43 tests; the remaining test reads status fields from the wrong response level. Changing only its wait to use status.state makes all 43 pass, including linked-feedback persistence and resolution. A delayed second discovery draft reproduces the original premature assertion and passes with that wait corrected. This is a test defect, not evidence that production feedback is lost.

CI failed in the unchanged code-mode execution-budget test. Its test, implementation, npm dependency files and workflow match the base; the focused test passes locally. I have not established a PR-caused regression or a matching failure on main. I reran the failed job once; the new CI result is pending. I did not repeat the paid-model discovery experiment or validate recommendation quality, native desktop layout or real user delivery.

P3: Please add the AI-usage declaration required by CONTRIBUTING.md, with tool/scope and applicable Generated-by: attribution. Missing attribution alone does not establish AI involvement.

await until(async () => {
const status: any = await f.service.call('assistant.status', {});
if (status.lastError) throw Error(status.lastError);
return round === 2 && !status.active;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

P3 — Wait for the nested initiative state before inspecting notebook results. assistant.status returns { state, bot, ... }, so status.active and status.lastError here are always absent. Once the second discovery runner increments round, this wait can finish before the judgement phase commits its feedback resolution, producing 0 !== 1 at the final assertion. I reproduced this with the original test and a delayed second draft; reading status.state.active / status.state.lastError fixes the same sequence without changing product code.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

CI follow-up for unchanged head 8201fde335d7861b466c419cab9f6d83bd5a5c9d: one new P2. CI run 39909989174, attempt 2 fails eight settlement-context tests because this PR makes MatterSettle.progressSummary required but leaves their fixture submissions unchanged. This is a PR-caused test failure, separate from the earlier execution-budget failure.

I fetched the head again, installed fresh dependencies and patches, and completed the normal root npm run build:test. Running node --test packages/runtime-host/dist/__tests__/matter-settlement-context.test.js reproduces the same eight failures (3 pass, 8 fail), all at schema parsing before settlement. Supplying only a valid progress summary in that test fixture makes all 11 pass with product code unchanged. Please migrate the fixture to the new tool contract and rerun CI. The inline comment identifies the required-field change.

The previous duplicate-Inbox P2 remains fixed; this follow-up does not reverse that result. The earlier Bot-test synchronization observation remains P3, and that test passed in CI attempt 2. No additional production or paid-model validation was performed in this follow-up. Protocol remains at epoch 227 with no wire change. This head is not ready while its test job fails.

.describe(
'Optional working note to retain for future activations. Omit to keep the previous note; no draft file is needed.',
),
progressSummary,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

P2 — Update the existing settlement-context test fixture with this required field. packages/runtime-host/src/__tests__/matter-settlement-context.test.ts still parses submissions without progressSummary, so eight tests now throw ZodError before reaching the settlement behavior. This reproduces locally after a clean build and in CI run 39909989174 attempt 2. Adding a valid progress summary only to the fixture changes the focused result from 3/11 to 11/11 without altering production code.

@xxhZs
xxhZs force-pushed the test/discovery-split-20261020 branch from 8201fde to cde0ef5 Compare October 23, 2026 09:18

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

I reviewed cde0ef50ca370c363a246a149d960e4f52905ff7, including the complete two-file follow-up (+8/-3) since 8201fde3. The previous CI P2 and Bot-test synchronization P3 are fixed. This follow-up changes tests only; production behavior is unchanged, and I found no new confirmed P0–P2 issue.

The settlement fixture now supplies the required progressSummary before parsing; all 11 settlement tests reach their intended assertions. The linked-feedback test now checks status.state.active and status.state.lastError and deliberately leaves the second draft in flight. After fresh dependencies, patches and the normal root npm run build:test, all 54 settlement, Bot and task-float tests passed. Reverting only the summary fixture in the loaded test reproduces the eight schema failures (3 pass, 8 fail). Keeping the new delay but reverting only the status nesting makes the linked-feedback regression fail with the uncommitted resolution count still zero. Product code stayed unchanged in both checks. Changed-file Biome, the protocol guard and git diff --check passed.

Exact-head CI run 39930909951 succeeded. The old duplicate-Inbox finding remains fixed, and the obsolete CI/test-wait findings should no longer block this head. A fresh static merge with main ac1d288c4017d1a37975c54859735195ea22cae1 still conflicts in packages/runtime-host/src/__tests__/assistant-initiative-boundary.test.ts; please reconcile that test with the discovery-tool restriction now on main and rerun the resulting head. I have not tested that unresolved merge result, repeated the live-model experiment, or assessed recommendation quality in this follow-up.

@github-actions github-actions Bot added effort/XXL Over 2500 readable lines and removed effort/XL Under 2500 readable lines labels Oct 24, 2026

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

xxhZs added 2 commits October 24, 2026 14:56
…lict

Keep the notebook-based mailbox regression and main's tool-filter fixture update.

Generated-by: OpenAI Codex
…porting

Keep all conversation mutation exclusions and read-tool assertions. Assert the removed legacy reporting tool stays absent.

Generated-by: OpenAI Codex
ggbdpq added a commit to ggbdpq/maka that referenced this pull request Nov 24, 2026
…t session

apache#6244 split the assistant heartbeat into discovery and judgement persistent
background sessions, but the initiative tool filter still matched only the
discovery session — the judgement session kept the full assistant catalog,
including the exact tool groups the apache#6256 boundary removed from discovery
(Matter mutations, memory-index mutations, Bot-only and initiative
configuration tools), constrained by nothing but prompt text. apache#6256's
execution-time rejections are scoped to the discovery session, so they do not
fire there either.

Match both background sessions in the filter. A discovery-boundary-style
catalog test locks the judgement session to the same exclusion set.

Fixes apache#6412

Generated-by: GLM-5.3-Flash (ZCode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants