Skip to content

fix: /clear keeps comments and health, plugin dbt runs keep the project's manifest, and five demo bugs - #42

Merged
hkaltai merged 15 commits into
mainfrom
fix/plugin-demo-bugs
Nov 20, 2026
Merged

hkaltai merged 15 commits into
mainfrom
fix/plugin-demo-bugs

Conversation

@hkaltai

@hkaltai hkaltai commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes for bugs found while recording a demo of the plugin against a DuckDB dbt project. Each one was reproduced on main first, and each fix has a regression test that fails on main.

What changed

  1. /clear lost team comments and project health. A /clear starts a new conversation under a new session id. Its $.state starts empty and no session.start follows, so the comments band disappeared, Claude reading a commented model got no threads until /comments or the 15-minute poll, and /health said "this session has none open yet". The plugin now watches for the new session id after session.end (reason: 'clear') and then:

    • reloads the comments (with the first-read wait, as at a session start);
    • restores health's baseline, unchecked changes and issues (a check the /clear cut short runs again);
    • restores the status line parts.

    The settings hooks' classic.SessionStart (source: clear) is not used, because another plugin in the chain can skip it.

  2. Plugin dbt runs replaced the project's manifest. Compile and validate (dbt show/dbt ls), /dbt-show, Re-run and the health check's parse now write to target/.altimate-plugin/ (DBT_TARGET_PATH). The project's target/manifest.json keeps every model's compiled SQL, so the lineage pane stops saying "No compiled SQL found".

    • The check reads the manifest its own dbt show wrote.
    • The health check passes DBT_TARGET_PATH plus ALTIMATE_TOOL_DAEMON=0 (a running tool daemon keeps the environment it started with), and copies catalog.json beside that manifest.
    • The doctor's Run dbt parse still writes the project's own manifest, because refreshing it is the point of that button.
    • Not covered here: a long-lived altimate-code tool daemon started by something else still parses into target/. That is an altimate-code fix.
  3. Docs coverage was stale after an SQL edit. When the project's manifest is older than the edited file, the coverage line says it is "as of the last dbt compile, before this edit". Once the edit's compile-and-validate check has run the model, /propagate reads the coverage again from that check's manifest. A renamed column now shows as undocumented.

  4. End-of-task summary for a new model. impact_analysis answers success: false for a model that the pre-task manifest lacks. That case is now read as "not in the manifest from before the task (new in it?): its reach is unknown, not zero" instead of "update altimate-code".

  5. Narrow (inline) Query results / lineage pane. Claude Code gives an inline pane the same height whatever rows it asks for. Measured at 100×42 and 100×70, Default and Max came out identical, and Min was only smaller on a tall terminal. Inline, the no-op Min / Default / Max row is replaced by a line saying so. Docked panes are unchanged.

  6. /defer and /target flags were invisible. When the plugin rewrites Claude's dbt command, Claude's result now says what the command ran as (for example dbt build --defer --state prod --favor-state). A band line shows the same thing until the next prompt. What runs is unchanged.

  7. Team comments list lag. Resolve on a thread that the lagging list still shows, but that is already resolved, now counts as done: the thread is hidden and the list is read again, instead of answering "Thread N is not an open thread". A reply to such a thread says the thread is no longer open and reads the list again.

There is no version bump. Open PRs #40 and #41 bump the version, and leaving it alone here avoids more conflicts. The changes are under ## [Unreleased] in the CHANGELOG. Against those branches, git merge-tree shows only a CHANGELOG conflict (both add a section at the top).

Tests

  • claude plugin test plugins/altimate-code: 1259 pass and 0 fail at the approved head, after main was merged in. The known timing flake "a dbt call that starts while another call reads its artifact" in runs.test.tsx sometimes fails. It does on main too, and passes when runs.test.tsx runs alone.
  • claude plugin validate --strict .: passes.
  • bash tests/*.sh: all 8 pass.
  • New tests, all of which fail when run against main's code:
    • /clear for comments and health: pane, Read context, band, /health, status line, and a check cut short. Tests play the engine's /clear (new session id, empty state) with hooks/clear-state.testkit.ts.
    • Scratch target path for checks, /dbt-show and the health check.
    • Docs coverage refreshed from the check's manifest.
    • New-model summary wording.
    • Inline size row.
    • Defer flags in the context line and the band.
    • Resolve and reply on a thread that is no longer open.

Review hardening

The review rounds also made these changes:

  • A check reads the manifest its dbt show wrote while the plugin's dbt queue is still held. The health check uses target/.altimate-plugin/health and runs one CLI call at a time, even across /clear.
  • Re-run drops a --target-path that Claude named.
  • An edit's coverage is answered only by its own check, and the first coverage read lands in edit order.
  • The /clear restore is idempotent. A push gate, /health or turn end arriving first joins it, within the gate's wait. A second /clear keeps the snapshot.
  • Only the integrations and altimate-code parts of the status line are kept across /clear.
  • Notices of the flags /defer and /target added are keyed by tool call, and are given only when the rewritten command is the one that ran.

Checked live

Each case was run in Claude Code 2.1.328 with --plugin-dir, against a copy of the demo DuckDB project:

  • After /clear, the band shows "💬 2 open team comments", Claude reading customer_revenue.sql reports both threads, and /health answers "No new health issues…".
  • Nodes with compiled SQL in target/manifest.json stay at 19 through session start (health baseline) and through compile and validate. On main the count went to 0.
  • After renaming payment_count to payments, /propagate shows "orders: 4 of 6 columns documented (66.7%) · no description: customer_id, payments".
  • A new region_revenue model reads "region not in the manifest from before the task (new in it?)…".
  • Claude says its build ran with --defer --state prod --favor-state, and the band shows the same.
  • Resolve on a thread resolved elsewhere shows "Already resolved: the list was behind."
  • At 100 columns, the results pane shows the inline note.

🤖 Generated with Claude Code

…ct's manifest, and five smaller demo bugs

- /clear: the new conversation (a new session id, with empty state and no
  session.start) reloads the team comments and keeps project health's
  baseline, pending changes and issues; the status line keeps its parts.
- The dbt runs the plugin starts itself (compile and validate, /dbt-show,
  Re-run, the health check's parse) write to target/.altimate-plugin, so the
  project's manifest keeps every model's compiled SQL.
- Docs coverage after an SQL edit dbt has not compiled says it is from before
  the edit, and is read again from the edit check's manifest.
- A model the task created is called new in the end-of-task summary, not an
  old altimate-code.
- Inline (narrow) panes replace the no-op Min/Default/Max row with a note.
- The flags /defer and /target add are told to Claude and shown in the band.
- Resolve on a thread the lagging list still shows is done; a reply to one
  says it is no longer open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hkaltai
hkaltai marked this pull request as ready for review November 19, 2026 18:59
hkaltai and others added 5 commits November 20, 2026 00:42
…s own folder, coverage waits for its own check

- Re-run of Claude's dbt show drops a --target-path Claude named, so the
  replay writes to the plugin's folder.
- The health check's parse writes to target/.altimate-plugin/health: it runs
  outside the plugin's dbt queue, so it never rewrites a check's manifest.
- An edit's coverage is answered only by a check that started after it, and
  is dropped when the check's manifest was rewritten while it was read; the
  coverage id is resolved from the manifest being read; a wait that times out
  or a session that ends leaves no waiter behind.
- Changes recorded right after /clear are merged into the kept health state.
- Two identical rewritten dbt commands each get their flags line.
- The doctor test presses Run dbt parse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	plugins/altimate-code/CHANGELOG.md
…r restore before a push, coverage writes in edit order

- A check reads the manifest its dbt show wrote while the plugin's dbt queue
  is still held, so a queued run cannot replace it first.
- Health's /clear restore runs once, at the session id's change or the new
  conversation's first push gate, turn end or /health, whichever is first;
  a second /clear before it keeps what the first carried.
- An edit's first coverage read that lands late does not replace newer
  coverage; a read running at session end writes nothing.
- The status line parts are kept at /clear, apart from later updates.
- Defer flag notices are keyed by tool call and let go when a call is refused.
- The health check removes its catalog copy before each run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rage order taken before the first wait, removed status parts stay removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s wait; a status part removed during the restore stays removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
export async function featuresSessionEnd($: EngineInterface, e: Args<'session.end'>) {
// Taken before the features end: a /clear goes on under another id once they have.
if (e.reason === 'clear' && typeof e.sessionId === 'string') {
keepStatusParts()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Snapshotting every drawn part also restores parts whose session state /clear drops.

keepStatusParts() keeps all drawn parts and restoreStatusParts() puts them back, but several parts are computed from $.state, which starts empty in the new conversation. docs' docs N to copy comes from DocsState (docs.tsx showStatus) and nothing recomputes it for the new conversation (there is no docs clearStart, and sessionStart is not called after /clear), so a /clear right after /propagate leaves the line saying docs N to copy while the docs pane is empty, until the next docs action (an edit that sets groups, Apply/Dismiss, or /propagate). cost's scan ≈ … (from costAtom) and defer's statusText(state) have the same source and are only refreshed on the next estimate/dbt call. health deliberately recomputes its part in healthClearStart; the others do not. Either skip these ids at /clear, or have their owners clear their part in sessionEnd (as cte-profile's interrupt does).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, fixed in c2ceebb. keepStatusParts() now keeps only the parts that describe the machine rather than the conversation: integrations and altimateCode. A feature part comes from session state, which /clear empties, so it is dropped and its feature draws it again once it has the state back. Health restores its state and redraws its own part (drawStatus). docs, cost and defer redraw on their next action, as before this PR.

}

/** The state a /clear carries, with the changes a conversation recorded on top of it. */
function mergeKept(kept: HealthState, later: HealthState): HealthState {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: later here shadows the later helper imported from ../altimate-cli (used elsewhere in this file), so a future later(...) call inside mergeKept would silently resolve to this HealthState parameter and fail at runtime. Renaming the parameters (kept / recorded) removes the trap without changing behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, renamed to recorded in c2ceebb. No behaviour change.

@kilo-code-bot

kilo-code-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/health.test.tsx 359 Still present: the new test's concurrent.most assertion cannot exceed 1. For unheld calls the mock increments and decrements the counter in one synchronous block (health.test.tsx:144-146), and hold takes a single index, so only the one held call is ever in flight across an await; two concurrent post-/clear checks would still report most === 1. The test does not guard the serialization it was added for. Hold one of the post-/clear calls and assert the next has not started, or keep the counter open across an await for every call.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/health.tsx 69 Still present: oneAtATime chains on a module-level cliQueue with no deadline and no reset at sessionStart (which resets running, inFlight, generation but not this, health.tsx:697-718). The previous code bounded the same wait with within(...). A call whose promise never settles (a CLI left running when a session's engine is torn down) now blocks every later health check for the life of the process, and the queued check's until is already spent by then.
Files Reviewed (4 files)
  • plugins/altimate-code/hooks/features/defer.tsx - no new issues; storing { command, added } and skipping the result line when the command that ran differs from the rewritten one correctly covers the dropped-rewrite case, and the entry is deleted before the comparison so nothing is leaked on that path
  • plugins/altimate-code/hooks/features/defer.test.ts - no issues; the new test drives the rewrite past PHASE_TIMEOUT_MS, lets the held settings read finish against the already-running original command, and fails on the pre-fix code because the stale addedTo entry would still produce the "ran as" line
  • plugins/altimate-code/hooks/features/health.tsx - 1 carried-forward suggestion (re-verified in current code, unchanged since the previous review)
  • plugins/altimate-code/hooks/health.test.tsx - 1 carried-forward warning (re-verified in current code, unchanged since the previous review)

Fix these issues in Kilo Cloud

Previous Review Summaries (7 snapshots, latest commit d50a1eb)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d50a1eb)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/health.test.tsx 359 The new test's concurrent.most assertion can never exceed 1: for unheld calls the mock increments and decrements the counter in one synchronous block, and only the single held index stays in flight across an await, so two concurrently running post-/clear checks would still report most === 1. The test does not guard the serialization it was added for.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/health.tsx 69 oneAtATime chains on a module-level cliQueue with no deadline and no reset at sessionStart; the previous code bounded the same wait with within(...). A call whose promise never settles (a CLI left running when a session's engine is torn down) now blocks every later health check for the life of the process, and the queued check's until is already spent by then.
Files Reviewed (3 files)
  • plugins/altimate-code/hooks/features/comments.tsx - no issues; the newConversation() helper is called from both the session start and the /clear branch of sessionEnd, the two sites that reset firstWaitSpent/pendingFor, and the non-clear end keeps its own intentional pendingFor = null only
  • plugins/altimate-code/hooks/features/health.tsx - 1 suggestion; the queue place is now taken before checkEnv, so the finding from the previous round (a cut-short check's call could start outside the guard) is fixed; the job's rejection is handled and the queue stays usable after a failed call
  • plugins/altimate-code/hooks/health.test.tsx - 1 warning; the counter instrumentation and the held-call setup cannot observe overlap between unheld calls

Fix these issues in Kilo Cloud

Previous review (commit 73a117b)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/features/health.tsx 519 The one-at-a-time CLI guard is registered after await checkEnv($), and check never compares generation, so a check cut short by /clear while inside checkEnv can still launch its own dbt_health while the restored conversation's check starts one too - both sharing target/.altimate-plugin/health.
Files Reviewed (4 files)
  • plugins/altimate-code/hooks/features/health.tsx - 1 warning; the new cliCall serialization correctly covers a call whose loop was cut short once the call has been registered, but the registration happens after checkEnv and the old check is not stopped from starting after a generation bump; the remaining paths (settled-promise mapping, finally clearing, deadline computed before the wait) check out
  • plugins/altimate-code/hooks/health.test.tsx - no issues; the new test holds call 2, plays the /clear through playsClear, and only releases it after asserting no third call started, so it fails on the pre-fix code
  • plugins/altimate-code/hooks/features/comments.tsx - no issues; moving the firstWaitSpent/pendingFor reset into sessionEnd's clear branch keeps the pre-clearStart read covered, and the new if ((await get($)).root) return in clearStart preserves a project a first read in the new conversation found (the read's attach already scheduled its load and started the poll)
  • plugins/altimate-code/hooks/comments.test.tsx - no issues; the test reads another project's file while the session id still lags, then releases the id, so clearStart runs with a set root and the old attach-the-session-cwd path would overwrite it and fail the assertion

Fix these issues in Kilo Cloud

Previous review (commit 4c8f2fe)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/comments.tsx 246 The per-conversation reset (firstWaitSpent, pendingFor) is now copied into sessionEnd as a third site beside sessionStart and clearStart; the split between those sites is exactly what left the pre-clearStart read uncovered.
Files Reviewed (3 files)
  • plugins/altimate-code/hooks/features/comments.tsx - 1 suggestion; the clear branch of sessionEnd now reproduces clearStart's firstWaitSpent/pendingFor reset (verified the mine === generation and loadRun guards are untouched, so the poll and an in-flight load still carry over)
  • plugins/altimate-code/hooks/clear-state.testkit.ts - no issues; idLagsUntil keeps session.id naming the ended session until released, and the first read (before clears advances) still resolves to session-0
  • plugins/altimate-code/hooks/comments.test.tsx - no issues; the new test spends the first conversation's wait, plays the /clear with a lagging id, and the read itself starts list call 1, so it fails on the old code

Fix these issues in Kilo Cloud

Previous review (commit 47187ac)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/status-line.ts 58 The comment still promises the apply-time read, but kept is captured before await update, so a part removed while the write waits would be re-added. Unreachable today (only integrations/altimateCode are kept and neither is ever removed via setStatusPart), but the comment no longer matches the code.
Files Reviewed (3 files)
  • plugins/altimate-code/hooks/features/health.tsx - the clear queue now drains a second /clear that arrived during a restore; verified it coalesces per clear, cannot double-run a restore, and cannot hot-spin on a settled restoring promise
  • plugins/altimate-code/hooks/health.test.tsx - new test exercises the drain: with the old if (restoring) return restoring, the second conversation's state is never restored (the held write lands in the ended conversation), so it fails on the old code
  • plugins/altimate-code/hooks/status-line.ts - 1 suggestion

Fix these issues in Kilo Cloud

Previous review (commit 5b0d7d2)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • plugins/altimate-code/hooks/clear-state.testkit.ts
  • plugins/altimate-code/hooks/features/docs.test.tsx
  • plugins/altimate-code/hooks/features/health.tsx
  • plugins/altimate-code/hooks/health.test.tsx

Previous review (commit c2ceebb)

Status: 1 Issue Found | Recommendation: Merge after the suggestion

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/status-line.ts 50 The new KEPT_ACROSS_CLEAR filter is the actual fix for stale docs / cost / defer parts, but no test covers it; reverting to { ...drawnParts } would keep the suite green and reintroduce the bug.
Previous findings re-checked on c2ceebb (resolved)
  • features/index.ts:295 — keepStatusParts() now keeps only integrations and altimateCode; feature parts are dropped and redrawn by their owners (health redraws in healthClearStart/restore → drawStatus). Fixed.
  • features/health.tsx:751 — mergeKept(kept, recorded) no longer shadows the later helper. Fixed.
Files Reviewed (3 files)
  • plugins/altimate-code/CHANGELOG.md
  • plugins/altimate-code/hooks/features/health.tsx
  • plugins/altimate-code/hooks/status-line.ts - 1 suggestion

Fix these issues in Kilo Cloud

Previous review (commit 0e64040)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
plugins/altimate-code/hooks/features/index.ts 295 keepStatusParts() restores every drawn part, including parts computed from $.state that /clear drops: docs' docs N to copy (from DocsState) is not recomputed for the new conversation, so it can stay on the status line with an empty docs pane until the next docs action; cost's scan ≈ … and defer's status have the same state source and only refresh on the next estimate/dbt call. health avoids this by recomputing in healthClearStart.

SUGGESTION

File Line Issue
plugins/altimate-code/hooks/features/health.tsx 751 mergeKept(kept, later) shadows the later helper imported from ../altimate-cli; rename the parameter (e.g. recorded) so a future later(...) call inside the function is not silently shadowed.
Files Reviewed (21 files)
  • plugins/altimate-code/CHANGELOG.md
  • plugins/altimate-code/hooks/altimate-cli.ts
  • plugins/altimate-code/hooks/clear-state.testkit.ts
  • plugins/altimate-code/hooks/comments.test.tsx
  • plugins/altimate-code/hooks/dbt-mods-core.ts
  • plugins/altimate-code/hooks/dbt-mods.test.tsx
  • plugins/altimate-code/hooks/dbt-mods.tsx
  • plugins/altimate-code/hooks/features/comments.tsx
  • plugins/altimate-code/hooks/features/defer.test.ts
  • plugins/altimate-code/hooks/features/defer.tsx
  • plugins/altimate-code/hooks/features/docs.test.tsx
  • plugins/altimate-code/hooks/features/docs.tsx
  • plugins/altimate-code/hooks/features/health.tsx - 1 suggestion
  • plugins/altimate-code/hooks/features/index.ts - 1 warning
  • plugins/altimate-code/hooks/health.test.tsx
  • plugins/altimate-code/hooks/lineage.tsx
  • plugins/altimate-code/hooks/pane-size.tsx
  • plugins/altimate-code/hooks/status-line.ts
  • plugins/altimate-code/hooks/task-impact.test.tsx
  • plugins/altimate-code/hooks/task-impact.tsx
  • plugins/altimate-code/types/index.d.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 77.3K · Output: 12K · Cached: 1.1M

…ross /clear; rename a parameter that shadowed `later`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

/** At a /clear: keeps the machine's parts drawn now, which a part set before restoreStatusParts must not replace. */
export function keepStatusParts() {
const kept = Object.fromEntries(KEPT_ACROSS_CLEAR.filter(id => drawnParts[id]).map(id => [id, drawnParts[id]!]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The new kept-parts filter has no regression test.

KEPT_ACROSS_CLEAR is the actual fix for the stale docs N to copy / scan ≈ … / defer parts, but nothing covers it: the playsClear tests assert the comments pane, the health part (health.test.tsx:182) and the band, and none asserts that a docs/cost/defer part is dropped while integrations survives a /clear. Reverting this line to the old beforeClear = { ...(beforeClear ?? {}), ...drawnParts } would keep the suite green and silently bring the stale parts back. A test that draws integrations plus one feature part, plays /clear through clear-state.testkit.ts, and checks the ui.status text would lock the behaviour in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added in 5b0d7d2: /clear drops the "docs N to copy" status part with the offers it counted, which the new conversation does not have (features/docs.test.tsx). A docs offer puts docs 2 to copy on the status line, then playsClear plays the /clear, and the test checks the redrawn line has no docs part. With keepStatusParts() keeping every drawn part, as before c2ceebb, the test fails.

hkaltai and others added 3 commits November 20, 2026 01:44
…keeps the health snapshot; the test /clear reads a value as written only once it is

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ns the one a later /clear asked for; a status restore lets go only of its own snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
export async function restoreStatusParts($: EngineInterface) {
const kept = beforeClear
if (!kept) return
// Read when the write applies, so a part removed while it waits stays removed; let go only once written, and only

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The comment still promises the apply-time read, but kept is captured on line 56 before await update.

setStatusPart keeps a removal working through a pending restore by deleting from beforeClear (line 33), and the old updater re-read beforeClear when the write applied, so { ...(beforeClear ?? {}), ...prev } saw that deletion. Now the write uses the snapshot taken before the await, so a setStatusPart(id, null) that lands while the write waits is re-added by { ...kept, ...prev } and drawn again at line 63.

That is unreachable today, because KEPT_ACROSS_CLEAR holds only integrations and altimateCode, and integrations is always a non-empty string (integrations.tsx:132-136) while altimateCode is only ever set to a notice (integrations.tsx:587), so neither is ever removed through setStatusPart. Still, the comment now describes a guarantee the code does not give: either read beforeClear inside the updater while it is still kept, or reword the comment to say that only the snapshot taken at restore start is written and that a later /clear's snapshot is left to its own restore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The updater does still see a removal made while it waits. kept is the same object as beforeClear, not a copy, and setStatusPart(id, null) removes the part with delete beforeClear[id], which changes that object in place. So { ...kept, ...prev } reads it without the part when the write applies. The two only differ once a later /clear puts a new snapshot in beforeClear. After that, removals go to the new snapshot, which belongs to that /clear's own restore, and if (beforeClear === kept) leaves it alone. As you note, neither kept part (integrations, altimateCode) is ever removed today, so I left the code as it is.

…onversation's comments even before clearStart runs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
if (e.reason === 'clear') {
// The next conversation starts with empty state: its first read of a model waits for its list, as a session's
// first read does, even when it comes before clearStart.
firstWaitSpent = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The per-conversation reset is now copied in three places.

firstWaitSpent = false / pendingFor = null now appear here (the pre-clearStart window), in clearStart (comments.tsx:226-227) and in sessionStart (comments.tsx:204-205). The bug this commit fixes exists because that reset lived only in clearStart: a read that came before it still saw the previous conversation's firstWaitSpent. A future conversation-scoped flag has to be added to both sites again, or the same window regresses. One newConversation() helper called from all three (each site keeps its own extras: sessionStart also resets uncertain/resolvedAt/posting, clearStart also clears searched/within) would keep the shared part in one place.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in d50a1eb. A newConversation() helper now resets the first-read wait and the pending first load. sessionStart and the /clear branch of sessionEnd both call it. clearStart no longer resets them (since 73a117b), so a read that came first keeps its own project and wait.

…project a read found before clearStart stays

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
// One CLI call at a time, across a /clear or a new session too: a call whose loop was cut short still runs, and
// the next one would share its artifact folder, so it waits for it.
const before = cliCall
if (before) await within($, Math.max(0, until - (await $.clock.now())), before)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: The one-at-a-time guard is taken after await checkEnv($), so the overlap it exists to prevent is still reachable.

check reads cliCall here, but only publishes its own call on line 526, with await checkEnv($) on line 520 in between (that runs rm, exists, mkdir and cp of catalog.json, the last with a 60 s timeout). check never compares generation (only loop does, on line 585, after the call returns), so a check from the conversation that ended keeps going after /clear bumps generation. If /clear lands while that check is inside checkEnv, the restore()/kick() it triggers starts the next conversation's check, which also sees cliCall === null; both then launch dbt_health against the same target/.altimate-plugin/health, which is exactly the shared-folder case this commit set out to prevent.

Reserve the slot before checkEnv (or capture const mine = generation in check and skip runTool once it changed, since the loop discards this result anyway) so a check whose loop was cut short cannot start a call the serialization does not know about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, fixed in d50a1eb. check() now runs checkEnv() and the dbt_health call together through oneAtATime(), and the queue place is taken before anything is awaited (cliQueue = cliQueue.then(job, job)). A check from a conversation that ended therefore runs its folder preparation and its call in turn too, and the next one starts only after it settles. New regression: two /clears while a cut-short CLI call runs still start their checks one after another. It counts concurrent dbt_health calls and requires at most one.

…wait, folder preparation included; one reset for a new conversation's comments

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
release()
await clock.settle()
expect(calls.length).toBeGreaterThanOrEqual(3)
expect(concurrent.most).toBe(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: concurrent.most can never exceed 1, so this assertion cannot fail.

For every call that is not held, the counter is bumped and released in one synchronous block: concurrent.most = Math.max(concurrent.most, ++concurrent.now) on line 144, then concurrent.now-- on line 146, with no await in between unless options.hold?.at === index. Only the held call stays inside that window, and hold takes a single index, so the pre-/clear call (index 1) is the only one that is ever in flight across an await. The two post-/clear calls (indexes 2 and 3) can therefore run concurrently and still report most === 1, and calls.length >= 3 does not tell serial from parallel. Removing oneAtATime and starting both checks after release() would keep this test green.

Hold one of the post-/clear calls (e.g. index 2, then assert that index 3 has not started until it is released, as the previous test does), or make the mock keep the counter open across an await for every call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The case this test is for is still covered: the restored conversation's check overlapping the call that /clear cut short. That cut-short call is the held one (index 1), so it is inside the counted window. With oneAtATime removed (the check runs checkEnv and runTool directly), the test fails with concurrent.most === 2, and so does the one before it. I ran that mutation on this head. You are right that the counter does not catch two post-/clear checks running in parallel with each other. That needs both restores to start checks while neither is held, and loop's running guard already rules it out within one generation. Extending the mock to keep every call open across an await is a reasonable hardening. I have left it out of this PR so the approved head stays as reviewed.


/** Runs `job` after every one queued before it; its place is taken at once, before anything is awaited. */
function oneAtATime<T>(job: () => Promise<T>): Promise<T> {
const run = cliQueue.then(job, job)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: The queue has no deadline and is not reset at a session start, so one call that never settles blocks every later health check for the rest of the process.

oneAtATime chains on the module-level cliQueue and nothing ever bounds or clears it: sessionStart resets the other module state (running, inFlight, generation) but not this. The previous code bounded the same wait with within($, until - now, before), so a call whose promise never settled - a CLI left running when the session's engine is torn down, which altimate-cli.ts:113 notes as possible - only delayed the next check until the deadline. Now that check, and every check after it, waits forever, because the queued job's until is already spent by the time it can run and runTool rejects with out of time instead of recovering.

health.test.tsx:683 deliberately models this shape by holding a dbt_health call with a promise that is never released. Capping the wait with the existing until deadline, or resetting cliQueue in sessionStart (a new session does not share the ended engine, and a /clear does not call sessionStart, so the cross-/clear guarantee is kept), would preserve the serialization without the permanent block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Every queued job is bounded, so the queue cannot block forever on a CLI call. runTool passes the job's until to runAltimate as the process timeoutMs, and the engine kills the child and rejects at that time. The job therefore settles at the latest by CHECK_MS, and cliQueue moves on either way (then(() => {}, () => {})). A job whose deadline passed while it waited rejects at once with out of time, which becomes a told problem, and the next change or /health asks again with a fresh deadline. The never-released hold in health.test.tsx:683 stands in for the mock's process.run inside one test only; the real process.run cannot hang past timeoutMs. I did not reset the queue in sessionStart: a resumed session in the same process can still have the previous call writing target/.altimate-plugin/health, and that overlap is exactly what the queue prevents.

…hat ran is the rewritten one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hkaltai

hkaltai commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

review-loop: APPROVED at 4c6f857 (reviewers: gpt-6-astra high, gpt-6.1-sol high)

One non-blocking MINOR from the last round is left as a follow-up: if a read in project B lands while the restore triggered by /clear is still waiting on session.cwd(), the restore can switch the comments pane back to the session folder's project. It recovers on the next read of a model, and the case where B is read before the restore starts is covered.

@hkaltai

hkaltai commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Re the Kilo Code Review summary: each finding has a reply on its inline thread. The status-part restore now keeps only the integrations and altimate-code parts, and has a regression test. The later shadowing is renamed. The kept-parts test is added. The comment about the apply-time read is answered. The health queue now takes its place before any await, and its deadline is explained. The concurrency test is mutation-checked.

@saravmajestic saravmajestic 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. Kilo's rounds were fixed or answered convincingly: after /clear the status line keeps only the integrations and altimate-code parts, the health check's one-at-a-time queue is taken before any await, and the concurrency test was mutation-checked. The scratch DBT_TARGET_PATH for the plugin's own dbt runs keeps the project manifest intact, as the live check shows. Locally: 1259 pass, 0 fail, and 1264/0 merged with #41 on main (only CHANGELOG.md conflicts). The pane-switch race during the /clear restore is fine as a follow-up.

# Conflicts:
#	plugins/altimate-code/CHANGELOG.md
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.

2 participants