Originally created by: bearycool11
Originally owned by: josefkedwards
// Constants
// Session context structure
typedef struct {
io_socket_t io_socket;
PMLL_ARLL_EFLL_State state;
Graph knowledge_graph;
RSA encryption_key;
memory_silo_t *persistent_silo;
} SessionContext;
// Function declarations
SessionContext create_session(const char ip, int port,
int max_retries, int feedback_threshold,
const char encryption_key_file);
void process_chatlog(SessionContext ctx, const char input); void send_secure_graph_update(SessionContext ctx); void save_session_state(SessionContext ctx, const char filename); void handle_network_error(SessionContext ctx);
void run_session_loop(SessionContext ctx);
// Utility function declarations (assumed to be implemented elsewhere) RSA load_rsa_key(const char filename);
RSA generate_rsa_key(int key_size);
void save_rsa_key(const char filename, RSA key); char sanitize_input(const char input);
EncryptedNode encrypt_node_data(RSA key, const char data); int add_encrypted_node(Graph graph, EncryptedNode enode); void update_arll_weights(PMLL_ARLL_EFLL_State state, int hash); unsigned char serialize_graph(Graph graph, size_t size); size_t rsa_encrypt(RSA key, const unsigned char data, size_t data_size,
unsigned char encrypted, size_t encrypted_size);
unsigned char rsa_encrypt_buffer(RSA key, const unsigned char data, size_t data_size,
size_t encrypted_size);
unsigned int calculate_checksum(const unsigned char data, size_t size); void write_file_atomically(const char filename, const unsigned char data, size_t size); unsigned int calculate_graph_hash(Graph graph);
memory_silo_t connect_memory_silo(int silo_type); void load_initial_knowledge(SessionContext ctx, const char filename); void perform_garbage_collection(Graph graph);
void optimize_memory_usage(memory_silo_t silo);
void initiate_graceful_shutdown(SessionContext ctx); void validate_session_integrity(SessionContext ctx); int initialize_subsystems(SessionContext ctx);
int process_queued_messages(SessionContext ctx);
void handle_runtime_error(SessionContext ctx);
int attempt_state_recovery(SessionContext ctx);
void destroy_session(SessionContext *ctx);
New Features
Improvements
Security Enhancements
Originally posted by: coderabbitai[bot]
Walkthrough
The changes in
Persistence.c
introduce a comprehensive session management system with enhanced security and error handling. A newSessionContext
structure is implemented to centralize session-related data, including socket connections, encryption keys, and knowledge graph management. The modifications restructure the main function to create and manage sessions more robustly, with improved mechanisms for secure communication, state persistence, and network error recovery through an exponential backoff strategy.Changes
Persistence.c
SessionContext
structure- Introduced
create_session()
for session initialization- Added
process_chatlog()
with secure tokenization- Implemented
send_secure_graph_update()
for encrypted data transmission- Enhanced
save_session_state()
with atomic file writing- Added
handle_network_error()
for connection recovery- Created
run_session_loop()
as a state machineSequence Diagram
Poem
🪧 Tips
### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </commit_id>Originally posted by: bearycool11
@mergify update
Originally posted by: bearycool11
@mergify rebase
Originally posted by: bearycool11
@mergify refresh
Originally posted by: bearycool11
@mergify requeue
Originally posted by: mergify[bot]
❌ Base branch update has failed
Originally posted by: mergify[bot]
❌ Base branch update has failed
Originally posted by: mergify[bot]
✅ Pull request refreshed
Originally posted by: mergify[bot]
❌ This pull request head commit has not been previously disembarked from queue.