Skip to content

fix: add padId to padUpdate/padCreate hook context#7452

Merged
JohnMcLear merged 1 commit intoether:developfrom
JohnMcLear:fix/padUpdate-padId-5814
Apr 4, 2026
Merged

fix: add padId to padUpdate/padCreate hook context#7452
JohnMcLear merged 1 commit intoether:developfrom
JohnMcLear:fix/padUpdate-padId-5814

Conversation

@JohnMcLear
Copy link
Copy Markdown
Member

Summary

One-line fix: adds padId: this.id to the padUpdate and padCreate hook context object.

Root Cause

The pad object's toJSON() intentionally strips the id property (line 151 in Pad.ts) because it's redundant with the database key (pad:{id}). This meant that when plugins serialized the hook context (e.g., logging), the pad ID was missing.

While context.pad.id works on the live object, adding padId as a top-level property is clearer and survives serialization.

Test plan

  • Type check passes
  • Backend tests pass (744/744)

Fixes #5814

🤖 Generated with Claude Code

The pad object's toJSON() intentionally strips the id property (since
it's part of the database key), which caused confusion when plugins
serialized the hook context. Adding padId as a top-level property on
the hook context makes it directly accessible without relying on the
pad object's internal properties.

Fixes ether#5814

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JohnMcLear
Copy link
Copy Markdown
Member Author

/review

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Apr 4, 2026

Code Review by Qodo

Grey Divider

New Review Started

This review has been superseded by a new analysis

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Add padId to padUpdate/padCreate hook context

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Adds padId property to padUpdate and padCreate hook context
• Ensures pad ID is accessible after hook context serialization
• Resolves issue where plugins couldn't access pad ID from serialized context
Diagram
flowchart LR
  A["Hook Context Object"] -->|"Add padId property"| B["padId: this.id"]
  A -->|"Existing properties"| C["pad, authorId"]
  B -->|"Survives serialization"| D["Plugin Access"]
Loading

Grey Divider

File Changes

1. src/node/db/Pad.ts 🐞 Bug fix +1/-0

Add padId property to hook context

• Adds padId: this.id to the hook context object passed to aCallAll()
• Makes pad ID directly accessible as a top-level property
• Ensures pad ID is preserved when hook context is serialized by plugins
• Addresses issue where toJSON() strips the id property from pad objects

src/node/db/Pad.ts


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Apr 4, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (2) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. padId undocumented in hooks 📘 Rule violation ⚙ Maintainability
Description
The PR adds a new top-level padId property to the padCreate/padUpdate hook context, but the
server-side hooks documentation does not mention it. This violates the requirement to update doc/
alongside public hook payload changes, leaving plugin authors unaware of the new field.
Code

src/node/db/Pad.ts[R126-129]

      hooks.aCallAll(hook, {
        pad: this,
+        padId: this.id,
        authorId,
Evidence
Pad.appendRevision() now passes padId: this.id to hooks.aCallAll() for padCreate and
padUpdate, but both the Markdown and AsciiDoc server-side hooks docs list context properties
without padId for these hooks.

src/node/db/Pad.ts[110-142]
doc/api/hooks_server-side.md[267-328]
doc/api/hooks_server-side.adoc[270-331]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The `padCreate` and `padUpdate` hook context now includes a new top-level `padId` field, but the hook documentation does not list it.

## Issue Context
Plugins often serialize the hook context, and `pad.toJSON()` strips `id`, so `padId` is the reliable serialized identifier. Docs should reflect the new payload shape.

## Fix Focus Areas
- doc/api/hooks_server-side.md[267-328]
- doc/api/hooks_server-side.adoc[270-331]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. No regression test added 📘 Rule violation ☼ Reliability
Description
The PR changes the public hook payload by adding padId to the padCreate/padUpdate context, but
the provided diff includes no accompanying automated regression test. Without a test, this bug can
easily reappear if the field is removed or refactored away.
Code

src/node/db/Pad.ts[R126-129]

      hooks.aCallAll(hook, {
        pad: this,
+        padId: this.id,
        authorId,
Evidence
The PR modifies the hook context in Pad.appendRevision() by adding padId, but there is no
corresponding test coverage for padCreate/padUpdate hook context in the existing Pad backend
specs (they currently cover padDefaultContent only).

src/node/db/Pad.ts[110-142]
src/tests/backend/specs/Pad.ts[56-142]
Best Practice: Repository guidelines

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
There is no automated regression test asserting that the `padCreate` and `padUpdate` hook context includes `padId` (and that it survives serialization).

## Issue Context
The change is meant to ensure plugins can reliably determine the pad identifier even if they serialize the hook context. A regression test should fail if `padId` is removed/reverted.

## Fix Focus Areas
- src/tests/backend/specs/Pad.ts[1-142]
- src/node/db/Pad.ts[110-142]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment thread src/node/db/Pad.ts
Comment on lines 126 to 129
hooks.aCallAll(hook, {
pad: this,
padId: this.id,
authorId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. padid undocumented in hooks 📘 Rule violation ⚙ Maintainability

The PR adds a new top-level padId property to the padCreate/padUpdate hook context, but the
server-side hooks documentation does not mention it. This violates the requirement to update doc/
alongside public hook payload changes, leaving plugin authors unaware of the new field.
Agent Prompt
## Issue description
The `padCreate` and `padUpdate` hook context now includes a new top-level `padId` field, but the hook documentation does not list it.

## Issue Context
Plugins often serialize the hook context, and `pad.toJSON()` strips `id`, so `padId` is the reliable serialized identifier. Docs should reflect the new payload shape.

## Fix Focus Areas
- doc/api/hooks_server-side.md[267-328]
- doc/api/hooks_server-side.adoc[270-331]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread src/node/db/Pad.ts
Comment on lines 126 to 129
hooks.aCallAll(hook, {
pad: this,
padId: this.id,
authorId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. No regression test added 📘 Rule violation ☼ Reliability

The PR changes the public hook payload by adding padId to the padCreate/padUpdate context, but
the provided diff includes no accompanying automated regression test. Without a test, this bug can
easily reappear if the field is removed or refactored away.
Agent Prompt
## Issue description
There is no automated regression test asserting that the `padCreate` and `padUpdate` hook context includes `padId` (and that it survives serialization).

## Issue Context
The change is meant to ensure plugins can reliably determine the pad identifier even if they serialize the hook context. A regression test should fail if `padId` is removed/reverted.

## Fix Focus Areas
- src/tests/backend/specs/Pad.ts[1-142]
- src/node/db/Pad.ts[110-142]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@JohnMcLear JohnMcLear merged commit 4896b52 into ether:develop Apr 4, 2026
26 checks passed
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.

padUpdate missing padId

1 participant