Skip to content

feat(hub): sync canvas improvement notes and recall learnings - #486

Open
weastler wants to merge 2 commits into
weastler-canvas-share-linksfrom
weastler-canvas-notes-recall
Open

weastler wants to merge 2 commits into
weastler-canvas-share-linksfrom
weastler-canvas-notes-recall

Conversation

@weastler

@weastler weastler commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: d5f05e314f4108dd60f1f0de94c282ce990b4307

Dimension Assessment Rationale
Change confidence 8/10 ↑ Database cases drive the unchanged extension client against note sync. They cover the lifecycle, idempotent retries, every 409 conflict, history and thread rules, NUL and malformed text, author separation, cross-prototype Builds, unregistered prototypes, revoked connections, reader permissions, renamed authors and the include/only feeds.
↑ Seven pure validator cases came from an independent test writer and were confirmed red against broken rules.
↑ Four code-review findings are fixed: live author login, text the database can store, a fail-fast recall deadline, and a per-connection recall limit.
↑ Lint, db:validate, types, unit (4015) and database (888) suites and the build pass locally on this head.
↓ Recall isn't exercised against a real learning store; its command and lock are mocked.
↓ There's no dedicated migration-compatibility test for the added table.
↓ CI hasn't run yet.

Why

The canvas extension backs up Pick & polish notes through /api/canvas/repositories/…/prototypes/…/improvement_notes. Its learnings hook calls POST /api/canvas/learnings/recall before each prompt. The Rails Hub on main served both, but the Node Hub doesn't, so note backup and Hub learnings are unavailable in the canvas against build/hub/new. This is the third of three server PRs in the Canvas Hub API contract shared with @arniebradfo. It's stacked on #485, which is stacked on #481.

What changes

Improvement notes.

  • Storage. A new improvement_notes table backs up each author's notes: one row per author, prototype and the extension's local note ID. Each row holds the anchor and conversation as JSON, the successful Build it was written against, and a tombstone after deletion.

  • GET returns only the viewer's own notes and needs repository read access.

  • POST saves one complete revision and needs repository write access, as on Rails. It ports Rails's synchronize!:

    • retrying the saved revision is accepted unchanged;
    • stale, diverging, re-anchored or re-Built revisions return 409;
    • a deleted note can't be restored.
  • Thread rules. These port Rails's thread and message contracts:

    • an owner-only author snapshot;
    • unique message IDs;
    • agent answers that reference earlier requests;
    • a note status that matches its requests;
    • history that only grows.

    A thread that breaks them returns 422. Text with NUL or malformed characters also returns 422, because PostgreSQL can't store it.

  • Feeds. The review-comment feeds now accept improvement_notes=include|only and add everyone's notes.

  • Author login. Notes show the author's current login, because the extension matches notes to its signed-in login.

Learning recall. POST /api/canvas/learnings/recall returns the learnings the repository's administrators accepted as { text, memories: [{ id, digest }] }.

  • It needs repository read access, and the prompt is never sent.
  • It runs replica-learning recall under the learning execution lock and records the recall as a delivery to agent:hub-canvas-connection-<id>.
  • With the new failFast lock option, a held authority lock counts as busy instead of a wait, so recall answers within 1.5 seconds or returns 503.
  • It's limited to 30 requests a minute per connection.
  • Repositories without Hub-hosted learnings, including local checkouts, return 404 with code: "learnings_off".

Refactor. The canvas routers now share authorize-canvas-request, confirm-canvas-read and find-canvas-avatars, instead of duplicating them.

flowchart LR
  Ext[Canvas extension] -->|POST revision| Notes[improvement_notes route]
  Notes --> Sync[synchronizeImprovementNote: serializable, recheck connection]
  Sync --> Table[(improvement_notes)]
  Ext -->|POST learnings/recall| Recall[recallCanvasLearnings]
  Recall --> Lock[learning lock, failFast]
  Lock --> CLI[replica-learning recall]
Loading

Divergences from main and risks

  • Conversation storage. The conversation is stored as validated JSON on the note row, not in Rails's relational message and response-link rows. The API shape is unchanged, and the immutability rules are enforced in code under a serializable transaction.
  • Deleted-note retries. Retrying the saved revision of a deleted note returns the tombstone without rechecking the thread sent with it. Rails validated that thread and could return 422.
  • Text rules. Bodies containing NUL or malformed text return 422. Rails stored them.
  • Recall actor. Recall records the delivery under the connection (agent:hub-canvas-connection-<id>), as Hub's agent connections do, rather than under the person. Each recall is still recorded as a use, as the user decided.
  • Recall consent. There's no per-connection learnings consent, so 403 learnings_consent_required is never returned. Repository learning settings govern learnings.
  • Local repositories. They have no Hub-hosted learnings, so recall returns learnings_off and the extension's local learning mode applies.
  • Shared lock integration. withLearningExecutionLock gains an opt-in failFast option. Existing callers are unchanged.
  • Feed filter. improvement_notes=include|only is now accepted, so feat(hub): serve canvas review comments #481's 400 for those values no longer applies.
  • Dependencies. This PR is stacked on feat(hub): serve canvas share links #485 and feat(hub): serve canvas review comments #481; merge those first. The migration 20261230090000_canvas_improvement_notes sorts after fix(hub): harden canvas and agent authorization #470's 20261229090000 migration.
  • Verification gaps.
    • Recall isn't exercised against a real learning store.
    • A connection revoked during a note save isn't exercised. The route uses the same in-transaction authorizeCanvasMutation that feat(hub): serve canvas review comments #481 tests.
    • There's no dedicated migration-compatibility test for the added table.
weastler and others added 2 commits December 2, 2026 00:53
Back up Pick & polish notes from the canvas with the Rails revision and
conversation rules, add them to the comment feeds on request, and recall
accepted learnings for the canvas learnings hook.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject NUL and malformed text before it reaches PostgreSQL, present each
note author's current login, fail fast instead of waiting behind authority
locks during recall, answer recall within its deadline, and limit recall per
connection. Add independent note and validator coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@weastler
weastler requested review from a team and nshki as code owners December 2, 2026 09:18
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 09:18

/** Nonblank text PostgreSQL can store: well-formed, without NUL characters. */
export function isValidNoteText(value: string) {
return Boolean(value.trim()) && !loneSurrogate.test(value) && !value.includes("\0")

Copilot AI 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.

🟡 Changes recommended

Authorization races can expose private data or permit writes after access changes, while unbounded note feeds can exhaust server memory.

12 open issues
What changed in this PR

Adds Node Hub support for backing up canvas Pick & polish notes and recalling accepted learnings, building on the review-comment and share-link APIs.

Changes:

  • Stores note revisions, validates conversations, preserves deletion tombstones, and includes notes in feeds.
  • Adds rate-limited learning recall with execution deadlines and delivery tracking.
  • Shares canvas helpers and expands contracts, tests, and documentation.
File Description
hub/​server/​routes/​index.ts Passes learning dependencies to canvas routes.
hub/​server/​routes/​api/​repositories/​prototypes/​builds/​get/​index.test.ts Updates product dependency mocks.
hub/​server/​routes/​api/​product/​types.ts Defines transactional canvas authorization.
hub/​server/​routes/​api/​product/​create-product-route-dependencies/​index.ts Shares mutation authorization.
hub/​server/​routes/​api/​canvas/​share-links/​index.ts Uses shared request authorization.
hub/​server/​routes/​api/​canvas/​share-links/​constants.ts Removes extracted parameter schemas.
hub/​server/​routes/​api/​canvas/​review-comments/​index.ts Adds notes to comment feeds.
hub/​server/​routes/​api/​canvas/​review-comments/​index.db.test.ts Updates invalid-filter coverage.
hub/​server/​routes/​api/​canvas/​review-comments/​constants.ts Accepts note feed filters.
hub/​server/​routes/​api/​canvas/​recall.db.test.ts Covers recall guards and rate limits.
hub/​server/​routes/​api/​canvas/​present-canvas-improvement-note/​index.ts Serializes notes and edit permissions.
hub/​server/​routes/​api/​canvas/​index.ts Mounts note and recall endpoints.
hub/​server/​routes/​api/​canvas/​improvement-notes/​index.ts Serves note reads and synchronization.
hub/​server/​routes/​api/​canvas/​improvement-notes/​index.db.test.ts Covers note lifecycle and access rules.
hub/​server/​routes/​api/​canvas/​improvement-notes/​constants.ts Defines note request schemas.
hub/​server/​routes/​api/​canvas/​find-canvas-avatars/​index.ts Shares immutable-ID avatar lookup.
hub/​server/​routes/​api/​canvas/​contracts.ts Adds note and recall response types.
hub/​server/​routes/​api/​canvas/​confirm-canvas-read/​index.ts Extracts final read-access checks.
hub/​server/​routes/​api/​canvas/​authorize-canvas-request/​index.ts Extracts canvas request authorization.
hub/​server/​repositories/​improvement-notes/​save-improvement-note/​index.ts Persists note revisions.
hub/​server/​repositories/​improvement-notes/​list-improvement-notes/​index.ts Queries notes and presentation data.
hub/​server/​repositories/​improvement-notes/​find-note-build/​index.ts Finds eligible successful Builds.
hub/​server/​repositories/​improvement-notes/​find-improvement-note/​index.ts Finds an author's saved note.
hub/​server/​integrations/​postgres/​with-learning-execution-lock/​index.ts Adds fail-fast lock acquisition.
hub/​server/​integrations/​postgres/​with-learning-execution-lock/​index.db.test.ts Covers fail-fast authority locking.
hub/​server/​domains/​improvement-notes/​validate-improvement-thread/​index.ts Validates conversations and history.
hub/​server/​domains/​improvement-notes/​validate-improvement-thread/​index.test.ts Tests conversation validation rules.
hub/​server/​domains/​improvement-notes/​synchronize-improvement-note/​index.ts Enforces revision and tombstone rules.
hub/​server/​domains/​improvement-notes/​is-valid-note-text/​index.ts Checks database-safe note text.
hub/​server/​domains/​improvement-notes/​errors.ts Defines note synchronization errors.
hub/​server/​domains/​improvement-notes/​constants.ts Defines statuses and validation limits.
hub/​server/​domains/​canvas/​recall-canvas-learnings/​index.ts Executes and formats learning recall.
hub/​server/​domains/​canvas/​recall-canvas-learnings/​index.test.ts Covers recall results and failures.
hub/​server/​domains/​canvas/​authorize-canvas-review/​index.ts Supports token-scoped repository requests.
hub/​schema/​user.prisma Adds the note-author relation.
hub/​schema/​prototype.prisma Adds prototype notes.
hub/​schema/​migrations/​migration_lock.toml Adds generated header comments only.
hub/​schema/​migrations/​20261230090000_canvas_improvement_notes/​migration.sql Creates note storage and constraints.
hub/​schema/​improvement-note.prisma Defines the improvement-note model.
hub/​schema/​build.prisma Adds Build-linked notes.
hub/​docs/​prototype-canvas.md Documents note synchronization and recall.
hub/​docs/​database.md Documents note persistence rules.

Review effort: Max (adaptive)

Comment on lines +3 to +25
import type { PrismaClient } from "../../../../generated/prisma/client.ts"
import { verifyCanvasAccess } from "../../../../repositories/canvas/grants/index.ts"
import type { ProductRouteDependencies } from "../../product/types.ts"
import type { CanvasScope } from "../authorize-canvas-request/index.ts"

/**
* Rechecks the connection and the stored repository access after a protected read, as Hub's
* review pages do, so access withdrawn during the read returns nothing. Answers 401 itself.
*/
export async function confirmCanvasRead(
response: Response,
database: PrismaClient,
isRepositoryVisible: ProductRouteDependencies["isRepositoryVisible"],
scope: CanvasScope,
) {
if (
(await verifyCanvasAccess(database, scope.grantId, scope.tokenDigest, new Date())) &&
(await isRepositoryVisible(scope.viewer, scope.repository.id))
)
return true
response.status(401).json({ error: "Canvas connection is no longer active." })
return false
}
Comment on lines +110 to +116
authorize: (transaction: Prisma.TransactionClient) =>
input.product.authorizeCanvasMutation(
transaction,
scope.tokenDigest,
userId,
scope.repository.id,
),
status(response, 503, "Hub could not recall learnings. Try again.")
return
}
response.json({ text: result.text, memories: [...result.memories] } satisfies CanvasRecall)
Comment on lines +251 to +253
: await listImprovementNotes(transaction, {
prototype: eligibleReviewPrototype(scope.repository),
}),
root: learning.root,
staticDirectories: learning.staticDirectories,
})
if (!directory) return { status: "ok", text: "", memories: [] } as const
)
let anchor: Prisma.InputJsonValue
try {
anchor = parseReviewAnchor(note.anchor) as unknown as Prisma.InputJsonValue
if (!same) conflict("This note revision has different content.")
return saved
}
if (saved.deletedAt) conflict("A deleted note cannot be restored.")
invalid("Author snapshots must identify this note's owner.")
const avatar = author.avatarUrl
if (avatar === null) return
const url = typeof avatar === "string" && avatar.length <= 2048 && URL.parse(avatar)
router.post(
path,
input.limit("canvas-improvement-note", 120),
express.json({ limit: "1600kb", strict: true }),
Comment on lines +91 to +92
if (prototype.registeredAt === null)
return fail(response, 404, "Hub has not registered a reviewable prototype on this branch.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants