Implement Project Homepage, BRAIN, and polished context UX - #4
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53015bf8ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| PROJECT_CONTEXT.add_artifact( | ||
| project_id, | ||
| title=conversation.get("title") or "Assistant output", | ||
| body=message["content"], | ||
| conversation_id=conversation_id, | ||
| source_message_index=index, |
There was a problem hiding this comment.
Preserve artifact deletions during backfill
After an artifact backed by a conversation message is deleted, the Project Homepage immediately calls backfill_project_artifacts, and this unconditional add_artifact recreates it because the original assistant message still exists. Consequently, the UI's delete operation appears to succeed but the artifact returns on the ensuing refresh; persist a deletion tombstone or make backfill distinguish intentionally deleted sources.
Useful? React with 👍 / 👎.
| connection.execute( | ||
| """ | ||
| INSERT OR IGNORE INTO project_artifacts | ||
| (artifact_id, project_id, conversation_id, source_message_index, | ||
| title, kind, body, token_count, pinned, archived, created_at, updated_at) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?) |
There was a problem hiding this comment.
Avoid identifying artifacts by reusable message indexes
When an attached conversation is cleared through /conversations/{id}/clear, its message indexes restart from zero while its existing artifacts remain. A subsequent assistant response can therefore reuse an old (project_id, conversation_id, source_message_index) key; this INSERT OR IGNORE silently keeps the old artifact and drops the new response from artifact history. Use a stable per-message identifier or retire the old source keys when clearing a conversation.
Useful? React with 👍 / 👎.
| project_instruction_tokens = estimate_project_tokens(project.get("system_prompt") or "") | ||
| non_project_tokens = max(0, base_tokens - project_instruction_tokens) |
There was a problem hiding this comment.
Reserve legacy replacement prompts in the context budget
For an upgraded conversation in legacy instruction_mode == "replace", the effective system_prompt does not contain the project's instructions, but these lines still subtract their token count from base_tokens. With large project instructions, this can erase the accounting for the replacement prompt and conversation history, over-allocate project context, and send a payload beyond the selected model's context window. Only subtract project-instruction tokens when that text is actually present in the effective system message.
Useful? React with 👍 / 👎.
| preferred_node: Optional[str] = None | ||
| max_budget: Optional[float] = None | ||
| description: Optional[str] = None | ||
| context_budget_tokens: Optional[int] = Field(default=16_384, ge=1_024, le=262_144) |
There was a problem hiding this comment.
Honor the configured default project context budget
When DAVE_PROJECT_CONTEXT_TOKENS is set, newly created projects still receive 16,384 tokens because ProjectCreate supplies this literal default, so create_project never falls back to PROJECT_CONTEXT.default_context_budget. Operators configuring a smaller or larger default therefore see no effect for normal API/UI-created projects; derive this field's creation default from the configured value instead.
Useful? React with 👍 / 👎.
| connection.execute( | ||
| """ | ||
| UPDATE brain_states | ||
| SET pinned_text = ?, active_text = ?, recent_text = ?, compact_threshold = ?, | ||
| token_count = ?, revision = ?, updated_at = ?, last_compacted_at = ?, | ||
| deleted_at = NULL | ||
| WHERE project_id = ? |
There was a problem hiding this comment.
Validate restored BRAIN revisions against the current budget
If a project once had a large BRAIN revision, then its active BRAIN is reduced and its project budget is lowered, restoring the older revision copies its protected text and compaction threshold back without checking the current allocation. The restore reports success, but subsequent context previews and chats can fail with ContextBudgetError until the BRAIN is edited again. Apply the same protected-content and threshold checks used by BRAIN/profile updates before committing a restore.
Useful? React with 👍 / 👎.
What changed
Verification
Boundaries