From e86053156a9af214ac93293a3d2f0a5829fa8836 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:32 +0800 Subject: [PATCH 1/9] fix(api): add archived-channel error --- apps/api/internal/store/types.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/api/internal/store/types.go b/apps/api/internal/store/types.go index 80265377..4296792d 100644 --- a/apps/api/internal/store/types.go +++ b/apps/api/internal/store/types.go @@ -32,6 +32,9 @@ var ErrInvalidEventDeliveryCursor = errors.New("invalid or stale event delivery // a write. HTTP callers surface it as a 403 or 429 depending on the rule. var ErrModerationRestricted = errors.New("moderation restriction") +// ErrChannelArchived is returned when a post targets an archived channel. +var ErrChannelArchived = errors.New("channel is archived") + // ErrMessageNotWritable is returned when a user can read a message but cannot // mutate it. var ErrMessageNotWritable = errors.New("message is not writable") From 7ae4fdd5ff91149c40bbbfed213a7a7ba8e39a92 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:35 +0800 Subject: [PATCH 2/9] fix(api): reject posts to archived channels (postgres) --- apps/api/internal/store/postgres/moderation.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/api/internal/store/postgres/moderation.go b/apps/api/internal/store/postgres/moderation.go index 8093f4ea..497711fd 100644 --- a/apps/api/internal/store/postgres/moderation.go +++ b/apps/api/internal/store/postgres/moderation.go @@ -148,6 +148,13 @@ func requireNoModerationBlockTx(ctx context.Context, tx *sql.Tx, workspaceID, us } func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, userID string) error { + channel, err := storedb.New(tx).GetChannel(ctx, channelID) + if err != nil { + return err + } + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived + } role, err := memberRoleTx(ctx, tx, workspaceID, userID) if err != nil { return err From e13bd6eb1309ea48b61582ed01eae37681bfc8a8 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:38 +0800 Subject: [PATCH 3/9] fix(api): reject posts to archived channels (sqlite) --- apps/api/internal/store/sqlite/moderation.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/api/internal/store/sqlite/moderation.go b/apps/api/internal/store/sqlite/moderation.go index 1ab26f89..813c42ea 100644 --- a/apps/api/internal/store/sqlite/moderation.go +++ b/apps/api/internal/store/sqlite/moderation.go @@ -148,6 +148,13 @@ func requireNoModerationBlockTx(ctx context.Context, tx *sql.Tx, workspaceID, us } func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, userID string) error { + channel, err := storedb.New(tx).GetChannel(ctx, channelID) + if err != nil { + return err + } + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived + } role, err := memberRoleTx(ctx, tx, workspaceID, userID) if err != nil { return err From 6e9b15b194b40d6318e00bbf29d7f118ad3d8676 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:41 +0800 Subject: [PATCH 4/9] fix(api): map archived-channel errors to 409 --- apps/api/internal/httpapi/responses.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/api/internal/httpapi/responses.go b/apps/api/internal/httpapi/responses.go index 890cee72..0d6c6a73 100644 --- a/apps/api/internal/httpapi/responses.go +++ b/apps/api/internal/httpapi/responses.go @@ -122,6 +122,8 @@ func writeStoreError(w http.ResponseWriter, err error) { writeError(w, http.StatusNotFound, err) case errors.Is(err, store.ErrModerationRestricted): writeError(w, http.StatusForbidden, err) + case errors.Is(err, store.ErrChannelArchived): + writeError(w, http.StatusConflict, err) case errors.Is(err, store.ErrNotWorkspaceManager): writeError(w, http.StatusForbidden, err) case errors.Is(err, store.ErrNotWorkspaceMember): From 41c0f6f3b212a82d0b7869cfa18a3a3c485545bc Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:44 +0800 Subject: [PATCH 5/9] test(api): cover archived-channel post rejection (postgres) --- .../store/postgres/moderation_test.go | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/apps/api/internal/store/postgres/moderation_test.go b/apps/api/internal/store/postgres/moderation_test.go index 420b2e06..904bf780 100644 --- a/apps/api/internal/store/postgres/moderation_test.go +++ b/apps/api/internal/store/postgres/moderation_test.go @@ -155,3 +155,38 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) { t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err) } } + +func TestCreateMessageRejectsArchivedChannel(t *testing.T) { + ctx := t.Context() + st := newIsolatedPostgresTestStore(t) + if err := st.Migrate(ctx); err != nil { + t.Fatal(err) + } + owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com") + if err != nil { + t.Fatal(err) + } + workspaces, err := st.ListWorkspaces(ctx, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(workspaces) == 0 { + t.Fatal("expected a workspace") + } + workspace := workspaces[0] + channels, err := st.ListChannels(ctx, workspace.ID, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(channels) == 0 { + t.Fatal("expected a channel") + } + channel := channels[0] + archived := true + if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil { + t.Fatal(err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected ErrChannelArchived, got %v", err) + } +} From 9d0d02c26b3c5940803c468d64c0fb68688fdf23 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:52:48 +0800 Subject: [PATCH 6/9] test(api): cover archived-channel post rejection (http) --- apps/api/internal/httpapi/message_routes_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/api/internal/httpapi/message_routes_test.go b/apps/api/internal/httpapi/message_routes_test.go index 4da15425..8733aa0d 100644 --- a/apps/api/internal/httpapi/message_routes_test.go +++ b/apps/api/internal/httpapi/message_routes_test.go @@ -132,6 +132,7 @@ func TestEnsureMessageRouteEndpointIsLazyBoundedAndPermissionChecked(t *testing. patchJSON[struct { Channel store.Channel `json:"channel"` }](t, server.URL+"/api/channels/"+channel.ID, map[string]bool{"archived": true}) + expectStatusAsUser(t, member.ID, http.MethodPost, server.URL+"/api/channels/"+channel.ID+"/messages", map[string]string{"body": "archived"}, http.StatusConflict) archived := postJSONAsUser[struct { Message store.Message `json:"message"` }](t, member.ID, server.URL+"/api/messages/"+archivedRoot.ID+"/route", struct{}{}) From cc5f2ae85a67bbfc917025bb39565fd898a20b63 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 12:54:43 +0800 Subject: [PATCH 7/9] test(api): pass a JSON reader to the archived-channel assertion --- apps/api/internal/httpapi/message_routes_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/api/internal/httpapi/message_routes_test.go b/apps/api/internal/httpapi/message_routes_test.go index 8733aa0d..0b9d04e2 100644 --- a/apps/api/internal/httpapi/message_routes_test.go +++ b/apps/api/internal/httpapi/message_routes_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "path/filepath" + "strings" "testing" "github.com/openclaw/clickclack/apps/api/internal/realtime" @@ -132,7 +133,7 @@ func TestEnsureMessageRouteEndpointIsLazyBoundedAndPermissionChecked(t *testing. patchJSON[struct { Channel store.Channel `json:"channel"` }](t, server.URL+"/api/channels/"+channel.ID, map[string]bool{"archived": true}) - expectStatusAsUser(t, member.ID, http.MethodPost, server.URL+"/api/channels/"+channel.ID+"/messages", map[string]string{"body": "archived"}, http.StatusConflict) + expectStatusAsUser(t, member.ID, http.MethodPost, server.URL+"/api/channels/"+channel.ID+"/messages", strings.NewReader(`{"body":"archived"}`), http.StatusConflict) archived := postJSONAsUser[struct { Message store.Message `json:"message"` }](t, member.ID, server.URL+"/api/messages/"+archivedRoot.ID+"/route", struct{}{}) From 521653b4fa0a7daae3f3eae6e320de754c2d8310 Mon Sep 17 00:00:00 2001 From: tre1d / digitalnav Date: Mon, 9 Nov 2026 14:17:18 +0800 Subject: [PATCH 8/9] fix(api): explain how to recover from an archived-channel rejection --- apps/api/internal/store/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api/internal/store/types.go b/apps/api/internal/store/types.go index 4296792d..fa05c34a 100644 --- a/apps/api/internal/store/types.go +++ b/apps/api/internal/store/types.go @@ -33,7 +33,7 @@ var ErrInvalidEventDeliveryCursor = errors.New("invalid or stale event delivery var ErrModerationRestricted = errors.New("moderation restriction") // ErrChannelArchived is returned when a post targets an archived channel. -var ErrChannelArchived = errors.New("channel is archived") +var ErrChannelArchived = errors.New("channel is archived; choose an active channel or ask a workspace owner to restore it") // ErrMessageNotWritable is returned when a user can read a message but cannot // mutate it. From 198d587fe24cc311cb58280bfa0f2ae58029145f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Nov 2026 23:36:07 -0800 Subject: [PATCH 9/9] fix(api): finish archive guards and patch the Go build toolchain --- CHANGELOG.md | 4 ++ Dockerfile | 2 +- Dockerfile.cloudflare | 2 +- README.md | 2 +- .../api/internal/store/postgres/moderation.go | 12 ++--- .../store/postgres/moderation_test.go | 15 ++++++ apps/api/internal/store/sqlite/moderation.go | 12 ++--- .../internal/store/sqlite/moderation_test.go | 50 +++++++++++++++++++ docs/deployment.md | 2 +- docs/features/workspaces.md | 7 +++ go.mod | 2 +- 11 files changed, 93 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fecc5d01..68ea8472 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Build with Go 1.27.4 to fix the reachable HTTP/1 header race (GO-2026-6859), retaining the Go 1.26.6 module minimum. + +- Reject new posts and thread replies to archived channels with a clear HTTP 409 error, and document restoring a channel without changing its ID. Thanks @tre1d. + - List the commands in `clickclack help`, `-h`, and `--help` instead of only the client flags; `clickclack help` no longer fails with `unknown command "help"`. Thanks @KrasimirKralev. ## 0.9.4 - 2026-11-05 diff --git a/Dockerfile b/Dockerfile index 95ddda38..a041440a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY packages packages COPY scripts scripts RUN pnpm build -FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api +FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 WORKDIR /src COPY go.mod go.sum ./ diff --git a/Dockerfile.cloudflare b/Dockerfile.cloudflare index ffacd348..a79986ba 100644 --- a/Dockerfile.cloudflare +++ b/Dockerfile.cloudflare @@ -16,7 +16,7 @@ COPY packages packages COPY scripts scripts RUN pnpm build -FROM golang:1.27.3-alpine@sha256:f2c872bcee949b7be9c490efd02b48a8a2fbf947cdf533f1c58525ec9d8170fd AS api +FROM golang:1.27.4-alpine@sha256:0a5f7fe796599ff487605987432e7619ae45beeb2fba4c2ce0b907879932aebf AS api RUN apk add --no-cache --upgrade ca-certificates=20261020-r0 ca-certificates-bundle=20261020-r0 WORKDIR /src COPY go.mod go.sum ./ diff --git a/README.md b/README.md index 216b9a1c..961636e0 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ The complete documentation is at **[docs.clickclack.chat](https://docs.clickclac ## Development -Source builds use Go 1.27.3, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.3 for normal builds. +Source builds use Go 1.27.4, Node.js 24 or newer, and pnpm 12.15.0. The module minimum remains Go 1.26.6 so managed CodeQL can build with its preinstalled compiler; the `toolchain` directive selects Go 1.27.4 for normal builds. ```sh pnpm install --frozen-lockfile diff --git a/apps/api/internal/store/postgres/moderation.go b/apps/api/internal/store/postgres/moderation.go index 497711fd..7dd5b9d6 100644 --- a/apps/api/internal/store/postgres/moderation.go +++ b/apps/api/internal/store/postgres/moderation.go @@ -148,19 +148,19 @@ func requireNoModerationBlockTx(ctx context.Context, tx *sql.Tx, workspaceID, us } func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, userID string) error { - channel, err := storedb.New(tx).GetChannel(ctx, channelID) + role, err := memberRoleTx(ctx, tx, workspaceID, userID) if err != nil { return err } - if channel.ArchivedAt.Valid { - return store.ErrChannelArchived + if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { + return err } - role, err := memberRoleTx(ctx, tx, workspaceID, userID) + channel, err := storedb.New(tx).GetChannel(ctx, channelID) if err != nil { return err } - if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { - return err + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived } if role != store.WorkspaceRoleGuest { return nil diff --git a/apps/api/internal/store/postgres/moderation_test.go b/apps/api/internal/store/postgres/moderation_test.go index 904bf780..47fe00a1 100644 --- a/apps/api/internal/store/postgres/moderation_test.go +++ b/apps/api/internal/store/postgres/moderation_test.go @@ -182,6 +182,10 @@ func TestCreateMessageRejectsArchivedChannel(t *testing.T) { t.Fatal("expected a channel") } channel := channels[0] + root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"}) + if err != nil { + t.Fatal(err) + } archived := true if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil { t.Fatal(err) @@ -189,4 +193,15 @@ func TestCreateMessageRejectsArchivedChannel(t *testing.T) { if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) { t.Fatalf("expected ErrChannelArchived, got %v", err) } + if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected archived reply rejection, got %v", err) + } + archived = false + restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}) + if err != nil || restored.ID != channel.ID { + t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil { + t.Fatalf("restored channel must accept messages: %v", err) + } } diff --git a/apps/api/internal/store/sqlite/moderation.go b/apps/api/internal/store/sqlite/moderation.go index 813c42ea..01ab82f1 100644 --- a/apps/api/internal/store/sqlite/moderation.go +++ b/apps/api/internal/store/sqlite/moderation.go @@ -148,19 +148,19 @@ func requireNoModerationBlockTx(ctx context.Context, tx *sql.Tx, workspaceID, us } func requireCanPostTx(ctx context.Context, tx *sql.Tx, workspaceID, channelID, userID string) error { - channel, err := storedb.New(tx).GetChannel(ctx, channelID) + role, err := memberRoleTx(ctx, tx, workspaceID, userID) if err != nil { return err } - if channel.ArchivedAt.Valid { - return store.ErrChannelArchived + if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { + return err } - role, err := memberRoleTx(ctx, tx, workspaceID, userID) + channel, err := storedb.New(tx).GetChannel(ctx, channelID) if err != nil { return err } - if err := requireNoModerationBlockTx(ctx, tx, workspaceID, userID); err != nil { - return err + if channel.ArchivedAt.Valid { + return store.ErrChannelArchived } if role != store.WorkspaceRoleGuest { return nil diff --git a/apps/api/internal/store/sqlite/moderation_test.go b/apps/api/internal/store/sqlite/moderation_test.go index 838155f9..4e7f1884 100644 --- a/apps/api/internal/store/sqlite/moderation_test.go +++ b/apps/api/internal/store/sqlite/moderation_test.go @@ -666,3 +666,53 @@ func TestModerationHydrationFailureRollsBack(t *testing.T) { t.Fatalf("failed moderation committed an event: before=%s after=%s error=%v", before, after, err) } } + +func TestCreateMessageRejectsArchivedChannel(t *testing.T) { + ctx := t.Context() + st := newTestStore(t) + if err := st.Migrate(ctx); err != nil { + t.Fatal(err) + } + owner, err := st.EnsureBootstrap(ctx, "Owner", "archived-owner@example.com") + if err != nil { + t.Fatal(err) + } + workspaces, err := st.ListWorkspaces(ctx, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(workspaces) == 0 { + t.Fatal("expected a workspace") + } + workspace := workspaces[0] + channels, err := st.ListChannels(ctx, workspace.ID, owner.ID) + if err != nil { + t.Fatal(err) + } + if len(channels) == 0 { + t.Fatal("expected a channel") + } + channel := channels[0] + root, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "before archive"}) + if err != nil { + t.Fatal(err) + } + archived := true + if _, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}); err != nil { + t.Fatal(err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "blocked"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected ErrChannelArchived, got %v", err) + } + if _, _, _, err := st.CreateThreadReply(ctx, store.CreateThreadReplyInput{RootMessageID: root.ID, AuthorID: owner.ID, Body: "blocked reply"}); !errors.Is(err, store.ErrChannelArchived) { + t.Fatalf("expected archived reply rejection, got %v", err) + } + archived = false + restored, _, err := st.UpdateChannel(ctx, store.UpdateChannelInput{ChannelID: channel.ID, UserID: owner.ID, Archived: &archived}) + if err != nil || restored.ID != channel.ID { + t.Fatalf("restore must preserve channel ID: channel=%+v err=%v", restored, err) + } + if _, _, err := st.CreateMessage(ctx, store.CreateMessageInput{ChannelID: channel.ID, AuthorID: owner.ID, Body: "restored"}); err != nil { + t.Fatalf("restored channel must accept messages: %v", err) + } +} diff --git a/docs/deployment.md b/docs/deployment.md index c9d2ebb8..6987568f 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -88,7 +88,7 @@ docker run --rm -p 8080:8080 -v clickclack-data:/app/data clickclack Stages: 1. `node:26-alpine` — installs pnpm dependencies and runs `pnpm build`. -2. `golang:1.27.3-alpine` — builds the Go binary, importing the SPA dist. +2. `golang:1.27.4-alpine` — builds the Go binary, importing the SPA dist. 3. `alpine:3.24` — runtime image, runs as the `clickclack` user, exposes `8080`, mounts `/app/data` as a volume. diff --git a/docs/features/workspaces.md b/docs/features/workspaces.md index c4ef2e34..fd84a3c9 100644 --- a/docs/features/workspaces.md +++ b/docs/features/workspaces.md @@ -95,6 +95,13 @@ the nullable display, external, or sidebar fields clears that field. Omitted fields retain their current values, including changes committed by concurrent updates. +Archived channels retain their history and identity, but reject new messages, +thread replies, and other posting activity with HTTP `409` and a clear +`channel is archived` error. Restore one with `PATCH /api/channels/{channel_id}` +and `{"archived": false}`; it keeps the same ID and links. Creating another +channel is a separate operation and allocates a new ID. There is no channel +purge endpoint. + Channel updates require a workspace owner or an appropriately scoped bot. The web app only offers channel settings to owners; other people receive `403 workspace owner permission required` if they call the update API directly. diff --git a/go.mod b/go.mod index fe75e09a..c53055b9 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/openclaw/clickclack go 1.26.6 -toolchain go1.27.3 +toolchain go1.27.4 require ( github.com/coder/websocket v1.8.15